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}`,