Limit the use of the same shortcut name when adding a shortcut

Signed-off-by: AmbrishRamachandiran <ambrish.r@infosys.com>
This commit is contained in:
AmbrishRamachandiran
2023-07-26 08:15:33 +05:30
parent dcd7e1622c
commit ee52a48b63
3 changed files with 31 additions and 12 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-shortcuts': patch
---
Limit the use of the duplicate shortcut name when adding a shortcut
+13 -6
View File
@@ -67,12 +67,19 @@ export const AddShortcut = ({
const shortcut: Omit<Shortcut, 'id'> = { 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}`,
+13 -6
View File
@@ -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}`,