Skip to content

Commit aec0007

Browse files
fix: [UIE-8516] - DBaaS: Advanced Config - refactoring, validation fix, unit test
1 parent 6f5958f commit aec0007

8 files changed

Lines changed: 73 additions & 12 deletions

File tree

packages/api-v4/.changeset/pr-11885-changed-1742400890057.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@linode/api-v4": Changed
33
---
44

5-
Remove `engine_config` from the DatabaseEngineConfig type ([#11885](https://github.com/linode/manager/pull/11885))
5+
DBaaS Advanced Configurations: remove `engine_config` from the DatabaseEngineConfig type ([#11885](https://github.com/linode/manager/pull/11885))

packages/api-v4/src/databases/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export interface ConfigurationItem {
5858
maxLength?: number;
5959
minLength?: number;
6060
pattern?: string;
61-
type?: string | number | boolean | [string, null] | string[];
61+
type?: string | [string, null] | string[];
6262
enum?: string[];
6363
restart_cluster?: boolean;
6464
}

packages/manager/src/features/Databases/DatabaseDetail/DatabaseAdvancedConfiguration/DatabaseAdvancedConfiguration.style.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ export const StyledConfigValue = styled(StyledValueGrid, {
99
}));
1010

1111
export const GroupHeader = styled('div')(({ theme }) => ({
12-
background: theme.tokens.color.Neutrals[5],
12+
background:
13+
theme.palette.mode === 'dark'
14+
? theme.tokens.color.Neutrals[90]
15+
: theme.tokens.color.Neutrals[10],
1316
color:
1417
theme.palette.mode === 'dark'
1518
? theme.tokens.color.Neutrals[5]

packages/manager/src/features/Databases/DatabaseDetail/DatabaseAdvancedConfiguration/DatabaseAdvancedConfigurationDrawer.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ import {
2525
convertExistingConfigsToArray,
2626
findConfigItem,
2727
formatConfigPayload,
28-
isConfigBoolean,
29-
isConfigStringWithEnum,
28+
getDefaultConfigValue,
3029
} from '../../utilities';
3130
import { DatabaseConfigurationItem } from './DatabaseConfigurationItem';
3231
import { DatabaseConfigurationSelect } from './DatabaseConfigurationSelect';
@@ -125,11 +124,7 @@ export const DatabaseAdvancedConfigurationDrawer = (props: Props) => {
125124
category: config?.category ?? '',
126125
isNew: true,
127126
label: config?.label ?? '',
128-
value: isConfigBoolean(config)
129-
? false
130-
: isConfigStringWithEnum(config)
131-
? config.enum?.[0] ?? ''
132-
: '',
127+
value: getDefaultConfigValue(config),
133128
});
134129

135130
setSelectedConfig(null);

packages/manager/src/features/Databases/DatabaseDetail/DatabaseAdvancedConfiguration/DatabaseConfigurationItem.style.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ export const StyledWrapper = styled(Box, {
1010
export const StyledBox = styled(Box, {
1111
label: 'StyledBox',
1212
})(({ theme }) => ({
13-
background: theme.tokens.color.Neutrals[5],
13+
background:
14+
theme.palette.mode === 'dark'
15+
? theme.tokens.color.Neutrals[100]
16+
: theme.tokens.color.Neutrals[10],
1417
padding: theme.tokens.spacing.S8,
1518
width: '100%',
1619
}));

packages/manager/src/features/Databases/DatabaseDetail/DatabaseSummary/DatabaseSummaryClusterConfiguration.style.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ export const StyledGridContainer = styled(Grid2, {
2828
export const StyledLabelTypography = styled(Typography, {
2929
label: 'StyledLabelTypography',
3030
})(({ theme }) => ({
31-
background: theme.tokens.color.Neutrals[5],
31+
background:
32+
theme.palette.mode === 'dark'
33+
? theme.tokens.color.Neutrals[100]
34+
: theme.tokens.color.Neutrals[10],
3235
color: theme.palette.mode === 'dark' ? theme.color.grey6 : 'inherit',
3336
font: theme.font.bold,
3437
height: '100%',

packages/manager/src/features/Databases/utilities.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
formatConfigPayload,
1515
formatConfigValue,
1616
getDatabasesDescription,
17+
getDefaultConfigValue,
1718
hasPendingUpdates,
1819
isDateOutsideBackup,
1920
isDefaultDatabase,
@@ -771,3 +772,42 @@ describe('formatConfigPayload', () => {
771772
});
772773
});
773774
});
775+
776+
describe('getDefaultConfigValue', () => {
777+
it('should return false for boolean type', () => {
778+
const config: ConfigurationOption = {
779+
category: '',
780+
label: '',
781+
type: 'boolean',
782+
};
783+
expect(getDefaultConfigValue(config)).toBe(false);
784+
});
785+
786+
it('should return first enum value for string with enum', () => {
787+
const config: ConfigurationOption = {
788+
category: '',
789+
enum: ['option1', 'option2'],
790+
label: '',
791+
type: 'string',
792+
};
793+
expect(getDefaultConfigValue(config)).toBe('option1');
794+
});
795+
796+
it('should return 0 for number type', () => {
797+
const config: ConfigurationOption = {
798+
category: '',
799+
label: '',
800+
type: 'number',
801+
};
802+
expect(getDefaultConfigValue(config)).toBe(0);
803+
});
804+
805+
it('should return 0 for integer type', () => {
806+
const config: ConfigurationOption = {
807+
category: '',
808+
label: '',
809+
type: 'integer',
810+
};
811+
expect(getDefaultConfigValue(config)).toBe(0);
812+
});
813+
});

packages/manager/src/features/Databases/utilities.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ export const convertExistingConfigsToArray = (
394394
}
395395
return options;
396396
};
397+
397398
/**
398399
* Formats the configuration payload by organizing form data into categorized fields.
399400
*
@@ -442,3 +443,19 @@ export const isConfigStringWithEnum = (config: ConfigurationOption) => {
442443
config.enum)
443444
);
444445
};
446+
447+
/**
448+
* Determines the default value for a configuration item based on its type.
449+
*
450+
* @param config - The configuration object
451+
* @returns - The default value for the given configuration
452+
*/
453+
export const getDefaultConfigValue = (config: ConfigurationOption) => {
454+
return isConfigBoolean(config)
455+
? false
456+
: isConfigStringWithEnum(config)
457+
? config.enum?.[0] ?? ''
458+
: config?.type === 'number' || config?.type === 'integer'
459+
? 0
460+
: '';
461+
};

0 commit comments

Comments
 (0)