Skip to content

Commit

Permalink
Use existing hooks instead of react-query in PersonView filter
Browse files Browse the repository at this point in the history
  • Loading branch information
richardolsson committed Oct 29, 2023
1 parent 25a4778 commit 4624018
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import { useQuery } from 'react-query';
import { useRouter } from 'next/router';

import getViews from 'features/smartSearch/fetching/getViews';
import { Msg } from 'core/i18n';
import {
OPERATION,
Expand All @@ -12,21 +8,19 @@ import {
import messageIds from 'features/smartSearch/l10n/messageIds';
import UnderlinedMsg from '../../UnderlinedMsg';
import UnderlinedText from '../../UnderlinedText';
import { useNumericRouteParams } from 'core/hooks';
import useViewTree from 'features/views/hooks/useViewTree';
const localMessageIds = messageIds.filters.personView;

interface DisplayPersonViewProps {
filter: SmartSearchFilterWithId<PersonViewFilterConfig>;
}

const DisplayPersonView = ({ filter }: DisplayPersonViewProps): JSX.Element => {
const { orgId } = useRouter().query;
const { config } = filter;

const personViewsQuery = useQuery(
['personviews', orgId],
getViews(orgId as string)
);
const personViews = personViewsQuery?.data || [];
const { orgId } = useNumericRouteParams();
const viewTree = useViewTree(orgId);
const personViews = viewTree.data?.views ?? [];

const view = personViews.find((v) => v.id == config.view);
const operator = config.operator;
Expand Down
15 changes: 5 additions & 10 deletions src/features/smartSearch/components/filters/PersonView/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { FormEvent } from 'react';
import { MenuItem } from '@mui/material';
import { useQuery } from 'react-query';
import { useRouter } from 'next/router';

import FilterForm from '../../FilterForm';
import getViews from 'features/smartSearch/fetching/getViews';
import { Msg } from 'core/i18n';
import StyledSelect from '../../inputs/StyledSelect';
import { useNumericRouteParams } from 'core/hooks';
import useSmartSearchFilter from 'features/smartSearch/hooks/useSmartSearchFilter';
import useViewTree from 'features/views/hooks/useViewTree';
import {
IN_OPERATOR,
NewSmartSearchFilter,
Expand Down Expand Up @@ -37,13 +36,9 @@ const PersonView = ({
onCancel,
filter: initialFilter,
}: PersonViewProps): JSX.Element => {
const { orgId } = useRouter().query;

const personViewsQuery = useQuery(
['personviews', orgId],
getViews(orgId as string)
);
const personViews = personViewsQuery?.data || [];
const { orgId } = useNumericRouteParams();
const viewTree = useViewTree(orgId);
const personViews = viewTree.data?.views ?? [];

const { filter, setConfig, setOp } =
useSmartSearchFilter<PersonViewFilterConfig>(initialFilter, {
Expand Down
10 changes: 0 additions & 10 deletions src/features/smartSearch/fetching/getViews.ts

This file was deleted.

0 comments on commit 4624018

Please sign in to comment.