Skip to content
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

CARDS-2606: Improve delete dialog with long names #1846

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ function DeleteButton(props) {
const [ deletionInProgress, setDeletionInProgress ] = useState(false);

const buttonText = label || ("Delete " + (entryType?.toLowerCase() || '')).trim();
const defaultDialogAction = `Are you sure you want to delete ${entryType} ${entryName}?`;
const defaultErrorMessage = `${entryName || "The item"} could not be removed.`;
const defaultDialogMessage = `Are you sure you want to delete the following ${entryType}:`;
const defaultDialogAction = entryName;
const defaultErrorMessage = `The ${entryType?.toLowerCase() || "item"} could not be removed.`;
const history = useHistory();

const globalLoginDisplay = useContext(GlobalLoginContext);
Expand Down Expand Up @@ -98,6 +99,10 @@ function DeleteButton(props) {
}
}

let capitalize = (text) => {
return text.charAt(0).toUpperCase() + text.slice(1);
}

let handleJsonError = (status, json) => {
if (status === 409) {
if (deleteRecursive) {
Expand All @@ -106,8 +111,8 @@ function DeleteButton(props) {
openError();
} else {
let label = entryLabel ? entryLabel.concat(' ') : entryType ? entryType.concat(' ') : '';
setDialogMessage(`${json["status.message"].replace("This item", label + entryName)}`);
setDialogAction(`Would you like to delete ${entryName} and all items that reference it?`);
setDialogMessage(`${json["status.message"].replace("This item", capitalize(label) + '"' + entryName + '"')}`);
setDialogAction(`Would you like to delete this ${label.toLowerCase()} and all items that reference it?`);
setDeleteRecursive(true);
openDialog();
}
Expand Down Expand Up @@ -150,7 +155,7 @@ function DeleteButton(props) {

let handleClick = () => {
onClick?.();
setDialogMessage(null);
setDialogMessage(defaultDialogMessage);
setDialogAction(defaultDialogAction);
setDeleteRecursive(false);
openDialog();
Expand All @@ -171,7 +176,7 @@ function DeleteButton(props) {
</ErrorDialog>
<Dialog open={open} onClose={closeDialog}>
<DialogTitle>
Delete {entryLabel ? entryLabel.concat(' ') : ''}{entryName}{deleteRecursive ? " and dependent items": null }
Delete {entryLabel ? entryLabel.concat(' ') : entryType.concat(' ')}{deleteRecursive ? " and dependent items": null }
</DialogTitle>
<DialogContent>
<Typography variant="body1">{dialogMessage}</Typography>
Expand Down