Skip to content

Commit

Permalink
fix: unable to reset storage section
Browse files Browse the repository at this point in the history
  • Loading branch information
robot9706 committed Dec 13, 2024
1 parent c1a09d9 commit f58c601
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
23 changes: 21 additions & 2 deletions web/crux/src/app/container/container-config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { EditorLeftMessage, EditorMessage } from '../editor/editor.message'
import EditorServiceProvider from '../editor/editor.service.provider'
import ContainerConfigDomainEventListener from './container-config.domain-event.listener'
import { ConfigUpdatedMessage, WS_TYPE_CONFIG_UPDATED } from './container-config.message'
import { ContainerConfigProperty } from './container.const'
import {
ContainerConfigDetailsDto,
ContainerConfigRelationsDto,
Expand Down Expand Up @@ -265,13 +266,13 @@ export default class ContainerConfigService {
},
})

const data: ContainerConfigData = this.mapper.configDtoToConfigData(
let data: ContainerConfigData = this.mapper.configDtoToConfigData(
config as any as ContainerConfigData,
req.config ?? {},
)

if (req.resetSection) {
data[req.resetSection] = null
data = this.resetSection(data, req.resetSection)
}

await this.prisma.containerConfig.update({
Expand Down Expand Up @@ -319,6 +320,24 @@ export default class ContainerConfigService {
return message
}

private resetSection(config: ContainerConfigData, resetKey: ContainerConfigProperty) {
config[resetKey] = null

switch (resetKey) {
case 'storage':
config.storageSet = false
config.storageId = null
config.storageConfig = null
break

default:
config[resetKey as ContainerConfigProperty] = null
break
}

return config
}

private async checkMutability(configId: string): Promise<boolean> {
const deploymentSelect: Prisma.DeploymentSelect = {
status: true,
Expand Down
2 changes: 1 addition & 1 deletion web/crux/src/app/container/container.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export default class ContainerMapper {
if ('storage' in patch) {
result = {
...result,
storageSet: true,
storageSet: !!patch.storage?.storageId,
storageId: patch.storage?.storageId ?? null,
storageConfig: patch.storage?.storageId
? {
Expand Down

0 comments on commit f58c601

Please sign in to comment.