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:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-shortcuts': patch
|
||||
---
|
||||
|
||||
Limit the use of the duplicate shortcut name when adding a shortcut
|
||||
@@ -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}`,
|
||||
|
||||
@@ -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}`,
|
||||
|
||||
Reference in New Issue
Block a user