Skip to content

Commit

Permalink
feat(UI): User now gets feedback when they try to add a duplicate act…
Browse files Browse the repository at this point in the history
…ion to the shopping cart (#1981)

<img width="1724" alt="Screenshot 2024-09-25 at 14 17 12"
src="https://github.com/user-attachments/assets/ca4e83d2-9229-4a53-af7d-697c7af26c07">


Ref: SRX-FFMDKH
  • Loading branch information
miguel-crespo-fdc authored Oct 1, 2024
1 parent 878e1f8 commit 127d6ec
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
11 changes: 9 additions & 2 deletions services/frontend-service/src/ui/utils/store.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
appendAction,
DisplayLock,
FlushRolloutStatus,
SnackbarStatus,
UpdateAction,
updateActions,
UpdateOverview,
Expand Down Expand Up @@ -699,22 +700,26 @@ describe('Test addAction duplicate detection', () => {
it(testcase.name, () => {
// given
updateActions([]);
UpdateSnackbar.set({ show: false, status: SnackbarStatus.SUCCESS, content: '' });

expect(UpdateSnackbar.get().show).toStrictEqual(false);
// when
addAction(testcase.firstAction);
expect(UpdateSnackbar.get().show).toStrictEqual(false);
// then
expect(UpdateAction.get().actions.length).toStrictEqual(1);

// when
addAction(testcase.firstAction);
// then
expect(UpdateAction.get().actions.length).toStrictEqual(1);
//and
expect(UpdateSnackbar.get().show).toStrictEqual(true);

// when
addAction(testcase.differentAction);
// then
expect(UpdateAction.get().actions.length).toStrictEqual(2);

// when
addAction(testcase.differentAction);
// then
Expand Down Expand Up @@ -756,7 +761,8 @@ describe('Test maxActions', () => {
it(testcase.name, () => {
// given
updateActions([]);

//and
UpdateSnackbar.set({ show: false, status: SnackbarStatus.SUCCESS, content: '' });
// when
for (let i = 0; i < testcase.inputActionsLen; i++) {
appendAction([
Expand All @@ -774,6 +780,7 @@ describe('Test maxActions', () => {
},
]);
}

// then
expect(UpdateSnackbar.get().show).toStrictEqual(testcase.expectedShowError);
expect(UpdateAction.get().actions.length).toStrictEqual(testcase.expectedLen);
Expand Down
26 changes: 16 additions & 10 deletions services/frontend-service/src/ui/utils/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ export const addAction = (action: BatchAction): void => {
showSnackbarError('Maximum number of actions is ' + String(maxBatchActions));
return;
}
let isDuplicate = false;
// checking for duplicates
switch (action.action?.$case) {
case 'createEnvironmentLock':
Expand All @@ -259,7 +260,7 @@ export const addAction = (action: BatchAction): void => {
// lockId and message are ignored
)
)
return;
isDuplicate = true;
break;
case 'deleteEnvironmentLock':
if (
Expand All @@ -272,7 +273,7 @@ export const addAction = (action: BatchAction): void => {
act.action.deleteEnvironmentLock.lockId === action.action.deleteEnvironmentLock.lockId
)
)
return;
isDuplicate = true;
break;
case 'createEnvironmentApplicationLock':
if (
Expand All @@ -287,7 +288,7 @@ export const addAction = (action: BatchAction): void => {
// lockId and message are ignored
)
)
return;
isDuplicate = true;
break;
case 'deleteEnvironmentApplicationLock':
if (
Expand All @@ -303,7 +304,7 @@ export const addAction = (action: BatchAction): void => {
action.action.deleteEnvironmentApplicationLock.application
)
)
return;
isDuplicate = true;
break;
case 'createEnvironmentTeamLock':
if (
Expand All @@ -319,7 +320,7 @@ export const addAction = (action: BatchAction): void => {
// lockId and message are ignored
)
)
return;
isDuplicate = true;
break;
case 'deleteEnvironmentTeamLock':
if (
Expand All @@ -334,7 +335,7 @@ export const addAction = (action: BatchAction): void => {
act.action.deleteEnvironmentTeamLock.team === action.action.deleteEnvironmentTeamLock.team
)
)
return;
isDuplicate = true;
break;
case 'deploy':
if (
Expand All @@ -348,7 +349,8 @@ export const addAction = (action: BatchAction): void => {
// version, lockBehavior and ignoreAllLocks are ignored
)
)
return;
isDuplicate = true;

break;
case 'undeploy':
if (
Expand All @@ -359,7 +361,7 @@ export const addAction = (action: BatchAction): void => {
act.action.undeploy.application === action.action.undeploy.application
)
)
return;
isDuplicate = true;
break;
case 'prepareUndeploy':
if (
Expand All @@ -370,7 +372,7 @@ export const addAction = (action: BatchAction): void => {
act.action.prepareUndeploy.application === action.action.prepareUndeploy.application
)
)
return;
isDuplicate = true;
break;
case 'releaseTrain':
// only allow one release train at a time to avoid conflicts or if there are existing deploy actions
Expand All @@ -383,7 +385,11 @@ export const addAction = (action: BatchAction): void => {

break;
}
UpdateAction.set({ actions: [...UpdateAction.get().actions, action] });
if (isDuplicate) {
showSnackbarSuccess('This action was already added.');
} else {
UpdateAction.set({ actions: [...UpdateAction.get().actions, action] });
}
};

export const useOpenReleaseDialog = (app: string, version: number): (() => void) => {
Expand Down

0 comments on commit 127d6ec

Please sign in to comment.