Skip to content

Commit f0e0a31

Browse files
authored
add confirmation dialog conditional functionality in ApplicationTable (#558)
1 parent c81fcf4 commit f0e0a31

10 files changed

Lines changed: 108 additions & 19 deletions

File tree

apps/app-orch/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.0.5-dev
1+
4.0.5

apps/app-orch/deploy/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ apiVersion: v2
44
name: orch-ui-app-orch
55
description: Deploy the Edge Orchestrator app-orch pod
66
type: application
7-
version: 4.0.5-dev
7+
version: 4.0.5
88
# Default appVersion will be overwritten by a the build to use the version from package.json.
99

1010
# This value is supplied only to enable local unbuilt deployment of released content.
11-
appVersion: "4.0.5-dev"
11+
appVersion: "4.0.5"
1212
annotations: {}
1313
dependencies: []

apps/app-orch/src/components/organisms/applications/ApplicationTable/ApplicationTable.cy.tsx

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,50 @@ describe("<ApplicationTable />", () => {
6464
});
6565
it("should redirect to the correct URL", () => {
6666
pom.empty.el.emptyActionBtn.click();
67-
pom.confirmationDialog.el.confirmBtn.click();
6867
pom.getPath().should("eq", "/applications/applications/add");
6968
});
7069
});
7170
describe("the ribbon component", () => {
7271
it("should redirect to the correct URL", () => {
7372
pom.el.newAppRibbonButton.click();
74-
pom.confirmationDialog.el.confirmBtn.click();
7573
pom.getPath().should("eq", "/applications/applications/add");
7674
});
7775
});
7876
});
7977

78+
describe("when confirmBeforeAdd is true", () => {
79+
beforeEach(() => {
80+
pom.interceptApis([pom.api.appEmpty]);
81+
cy.mount(<div />, {
82+
routerProps: { initialEntries: ["/applications/applications"] },
83+
routerRule: [
84+
{
85+
path: "/applications/applications",
86+
element: (
87+
<ApplicationTable
88+
kind={"KIND_NORMAL"}
89+
hasPermission
90+
confirmBeforeAdd
91+
/>
92+
),
93+
},
94+
],
95+
});
96+
pom.waitForApis();
97+
pom.empty.root.should("be.visible");
98+
});
99+
it("should show confirmation dialog and redirect on confirm via empty action", () => {
100+
pom.empty.el.emptyActionBtn.click();
101+
pom.confirmationDialog.el.confirmBtn.click();
102+
pom.getPath().should("eq", "/applications/applications/add");
103+
});
104+
it("should show confirmation dialog and redirect on confirm via ribbon", () => {
105+
pom.el.newAppRibbonButton.click();
106+
pom.confirmationDialog.el.confirmBtn.click();
107+
pom.getPath().should("eq", "/applications/applications/add");
108+
});
109+
});
110+
80111
describe("when the Extensions table is empty", () => {
81112
beforeEach(() => {
82113
pom.interceptApis([pom.api.appEmpty]);
@@ -139,7 +170,6 @@ describe("<ApplicationTable />", () => {
139170
pom.waitForApis();
140171
pom.empty.root.should("be.visible");
141172
pom.empty.el.emptyActionBtn.click();
142-
pom.confirmationDialog.el.confirmBtn.click();
143173
cy.get("#pathname").contains("/add");
144174
});
145175

apps/app-orch/src/components/organisms/applications/ApplicationTable/ApplicationTable.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ interface ApplicationTableProps {
5858
hideRibbon?: boolean;
5959
isDialogOpen?: boolean;
6060

61+
/** When true, show a confirmation dialog before navigating to the add application page.
62+
* Use when ApplicationTable is embedded in a flow where navigation would lose progress (e.g. DeploymentPackageCreateEdit). */
63+
confirmBeforeAdd?: boolean;
64+
6165
// for Row Selection
6266
canSelect?: boolean;
6367
selectedIds?: string[];
@@ -76,6 +80,7 @@ const ApplicationTable = ({
7680
hideRibbon = false,
7781
manualSearch,
7882
isDialogOpen,
83+
confirmBeforeAdd = false,
7984
canSelect,
8085
selectedIds = [],
8186
onSelect,
@@ -102,6 +107,14 @@ const ApplicationTable = ({
102107
navigate("/applications/applications/add", { relative: "path" });
103108
};
104109

110+
const handleAddApplicationClick = () => {
111+
if (confirmBeforeAdd) {
112+
setShowConfirmDialog(true);
113+
} else {
114+
handleAddApplicationConfirm();
115+
}
116+
};
117+
105118
const columns: TableColumn<catalog.Application>[] = [
106119
{
107120
Header: "Name",
@@ -230,7 +243,7 @@ const ApplicationTable = ({
230243
if (kind === "KIND_NORMAL") {
231244
// Adding "Add application" action to applications
232245
emptyDataAction.push({
233-
action: () => setShowConfirmDialog(true),
246+
action: handleAddApplicationClick,
234247
name: `Add ${applicationType}`,
235248
disable: !hasPermission,
236249
});
@@ -258,9 +271,7 @@ const ApplicationTable = ({
258271
hasPermission ? (
259272
<Button
260273
data-cy="newAppRibbonButton"
261-
onPress={() => {
262-
setShowConfirmDialog(true);
263-
}}
274+
onPress={handleAddApplicationClick}
264275
isDisabled={!hasPermission}
265276
>
266277
Add Application
@@ -274,9 +285,7 @@ const ApplicationTable = ({
274285
>
275286
<Button
276287
data-cy="newAppRibbonButton"
277-
onPress={() => {
278-
setShowConfirmDialog(true);
279-
}}
288+
onPress={handleAddApplicationClick}
280289
isDisabled={!hasPermission}
281290
>
282291
Add Application
@@ -430,7 +439,7 @@ const ApplicationTable = ({
430439
/>
431440
)}
432441

433-
{showConfirmDialog && (
442+
{confirmBeforeAdd && showConfirmDialog && (
434443
<ConfirmationDialog
435444
isOpen={true}
436445
title="Confirm Navigation"

apps/app-orch/src/components/organisms/deploymentPackages/DeploymentPackageCreateEdit/DeploymentPackageCreateEdit.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ const DeploymentPackageCreateEdit = ({
352352
});
353353
}}
354354
kind={deploymentPackage.kind ?? "KIND_NORMAL"}
355+
confirmBeforeAdd
355356
/>
356357
<div className="deployment-package-create-edit__footer">
357358
<Button

apps/root/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.0.6-dev
1+
4.0.6

apps/root/deploy/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ apiVersion: v2
44
name: orch-ui-root
55
description: Deploy Edge Orchestrator UI pods on Kubernetes
66
type: application
7-
version: 4.0.6-dev
7+
version: 4.0.6
88
# Default appVersion will be overwritten by a the build to use the version from package.json.
99

1010
# This value is supplied only to enable local unbuilt deployment of released content.
11-
appVersion: "4.0.6-dev"
11+
appVersion: "4.0.6"
1212
annotations: {}
1313
dependencies: []

library/components/atomic-design/atoms/ConfirmationDialog/ConfirmationDialog.cy.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,41 @@ describe("<ConfirmationDialog/>", () => {
160160
cyGet("dialog").should("exist").should("be.visible");
161161
});
162162
});
163+
164+
describe("reopening after dismiss", () => {
165+
beforeEach(() => {
166+
cy.mount(
167+
<ConfirmationDialog
168+
showTriggerButton
169+
isOpen={false}
170+
confirmCb={cy.stub().as("confirmCb")}
171+
cancelCb={cy.stub().as("cancelCb")}
172+
confirmBtnText="Confirm"
173+
cancelBtnText="Cancel"
174+
title="Test Dialog"
175+
content="Test content"
176+
/>,
177+
);
178+
});
179+
180+
it("should reopen after being dismissed via the X button", () => {
181+
pom.el.open.click();
182+
cyGet("dialog").should("exist").should("be.visible");
183+
cy.get(".spark-icon-cross").click();
184+
pom.el.dialog.should("not.exist");
185+
186+
pom.el.open.click();
187+
cyGet("dialog").should("exist").should("be.visible");
188+
});
189+
190+
it("should reopen after being dismissed via the cancel button", () => {
191+
pom.el.open.click();
192+
cyGet("dialog").should("exist").should("be.visible");
193+
cyGet("cancelBtn").click();
194+
pom.el.dialog.should("not.exist");
195+
196+
pom.el.open.click();
197+
cyGet("dialog").should("exist").should("be.visible");
198+
});
199+
});
163200
});

library/components/atomic-design/atoms/ConfirmationDialog/ConfirmationDialog.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,14 @@ export const ConfirmationDialog = ({
121121

122122
return (
123123
<div {...cy} className={cssSelector}>
124-
<DialogTrigger isDismissible defaultOpen={isOpen} size={size}>
124+
<DialogTrigger
125+
isDismissible
126+
defaultOpen={isOpen}
127+
size={size}
128+
onOpenChange={(open: boolean) => {
129+
if (!open && cancelCb) cancelCb();
130+
}}
131+
>
125132
<Button
126133
id={triggerButtonId}
127134
data-cy="open"
@@ -146,7 +153,6 @@ export const ConfirmationDialog = ({
146153
className="cd-button"
147154
variant={cancelBtnVariant}
148155
onPress={() => {
149-
if (cancelCb) cancelCb();
150156
close();
151157
}}
152158
data-cy="cancelBtn"

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,36 @@
1010
"app:admin:lint": "cd apps/admin && prettier --check ./src && eslint ./src",
1111
"app:admin:fix": "cd apps/admin && prettier --write ./src && eslint --fix ./src",
1212
"app:admin:cy:component": "cd tests/admin && cypress run --component --spec ../../apps/admin/unit-tests.cy.ts --env ORCH_DEFAULT_PASSWORD=${ORCH_DEFAULT_PASSWORD}",
13+
"app:admin:cy:open": "cd tests/admin && cypress open --env ORCH_DEFAULT_PASSWORD=${ORCH_DEFAULT_PASSWORD}",
1314
"app:infra": "cd apps/infra && webpack serve --config=config/webpack.dev.js",
1415
"app:infra:build": "cd apps/infra && webpack --config=config/webpack.prod.js",
1516
"app:infra:lint": "cd apps/infra && prettier --check ./src && eslint ./src",
1617
"app:infra:fix": "cd apps/infra && prettier --write ./src && eslint --fix ./src",
1718
"app:infra:cy:component": "cd tests/infra && TZ=\"Asia/Kolkata\" cypress run --component --spec ../../apps/infra/unit-tests.cy.ts --env ORCH_DEFAULT_PASSWORD=${ORCH_DEFAULT_PASSWORD}",
19+
"app:infra:cy:open": "cd tests/infra && cypress open --env ORCH_DEFAULT_PASSWORD=${ORCH_DEFAULT_PASSWORD}",
1820
"app:app-orch": "cd apps/app-orch && webpack serve --config=config/webpack.dev.js",
1921
"app:app-orch:build": "cd apps/app-orch && webpack --config=config/webpack.prod.js",
2022
"app:app-orch:lint": "cd apps/app-orch && prettier --check ./src && eslint ./src",
2123
"app:app-orch:fix": "cd apps/app-orch && prettier --write ./src && eslint --fix ./src",
2224
"app:app-orch:cy:component": "cd tests/app-orch && cypress run --component --spec ../../apps/app-orch/unit-tests.cy.ts --env ORCH_DEFAULT_PASSWORD=${ORCH_DEFAULT_PASSWORD}",
25+
"app:app-orch:cy:open": "cd tests/app-orch && cypress open --env ORCH_DEFAULT_PASSWORD=${ORCH_DEFAULT_PASSWORD}",
2326
"app:root": "cd apps/root && webpack serve --config=config/webpack.dev.js",
2427
"app:root:build": "cd apps/root && webpack --config=config/webpack.prod.js",
2528
"app:root:lint": "cd apps/root && prettier --check ./src && eslint ./src",
2629
"app:root:fix": "cd apps/root && prettier --write ./src && eslint --fix ./src",
2730
"app:root:cy:component": "cd tests/root && cypress run --component --spec ../../apps/root/unit-tests.cy.ts --env ORCH_DEFAULT_PASSWORD=${ORCH_DEFAULT_PASSWORD}",
31+
"app:root:cy:open": "cd tests/root && cypress open --env ORCH_DEFAULT_PASSWORD=${ORCH_DEFAULT_PASSWORD}",
2832
"app:cluster-orch": "cd apps/cluster-orch && webpack serve --config=config/webpack.dev.js",
2933
"app:cluster-orch:build": "cd apps/cluster-orch && webpack --config=config/webpack.prod.js",
3034
"app:cluster-orch:lint": "cd apps/cluster-orch && prettier --check ./src && eslint ./src",
3135
"app:cluster-orch:fix": "cd apps/cluster-orch && prettier --write ./src && eslint --fix ./src",
3236
"app:cluster-orch:cy:component": "cd tests/cluster-orch && cypress run --component --spec ../../apps/cluster-orch/unit-tests.cy.ts --env ORCH_DEFAULT_PASSWORD=${ORCH_DEFAULT_PASSWORD}",
37+
"app:cluster-orch:cy:open": "cd tests/cluster-orch && cypress open --env ORCH_DEFAULT_PASSWORD=${ORCH_DEFAULT_PASSWORD}",
3338
"cypress:component": "cd tests && cypress open --component",
3439
"library:lint": "prettier --check ./library && eslint ./library",
3540
"library:fix": "cd library && prettier --write ./ && eslint --fix ./",
3641
"library:cy:component": "cd tests/library && cypress run --component --spec ./unit-tests.cy.ts --env ORCH_DEFAULT_PASSWORD=${ORCH_DEFAULT_PASSWORD}",
42+
"library:cy:open": "cd tests/library && cypress open --env ORCH_DEFAULT_PASSWORD=${ORCH_DEFAULT_PASSWORD}",
3743
"tests:component": "cd tests && cypress open --component",
3844
"tests:e2e": "cd tests && cypress open --e2e --env EN_UUID=398395da-c10e-7c47-9b4f-efb34c0b261e",
3945
"tests:build": "cd tests && webpack build --config webpack.config.js",

0 commit comments

Comments
 (0)