-
Notifications
You must be signed in to change notification settings - Fork 15
Description
Goes with #1178. We don't want to do refetching haphazardly and opaquely; we want to give the user control.
Figma
Implementation thoughts
We are probably using the picker to get a value for RQ refetchInterval. No other approach comes to mind. In order to make this value available to the useQuery call is, either there needs to be a hook, or we could go the traditional route and use local state and a Listbox with an onChange. This is simple enough that it should probably just be a hook that wraps everything up. On the other hand I had some trouble with the date range picker hook returning an element that caused me to refactor it in #1225 into a hook for the state + a normal component. The normal component is definitely more testable.
const { refetchInterval, refetchIntervalPicker } = useRefetchIntervalPicker()
const { data, dataUpdatedAt } = useApiQuery('organizationList', {}, { refetchInterval })
return (
<>
<DataUpdatedAt ts={dataUpdatedAt} />
{refetchIntervalPicker}
</>
)useQuery returns a dataUpdatedAt timestamp we can use for the Updated 15 seconds ago bit. The hook needs to return false if refetch is set to Off because that's what RQ wants.
Note that the hook can't handle rendering the timestamp because that depends on the useQuery. We could however write a new hook useRefetchApiQuery() 😁 that combines both — it would keep the same calling interface as useApiQuery(), the only difference would be that it would also return the picker to render. But we tend to regret making combined things like this without trying the separated version first.
