-
Notifications
You must be signed in to change notification settings - Fork 367
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
tech-story: [M3-8940] - Dev Tools fixes and improvements #11328
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e6f93b4
nested JSON flags
abailly-akamai 75217ec
fix overflow
abailly-akamai 9f29642
Styling updates
abailly-akamai a23e596
save progress
abailly-akamai f4bb4a8
save progress
abailly-akamai 4a10cfe
Fix types
abailly-akamai 78c75bd
Wrapping up account customization
abailly-akamai ad19f6d
form improvements profile
abailly-akamai a50b984
cleanup
abailly-akamai 4e96279
Added changeset: Dev Tools fixes and improvements
abailly-akamai 33438f1
fix flake
abailly-akamai af6d982
feedback @jaalah-akamai
abailly-akamai 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 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
5 changes: 5 additions & 0 deletions
5
packages/manager/.changeset/pr-11328-tech-stories-1732650627657.md
This file contains 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,5 @@ | ||
--- | ||
"@linode/manager": Tech Stories | ||
--- | ||
|
||
Dev Tools fixes and improvements ([#11328](https://github.com/linode/manager/pull/11328)) |
File renamed without changes.
This file contains 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 |
---|---|---|
|
@@ -39,28 +39,85 @@ const options: { flag: keyof Flags; label: string }[] = [ | |
{ flag: 'iam', label: 'Identity and Access Beta' }, | ||
]; | ||
|
||
interface RenderFlagItemProps { | ||
label: string; | ||
onCheck: (e: React.ChangeEvent, flag: string) => void; | ||
path: string; | ||
searchTerm: string; | ||
value: boolean | object | string | undefined; | ||
} | ||
|
||
const renderFlagItem = ({ | ||
label, | ||
onCheck, | ||
path = '', | ||
searchTerm, | ||
value, | ||
}: RenderFlagItemProps) => { | ||
const isObject = typeof value === 'object' && value !== null; | ||
|
||
if (!isObject) { | ||
return ( | ||
<label title={label}> | ||
<input | ||
checked={Boolean(value)} | ||
onChange={(e) => onCheck(e, path || label)} | ||
type="checkbox" | ||
/> | ||
{label} | ||
</label> | ||
); | ||
} | ||
|
||
const sortedEntries = Object.entries(value).sort((a, b) => | ||
a[0].localeCompare(b[0]) | ||
); | ||
|
||
return ( | ||
<ul> | ||
<details> | ||
<summary>{label}</summary> | ||
{sortedEntries.map(([key, nestedValue], index) => ( | ||
<li key={`${key}-${index}`}> | ||
{renderFlagItem({ | ||
label: key, | ||
onCheck, | ||
path: path ? `${path}.${key}` : key, | ||
searchTerm, | ||
value: nestedValue, | ||
})} | ||
</li> | ||
))} | ||
</details> | ||
</ul> | ||
); | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Allowing recursiveness so the JSON flag can be as deep as needed and represented here Left to do: handle the cases for when a flag is something else than a boolean, which we rarely do |
||
|
||
const renderFlagItems = ( | ||
flags: Partial<Flags>, | ||
onCheck: (e: React.ChangeEvent, flag: string) => void | ||
onCheck: (e: React.ChangeEvent, flag: string) => void, | ||
searchTerm: string | ||
) => { | ||
return options.map((option) => { | ||
const sortedOptions = options.sort((a, b) => a.label.localeCompare(b.label)); | ||
return sortedOptions.map((option) => { | ||
const flagValue = flags[option.flag]; | ||
const isChecked = | ||
typeof flagValue === 'object' && 'enabled' in flagValue | ||
? Boolean(flagValue.enabled) | ||
: Boolean(flagValue); | ||
const isSearchMatch = option.label | ||
.toLowerCase() | ||
.includes(searchTerm.toLowerCase()); | ||
|
||
if (!isSearchMatch) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<li key={option.flag}> | ||
<input | ||
style={{ | ||
marginRight: 12, | ||
}} | ||
checked={isChecked} | ||
onChange={(e) => onCheck(e, option.flag)} | ||
type="checkbox" | ||
/> | ||
<span title={option.label}>{option.label}</span> | ||
{renderFlagItem({ | ||
label: option.label, | ||
onCheck, | ||
path: option.flag, | ||
searchTerm, | ||
value: flagValue, | ||
})} | ||
</li> | ||
); | ||
}); | ||
|
@@ -70,6 +127,7 @@ export const FeatureFlagTool = withFeatureFlagProvider(() => { | |
const dispatch: Dispatch = useDispatch(); | ||
const flags = useFlags(); | ||
const ldFlags = ldUseFlags(); | ||
const [searchTerm, setSearchTerm] = React.useState(''); | ||
|
||
React.useEffect(() => { | ||
const storedFlags = getStorage(MOCK_FEATURE_FLAGS_STORAGE_KEY); | ||
|
@@ -82,15 +140,33 @@ export const FeatureFlagTool = withFeatureFlagProvider(() => { | |
e: React.ChangeEvent<HTMLInputElement>, | ||
flag: keyof FlagSet | ||
) => { | ||
const currentFlag = flags[flag]; | ||
const updatedValue = | ||
typeof currentFlag == 'object' && 'enabled' in currentFlag | ||
? { ...currentFlag, enabled: e.target.checked } // If current flag is an object, update 'enabled' key | ||
: e.target.checked; | ||
const updatedFlags = { | ||
...getStorage(MOCK_FEATURE_FLAGS_STORAGE_KEY), | ||
[flag]: updatedValue, | ||
}; | ||
const updatedValue = e.target.checked; | ||
const storedFlags = getStorage(MOCK_FEATURE_FLAGS_STORAGE_KEY) || {}; | ||
|
||
const flagParts = flag.split('.'); | ||
const updatedFlags = { ...storedFlags }; | ||
|
||
// If the flag is not a nested flag, update it directly | ||
if (flagParts.length === 1) { | ||
updatedFlags[flag] = updatedValue; | ||
} else { | ||
abailly-akamai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// If the flag is a nested flag, update the specific property that changed | ||
const [parentKey, childKey] = flagParts; | ||
const currentParentValue = ldFlags[parentKey]; | ||
const existingValues = storedFlags[parentKey] || {}; | ||
|
||
// Only update the specific property that changed | ||
updatedFlags[parentKey] = { | ||
...currentParentValue, // Keep original LD values | ||
...existingValues, // Apply any existing stored overrides | ||
[childKey]: updatedValue, // Apply the new change | ||
}; | ||
} | ||
|
||
updateFlagStorage(updatedFlags); | ||
}; | ||
|
||
const updateFlagStorage = (updatedFlags: object) => { | ||
dispatch(setMockFeatureFlags(updatedFlags)); | ||
setStorage(MOCK_FEATURE_FLAGS_STORAGE_KEY, JSON.stringify(updatedFlags)); | ||
abailly-akamai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
@@ -103,6 +179,10 @@ export const FeatureFlagTool = withFeatureFlagProvider(() => { | |
setStorage(MOCK_FEATURE_FLAGS_STORAGE_KEY, ''); | ||
}; | ||
|
||
const handleSearch = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
setSearchTerm(e.target.value); | ||
}; | ||
|
||
return ( | ||
<div className="dev-tools__tool"> | ||
<div className="dev-tools__tool__header"> | ||
|
@@ -112,7 +192,13 @@ export const FeatureFlagTool = withFeatureFlagProvider(() => { | |
</div> | ||
<div className="dev-tools__tool__body"> | ||
<div className="dev-tools__list-box"> | ||
<ul>{renderFlagItems(flags, handleCheck)}</ul> | ||
<input | ||
onChange={handleSearch} | ||
placeholder="Search feature flags" | ||
style={{ margin: 12 }} | ||
type="text" | ||
/> | ||
<ul>{renderFlagItems(flags, handleCheck, searchTerm)}</ul> | ||
</div> | ||
</div> | ||
<div className="dev-tools__tool__footer"> | ||
|
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.
This changes nothing to the types, just allows to export the values