Skip to content

Commit df2d243

Browse files
authored
Subscribe to individual system query in manual create (#3662)
1 parent b4f1b3b commit df2d243

File tree

4 files changed

+59
-38
lines changed

4 files changed

+59
-38
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ The types of changes are:
6969
- Update to latest asyncpg dependency to avoid build error [#3614](https://github.com/ethyca/fides/pull/3614)
7070
- Fix bug where editing a data use on a system could delete existing data uses [#3627](https://github.com/ethyca/fides/pull/3627)
7171
- Restrict Privacy Center debug logging to development-only [#3638](https://github.com/ethyca/fides/pull/3638)
72+
- Fix bug where linking an integration would not update the tab when creating a new system [#3662](https://github.com/ethyca/fides/pull/3662)
7273

7374
### Changed
7475

clients/admin-ui/cypress/e2e/systems.cy.ts

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ describe("System management page", () => {
111111

112112
it("Can step through the flow", () => {
113113
cy.fixture("systems/system.json").then((system) => {
114+
cy.intercept("GET", "/api/v1/system/*", {
115+
body: { ...system, privacy_declarations: [] },
116+
}).as("getDemoSystem");
114117
// Fill in the describe form based on fixture data
115118
cy.visit(ADD_SYSTEMS_ROUTE);
116119
cy.getByTestId("manual-btn").click();
@@ -145,6 +148,7 @@ describe("System management page", () => {
145148
"@getDataSubjects",
146149
"@getDataUses",
147150
"@getFilteredDatasets",
151+
"@getDemoSystem",
148152
]);
149153
cy.getByTestId("new-declaration-form");
150154
const declaration = system.privacy_declarations[0];
@@ -180,32 +184,41 @@ describe("System management page", () => {
180184
});
181185

182186
it("can render a warning when there is unsaved data", () => {
183-
cy.visit(ADD_SYSTEMS_MANUAL_ROUTE);
184-
cy.wait("@getSystems");
185-
cy.wait("@getConnectionTypes");
186-
cy.getByTestId("create-system-btn").click();
187-
cy.getByTestId("input-name").type("test");
188-
cy.getByTestId("input-fides_key").type("test");
189-
cy.getByTestId("save-btn").click();
190-
cy.wait("@postSystem");
187+
cy.fixture("systems/system.json").then((system) => {
188+
cy.intercept("GET", "/api/v1/system/*", {
189+
body: { ...system, privacy_declarations: [] },
190+
}).as("getDemoSystem");
191+
cy.visit(ADD_SYSTEMS_MANUAL_ROUTE);
192+
cy.wait("@getSystems");
193+
cy.wait("@getConnectionTypes");
194+
cy.getByTestId("create-system-btn").click();
195+
cy.getByTestId("input-name").type(system.name);
196+
cy.getByTestId("input-fides_key").type(system.fides_key);
197+
cy.getByTestId("input-description").type(system.description);
198+
cy.getByTestId("save-btn").click();
199+
cy.wait("@postSystem");
191200

192-
// start typing a description
193-
const description = "half formed thought";
194-
cy.getByTestId("input-description").type(description);
195-
// then try navigating to the privacy declarations tab
196-
cy.getByTestId("tab-Data uses").click();
197-
cy.getByTestId("confirmation-modal");
198-
// make sure canceling works
199-
cy.getByTestId("cancel-btn").click();
200-
cy.getByTestId("input-description").should("have.value", description);
201-
// now actually discard
202-
cy.getByTestId("tab-Data uses").click();
203-
cy.getByTestId("continue-btn").click();
204-
// should load the privacy declarations page
205-
cy.getByTestId("privacy-declaration-step");
206-
// navigate back
207-
cy.getByTestId("tab-System information").click();
208-
cy.getByTestId("input-description").should("have.value", "");
201+
// start typing a description
202+
const description = "half formed thought";
203+
cy.getByTestId("input-description").clear().type(description);
204+
// then try navigating to the privacy declarations tab
205+
cy.getByTestId("tab-Data uses").click();
206+
cy.getByTestId("confirmation-modal");
207+
// make sure canceling works
208+
cy.getByTestId("cancel-btn").click();
209+
cy.getByTestId("input-description").should("have.value", description);
210+
// now actually discard
211+
cy.getByTestId("tab-Data uses").click();
212+
cy.getByTestId("continue-btn").click();
213+
// should load the privacy declarations page
214+
cy.getByTestId("privacy-declaration-step");
215+
// navigate back and make sure description has the original description
216+
cy.getByTestId("tab-System information").click();
217+
cy.getByTestId("input-description").should(
218+
"have.value",
219+
system.description
220+
);
221+
});
209222
});
210223
});
211224
});
@@ -311,6 +324,7 @@ describe("System management page", () => {
311324
const { body } = interception.request;
312325
expect(body.joint_controller.name).to.eql(controllerName);
313326
});
327+
cy.wait("@getFidesctlSystem");
314328

315329
// Switch to the Data Uses tab
316330
cy.getByTestId("tab-Data uses").click();
@@ -336,15 +350,15 @@ describe("System management page", () => {
336350
// edit the existing declaration
337351
cy.getByTestId("accordion-header-improve.system").click();
338352
cy.getByTestId("improve.system-form").within(() => {
339-
cy.getByTestId("input-data_subjects").type(`anonymous{enter}`);
353+
cy.getByTestId("input-data_subjects").type(`customer{enter}`);
340354
cy.getByTestId("save-btn").click();
341355
});
342356
cy.wait("@putSystem").then((interception) => {
343357
const { body } = interception.request;
344358
expect(body.privacy_declarations.length).to.eql(1);
345359
expect(body.privacy_declarations[0].data_subjects).to.eql([
346-
"customer",
347360
"anonymous_user",
361+
"customer",
348362
]);
349363
});
350364
cy.getByTestId("saved-indicator");

clients/admin-ui/src/features/system/SystemFormTabs.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import ConnectionForm from "~/features/datastore-connections/system_portal_confi
1212
import PrivacyDeclarationStep from "~/features/system/privacy-declarations/PrivacyDeclarationStep";
1313
import { System, SystemResponse } from "~/types/api";
1414

15-
import { selectActiveSystem, setActiveSystem } from "./system.slice";
15+
import {
16+
selectActiveSystem,
17+
setActiveSystem,
18+
useGetSystemByFidesKeyQuery,
19+
} from "./system.slice";
1620
import SystemInformationForm from "./SystemInformationForm";
1721
import UnmountWarning from "./UnmountWarning";
1822

@@ -79,6 +83,17 @@ const SystemFormTabs = ({
7983
const dispatch = useAppDispatch();
8084
const activeSystem = useAppSelector(selectActiveSystem) as SystemResponse;
8185

86+
// Once we have saved the system basics, subscribe to the query so that activeSystem
87+
// stays up to date when redux invalidates the cache (for example, when we patch a connection config)
88+
const { data: systemFromApi } = useGetSystemByFidesKeyQuery(
89+
activeSystem?.fides_key,
90+
{ skip: !activeSystem }
91+
);
92+
93+
useEffect(() => {
94+
dispatch(setActiveSystem(systemFromApi));
95+
}, [systemFromApi, dispatch]);
96+
8297
const handleSuccess = (system: System) => {
8398
// show a save message if this is the first time the system was saved
8499
if (activeSystem === undefined) {

clients/admin-ui/src/features/system/privacy-declarations/PrivacyDeclarationStep.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { Heading, Spinner, Stack, Text } from "@fidesui/react";
22
import NextLink from "next/link";
33

4-
import { useAppDispatch } from "~/app/hooks";
5-
import { setActiveSystem } from "~/features/system";
6-
import { System, SystemResponse } from "~/types/api";
4+
import { SystemResponse } from "~/types/api";
75

86
import { usePrivacyDeclarationData } from "./hooks";
97
import PrivacyDeclarationManager from "./PrivacyDeclarationManager";
@@ -13,16 +11,10 @@ interface Props {
1311
}
1412

1513
const PrivacyDeclarationStep = ({ system }: Props) => {
16-
const dispatch = useAppDispatch();
17-
1814
const { isLoading, ...dataProps } = usePrivacyDeclarationData({
1915
includeDatasets: true,
2016
});
2117

22-
const onSave = (savedSystem: System) => {
23-
dispatch(setActiveSystem(savedSystem));
24-
};
25-
2618
return (
2719
<Stack spacing={3} data-testid="privacy-declaration-step">
2820
<Heading as="h3" size="md">
@@ -46,7 +38,6 @@ const PrivacyDeclarationStep = ({ system }: Props) => {
4638
) : (
4739
<PrivacyDeclarationManager
4840
system={system}
49-
onSave={onSave}
5041
includeCustomFields
5142
includeCookies
5243
{...dataProps}

0 commit comments

Comments
 (0)