Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/7499-tree-ancestors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type: Changed
description: Monitor tree now applies active filters when refreshing after resource actions
pr: 7499
labels: []
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,18 @@ const actionCenterApi = baseApi.injectEndpoints({
Array<DatastoreStagedResourceTreeAPIResponse>,
{
monitor_config_id: string;
staged_resource_urn?: string;
staged_resource_urn: string;
diff_status?: DiffStatus[];
}
>({
query: ({ monitor_config_id, staged_resource_urn }) => ({
url: `/plus/discovery-monitor/${monitor_config_id}/tree/ancestors-statuses`,
params: { staged_resource_urn },
}),
query: ({ monitor_config_id, staged_resource_urn, diff_status }) => {
const urlParams = buildArrayQueryParams({ diff_status });
const queryString = urlParams ? `?${urlParams}` : "";

return {
url: `/plus/discovery-monitor/${monitor_config_id}/tree/ancestors-statuses/${encodeURIComponent(staged_resource_urn)}${queryString}`,
};
},
}),

getDiscoveredSystemAggregate: build.query<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import palette from "fidesui/src/palette/palette.module.scss";

import { DiffStatus, StagedResourceTypeValue } from "~/types/api";

export const TREE_PAGE_SIZE = 100;
export const TREE_PAGE_SIZE = 25;
export const TREE_NODE_LOAD_MORE_TEXT = "Load more...";
export const TREE_NODE_LOAD_MORE_KEY_PREFIX = "load_more";
export const TREE_NODE_SKELETON_KEY_PREFIX = "skeleton";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,59 @@ const MonitorTree = forwardRef<
*/
const refreshResourcesAndAncestors = useCallback(
async (urns: string[]) => {
const updateAncestorsForUrn = async (urn?: string) => {
// Special case: when no URNs provided (bulk action on all filtered resources),
// we use get_tree instead of get_ancestors because there's no specific resource
// to get ancestors for. This refreshes top-level databases with filtered descendants.
if (urns.length === 0) {
try {
const result = await trigger({
monitor_config_id: monitorId,
size: TREE_PAGE_SIZE,
});

if (result.error) {
errorAlert(
getErrorMessage(result.error),
"Failed to get schema explorer top-level resources",
);
return;
}

const topLevelData = result.data;
if (!topLevelData?.items) {
return;
}

topLevelData.items.forEach((node) => {
collapseNodeAndRemoveChildren(node.urn);
});

setTreeData((prevTreeData) =>
topLevelData.items.reduce(
(tree, node) =>
updateNodeStatus(tree, node.urn, node.diff_status),
prevTreeData,
),
);
} catch (error) {
errorAlert(
"An unexpected error occurred while refreshing the schema explorer",
);
}
return;
}

// For specific URNs, get ancestors and update them
const updateAncestorsForUrn = async (urn: string) => {
try {
const result = await triggerAncestorsStatuses({
monitor_config_id: monitorId,
...(urn && { staged_resource_urn: urn }),
staged_resource_urn: urn,
diff_status: [
...DEFAULT_FILTER_STATUSES.flatMap(intoDiffStatus),
...(showIgnored ? intoDiffStatus("Ignored") : []),
...(showApproved ? intoDiffStatus("Approved") : []),
],
});

if (result.error) {
Expand All @@ -544,26 +592,17 @@ const MonitorTree = forwardRef<
return;
}

// Collapse the affected URN and remove its children
if (urn) {
collapseNodeAndRemoveChildren(urn);
} else {
// ancestorsData contains the databases of the monitor
ancestorsData.forEach((ancestorNode) => {
collapseNodeAndRemoveChildren(ancestorNode.urn);
});
}
collapseNodeAndRemoveChildren(urn);

// Update the status and diffStatus of each ancestor node
setTreeData((origin) =>
setTreeData((prevTreeData) =>
ancestorsData.reduce(
(tree, ancestorNode) =>
updateNodeStatus(
tree,
ancestorNode.urn,
ancestorNode.diff_status,
),
origin,
prevTreeData,
),
);
} catch (error) {
Expand All @@ -573,19 +612,17 @@ const MonitorTree = forwardRef<
}
};

if (urns.length === 0) {
await updateAncestorsForUrn();
return;
}

// Process all URNs in parallel
await Promise.all(urns.map((urn) => updateAncestorsForUrn(urn)));
},
[
trigger,
triggerAncestorsStatuses,
monitorId,
collapseNodeAndRemoveChildren,
errorAlert,
showIgnored,
showApproved,
],
);

Expand Down
Loading