Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
robot9706 committed Dec 4, 2024
1 parent 07b224e commit becb0cc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 28 deletions.
46 changes: 24 additions & 22 deletions web/crux-ui/src/validations/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,28 +503,30 @@ const testRules = (rules: [string, EnvironmentRule][], arr: UniqueKeyValue[], fi
}

const createContainerConfigBaseSchema = (imageLabels: Record<string, string>) =>
yup.object().shape({
name: matchContainerName(yup.string().nullable().optional().label('container:common.containerName')),
environment: uniqueKeyValuesSchema
.default(null)
.nullable()
.optional()
.label('container:common.environment')
.test('ruleValidation', 'errors:yup.mixed.required', testEnvironment(imageLabels)),
routing: routingRule,
expose: exposeRule,
user: yup.number().default(null).min(UID_MIN).max(UID_MAX).nullable().optional().label('container:common.user'),
workingDirectory: yup.string().default(null).nullable().optional().label('container:common.workingDirectory'),
tty: yup.boolean().default(null).nullable().optional().label('container:common.tty'),
configContainer: configContainerRule,
ports: portConfigRule,
portRanges: portRangeConfigRule,
volumes: volumeConfigRule,
commands: shellCommandSchema.default(null).nullable().optional(),
args: shellCommandSchema.default(null).nullable().optional(),
initContainers: initContainerRule,
capabilities: uniqueKeyValuesSchema.default(null).nullable().optional().label('container:common.capabilities'),
storage: storageRule,
yup
.object()
.shape({
name: matchContainerName(yup.string().nullable().optional().label('container:common.containerName')),
environment: uniqueKeyValuesSchema
.default(null)
.nullable()
.optional()
.label('container:common.environment')
.test('ruleValidation', 'errors:yup.mixed.required', testEnvironment(imageLabels)),
routing: routingRule,
expose: exposeRule,
user: yup.number().default(null).min(UID_MIN).max(UID_MAX).nullable().optional().label('container:common.user'),
workingDirectory: yup.string().default(null).nullable().optional().label('container:common.workingDirectory'),
tty: yup.boolean().default(null).nullable().optional().label('container:common.tty'),
configContainer: configContainerRule,
ports: portConfigRule,
portRanges: portRangeConfigRule,
volumes: volumeConfigRule,
commands: shellCommandSchema.default(null).nullable().optional(),
args: shellCommandSchema.default(null).nullable().optional(),
initContainers: initContainerRule,
capabilities: uniqueKeyValuesSchema.default(null).nullable().optional().label('container:common.capabilities'),
storage: storageRule,

// dagent:
logConfig: logConfigRule,
Expand Down
4 changes: 2 additions & 2 deletions web/crux/src/app/image/image.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export default class ImageService {
}, {}) ?? {}

const mergedEnv = Object.entries(rules)
.filter(([_, rule]) => !rule.secret)
.filter(([, rule]) => !rule.secret)
.reduce((map, it) => {
const [key, rule] = it

Expand All @@ -345,7 +345,7 @@ export default class ImageService {
}, {}) ?? {}

const mergedSecrets = Object.entries(rules)
.filter(([_, rule]) => rule.secret)
.filter(([, rule]) => rule.secret)
.reduce((map, it) => {
const [key, rule] = it

Expand Down
8 changes: 4 additions & 4 deletions web/crux/src/domain/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,14 +398,14 @@ const validateLabelRule = (rule: EnvironmentRule, field: string, env: KeyValueLi
}

const testRules = (rules: [string, EnvironmentRule][], arr: UniqueKeyValue[], fieldName: string) => {
if (rules.length == 0) {
if (rules.length === 0) {
return null
}

const requiredKeys = rules.map(([key]) => key)
const foundKeys = arr.map(it => it.key)

if (requiredKeys.length > 0 && (!arr || arr.length == 0)) {
if (requiredKeys.length > 0 && (!arr || arr.length === 0)) {
return new yup.ValidationError('errors:yup.mixed.required', fieldName, fieldName)
}

Expand Down Expand Up @@ -472,8 +472,8 @@ export const createStartDeploymentSchema = (instanceValidation: Record<string, I

const requiredRules = Object.entries(validation.environmentRules).filter(([, rule]) => rule.required)

const envRules = requiredRules.filter(([_, rule]) => !rule.secret)
const secretRules = requiredRules.filter(([_, rule]) => rule.secret)
const envRules = requiredRules.filter(([, rule]) => !rule.secret)
const secretRules = requiredRules.filter(([, rule]) => rule.secret)

const envError = testRules(envRules, it.config.environment as UniqueKeyValue[], 'environment')
if (envError) {
Expand Down

0 comments on commit becb0cc

Please sign in to comment.