Skip to content

Commit

Permalink
feat(web): add option to disable deployment copy on version increase (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
m8vago committed May 23, 2024
1 parent 07b4e70 commit 3878ebb
Show file tree
Hide file tree
Showing 11 changed files with 300 additions and 86 deletions.
1 change: 1 addition & 0 deletions web/crux-ui/locales/en/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"type": "Type",
"incremental": "Incremental",
"rolling": "Rolling",
"copyDeployments": "Copy deployments while increasing",
"noItems": "You haven't added a version to this project yet. Click on 'Add Version'.",
"noDeployments": "You haven't added a deployment to this version. Click 'Add deployment' to browse images you can add.",

Expand Down
2 changes: 1 addition & 1 deletion web/crux-ui/src/components/projects/edit-project-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const EditProjectCard = (props: EditProjectCardProps) => {
value={formik.values.description}
/>

{editing ? null : (
{!editing && (
<DyoToggle
className="justify-self-start mt-8"
name="type"
Expand Down
49 changes: 32 additions & 17 deletions web/crux-ui/src/components/projects/versions/edit-version-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import { DyoHeading } from '@app/elements/dyo-heading'
import { DyoInput } from '@app/elements/dyo-input'
import { DyoLabel } from '@app/elements/dyo-label'
import DyoTextArea from '@app/elements/dyo-text-area'
import DyoToggle from '@app/elements/dyo-toggle'
import { defaultApiErrorHandler } from '@app/errors'
import useDyoFormik from '@app/hooks/use-dyo-formik'
import { SubmitHook } from '@app/hooks/use-submit'
import useTeamRoutes from '@app/hooks/use-team-routes'
import { CreateVersion, EditableVersion, Project, UpdateVersion, VERSION_TYPE_VALUES } from '@app/models'
import { sendForm } from '@app/utils'
import { createVersionSchema, updateVersionSchema } from '@app/validations'
import clsx from 'clsx'
import useTranslation from 'next-translate/useTranslation'
import { useState } from 'react'

Expand All @@ -37,7 +39,7 @@ const EditVersionCard = (props: EditVersionCardProps) => {
name: '',
changelog: '',
type: 'incremental',
increasable: true,
autoCopyDeployments: true,
audit: null,
},
)
Expand All @@ -57,6 +59,7 @@ const EditVersionCard = (props: EditVersionCardProps) => {
t,
onSubmit: async (values, { setFieldError }) => {
const body: CreateVersion | UpdateVersion = values
body.autoCopyDeployments = values.type === 'incremental' ? body.autoCopyDeployments : null

const res = !editing
? await sendForm('POST', routes.project.versions(project.id).api.list(), body as CreateVersion)
Expand Down Expand Up @@ -116,23 +119,35 @@ const EditVersionCard = (props: EditVersionCardProps) => {
message={formik.errors.changelog}
/>

{editing ? null : (
<>
<DyoLabel textColor="mt-8 mb-2.5 text-light-eased">{t('type')}</DyoLabel>

<DyoChips
className="text-bright"
name="versionType"
choices={VERSION_TYPE_VALUES}
selection={formik.values.type}
converter={it => t(it)}
onSelectionChange={async (type): Promise<void> => {
await formik.setFieldValue('type', type, false)
}}
qaLabel={chipsQALabelFromValue}
<div className="flex flex-row gap-8">
{!editing && (
<div className="flex flex-col">
<DyoLabel textColor="mt-8 mb-2.5 text-light-eased">{t('type')}</DyoLabel>

<DyoChips
className="text-bright"
name="versionType"
choices={VERSION_TYPE_VALUES}
selection={formik.values.type}
converter={it => t(it)}
onSelectionChange={async (type): Promise<void> => {
await formik.setFieldValue('type', type, false)
}}
qaLabel={chipsQALabelFromValue}
/>
</div>
)}

{formik.values.type === 'incremental' && (
<DyoToggle
className={clsx(!editing ? ' self-center mt-16' : 'mt-8 mb-2')}
name="autoCopyDeployments"
label={t('copyDeployments')}
checked={formik.values.autoCopyDeployments}
setFieldValue={formik.setFieldValue}
/>
</>
)}
)}
</div>

<DyoButton className="hidden" type="submit" />
</DyoForm>
Expand Down
7 changes: 5 additions & 2 deletions web/crux-ui/src/models/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@ export type Version = BasicVersion & {
changelog?: string
default: boolean
increasable: boolean
autoCopyDeployments?: boolean
audit: Audit
}

export type EditableVersion = Omit<Version, 'default'>
export type EditableVersion = Omit<Version, 'default' | 'increasable'>

export type IncreaseVersion = {
name: string
changelog?: string
}

export type UpdateVersion = IncreaseVersion
export type UpdateVersion = IncreaseVersion & {
autoCopyDeployments?: boolean
}

export type CreateVersion = UpdateVersion & {
type: VersionType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const VersionDetailsPage = (props: VersionDetailsPageProps) => {
newAllVersion[index] = {
...newVersion,
default: oldVersion.default,
increasable: oldVersion.increasable,
}
setAllVersions(newAllVersion)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Version" ADD COLUMN "autoCopyDeployments" BOOLEAN NOT NULL DEFAULT true;
21 changes: 11 additions & 10 deletions web/crux/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,17 @@ model Project {
}

model Version {
id String @id @default(uuid()) @db.Uuid
createdAt DateTime @default(now()) @db.Timestamptz(6)
createdBy String @db.Uuid
updatedAt DateTime @updatedAt @db.Timestamptz(6)
updatedBy String? @db.Uuid
name String @db.VarChar(70)
changelog String?
default Boolean @default(false)
type VersionTypeEnum @default(incremental)
projectId String @db.Uuid
id String @id @default(uuid()) @db.Uuid
createdAt DateTime @default(now()) @db.Timestamptz(6)
createdBy String @db.Uuid
updatedAt DateTime @updatedAt @db.Timestamptz(6)
updatedBy String? @db.Uuid
name String @db.VarChar(70)
changelog String?
default Boolean @default(false)
type VersionTypeEnum @default(incremental)
autoCopyDeployments Boolean @default(true)
projectId String @db.Uuid
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
images Image[]
Expand Down
17 changes: 16 additions & 1 deletion web/crux/src/app/version/version.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export class UpdateVersionDto {
@IsString()
@IsOptional()
changelog?: string

@IsBoolean()
@IsOptional()
autoCopyDeployments?: boolean
}

export class CreateVersionDto extends UpdateVersionDto {
Expand All @@ -53,7 +57,14 @@ export class CreateVersionDto extends UpdateVersionDto {
type: VersionTypeDto
}

export class IncreaseVersionDto extends UpdateVersionDto {}
export class IncreaseVersionDto {
@IsString()
name: string

@IsString()
@IsOptional()
changelog?: string
}

export class VersionDetailsDto extends VersionDto {
@IsBoolean()
Expand All @@ -62,6 +73,10 @@ export class VersionDetailsDto extends VersionDto {
@IsBoolean()
deletable: boolean

@IsBoolean()
@IsOptional()
autoCopyDeployments?: boolean

@Type(() => ImageDto)
images: ImageDto[]

Expand Down
1 change: 1 addition & 0 deletions web/crux/src/app/version/version.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default class VersionMapper {
mutable: versionIsMutable(version),
deletable: versionIsDeletable(version),
increasable: versionIsIncreasable(version),
autoCopyDeployments: version.autoCopyDeployments,
images: version.images.map(it => this.imageMapper.toDto(it)),
deployments: version.deployments.map(it =>
this.deployMapper.toDeploymentWithBasicNodeDto(it, nodeStatusLookup.get(it.nodeId)),
Expand Down
Loading

0 comments on commit 3878ebb

Please sign in to comment.