-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[4.1.x][6527] Cut/Paste via the Sidebar should warn users or allow th…
…em to act on broken dependencies caused by the move operation (#3761) * Cut/Paste via the Sidebar should warn users or allow them to act on broken dependencies caused by the move operation #6527 * Merge BrokenReferencesDialog UI and container, rename utils.ts to types.ts #6527 * Add types to brokenReferences dialog actions, handle error in BrokenReferencesDialog #6527 * Update dialog texts #6527
- Loading branch information
Showing
11 changed files
with
359 additions
and
14 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
ui/app/src/components/BrokenReferencesDialog/BrokenReferencesDialog.tsx
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,40 @@ | ||
/* | ||
* Copyright (C) 2007-2024 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 from 'react'; | ||
import { BrokenReferencesDialogProps } from './types'; | ||
import EnhancedDialog from '../EnhancedDialog'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import BrokenReferencesDialogContainer from './BrokenReferencesDialogContainer'; | ||
|
||
export function BrokenReferencesDialog(props: BrokenReferencesDialogProps) { | ||
const { path, references, error, onContinue, ...rest } = props; | ||
|
||
return ( | ||
<EnhancedDialog | ||
title={<FormattedMessage defaultMessage="Broken References Warning" />} | ||
subtitle={ | ||
<FormattedMessage defaultMessage="Proceeding would cause items listed below to have broken references" /> | ||
} | ||
{...rest} | ||
maxWidth="sm" | ||
> | ||
<BrokenReferencesDialogContainer path={path} references={references} onContinue={onContinue} error={error} /> | ||
</EnhancedDialog> | ||
); | ||
} | ||
|
||
export default BrokenReferencesDialog; |
119 changes: 119 additions & 0 deletions
119
ui/app/src/components/BrokenReferencesDialog/BrokenReferencesDialogContainer.tsx
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,119 @@ | ||
/* | ||
* Copyright (C) 2007-2024 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 from 'react'; | ||
import { BrokenReferencesDialogContainerProps } from './types'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { EmptyState } from '../EmptyState'; | ||
import { useDispatch } from 'react-redux'; | ||
import { fetchBrokenReferences, showEditDialog } from '../../state/actions/dialogs'; | ||
import useActiveSiteId from '../../hooks/useActiveSiteId'; | ||
import useEnv from '../../hooks/useEnv'; | ||
import { DialogBody } from '../DialogBody'; | ||
import Grid from '@mui/material/Grid'; | ||
import List from '@mui/material/List'; | ||
import ListItem from '@mui/material/ListItem'; | ||
import ListItemText from '@mui/material/ListItemText'; | ||
import ListItemSecondaryAction from '@mui/material/ListItemSecondaryAction'; | ||
import Button from '@mui/material/Button'; | ||
import DialogFooter from '../DialogFooter'; | ||
import SecondaryButton from '../SecondaryButton'; | ||
import PrimaryButton from '../PrimaryButton'; | ||
import ApiResponseErrorState from '../ApiResponseErrorState'; | ||
|
||
export function BrokenReferencesDialogContainer(props: BrokenReferencesDialogContainerProps) { | ||
const { references, error, onClose, onContinue } = props; | ||
const dispatch = useDispatch(); | ||
const site = useActiveSiteId(); | ||
const { authoringBase } = useEnv(); | ||
|
||
const onContinueClick = (e) => { | ||
onClose(e, null); | ||
onContinue(); | ||
}; | ||
|
||
const onEditReferenceClick = (path: string) => { | ||
dispatch(showEditDialog({ path, authoringBase, site, onSaveSuccess: fetchBrokenReferences() })); | ||
}; | ||
|
||
return error ? ( | ||
<ApiResponseErrorState error={error} /> | ||
) : references.length > 0 ? ( | ||
<> | ||
<DialogBody> | ||
<Grid container spacing={3}> | ||
<Grid item xs={12}> | ||
<List | ||
sx={{ | ||
border: (theme) => `1px solid ${theme.palette.divider}`, | ||
background: (theme) => theme.palette.background.paper | ||
}} | ||
> | ||
{references.map((reference, index) => ( | ||
<ListItem key={reference.path} divider={references.length - 1 !== index}> | ||
<ListItemText | ||
primary={reference.label} | ||
secondary={reference.path} | ||
primaryTypographyProps={{ | ||
title: reference.path, | ||
sx: { | ||
overflow: 'hidden', | ||
whiteSpace: 'nowrap', | ||
textOverflow: 'ellipsis' | ||
} | ||
}} | ||
/> | ||
<ListItemSecondaryAction> | ||
<Button | ||
color="primary" | ||
onClick={() => { | ||
onEditReferenceClick?.(reference.path); | ||
}} | ||
size="small" | ||
sx={{ | ||
marginLeft: 'auto', | ||
fontWeight: 'bold', | ||
verticalAlign: 'baseline' | ||
}} | ||
> | ||
<FormattedMessage defaultMessage="Edit" /> | ||
</Button> | ||
</ListItemSecondaryAction> | ||
</ListItem> | ||
))} | ||
</List> | ||
</Grid> | ||
</Grid> | ||
</DialogBody> | ||
<DialogFooter> | ||
{onClose && ( | ||
<SecondaryButton onClick={(e) => onClose(e, null)}> | ||
<FormattedMessage defaultMessage="Cancel" /> | ||
</SecondaryButton> | ||
)} | ||
{onContinue && ( | ||
<PrimaryButton onClick={onContinueClick} autoFocus> | ||
<FormattedMessage defaultMessage="Continue" /> | ||
</PrimaryButton> | ||
)} | ||
</DialogFooter> | ||
</> | ||
) : ( | ||
<EmptyState title={<FormattedMessage defaultMessage="No broken references have been detected" />} /> | ||
); | ||
} | ||
|
||
export default BrokenReferencesDialogContainer; |
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,19 @@ | ||
/* | ||
* Copyright (C) 2007-2024 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/>. | ||
*/ | ||
|
||
export { default } from './BrokenReferencesDialog'; | ||
|
||
export * from './BrokenReferencesDialog'; |
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,41 @@ | ||
/* | ||
* Copyright (C) 2007-2024 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 { EnhancedDialogProps } from '../EnhancedDialog'; | ||
import { EnhancedDialogState } from '../../hooks/useEnhancedDialogState'; | ||
import StandardAction from '../../models/StandardAction'; | ||
import React from 'react'; | ||
import { ApiResponse, SandboxItem } from '../../models'; | ||
|
||
export interface BrokenReferencesDialogBaseProps { | ||
path?: string; | ||
references?: SandboxItem[]; | ||
error?: ApiResponse; | ||
} | ||
|
||
export interface BrokenReferencesDialogProps extends BrokenReferencesDialogBaseProps, EnhancedDialogProps { | ||
onContinue?(response?: any): any; | ||
} | ||
|
||
export interface BrokenReferencesDialogStateProps extends BrokenReferencesDialogBaseProps, EnhancedDialogState { | ||
onClose?: StandardAction; | ||
onClosed?: StandardAction; | ||
onContinue?: StandardAction; | ||
} | ||
|
||
export interface BrokenReferencesDialogContainerProps | ||
extends BrokenReferencesDialogBaseProps, | ||
Pick<BrokenReferencesDialogProps, 'onContinue' | 'onClose'> {} |
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
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
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,55 @@ | ||
/* | ||
* Copyright (C) 2007-2024 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 { createReducer } from '@reduxjs/toolkit'; | ||
import GlobalState from '../../../models/GlobalState'; | ||
import { BrokenReferencesDialogStateProps } from '../../../components/BrokenReferencesDialog/types'; | ||
import { | ||
brokenReferencesDialogClosed, | ||
closeBrokenReferencesDialog, | ||
fetchBrokenReferencesFailed, | ||
showBrokenReferencesDialog, | ||
updateBrokenReferencesDialog | ||
} from '../../actions/dialogs'; | ||
|
||
const initialState: BrokenReferencesDialogStateProps = { | ||
open: false, | ||
isSubmitting: null, | ||
isMinimized: null, | ||
hasPendingChanges: null, | ||
error: null | ||
}; | ||
|
||
export default createReducer<GlobalState['dialogs']['brokenReferences']>(initialState, (builder) => { | ||
builder | ||
.addCase(showBrokenReferencesDialog, (state, { payload }) => ({ | ||
...state, | ||
onClose: closeBrokenReferencesDialog(), | ||
onClosed: brokenReferencesDialogClosed(), | ||
...(payload as Partial<BrokenReferencesDialogStateProps>), | ||
open: true | ||
})) | ||
.addCase(closeBrokenReferencesDialog, (state) => ({ ...state, open: false })) | ||
.addCase(brokenReferencesDialogClosed, () => initialState) | ||
.addCase(updateBrokenReferencesDialog, (state, { payload }) => ({ | ||
...state, | ||
...(payload as Partial<BrokenReferencesDialogStateProps>) | ||
})) | ||
.addCase(fetchBrokenReferencesFailed, (state, { payload }) => ({ | ||
...state, | ||
error: payload.response | ||
})); | ||
}); |
Oops, something went wrong.