Skip to content

Commit

Permalink
perf: optimize instr sci call query (#864)
Browse files Browse the repository at this point in the history
  • Loading branch information
TCMeldrum authored Nov 21, 2024
2 parents ad8fdc4 + 869ef5b commit 93aa4e8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useSearchParams } from 'react-router-dom';
import { Call } from 'generated/sdk';

type CallFilterProps = {
calls?: Call[];
calls?: Pick<Call, 'shortCode' | 'id'>[];
isLoading?: boolean;
onChange?: Dispatch<number>;
shouldShowAll?: boolean;
Expand Down
5 changes: 4 additions & 1 deletion apps/frontend/src/components/proposal/ProposalFilterBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ export const questionaryFilterFromUrlQuery = (urlQuery: {
}
};
type ProposalFilterBarProps = {
calls?: { data: Call[]; isLoading: boolean };
calls?: {
data: Pick<Call, 'shortCode' | 'id' | 'templateId'>[];
isLoading: boolean;
};
instruments?: { data: InstrumentMinimalFragment[]; isLoading: boolean };
proposalStatuses?: { data: ProposalStatus[]; isLoading: boolean };
setProposalFilter: (filter: ProposalsFilter) => void;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
query getCallsByInstrumentScientist($scientistId: Int!) {
callsByInstrumentScientist(scientistId: $scientistId) {
...call
id
shortCode
templateId
}
}
11 changes: 8 additions & 3 deletions apps/frontend/src/hooks/call/useInstrumentScientistCallsData.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { useEffect, useState } from 'react';

import { Call } from 'generated/sdk';
import { useDataApi } from 'hooks/common/useDataApi';

export type InstrumentScientistCallsData = {
id: number;
shortCode: string;
templateId: number;
};

export function useInstrumentScientistCallsData(scientistId: number) {
const [calls, setCalls] = useState<Call[]>([]);
const [calls, setCalls] = useState<InstrumentScientistCallsData[]>([]);
const [loadingCalls, setLoadingCalls] = useState(true);

const api = useDataApi();
Expand All @@ -21,7 +26,7 @@ export function useInstrumentScientistCallsData(scientistId: number) {
}

if (data.callsByInstrumentScientist) {
setCalls(data.callsByInstrumentScientist as Call[]);
setCalls(data.callsByInstrumentScientist);
}
setLoadingCalls(false);
});
Expand Down

0 comments on commit 93aa4e8

Please sign in to comment.