Skip to content

Commit

Permalink
change: [UIE-8082] - DBaaS GA Database Create GA review fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mpolotsk-akamai committed Nov 4, 2024
1 parent 5a676c7 commit 6f1b77e
Show file tree
Hide file tree
Showing 13 changed files with 294 additions and 278 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe('PrimaryNav', () => {

it('should show Databases menu item if the user has the account capability V2', async () => {
const account = accountFactory.build({
capabilities: ['Managed Databases Beta'],
capabilities: ['Managed Databases'],
});

server.use(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import Grid from '@mui/material/Unstable_Grid2';
import { groupBy } from 'ramda';
import React from 'react';

import MongoDBIcon from 'src/assets/icons/mongodb.svg';
import MySQLIcon from 'src/assets/icons/mysql.svg';
import PostgreSQLIcon from 'src/assets/icons/postgresql.svg';
import { Divider } from 'src/components/Divider';
import Select from 'src/components/EnhancedSelect';
import { _SingleValue } from 'src/components/EnhancedSelect/components/SingleValue';
import { RegionSelect } from 'src/components/RegionSelect/RegionSelect';
import { RegionHelperText } from 'src/components/SelectRegionPanel/RegionHelperText';
import { TextField } from 'src/components/TextField';
import { Typography } from 'src/components/Typography';
import { useStyles } from 'src/features/Databases/DatabaseCreate/DatabaseCreate.style';
import {
StyledLabelTooltip,
StyledTextField,
} from 'src/features/Databases/DatabaseCreate/DatabaseCreate.style';
import { EngineOption } from 'src/features/Databases/DatabaseCreate/EngineOption';
import { databaseEngineMap } from 'src/features/Databases/DatabaseLanding/DatabaseRow';
import { useRestrictedGlobalGrantCheck } from 'src/hooks/useRestrictedGlobalGrantCheck';
import { getSelectedOptionFromGroupedOptions } from 'src/utilities/getSelectedOptionFromGroupedOptions';

import { getEngineOptions } from './utilities';

import type {
ClusterSize,
ComprehensiveReplicationType,
Expand All @@ -42,7 +42,6 @@ export interface DatabaseCreateValues {
storage_engine: undefined;
type: string;
}
import { useRestrictedGlobalGrantCheck } from 'src/hooks/useRestrictedGlobalGrantCheck';

interface Props {
engines: DatabaseEngine[] | undefined;
Expand All @@ -53,60 +52,9 @@ interface Props {
}
export const DatabaseClusterData = (props: Props) => {
const { engines, errors, onChange, regionsData, values } = props;
const { classes } = useStyles();
const engineIcons = {
mongodb: <MongoDBIcon height="24" width="24" />,
mysql: <MySQLIcon height="24" width="24" />,
postgresql: <PostgreSQLIcon height="24" width="24" />,
redis: null,
};
const isRestricted = useRestrictedGlobalGrantCheck({
globalGrantType: 'add_databases',
});
const getEngineOptions = (engines: DatabaseEngine[]) => {
const groupedEngines = groupBy<DatabaseEngine>((engineObject) => {
if (engineObject.engine.match(/mysql/i)) {
return 'MySQL';
}
if (engineObject.engine.match(/postgresql/i)) {
return 'PostgreSQL';
}
if (engineObject.engine.match(/mongodb/i)) {
return 'MongoDB';
}
if (engineObject.engine.match(/redis/i)) {
return 'Redis';
}
return 'Other';
}, engines);
return ['MySQL', 'PostgreSQL', 'MongoDB', 'Redis', 'Other'].reduce(
(accum, thisGroup) => {
if (
!groupedEngines[thisGroup] ||
groupedEngines[thisGroup].length === 0
) {
return accum;
}
return [
...accum,
{
label: thisGroup,
options: groupedEngines[thisGroup]
.map((engineObject) => ({
...engineObject,
flag: engineIcons[engineObject.engine],
label: `${databaseEngineMap[engineObject.engine]} v${
engineObject.version
}`,
value: `${engineObject.engine}/${engineObject.version}`,
}))
.sort((a, b) => (a.version > b.version ? -1 : 1)),
},
];
},
[]
);
};

const engineOptions = React.useMemo(() => {
if (!engines) {
Expand All @@ -116,34 +64,34 @@ export const DatabaseClusterData = (props: Props) => {
}, [engines]);

const labelToolTip = (
<div className={classes.labelToolTipCtn}>
<StyledLabelTooltip>
<strong>Label must:</strong>
<ul>
<li>Begin with an alpha character</li>
<li>Contain only alpha characters or single hyphens</li>
<li>Be between 3 - 32 characters</li>
</ul>
</div>
</StyledLabelTooltip>
);

return (
<>
<Grid>
<Typography variant="h2">Name Your Cluster</Typography>
<TextField
<StyledTextField
data-qa-label-input
errorText={errors.label}
disabled={isRestricted}
errorText={errors.label}
label="Cluster Label"
onChange={(e) => onChange('label', e.target.value)}
tooltipClasses={classes.tooltip}
tooltipText={labelToolTip}
value={values.label}
/>
</Grid>
<Divider spacingBottom={12} spacingTop={38} />
<Grid>
<Typography variant="h2">Select Engine and Region</Typography>
{/* TODO: use Autocomplete instead of Select */}
<Select
onChange={(selected: Item<string>) => {
onChange('engine', selected.value);
Expand All @@ -152,14 +100,13 @@ export const DatabaseClusterData = (props: Props) => {
values.engine,
engineOptions
)}
className={classes.engineSelect}
components={{ Option: EngineOption, SingleValue: _SingleValue }}
disabled={isRestricted}
errorText={errors.engine}
isClearable={false}
label="Database Engine"
options={engineOptions}
placeholder={'Select a Database Engine'}
placeholder="Select a Database Engine"
/>
</Grid>
<Grid>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,88 +1,92 @@
import { makeStyles } from 'tss-react/mui';
import { Box } from '@linode/ui';
import { Grid, styled } from '@mui/material';

import type { Theme } from '@mui/material';
import { Autocomplete } from 'src/components/Autocomplete/Autocomplete';
import { Button } from 'src/components/Button/Button';
import { TextField } from 'src/components/TextField';
import { Typography } from 'src/components/Typography';
import { PlansPanel } from 'src/features/components/PlansPanel/PlansPanel';

export const useStyles = makeStyles()((theme: Theme) => ({
btnCtn: {
alignItems: 'center',
display: 'flex',
justifyContent: 'flex-end',
marginTop: theme.spacing(2),
[theme.breakpoints.down('sm')]: {
alignItems: 'flex-end',
flexDirection: 'column',
marginTop: theme.spacing(),
},
},
chip: {
marginLeft: 6,
marginTop: 4,
export const StyledLabelTooltip = styled(Box, {
label: 'StyledLabelTooltip',
})(() => ({
'& strong': {
padding: 8,
},
createBtn: {
[theme.breakpoints.down('md')]: {
marginRight: theme.spacing(),
},
whiteSpace: 'nowrap',
'& ul': {
margin: '4px',
},
createText: {
marginLeft: theme.spacing(),
marginRight: theme.spacing(3),
[theme.breakpoints.down('sm')]: {
marginRight: 0,
padding: theme.spacing(),
}));

export const StyledTextField = styled(TextField, {
label: 'StyledTextField',
})(({ theme }) => ({
'& .MuiTooltip-tooltip': {
[theme.breakpoints.up('md')]: {
minWidth: 350,
},
},
disabledOptionLabel: {
color:
theme.palette.mode === 'dark' ? theme.color.grey6 : theme.color.grey1,
},
engineSelect: {
'& .react-select__option--is-focused': {
'&:not(.react-select__option--is-selected)': {
'& svg': {
filter: 'brightness(0) invert(1)',
},
}));

export const StyledEngineSelect = styled(Autocomplete, {
label: 'StyledTextField',
})(() => ({
'& .react-select__option--is-focused': {
'&:not(.react-select__option--is-selected)': {
'& svg': {
filter: 'brightness(0) invert(1)',
},
},
},
formControlLabel: {
marginBottom: theme.spacing(),
},
labelToolTipCtn: {
'& strong': {
padding: 8,
},
'& ul': {
margin: '4px',
},
},
nodeHelpIcon: {
marginTop: '-2px',
padding: '0px 0px 0px 2px',
},
nodeSpanSpacing: {
marginRight: theme.spacing(1),
},
notice: {
fontSize: 15,
lineHeight: '18px',
},
selectPlanPanel: {
margin: 0,
padding: 0,
}));

export const StyledPlansPanel = styled(PlansPanel, {
label: 'StyledPlansPanel',
})(() => ({
margin: 0,
padding: 0,
}));

export const StyledBtnCtn = styled(Grid, {
label: 'StyledBtnCtn',
})(({ theme }) => ({
alignItems: 'center',
display: 'flex',
justifyContent: 'flex-end',
marginTop: theme.spacing(2),
[theme.breakpoints.down('sm')]: {
alignItems: 'flex-end',
flexDirection: 'column',
marginTop: theme.spacing(),
},
summarySpanBorder: {
borderRight: `1px solid ${theme.borderColors.borderTypography}`,
color: theme.textColors.tableStatic,
marginLeft: theme.spacing(1),
marginRight: theme.spacing(1),
paddingRight: theme.spacing(1),
}));

export const StyledCreateBtn = styled(Button, {
label: 'StyledCreateBtn',
})(({ theme }) => ({
[theme.breakpoints.down('md')]: {
marginRight: theme.spacing(),
},
tooltip: {
'& .MuiTooltip-tooltip': {
[theme.breakpoints.up('md')]: {
minWidth: 350,
},
},
whiteSpace: 'nowrap',
}));

export const StyledTypography = styled(Typography, {
label: 'StyledTypography',
})(({ theme }) => ({
marginLeft: theme.spacing(),
marginRight: theme.spacing(3),
[theme.breakpoints.down('sm')]: {
marginRight: 0,
padding: theme.spacing(),
},
}));

export const StyledSpan = styled('span', {
label: 'StyledSpan',
})(({ theme }) => ({
borderRight: `1px solid ${theme.borderColors.borderTypography}`,
color: theme.textColors.tableStatic,
marginLeft: theme.spacing(1),
marginRight: theme.spacing(1),
paddingRight: theme.spacing(1),
}));
Loading

0 comments on commit 6f1b77e

Please sign in to comment.