-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5369] Design and implement a Recycle Bin #3126
Closed
Closed
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cf40648
Initial work - Recycle Bin #5369
jvega190 2742ff5
Add main grid actions/proper cells rendering, add package details dia…
jvega190 ec48b93
Add Package details view and restore dialog #5630
jvega190 cdcd6d7
Add RestoreDialog, update styles and components loading states, etc #…
jvega190 22b9180
Set embedded true when opening siteRecycleBin from Launcher #5369
jvega190 071267e
Update according OAS, styles updates #5738
jvega190 8479816
Add RecycleBin model, update RestoreDialog styles #5369
jvega190 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -83,7 +83,7 @@ const states = { | |
disabled: { stateMap: { disabled: true } } | ||
}; | ||
|
||
const status = { | ||
export const status = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs a much better name if it is to be exported |
||
staged: { stateMap: { staged: true } }, | ||
live: { stateMap: { live: true } } | ||
}; | ||
|
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 |
---|---|---|
|
@@ -39,7 +39,9 @@ const LauncherLinkTile = (props: LauncherLinkTileProps) => { | |
const site = useActiveSiteId(); | ||
const dispatch = useDispatch(); | ||
const title = usePossibleTranslation(propTitle); | ||
const isDialog = ['siteDashboardDialog', 'siteToolsDialog', 'siteSearchDialog'].includes(systemLinkId); | ||
const isDialog = ['siteDashboardDialog', 'siteToolsDialog', 'siteSearchDialog', 'siteRecycleBin'].includes( | ||
systemLinkId | ||
); | ||
|
||
const onClick = isDialog | ||
? (e) => { | ||
|
@@ -50,6 +52,8 @@ const LauncherLinkTile = (props: LauncherLinkTileProps) => { | |
const id = systemLinkId === 'siteDashboardDialog' ? 'craftercms.components.Dashboard' : ( | ||
systemLinkId === 'siteToolsDialog' | ||
? 'craftercms.components.EmbeddedSiteTools' | ||
: systemLinkId === 'siteRecycleBin' | ||
? 'craftercms.components.RecycleBin' | ||
: 'craftercms.components.Search' | ||
); | ||
Comment on lines
52
to
58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace this with a lookup table |
||
dispatch( | ||
|
@@ -58,7 +62,12 @@ const LauncherLinkTile = (props: LauncherLinkTileProps) => { | |
showWidgetDialog({ | ||
id: systemLinkId, | ||
title, | ||
widget: { id, ...(systemLinkId === 'siteSearchDialog' && { configuration: { embedded: true } }) } | ||
widget: { | ||
id, | ||
...((systemLinkId === 'siteSearchDialog' || systemLinkId === 'siteRecycleBin') && { | ||
configuration: { embedded: true } | ||
}) | ||
} | ||
}) | ||
]) | ||
); | ||
|
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,221 @@ | ||
/* | ||
* Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 3 as published by | ||
* the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import React, { useCallback, useEffect, useState } from 'react'; | ||
import RecycleBinGridUI from './RecycleBinGridUI'; | ||
import Box from '@mui/material/Box'; | ||
import { ViewToolbar } from '../ViewToolbar'; | ||
import { SearchBar } from '../SearchBar'; | ||
import { ActionsBar } from '../ActionsBar'; | ||
import useEnhancedDialogState from '../../hooks/useEnhancedDialogState'; | ||
import useWithPendingChangesCloseRequest from '../../hooks/useWithPendingChangesCloseRequest'; | ||
import { RecycleBinPackageDialog } from '../RecycleBinPackageDialog'; | ||
import { RecycleBinPackage, RecycleBinProps } from './utils'; | ||
import { FormattedMessage, useIntl } from 'react-intl'; | ||
import { translations } from './translations'; | ||
import UseWithPendingChangesCloseRequest from '../../hooks/useWithPendingChangesCloseRequest'; | ||
import { RecycleBinRestoreDialog } from '../RecycleBinRestoreDialog'; | ||
import { asArray } from '../../utils/array'; | ||
import { fetchRecycleBinPackages, restoreRecycleBinPackages } from '../../services/content'; | ||
import useActiveSiteId from '../../hooks/useActiveSiteId'; | ||
import { useDispatch } from 'react-redux'; | ||
import { showErrorDialog } from '../../state/reducers/dialogs/error'; | ||
import { showSystemNotification } from '../../state/actions/system'; | ||
import { useStyles } from './styles'; | ||
import { GlobalAppToolbar } from '../GlobalAppToolbar'; | ||
import { ApiResponseErrorState } from '../ApiResponseErrorState'; | ||
import { LoadingState } from '../LoadingState'; | ||
|
||
export function RecycleBin(props: RecycleBinProps) { | ||
const { embedded } = props; | ||
const { classes } = useStyles(); | ||
const [pageSize, setPageSize] = useState(10); | ||
const [recycleBinPackages, setRecycleBinPackages] = useState<RecycleBinPackage[]>([]); | ||
const [selectedPackages, setSelectedPackages] = useState([]); | ||
const [recycleBinPackage, setRecycleBinPackage] = useState(null); | ||
const [restorePackages, setRestorePackages] = useState([]); | ||
const isAllChecked = recycleBinPackages.length > 0 && selectedPackages.length === recycleBinPackages.length; | ||
const isIndeterminate = selectedPackages.length > 0 && selectedPackages.length < recycleBinPackages.length; | ||
const { formatMessage } = useIntl(); | ||
const siteId = useActiveSiteId(); | ||
const dispatch = useDispatch(); | ||
const [fetchingPackages, setFetchingPackages] = useState(false); | ||
const [error, setError] = useState(); | ||
const fetchPackages = useCallback((siteId) => { | ||
setFetchingPackages(true); | ||
return fetchRecycleBinPackages(siteId).subscribe({ | ||
next(packages) { | ||
setRecycleBinPackages(packages); | ||
setFetchingPackages(false); | ||
}, | ||
error(error) { | ||
setError(error); | ||
setFetchingPackages(false); | ||
} | ||
}); | ||
}, []); | ||
|
||
const recycleBinPackageDialogState = useEnhancedDialogState(); | ||
const recycleBinPackageDialogPendingChangesCloseRequest = useWithPendingChangesCloseRequest( | ||
recycleBinPackageDialogState.onClose | ||
); | ||
|
||
const recycleBinRestoreDialogState = useEnhancedDialogState(); | ||
const recycleBinRestoreDialogPendingChangesCloseRequest = UseWithPendingChangesCloseRequest( | ||
recycleBinRestoreDialogState.onClose | ||
); | ||
|
||
useEffect(() => { | ||
fetchPackages(siteId); | ||
}, [siteId, fetchPackages]); | ||
|
||
const onToggleCheckedAll = () => { | ||
if (isAllChecked) { | ||
setSelectedPackages([]); | ||
} else { | ||
const checked = []; | ||
recycleBinPackages.forEach((recycleBinPackage) => checked.push(recycleBinPackage.id)); | ||
setSelectedPackages(checked); | ||
} | ||
}; | ||
|
||
const onOpenPackageDetails = (recycleBinPackage) => { | ||
setRecycleBinPackage(recycleBinPackage); | ||
recycleBinPackageDialogState.onOpen(); | ||
}; | ||
|
||
const onShowRestoreDialog = (packages: RecycleBinPackage[] | RecycleBinPackage) => { | ||
setRestorePackages(asArray(packages)); | ||
recycleBinRestoreDialogState.onOpen(); | ||
}; | ||
|
||
const onRestore = (ids: string[]) => { | ||
recycleBinRestoreDialogState.onSubmittingAndOrPendingChange({ isSubmitting: true }); | ||
restoreRecycleBinPackages(ids).subscribe({ | ||
next() { | ||
recycleBinRestoreDialogState.onSubmittingAndOrPendingChange({ isSubmitting: false }); | ||
recycleBinRestoreDialogState.onClose(); | ||
setSelectedPackages([]); | ||
fetchPackages(siteId); | ||
dispatch( | ||
showSystemNotification({ | ||
message: formatMessage(translations.restoreSuccess) | ||
}) | ||
); | ||
}, | ||
error(error) { | ||
dispatch(showErrorDialog({ error })); | ||
recycleBinRestoreDialogState.onSubmittingAndOrPendingChange({ isSubmitting: false }); | ||
} | ||
}); | ||
}; | ||
|
||
const onActionBarOptionClicked = (option: string) => { | ||
if (option === 'restore') { | ||
const packages = recycleBinPackages.filter((recycleBinPackage) => | ||
selectedPackages.includes(recycleBinPackage.id) | ||
); | ||
onShowRestoreDialog(packages); | ||
} | ||
}; | ||
|
||
return ( | ||
<Box> | ||
{!embedded && ( | ||
<GlobalAppToolbar | ||
title={<FormattedMessage id="recycleBin.title" defaultMessage="Recycle Bin" />} | ||
showHamburgerMenuButton | ||
showAppsButton | ||
/> | ||
)} | ||
{error ? ( | ||
<ApiResponseErrorState error={error} /> | ||
) : fetchingPackages ? ( | ||
<LoadingState /> | ||
) : ( | ||
<> | ||
<ViewToolbar styles={{ toolbar: { justifyContent: 'center' } }}> | ||
<section className={classes.searchBarContainer}> | ||
<SearchBar | ||
onChange={() => {}} // TODO: pending | ||
keyword={null} | ||
showActionButton={false} | ||
showDecoratorIcon | ||
classes={{ root: classes.searchPaper }} | ||
/> | ||
</section> | ||
</ViewToolbar> | ||
<Box> | ||
{(isIndeterminate || isAllChecked) && ( | ||
<ActionsBar | ||
classes={{ | ||
root: classes.actionsBarRoot, | ||
checkbox: classes.actionsBarCheckbox | ||
}} | ||
options={[ | ||
{ | ||
id: 'restore', | ||
label: formatMessage(translations.restore), | ||
icon: { id: '@mui/icons-material/SettingsBackupRestoreOutlined' } | ||
}, | ||
{ | ||
id: 'publish', | ||
label: formatMessage(translations.publishDeletion), | ||
icon: { id: '@mui/icons-material/CloudUploadOutlined' } | ||
} | ||
]} | ||
isIndeterminate={isIndeterminate} | ||
isChecked={isAllChecked} | ||
numOfSkeletonItems={2} | ||
onOptionClicked={onActionBarOptionClicked} | ||
onCheckboxChange={onToggleCheckedAll} | ||
/> | ||
)} | ||
<RecycleBinGridUI | ||
packages={recycleBinPackages} | ||
pageSize={pageSize} | ||
setPageSize={setPageSize} | ||
selectedPackages={selectedPackages} | ||
setSelectedPackages={setSelectedPackages} | ||
onOpenPackageDetails={onOpenPackageDetails} | ||
/> | ||
</Box> | ||
</> | ||
)} | ||
<RecycleBinPackageDialog | ||
open={recycleBinPackageDialogState.open} | ||
onClose={recycleBinPackageDialogState.onClose} | ||
recycleBinPackage={recycleBinPackage} | ||
onRestore={() => { | ||
recycleBinPackageDialogState.onClose(); | ||
onShowRestoreDialog(recycleBinPackage); | ||
}} | ||
onWithPendingChangesCloseRequest={recycleBinPackageDialogPendingChangesCloseRequest} | ||
onSubmittingAndOrPendingChange={recycleBinPackageDialogState.onSubmittingAndOrPendingChange} | ||
/> | ||
<RecycleBinRestoreDialog | ||
open={recycleBinRestoreDialogState.open} | ||
onClose={recycleBinRestoreDialogState.onClose} | ||
packages={restorePackages} | ||
onRestore={onRestore} | ||
onWithPendingChangesCloseRequest={recycleBinRestoreDialogPendingChangesCloseRequest} | ||
onSubmittingAndOrPendingChange={recycleBinRestoreDialogState.onSubmittingAndOrPendingChange} | ||
/> | ||
</Box> | ||
); | ||
} | ||
|
||
export default RecycleBin; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this for?