Skip to content

Commit

Permalink
fix: ds-438 add refetch interval to query helper (#485)
Browse files Browse the repository at this point in the history
Relates to JIRA: DISCOVERY-438
  • Loading branch information
nicolearagao authored Oct 17, 2024
1 parent baf4808 commit 21d441f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ REACT_APP_AUTH_COOKIE=user
REACT_APP_AUTH_COOKIE_EXPIRES=0.5
REACT_APP_AJAX_TIMEOUT=60000
REACT_APP_TOAST_NOTIFICATIONS_TIMEOUT=8000
REACT_APP_POLL_INTERVAL=120000
REACT_APP_POLL_INTERVAL=60000

REACT_APP_CONFIG_SERVICE_LOCALES_DEFAULT_LNG=en
REACT_APP_CONFIG_SERVICE_LOCALES_DEFAULT_LNG_DESC=English
Expand Down
10 changes: 8 additions & 2 deletions src/helpers/queryHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,15 @@ export const useServiceQuery = <TItem, TColumnKey extends string, TSortableColum
columnOrderMap?: Record<TSortableColumnKey, string>;
tableState: TableState<TItem, TColumnKey, TSortableColumnKey>;
setRefreshTime?: (date: Date) => void;
}) =>
useQuery<ServiceQueryResult<TItem>>({
}) => {
const pollInterval = process.env.REACT_APP_POLL_INTERVAL
? Number.parseInt(process.env.REACT_APP_POLL_INTERVAL, 10)
: undefined;

return useQuery<ServiceQueryResult<TItem>>({
queryKey: [...queryKey, tableState.cacheKey],
refetchOnWindowFocus: !helpers.DEV_MODE,
refetchInterval: pollInterval,
queryFn: async () => {
try {
const query = getServiceQueryUrl({ tableState, baseUrl, columnOrderMap });
Expand All @@ -77,3 +82,4 @@ export const useServiceQuery = <TItem, TColumnKey extends string, TSortableColum
}
}
});
};
4 changes: 2 additions & 2 deletions tests/__snapshots__/code.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ exports[`General code checks should only have specific console.[warn|log|info|er
"components/aboutModal/aboutModal.tsx:45: error => console.error(\`About status error: \${error} \`)",
"components/viewLayout/viewLayoutToolbar.tsx:69: console.log('selected', value);",
"components/viewLayout/viewLayoutToolbar.tsx:77: console.log('selected', value);",
"helpers/queryHelpers.ts:70: console.log(\`Query: \`, query);",
"helpers/queryHelpers.ts:75: console.error(error);",
"helpers/queryHelpers.ts:75: console.log(\`Query: \`, query);",
"helpers/queryHelpers.ts:80: console.error(error);",
"hooks/useCredentialApi.ts:81: console.log(missingCredsMsg);",
"hooks/useCredentialApi.ts:99: console.log(missingCredsMsg);",
"hooks/useCredentialApi.ts:145: console.error(error);",
Expand Down

0 comments on commit 21d441f

Please sign in to comment.