-
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
refactor: [UIE-8245] - DBaaS: Replace Select component with Autocomplete #11245
Merged
cpathipa
merged 4 commits into
linode:develop
from
mpolotsk-akamai:change-select-to-autocomplete
Nov 15, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3a46db8
change: [UIE-8245] - DBaaS: replace Select with Autocomplete
mpolotsk-akamai ce8e226
change: [UIE-8245] - DBaaS: replace Select with Autocomplete (Settingβ¦
mpolotsk-akamai 7f4a0ef
Added changeset: Replace Select component with Autocomplete
mpolotsk-akamai 611e4ca
change: [UIE-8245] - review fix, show default engine
mpolotsk-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
5 changes: 5 additions & 0 deletions
5
packages/manager/.changeset/pr-11245-changed-1731425235091.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": Changed | ||
--- | ||
|
||
Replace Select component with Autocomplete in DBaaS ([#11245](https://github.com/linode/manager/pull/11245)) |
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
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
90 changes: 90 additions & 0 deletions
90
packages/manager/src/features/Databases/DatabaseCreate/DatabaseEngineSelect.tsx
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,90 @@ | ||
import { Box } from '@linode/ui'; | ||
import Grid from '@mui/material/Unstable_Grid2'; | ||
import React from 'react'; | ||
|
||
import { Autocomplete } from 'src/components/Autocomplete/Autocomplete'; | ||
import { getEngineOptions } from 'src/features/Databases/DatabaseCreate/utilities'; | ||
import { useRestrictedGlobalGrantCheck } from 'src/hooks/useRestrictedGlobalGrantCheck'; | ||
|
||
import type { DatabaseEngine } from '@linode/api-v4'; | ||
|
||
interface Props { | ||
engines: DatabaseEngine[] | undefined; | ||
errorText: string | undefined; | ||
onChange: (filed: string, value: any) => void; | ||
value: string; | ||
} | ||
|
||
export const DatabaseEngineSelect = (props: Props) => { | ||
const { engines, errorText, onChange, value } = props; | ||
const isRestricted = useRestrictedGlobalGrantCheck({ | ||
globalGrantType: 'add_databases', | ||
}); | ||
|
||
const engineOptions = React.useMemo(() => { | ||
if (!engines) { | ||
return []; | ||
} | ||
return getEngineOptions(engines); | ||
}, [engines]); | ||
|
||
const selectedEngine = React.useMemo(() => { | ||
return engineOptions.find((val) => val.value === value); | ||
}, [value, engineOptions]); | ||
|
||
return ( | ||
<Autocomplete | ||
groupBy={(option) => { | ||
if (option.engine.match(/mysql/i)) { | ||
return 'MySQL'; | ||
} | ||
if (option.engine.match(/postgresql/i)) { | ||
return 'PostgreSQL'; | ||
} | ||
if (option.engine.match(/mongodb/i)) { | ||
return 'MongoDB'; | ||
} | ||
if (option.engine.match(/redis/i)) { | ||
return 'Redis'; | ||
} | ||
return 'Other'; | ||
}} | ||
onChange={(_, selected) => { | ||
onChange('engine', selected.value); | ||
}} | ||
renderOption={(props, option) => { | ||
const { key, ...rest } = props; | ||
return ( | ||
<li {...rest} data-testid="db-engine-option" key={key}> | ||
<Grid | ||
alignItems="center" | ||
container | ||
direction="row" | ||
justifyContent="flex-start" | ||
spacing={2} | ||
> | ||
<Grid className="py0">{option.flag}</Grid> | ||
<Grid>{option.label}</Grid> | ||
</Grid> | ||
</li> | ||
); | ||
}} | ||
textFieldProps={{ | ||
InputProps: { | ||
startAdornment: ( | ||
<Box sx={{ pr: 1, pt: 0.7 }}>{selectedEngine?.flag}</Box> | ||
), | ||
}, | ||
}} | ||
autoHighlight | ||
disableClearable | ||
disabled={isRestricted} | ||
errorText={errorText} | ||
isOptionEqualToValue={(option, value) => option.value === value.value} | ||
label="Database Engine" | ||
options={engineOptions ?? []} | ||
placeholder="Select a Database Engine" | ||
mjac0bs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
value={selectedEngine} | ||
/> | ||
); | ||
}; |
54 changes: 0 additions & 54 deletions
54
packages/manager/src/features/Databases/DatabaseCreate/EngineOption.tsx
This file was deleted.
Oops, something went wrong.
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
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.
A general note on error handling: surfacing the API error looks good. But I am wondering what happened to our schema validation on this field - it doesn't appear to be validating the Engine in prod, either, so this was an existing issue - optional but encouraged to address here. The engine field's behavior would ideally be consistent with that of other fields, validating before we get that API error. If not addressed in this PR, could you create a follow up to address?
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.
The schema validation didn't work because the field wasnβt empty; it had a default value intended to display prices in the Plan Table, which caused a minor bug. After discussing with Amit, I fixed it to properly display the default value in the 'Select a Database Engine' field.
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.
Ah, I see. Thanks for looking into this. Things for further consideration by you, the rest of the DBaaS folks, and UX: Is showing the priced plans in the Plan Table prior to any Engine selection a requirement? And does surfacing a default Engine selection have any implications we want to avoid?
In other sections of the app, when we require a selection (in this case, region) to be made first, we display the following in the Plan Table. I'm wondering if a 'Select an engine to view plans and prices' would be desirable for consistency here.
I think that change would probably require more code changes even further outside the scope of the Autocomplete swap, so potentially a follow up.