-
Notifications
You must be signed in to change notification settings - Fork 556
fix(onboarding): don't create or change flags in a project already in use #8217
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
Closed
talissoncosta
wants to merge
6
commits into
main
from
fix/onboarding-skip-flag-creation-existing-project
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
822408f
fix(onboarding): don't seed a demo flag into a project that has flags
talissoncosta 58fe0f4
chore(onboarding): move the non-hooks out of the hooks folder
talissoncosta 533a77f
fix(onboarding): only tour a flag we created
talissoncosta e85a053
fix(onboarding): stop polling when there is no flag to tour
talissoncosta 5ff882b
fix(onboarding): don't fail onboarding when the tag lookup fails
talissoncosta 1815f7d
fix(onboarding): recognise our own flag instead of refusing to tour
talissoncosta 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
Some comments aren't visible on the classic Files Changed page.
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
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
66 changes: 66 additions & 0 deletions
66
frontend/web/components/pages/onboarding/bootstrap/__tests__/demoFlag.test.ts
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,66 @@ | ||
| import { ProjectFlag, Tag } from 'common/types/responses' | ||
| import { | ||
| DEMO_FLAG_DESCRIPTION, | ||
| DEMO_FLAG_NAME, | ||
| ONBOARDING_TAG, | ||
| findDemoFlag, | ||
| findOnboardingTag, | ||
| } from 'components/pages/onboarding/bootstrap/demoFlag' | ||
|
|
||
| const flag = ( | ||
| name: string, | ||
| { description = '', tags = [] }: { description?: string; tags?: number[] } = {}, | ||
| ): ProjectFlag => ({ description, id: name.length, name, tags } as ProjectFlag) | ||
|
|
||
| const onboardingTag = { id: 7, ...ONBOARDING_TAG } as Tag | ||
|
|
||
| describe('findOnboardingTag', () => { | ||
| it('finds the tag a previous run created', () => { | ||
| expect( | ||
| findOnboardingTag([{ id: 3, label: 'Backend' } as Tag, onboardingTag]), | ||
| ).toBe(onboardingTag) | ||
| }) | ||
|
|
||
| it('ignores a tag the customer labelled Onboarding themselves', () => { | ||
| const theirs = { | ||
| description: 'Flags behind our signup flow', | ||
| id: 9, | ||
| label: 'Onboarding', | ||
| } as Tag | ||
| expect(findOnboardingTag([theirs])).toBeUndefined() | ||
| }) | ||
| }) | ||
|
|
||
| describe('findDemoFlag', () => { | ||
| it('finds a previous run by its tag, whatever it was renamed to', () => { | ||
| const renamed = flag('my_own_name', { tags: [onboardingTag.id] }) | ||
| expect( | ||
|
Check failure on line 37 in frontend/web/components/pages/onboarding/bootstrap/__tests__/demoFlag.test.ts
|
||
| findDemoFlag([flag('checkout_v2'), renamed], onboardingTag), | ||
| ).toBe(renamed) | ||
| }) | ||
|
|
||
| it('prefers the tag over anything else when both are present', () => { | ||
| const tagged = flag('renamed_by_hand', { tags: [onboardingTag.id] }) | ||
| const named = flag(DEMO_FLAG_NAME) | ||
| expect(findDemoFlag([named, tagged], onboardingTag)).toBe(tagged) | ||
| }) | ||
|
|
||
| it('falls back to our description when the tag is gone', () => { | ||
| // The rename carries the description over, so it outlives the name. | ||
| const renamed = flag('my_own_name', { description: DEMO_FLAG_DESCRIPTION }) | ||
| expect(findDemoFlag([flag('checkout_v2'), renamed], undefined)).toBe(renamed) | ||
| }) | ||
|
|
||
| it('falls back to the name for a flag seeded before we set a description', () => { | ||
| const legacy = flag(DEMO_FLAG_NAME) | ||
| expect(findDemoFlag([flag('checkout_v2'), legacy], undefined)).toBe(legacy) | ||
| }) | ||
|
|
||
| it('finds nothing in a project that never ran the tour', () => { | ||
| expect(findDemoFlag([flag('checkout_v2')], onboardingTag)).toBeUndefined() | ||
| }) | ||
|
|
||
| it('finds nothing in an empty project', () => { | ||
| expect(findDemoFlag([], onboardingTag)).toBeUndefined() | ||
| }) | ||
| }) | ||
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
File renamed without changes.
34 changes: 34 additions & 0 deletions
34
frontend/web/components/pages/onboarding/bootstrap/demoFlag.ts
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,34 @@ | ||
| import { ProjectFlag, Tag } from 'common/types/responses' | ||
|
|
||
| export const DEMO_FLAG_NAME = 'show_demo_button' | ||
|
|
||
| // Set on the flag we create, and carried over by the tour's rename, so it | ||
| // identifies our flag after the name has changed. Also tells anyone looking at | ||
| // their flag list why it is there. | ||
| export const DEMO_FLAG_DESCRIPTION = 'Created during onboarding' | ||
|
|
||
| export const ONBOARDING_TAG = { | ||
| color: '#3cb371', | ||
| description: DEMO_FLAG_DESCRIPTION, | ||
| label: 'Onboarding', | ||
| } | ||
|
|
||
| // Description too: a customer's own tag labelled Onboarding is not ours. | ||
| export const findOnboardingTag = (tags: Tag[]): Tag | undefined => | ||
| tags.find( | ||
| (t) => | ||
| t.label === ONBOARDING_TAG.label && | ||
| t.description === ONBOARDING_TAG.description, | ||
| ) | ||
|
|
||
| // Our flag, in descending order of how much the signal is worth. The tour | ||
| // renames by delete and recreate, carrying the tags and description over, so | ||
| // the name is the one thing that doesn't survive it: it only identifies flags | ||
| // seeded before we set a description. | ||
| export const findDemoFlag = ( | ||
| flags: ProjectFlag[], | ||
| onboardingTag?: Tag, | ||
| ): ProjectFlag | undefined => | ||
| (onboardingTag && flags.find((f) => f.tags?.includes(onboardingTag.id))) || | ||
| flags.find((f) => f.description === DEMO_FLAG_DESCRIPTION) || | ||
| flags.find((f) => f.name === DEMO_FLAG_NAME) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
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.
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 feel like silencing the error prevents us from at least retrying once maybe ? I'm thinking that if there has been a renaming, the tag would be the only option to resume the tour right ?