Skip to content

Commit c9ea54c

Browse files
authored
Action center: Bulk add/ignore system UI (#5740)
1 parent cc24c56 commit c9ea54c

File tree

7 files changed

+256
-49
lines changed

7 files changed

+256
-49
lines changed

clients/admin-ui/cypress/e2e/action-center.cy.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ describe("Action center", () => {
181181
cy.getByTestId("row-0-col-actions").within(() => {
182182
cy.getByTestId("ignore-btn").click({ force: true });
183183
});
184-
cy.wait("@ignoreMonitorResultUncategorizedSystem");
184+
cy.wait("@ignoreMonitorResultSystem").then((interception) => {
185+
expect(interception.request.url).to.contain("[undefined]");
186+
});
185187
cy.getByTestId("success-alert").should(
186188
"contain",
187189
"108 uncategorized assets have been ignored and will not appear in future scans.",
@@ -207,8 +209,42 @@ describe("Action center", () => {
207209
"10 assets from Google Tag Manager have been ignored and will not appear in future scans.",
208210
);
209211
});
212+
it("shouldn't allow bulk add when uncategorized system is selected", () => {
213+
cy.getByTestId("row-0-col-select").find("label").click();
214+
cy.getByTestId("selected-count").should("contain", "1 selected");
215+
cy.getByTestId("bulk-actions-menu").click();
216+
cy.getByTestId("bulk-add").should("be.disabled");
217+
});
218+
it("should bulk add results from categorized systems", () => {
219+
cy.getByTestId("bulk-actions-menu").should("be.disabled");
220+
cy.getByTestId("row-1-col-select").find("label").click();
221+
cy.getByTestId("row-2-col-select").find("label").click();
222+
cy.getByTestId("selected-count").should("contain", "2 selected");
223+
cy.getByTestId("bulk-actions-menu").should("not.be.disabled");
224+
cy.getByTestId("bulk-actions-menu").click();
225+
cy.getByTestId("bulk-add").click();
226+
cy.wait("@addMonitorResultSystem");
227+
cy.getByTestId("success-alert").should(
228+
"contain",
229+
"16 assets have been added to the system inventory.",
230+
);
231+
});
232+
it("should bulk ignore results from all systems", () => {
233+
cy.getByTestId("row-0-col-select").find("label").click();
234+
cy.getByTestId("row-1-col-select").find("label").click();
235+
cy.getByTestId("row-2-col-select").find("label").click();
236+
cy.getByTestId("selected-count").should("contain", "3 selected");
237+
cy.getByTestId("bulk-actions-menu").should("not.be.disabled");
238+
cy.getByTestId("bulk-actions-menu").click();
239+
cy.getByTestId("bulk-ignore").click();
240+
cy.wait("@ignoreMonitorResultSystem");
241+
cy.getByTestId("success-alert").should(
242+
"contain",
243+
"124 assets have been ignored and will not appear in future scans.",
244+
);
245+
});
210246
it("should navigate to table view on row click", () => {
211-
cy.getByTestId("row-1").click();
247+
cy.getByTestId("row-1-col-system_name").click();
212248
cy.url().should(
213249
"contain",
214250
"system_key-8fe42cdb-af2e-4b9e-9b38-f75673180b88",

clients/admin-ui/cypress/support/stubs.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -551,13 +551,6 @@ export const stubActionCenter = () => {
551551
cy.intercept("POST", "/api/v1/plus/discovery-monitor/*/mute*", {
552552
response: 200,
553553
}).as("ignoreMonitorResultSystem");
554-
cy.intercept(
555-
"POST",
556-
"/api/v1/plus/discovery-monitor/*/mute?resolved_system_id=%5Bundefined%5D",
557-
{
558-
response: 200,
559-
},
560-
).as("ignoreMonitorResultUncategorizedSystem");
561554
cy.intercept("POST", "/api/v1/plus/discovery-monitor/*/promote*", {
562555
response: 200,
563556
}).as("addMonitorResultSystem");

clients/admin-ui/src/features/data-discovery-and-detection/action-center/action-center.slice.ts

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { baseApi } from "~/features/common/api.slice";
2+
import { getQueryParamsFromArray } from "~/features/common/utils";
23
import { Page_StagedResourceAPIResponse_ } from "~/types/api";
34
import { PaginationQueryParams } from "~/types/common/PaginationQueryParams";
45

@@ -7,6 +8,11 @@ import {
78
MonitorSystemAggregatePaginatedResponse,
89
} from "./types";
910

11+
interface MonitorResultSystemQueryParams {
12+
monitor_config_key: string;
13+
resolved_system_ids: string[];
14+
}
15+
1016
const actionCenterApi = baseApi.injectEndpoints({
1117
endpoints: (build) => ({
1218
getAggregateMonitorResults: build.query<
@@ -56,30 +62,36 @@ const actionCenterApi = baseApi.injectEndpoints({
5662
}),
5763
providesTags: () => ["Discovery Monitor Results"],
5864
}),
59-
addMonitorResultSystem: build.mutation<
65+
addMonitorResultSystems: build.mutation<
6066
any,
61-
{ monitor_config_key?: string; resolved_system_id?: string }
67+
MonitorResultSystemQueryParams
6268
>({
63-
query: (params) => ({
64-
method: "POST",
65-
url: `/plus/discovery-monitor/${params.monitor_config_key}/promote`,
66-
params: {
67-
resolved_system_id: params.resolved_system_id,
68-
},
69-
}),
69+
query: ({ monitor_config_key, resolved_system_ids }) => {
70+
const params = getQueryParamsFromArray(
71+
resolved_system_ids,
72+
"resolved_system_ids",
73+
);
74+
return {
75+
method: "POST",
76+
url: `/plus/discovery-monitor/${monitor_config_key}/promote?${params}`,
77+
};
78+
},
7079
invalidatesTags: ["Discovery Monitor Results"],
7180
}),
72-
ignoreMonitorResultSystem: build.mutation<
81+
ignoreMonitorResultSystems: build.mutation<
7382
any,
74-
{ monitor_config_key?: string; resolved_system_id?: string }
83+
MonitorResultSystemQueryParams
7584
>({
76-
query: (params) => ({
77-
method: "POST",
78-
url: `/plus/discovery-monitor/${params.monitor_config_key}/mute`,
79-
params: {
80-
resolved_system_id: params.resolved_system_id,
81-
},
82-
}),
85+
query: ({ monitor_config_key, resolved_system_ids }) => {
86+
const params = getQueryParamsFromArray(
87+
resolved_system_ids,
88+
"resolved_system_ids",
89+
);
90+
return {
91+
method: "POST",
92+
url: `/plus/discovery-monitor/${monitor_config_key}/mute?${params}`,
93+
};
94+
},
8395
invalidatesTags: ["Discovery Monitor Results"],
8496
}),
8597
addMonitorResultAssets: build.mutation<any, { urnList?: string[] }>({
@@ -133,8 +145,8 @@ export const {
133145
useGetAggregateMonitorResultsQuery,
134146
useGetDiscoveredSystemAggregateQuery,
135147
useGetDiscoveredAssetsQuery,
136-
useAddMonitorResultSystemMutation,
137-
useIgnoreMonitorResultSystemMutation,
148+
useAddMonitorResultSystemsMutation,
149+
useIgnoreMonitorResultSystemsMutation,
138150
useAddMonitorResultAssetsMutation,
139151
useIgnoreMonitorResultAssetsMutation,
140152
useUpdateAssetsSystemMutation,

clients/admin-ui/src/features/data-discovery-and-detection/action-center/hooks/useDiscoveredSystemAggregateColumns.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { ColumnDef, createColumnHelper } from "@tanstack/react-table";
22

3-
import { DefaultCell } from "~/features/common/table/v2";
3+
import {
4+
DefaultCell,
5+
IndeterminateCheckboxCell,
6+
} from "~/features/common/table/v2";
47
import DiscoveredSystemDataUseCell from "~/features/data-discovery-and-detection/action-center/tables/cells/DiscoveredSystemDataUseCell";
58

69
import { DiscoveredSystemActionsCell } from "../tables/cells/DiscoveredSystemAggregateActionsCell";
@@ -11,6 +14,28 @@ export const useDiscoveredSystemAggregateColumns = (monitorId: string) => {
1114
const columnHelper = createColumnHelper<MonitorSystemAggregate>();
1215

1316
const columns: ColumnDef<MonitorSystemAggregate, any>[] = [
17+
columnHelper.display({
18+
id: "select",
19+
cell: ({ row }) => (
20+
<IndeterminateCheckboxCell
21+
isChecked={row.getIsSelected()}
22+
onChange={row.getToggleSelectedHandler()}
23+
dataTestId={`select-${row.original.name || row.id}`}
24+
/>
25+
),
26+
header: ({ table }) => (
27+
<IndeterminateCheckboxCell
28+
isChecked={table.getIsAllPageRowsSelected()}
29+
isIndeterminate={table.getIsSomeRowsSelected()}
30+
onChange={table.getToggleAllRowsSelectedHandler()}
31+
dataTestId="select-all-rows"
32+
/>
33+
),
34+
maxSize: 40,
35+
meta: {
36+
disableRowClick: true,
37+
},
38+
}),
1439
columnHelper.accessor((row) => row.name, {
1540
id: "system_name",
1641
cell: (props) => (

clients/admin-ui/src/features/data-discovery-and-detection/action-center/tables/DiscoveredAssetsTable.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import {
3636
} from "~/features/common/table/v2";
3737
import {
3838
useAddMonitorResultAssetsMutation,
39-
useAddMonitorResultSystemMutation,
39+
useAddMonitorResultSystemsMutation,
4040
useGetDiscoveredAssetsQuery,
4141
useIgnoreMonitorResultAssetsMutation,
4242
useUpdateAssetsSystemMutation,
@@ -66,8 +66,8 @@ export const DiscoveredAssetsTable = ({
6666
useAddMonitorResultAssetsMutation();
6767
const [ignoreMonitorResultAssetsMutation, { isLoading: isIgnoringResults }] =
6868
useIgnoreMonitorResultAssetsMutation();
69-
const [addMonitorResultSystemMutation, { isLoading: isAddingAllResults }] =
70-
useAddMonitorResultSystemMutation();
69+
const [addMonitorResultSystemsMutation, { isLoading: isAddingAllResults }] =
70+
useAddMonitorResultSystemsMutation();
7171
const [updateAssetsSystemMutation, { isLoading: isBulkUpdatingSystem }] =
7272
useUpdateAssetsSystemMutation();
7373

@@ -187,9 +187,9 @@ export const DiscoveredAssetsTable = ({
187187

188188
const handleAddAll = async () => {
189189
const assetCount = data?.items.length || 0;
190-
const result = await addMonitorResultSystemMutation({
190+
const result = await addMonitorResultSystemsMutation({
191191
monitor_config_key: monitorId,
192-
resolved_system_id: systemId,
192+
resolved_system_ids: [systemId],
193193
});
194194

195195
if (isErrorResult(result)) {

0 commit comments

Comments
 (0)