Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(UI): User now gets feedback when they try to add a duplicate action to the shopping cart #1981

Merged
merged 8 commits into from
Oct 1, 2024
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,
miguel-crespo-fdc marked this conversation as resolved.
Show resolved Hide resolved
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
Loading