-
-
Notifications
You must be signed in to change notification settings - Fork 716
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
374dfbc
commit e5d98fc
Showing
13 changed files
with
787 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
**Added functionality for a "Favorites Section in the Content Browser Sidebar" feature:** | ||
|
||
Created favourites file in {file}'/src/actions". | ||
Enhanced {file}/src/components/manage/Blocks/Block/EditBlockWrap per.jsx and added SaveBlockDialog.jsx. | ||
Modified {file}/src/components/manage/Blocks/Block/Snapshots/Blo cksForm.test.jsx`. | ||
Updated{file}/src/components/manage/Sidebar/Sidebar.jsx, sidebarPopup.jsx', and 'save.css', and added a new component FavouriteItem.jsx'. | ||
Implemented a new reducer in {file}/src/reducers/favourites/favouritesReducer.js" and updated {file}'/src/reducers/index.js' | ||
@TechSubham |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { cloneBlocks } from '@plone/volto/helpers/Blocks/cloneBlocks'; | ||
import config from '@plone/volto/registry'; | ||
|
||
export const ADD_TO_FAVORITES = 'ADD_TO_FAVORITES'; | ||
export const REMOVE_FROM_FAVORITES = 'REMOVE_FROM_FAVORITES'; | ||
export const LOAD_FAVORITES = 'LOAD_FAVORITES'; | ||
|
||
export function loadFavorites() { | ||
return { | ||
type: LOAD_FAVORITES, | ||
}; | ||
} | ||
|
||
export function addToFavorites(blockData) { | ||
const { id, type, data } = blockData; | ||
const blockConfig = config.blocks.blocksConfig[type]; | ||
const clonedData = blockConfig?.cloneData | ||
? blockConfig.cloneData(data) | ||
: cloneBlocks(data); | ||
|
||
return { | ||
type: ADD_TO_FAVORITES, | ||
block: { | ||
id, | ||
type, | ||
data: clonedData, | ||
}, | ||
}; | ||
} | ||
|
||
export function removeFromFavorites(blockId) { | ||
return { | ||
type: REMOVE_FROM_FAVORITES, | ||
blockId, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
packages/volto/src/components/manage/Blocks/Block/SaveBlockDialog.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React, { useState } from 'react'; | ||
import { useDispatch } from 'react-redux'; | ||
import { Button, Modal, Input, Header } from 'semantic-ui-react'; | ||
import { defineMessages, useIntl } from 'react-intl'; | ||
import { addToFavorites } from '@plone/volto/actions/favorites/favorites'; | ||
import config from '@plone/volto/registry'; | ||
|
||
const messages = defineMessages({ | ||
saveBlock: { | ||
id: 'Save Block', | ||
defaultMessage: 'Save Block', | ||
}, | ||
enterName: { | ||
id: 'Enter a name for this block', | ||
defaultMessage: 'Enter a name for this block', | ||
}, | ||
save: { | ||
id: 'Save', | ||
defaultMessage: 'Save', | ||
}, | ||
cancel: { | ||
id: 'Cancel', | ||
defaultMessage: 'Cancel', | ||
}, | ||
}); | ||
|
||
const SaveBlockDialog = ({ block, type, data, isOpen, onClose }) => { | ||
const intl = useIntl(); | ||
const dispatch = useDispatch(); | ||
const [name, setName] = useState(''); | ||
|
||
const handleSave = () => { | ||
const blockConfig = config.blocks.blocksConfig[type]; | ||
const blockData = { | ||
id: block, | ||
type: type, | ||
data: { | ||
...data, | ||
'@type': type, | ||
title: name, | ||
}, | ||
}; | ||
|
||
if (blockConfig?.cloneData) { | ||
blockData.data = blockConfig.cloneData(blockData.data)[1]; | ||
} | ||
dispatch(addToFavorites(blockData)); | ||
setName(''); | ||
onClose(); | ||
}; | ||
|
||
return ( | ||
<Modal open={isOpen} onClose={onClose} size="tiny"> | ||
<Header content={intl.formatMessage(messages.saveBlock)} /> | ||
<Modal.Content> | ||
<Input | ||
fluid | ||
placeholder={intl.formatMessage(messages.enterName)} | ||
value={name} | ||
onChange={(e) => setName(e.target.value)} | ||
/> | ||
</Modal.Content> | ||
<Modal.Actions> | ||
<Button onClick={onClose}>{intl.formatMessage(messages.cancel)}</Button> | ||
<Button primary onClick={handleSave} disabled={!name.trim()}> | ||
{intl.formatMessage(messages.save)} | ||
</Button> | ||
</Modal.Actions> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default SaveBlockDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.sidebar-metadata-container .save-button-wrapper { | ||
display: flex; | ||
width: 100%; | ||
align-items: center; | ||
justify-content: center; | ||
padding: 0.8rem; | ||
border: none; | ||
border-radius: 2px; | ||
margin: 1rem 0; | ||
background-color: #007eb1; | ||
color: white; | ||
cursor: pointer; | ||
} | ||
|
||
.sidebar-metadata-container .save-button-wrapper:hover { | ||
background-color: #006c98; | ||
} | ||
|
||
.sidebar-metadata-container .save-icon { | ||
margin-right: 0.5rem; | ||
} | ||
|
||
.sidebar-metadata-container .save-button-text { | ||
font-weight: 500; | ||
} |
Oops, something went wrong.