-
Notifications
You must be signed in to change notification settings - Fork 535
feat(experiments): wire up results refresh with a shared RefreshControl #7857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Zaimwa9
wants to merge
4
commits into
main
Choose a base branch
from
feat/experiment-results-refresh
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+507
−78
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0c77d12
feat(experiments): share RefreshControl and wire up results refresh
Zaimwa9 1f093fa
Merge branch 'main' of github.com:Flagsmith/flagsmith into worktree-s…
Zaimwa9 10fe499
fix(experiments): move results refresh to the Results heading and sto…
Zaimwa9 b89f2f7
fix(experiments): keep refresh button in loading state until recomput…
Zaimwa9 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
frontend/documentation/components/RefreshControl.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| import React from 'react' | ||
| import type { Meta, StoryObj } from 'storybook' | ||
|
|
||
| import RefreshControl from 'components/base/forms/RefreshControl' | ||
| import { themeClassNames } from 'components/base/forms/Button' | ||
|
|
||
| const themeOptions = Object.keys(themeClassNames) as Array< | ||
| keyof typeof themeClassNames | ||
| > | ||
|
|
||
| const meta: Meta<typeof RefreshControl> = { | ||
| argTypes: { | ||
| children: { | ||
| control: 'text', | ||
| description: 'Button label. Defaults to "Refresh".', | ||
| }, | ||
| disabled: { | ||
| control: 'boolean', | ||
| description: 'Disables the button, preventing interaction.', | ||
| }, | ||
| disabledReason: { | ||
| control: 'text', | ||
| description: 'Tooltip explaining why the button is disabled.', | ||
| }, | ||
| isRefreshing: { | ||
| control: 'boolean', | ||
| description: | ||
| 'Shows a busy label and disables the button while a refresh is in flight.', | ||
| }, | ||
| label: { | ||
| control: 'text', | ||
| description: | ||
| 'Related message rendered beneath the button — e.g. a retry countdown, an in-progress notice, or an error.', | ||
| }, | ||
| theme: { | ||
| control: 'select', | ||
| description: 'Visual variant of the button.', | ||
| options: themeOptions, | ||
| table: { defaultValue: { summary: 'secondary' } }, | ||
| }, | ||
| }, | ||
| args: { | ||
| children: 'Refresh', | ||
| disabled: false, | ||
| isRefreshing: false, | ||
| onRefresh: () => {}, | ||
| theme: 'secondary', | ||
| }, | ||
| component: RefreshControl, | ||
| parameters: { layout: 'centered' }, | ||
| title: 'Components/RefreshControl', | ||
| } | ||
|
|
||
| export default meta | ||
|
|
||
| type Story = StoryObj<typeof RefreshControl> | ||
|
|
||
| export const Default: Story = {} | ||
|
|
||
| export const Refreshing: Story = { | ||
| args: { | ||
| isRefreshing: true, | ||
| label: 'Computing… results will update automatically.', | ||
| }, | ||
| parameters: { | ||
| docs: { | ||
| description: { | ||
| story: | ||
| 'While a refresh is in flight the button shows a busy label and disables itself. The `label` slot carries the in-progress message.', | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| export const Throttled: Story = { | ||
| args: { | ||
| disabled: true, | ||
| label: 'Computing, retry in 4m 30s', | ||
| }, | ||
| parameters: { | ||
| docs: { | ||
| description: { | ||
| story: | ||
| 'After hitting the API rate limit (HTTP 429), the caller disables the button and feeds a Retry-After countdown into `label`.', | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| export const Disabled: Story = { | ||
| args: { | ||
| disabled: true, | ||
| disabledReason: 'Refresh is disabled because the experiment is complete.', | ||
| }, | ||
| parameters: { | ||
| docs: { | ||
| description: { | ||
| story: | ||
| 'Disabled state with a `disabledReason` surfaced as the button tooltip.', | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| export const PrimaryWithError: Story = { | ||
| args: { | ||
| children: 'Refresh results', | ||
| label: ( | ||
| <span className='text-danger'>The last results computation failed.</span> | ||
| ), | ||
| theme: 'primary', | ||
| }, | ||
| parameters: { | ||
| docs: { | ||
| description: { | ||
| story: | ||
| 'Primary theme as used on the experiment results header, with an error message in the `label` slot.', | ||
| }, | ||
| }, | ||
| }, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { FC, ReactNode } from 'react' | ||
| import Button, { themeClassNames } from './Button' | ||
|
|
||
| type RefreshControlProps = { | ||
| onRefresh: () => void | ||
| isRefreshing: boolean | ||
| disabled: boolean | ||
| disabledReason?: string | ||
| theme?: keyof typeof themeClassNames | ||
| label?: ReactNode | ||
| children?: ReactNode | ||
| } | ||
|
|
||
| const RefreshControl: FC<RefreshControlProps> = ({ | ||
| children, | ||
| disabled, | ||
| disabledReason, | ||
| isRefreshing, | ||
| label, | ||
| onRefresh, | ||
| theme = 'secondary', | ||
| }) => ( | ||
| <div className='d-flex flex-column align-items-end'> | ||
| <Button | ||
| disabled={disabled || isRefreshing} | ||
| onClick={onRefresh} | ||
| size='small' | ||
| theme={theme} | ||
| title={disabled ? disabledReason : undefined} | ||
| > | ||
| {isRefreshing ? 'Refreshing…' : children ?? 'Refresh'} | ||
| </Button> | ||
| {label ? ( | ||
| <div className='text-muted fs-caption mt-1 text-end'>{label}</div> | ||
| ) : null} | ||
| </div> | ||
| ) | ||
|
|
||
| export default RefreshControl | ||
36 changes: 0 additions & 36 deletions
36
frontend/web/components/experiments/results/AsOfRefreshControl.tsx
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd keep this one out of
base/formsand move it next to its consumers inexperiments/results/components.Looking at what it actually does over
Button: swap the label to "Refreshing…", foldisRefreshingintodisabled, mapdisabledReasontotitle, and a caption slot underneath. So it's really "a Button with a loading state" plus a refresh-specific caption, and both its importers are experiment panels. I don't think it earns a spot as a shared primitive yet.By the way, I like the idea of loading state, we should add a
isLoadingprop that can provide this behaviour easily.(if it moves local, the Storybook story can be moved under
Experimentsor be dropped, your call)