-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: [UIE-8245] - DBaaS: Replace Select component with Autocompl…
…ete (#11245) * change: [UIE-8245] - DBaaS: replace Select with Autocomplete * change: [UIE-8245] - DBaaS: replace Select with Autocomplete (Settings Tab) * Added changeset: Replace Select component with Autocomplete * change: [UIE-8245] - review fix, show default engine
- Loading branch information
1 parent
727dc75
commit 6898013
Showing
7 changed files
with
145 additions
and
154 deletions.
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" | ||
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.