Skip to content

Conversation

@david-crespo
Copy link
Collaborator

@david-crespo david-crespo commented Oct 20, 2022

In #1225 I split the picker into a component and a hook, and callers have to use both. As I tried to work on the refetch interval picker, I got madder and madder about that setup, so this is me cleaning that up. The real problem I had that caused the original refactor was that the tests weren't working as I expected. Because the component is split out nicely, the tests can exercise the component but I can still use the hook that wraps the component for the actual code.

Despite the branch name, this does not add any refetch controls. One real change that's made here is the behavior is more correct when switching range presets. As you would expect, the old refetch interval is cleared when the new one is created.

@vercel
Copy link

vercel bot commented Oct 20, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
console-ui-storybook ✅ Ready (Inspect) Visit Preview Nov 9, 2022 at 9:17PM (UTC)

@david-crespo david-crespo changed the title Refetch interval control Refetch button and auto toggle Nov 9, 2022

return () => vi.useRealTimers()
})

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this wasn't working before, now it is? ok

setStartTime(newStart)
setEndTime(newEnd)
}
}, [])
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly no reason not to memoize here. And I need it in the picker because a useCallback depends on this.

@david-crespo david-crespo changed the title Refetch button and auto toggle Refactor DateTimeRangePicker Nov 9, 2022
@david-crespo david-crespo changed the title Refactor DateTimeRangePicker Refactor DateTimeRangePicker again Nov 9, 2022
const intervalId = setInterval(() => callbackRef.current?.(), delay)
return () => clearInterval(intervalId)
}, [delay])
}, [delay, key])
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without key, this will only clear (and possibly remake) the interval if the delay changes. But if you want to delete and remake the interval while keeping the delay the same, you change key.

@david-crespo david-crespo merged commit c910d20 into main Nov 9, 2022
@david-crespo david-crespo deleted the refetch-control branch November 9, 2022 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants