Skip to content

Commit b6b1b18

Browse files
committed
fix: url form syncing [ENG-2469] (#7279)
1 parent e4f04aa commit b6b1b18

File tree

4 files changed

+56
-26
lines changed

4 files changed

+56
-26
lines changed

changelog/7279.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copy this file and rename it (e.g., pr-number.yaml or feature-name.yaml)
2+
# Fill in the required fields and delete this comment block
3+
4+
type: Fixed # One of: Added, Changed, Developer Experience, Deprecated, Docs, Fixed, Removed, Security
5+
description: syncing url and search form for the action center and removing default monitor filter
6+
pr: 7279 # PR number
7+
labels: [] # Optional: ["high-risk", "db-migration"]

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import {
77
} from "fidesui";
88
import { useEffect } from "react";
99

10-
import { useAppSelector } from "~/app/hooks";
11-
import { selectUser } from "~/features/auth";
1210
import { useFeatures } from "~/features/common/features";
1311
import { ACTION_CENTER_ROUTE } from "~/features/common/nav/routes";
1412
import { useAntPagination } from "~/features/common/pagination/useAntPagination";
@@ -40,16 +38,8 @@ const MonitorList = () => {
4038
...(oktaMonitorEnabled ? [MONITOR_TYPES.INFRASTRUCTURE] : []),
4139
] as const;
4240

43-
const currentUser = useAppSelector(selectUser);
44-
4541
const { requestData, ...formProps } = useSearchForm({
46-
queryState: SearchFormQueryState(
47-
[...availableMonitorTypes],
48-
currentUser?.isRootUser ? undefined : currentUser?.id,
49-
),
50-
initialValues: {
51-
steward_key: currentUser?.isRootUser ? null : (currentUser?.id ?? null),
52-
},
42+
queryState: SearchFormQueryState([...availableMonitorTypes]),
5343
translate: ({
5444
steward_key,
5545
search,

clients/admin-ui/src/features/data-discovery-and-detection/action-center/forms/MonitorListSearchForm.tsx

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { Flex, Form, Select } from "fidesui";
2+
import _ from "lodash";
23

4+
import { useAppSelector } from "~/app/hooks";
5+
import { selectUser } from "~/features/auth";
36
import SearchInput from "~/features/common/SearchInput";
47
import { formatUser } from "~/features/common/utils";
58
import useSearchForm from "~/features/data-discovery-and-detection/action-center/hooks/useSearchForm";
@@ -26,6 +29,8 @@ const MonitorListSearchForm = ({
2629
> & {
2730
availableMonitorTypes: readonly MONITOR_TYPES[];
2831
}) => {
32+
const currentUser = useAppSelector(selectUser);
33+
2934
const { data: eligibleUsersData, isLoading: isLoadingUserOptions } =
3035
useGetAllUsersQuery({
3136
page: 1,
@@ -34,24 +39,37 @@ const MonitorListSearchForm = ({
3439
exclude_approvers: true,
3540
});
3641

37-
const dataStewardOptions = (eligibleUsersData?.items || []).map((user) => ({
38-
label: formatUser(user),
39-
value: user.id,
40-
}));
42+
const dataStewardOptions = _.uniqBy(
43+
[
44+
...(currentUser
45+
? [
46+
{
47+
label: "Assigned to me",
48+
value: currentUser.id,
49+
},
50+
]
51+
: []),
52+
...(eligibleUsersData?.items || []).map((user) => ({
53+
label: formatUser(user),
54+
value: user.id,
55+
})),
56+
],
57+
"value",
58+
);
4159

4260
return (
4361
<Form
4462
form={form}
4563
{...formProps}
4664
layout="inline"
47-
className="flex grow gap-4"
65+
className="flex grow gap-2"
4866
>
4967
<Flex className="grow justify-between self-stretch">
5068
<Form.Item name="search" className="self-end">
5169
<SearchInput />
5270
</Form.Item>
5371
</Flex>
54-
<Form.Item name="monitor_type" className="self-end">
72+
<Form.Item name="monitor_type" className="!me-0 self-end">
5573
<Select
5674
options={availableMonitorTypes.map((monitorType) => ({
5775
value: monitorType,
@@ -64,7 +82,7 @@ const MonitorListSearchForm = ({
6482
aria-label="Filter by monitor type"
6583
/>
6684
</Form.Item>
67-
<Form.Item name="steward_key" className="self-end">
85+
<Form.Item name="steward_key" className="!me-0 self-end">
6886
<Select
6987
options={dataStewardOptions}
7088
loading={isLoadingUserOptions}

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

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Form, FormProps } from "fidesui";
22
import { useQueryStates, UseQueryStatesKeysMap, Values } from "nuqs";
3+
import { useEffect } from "react";
34

45
/**
56
* @description links ant form handler with nuqs query state
@@ -19,24 +20,38 @@ const useSearchForm = <RequestData, QueryState extends UseQueryStatesKeysMap>({
1920
const [form] = Form.useForm<Values<QueryState>>();
2021

2122
// Without a submit button, we want to re-submit on every change
22-
const onFieldsChange: FormProps<Values<QueryState>>["onFieldsChange"] = () =>
23-
form.submit();
24-
25-
// We are binding the ant form values to nuqs state using the form finished method
26-
const onFinish: FormProps<Values<QueryState>>["onFinish"] = (values) => {
27-
const filteredValues = Object.fromEntries(
23+
const onFieldsChange: FormProps<
24+
Values<QueryState>
25+
>["onFieldsChange"] = () => {
26+
const values = form.getFieldsValue(true);
27+
// Translation of undefined/empty string usage as default values in ant vs nuqs
28+
const translatedValues = Object.fromEntries(
2829
Object.entries(values).map(([key, value]) => [
2930
key,
3031
value === undefined ? "" : value,
3132
]),
3233
);
33-
setSearchForm(filteredValues as typeof values);
34+
setSearchForm(translatedValues as typeof values);
3435
};
3536

37+
// Unfortunate need for effect due to current routing strategy
38+
useEffect(() => {
39+
// Translation of undefined/empty string usage as default values in ant vs nuqs
40+
const translatedValues = Object.fromEntries(
41+
Object.entries(searchForm).map(([key, value]) => [
42+
key,
43+
value === "" ? undefined : value,
44+
]),
45+
);
46+
47+
form.setFieldsValue(
48+
translatedValues as Parameters<typeof form.setFieldsValue>[0],
49+
); // Casting again due to weird ant types
50+
}, [searchForm]);
51+
3652
return {
3753
form,
3854
onFieldsChange,
39-
onFinish,
4055
initialValues: {
4156
...initialValues,
4257
...searchForm,

0 commit comments

Comments
 (0)