From ee52a48b63d501874db0e7747752ee970e374be7 Mon Sep 17 00:00:00 2001 From: AmbrishRamachandiran Date: Wed, 26 Jul 2023 08:15:33 +0530 Subject: [PATCH] Limit the use of the same shortcut name when adding a shortcut Signed-off-by: AmbrishRamachandiran --- .changeset/nervous-suits-give.md | 5 +++++ plugins/shortcuts/src/AddShortcut.tsx | 19 +++++++++++++------ plugins/shortcuts/src/EditShortcut.tsx | 19 +++++++++++++------ 3 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 .changeset/nervous-suits-give.md diff --git a/.changeset/nervous-suits-give.md b/.changeset/nervous-suits-give.md new file mode 100644 index 0000000000..e08d8d89a2 --- /dev/null +++ b/.changeset/nervous-suits-give.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-shortcuts': patch +--- + +Limit the use of the duplicate shortcut name when adding a shortcut diff --git a/plugins/shortcuts/src/AddShortcut.tsx b/plugins/shortcuts/src/AddShortcut.tsx index 15850ab389..70988c49eb 100644 --- a/plugins/shortcuts/src/AddShortcut.tsx +++ b/plugins/shortcuts/src/AddShortcut.tsx @@ -67,12 +67,19 @@ export const AddShortcut = ({ const shortcut: Omit = { url, title }; try { - await api.add(shortcut); - alertApi.post({ - message: `Added shortcut '${title}' to your sidebar`, - severity: 'success', - display: 'transient', - }); + if (api.get().some(shortcutTitle => shortcutTitle.title === title)) { + alertApi.post({ + message: `Shortcut title already exist`, + severity: 'error', + }); + } else { + await api.add(shortcut); + alertApi.post({ + message: `Added shortcut '${title}' to your sidebar`, + severity: 'success', + display: 'transient', + }); + } } catch (error) { alertApi.post({ message: `Could not add shortcut: ${error.message}`, diff --git a/plugins/shortcuts/src/EditShortcut.tsx b/plugins/shortcuts/src/EditShortcut.tsx index 9f2ffe10be..ecc14d93d9 100644 --- a/plugins/shortcuts/src/EditShortcut.tsx +++ b/plugins/shortcuts/src/EditShortcut.tsx @@ -70,12 +70,19 @@ export const EditShortcut = ({ }; try { - await api.update(newShortcut); - alertApi.post({ - message: `Updated shortcut '${title}'`, - severity: 'success', - display: 'transient', - }); + if (api.get().some(shortcutTitle => shortcutTitle.title === title)) { + alertApi.post({ + message: `Shortcut title already exist`, + severity: 'error', + }); + } else { + await api.update(newShortcut); + alertApi.post({ + message: `Updated shortcut '${title}'`, + severity: 'success', + display: 'transient', + }); + } } catch (error) { alertApi.post({ message: `Could not update shortcut: ${error.message}`,