feat(KAN-40): rebuild workflow column and status settings
This commit is contained in:
@@ -0,0 +1,277 @@
|
||||
<script setup lang="ts">
|
||||
import { useForm } from '@inertiajs/vue3';
|
||||
import { computed, watch } from 'vue';
|
||||
import {
|
||||
destroy,
|
||||
destroyStatus,
|
||||
store,
|
||||
storeStatus,
|
||||
update,
|
||||
updateStatus,
|
||||
} from '@/actions/App/Http/Controllers/ProjectBoardSettingsController';
|
||||
import FormFeedback from '@/components/FormFeedback.vue';
|
||||
import InputError from '@/components/InputError.vue';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { useFormProtection } from '@/composables/useFormProtection';
|
||||
import { useLocalization } from '@/composables/useLocalization';
|
||||
import type { WorkflowEditorTarget } from '@/types/project-workflow';
|
||||
|
||||
const props = defineProps<{
|
||||
projectId: number;
|
||||
columnCount: number;
|
||||
target: WorkflowEditorTarget | null;
|
||||
}>();
|
||||
const emit = defineEmits<{ close: [] }>();
|
||||
const { t } = useLocalization();
|
||||
const form = useForm({ name: '', position: 1 });
|
||||
const protection = useFormProtection(form, {
|
||||
isDirty: () => props.target !== null && form.isDirty,
|
||||
});
|
||||
const deleting = computed(() => props.target?.action === 'delete');
|
||||
const title = computed(() => {
|
||||
if (props.target?.kind === 'column') {
|
||||
return t(
|
||||
props.target.action === 'create'
|
||||
? 'workflow.addColumn'
|
||||
: props.target.action === 'edit'
|
||||
? 'workflow.editColumn'
|
||||
: 'workflow.deleteColumn',
|
||||
);
|
||||
}
|
||||
return t(
|
||||
props.target?.action === 'create'
|
||||
? 'workflow.addStatus'
|
||||
: props.target?.action === 'edit'
|
||||
? 'workflow.editStatus'
|
||||
: 'workflow.deleteStatus',
|
||||
);
|
||||
});
|
||||
const description = computed(() => {
|
||||
const target = props.target;
|
||||
if (!target) {
|
||||
return '';
|
||||
}
|
||||
if (target.kind === 'column') {
|
||||
return t(
|
||||
target.action === 'delete'
|
||||
? 'workflow.deleteColumnDescription'
|
||||
: target.action === 'create'
|
||||
? 'workflow.addColumnDescription'
|
||||
: 'workflow.editColumnDescription',
|
||||
{ name: target.column?.name ?? '' },
|
||||
);
|
||||
}
|
||||
return t(
|
||||
target.action === 'delete'
|
||||
? 'workflow.deleteStatusDescription'
|
||||
: 'workflow.statusContext',
|
||||
{
|
||||
name: target.status?.name ?? '',
|
||||
context: target.column?.name ?? t('workflow.backlog'),
|
||||
replacement: target.replacement?.name ?? '',
|
||||
},
|
||||
);
|
||||
});
|
||||
const otherErrors = computed(() =>
|
||||
Object.entries(form.errors)
|
||||
.filter(([key]) => !['name', 'position'].includes(key))
|
||||
.map(([, message]) => message),
|
||||
);
|
||||
watch(
|
||||
() => props.target,
|
||||
(target) => {
|
||||
if (!target) {
|
||||
return;
|
||||
}
|
||||
form.defaults({
|
||||
name:
|
||||
target.kind === 'column'
|
||||
? (target.column?.name ?? '')
|
||||
: (target.status?.name ?? ''),
|
||||
position: target.column?.position ?? 1,
|
||||
});
|
||||
form.resetAndClearErrors();
|
||||
protection.clearFeedback();
|
||||
},
|
||||
);
|
||||
function close(open: boolean): void {
|
||||
if (open || form.processing || !protection.confirmLeave()) {
|
||||
return;
|
||||
}
|
||||
form.resetAndClearErrors();
|
||||
protection.clearFeedback();
|
||||
emit('close');
|
||||
}
|
||||
function submit(): void {
|
||||
const target = props.target;
|
||||
if (
|
||||
!target ||
|
||||
form.processing ||
|
||||
(target.kind === 'status' &&
|
||||
target.action === 'delete' &&
|
||||
!target.replacement)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const route =
|
||||
target.kind === 'column'
|
||||
? target.action === 'create'
|
||||
? store(props.projectId)
|
||||
: target.action === 'edit'
|
||||
? update([props.projectId, target.column.id])
|
||||
: destroy([props.projectId, target.column.id])
|
||||
: target.action === 'create'
|
||||
? storeStatus(props.projectId)
|
||||
: target.action === 'edit'
|
||||
? updateStatus([props.projectId, target.status.id])
|
||||
: destroyStatus([props.projectId, target.status.id]);
|
||||
form.transform((data) =>
|
||||
target.action === 'delete'
|
||||
? {}
|
||||
: target.kind === 'column' && target.action === 'edit'
|
||||
? data
|
||||
: target.kind === 'status' && target.action === 'create'
|
||||
? {
|
||||
name: data.name,
|
||||
board_column_id: target.column?.id ?? null,
|
||||
}
|
||||
: { name: data.name },
|
||||
);
|
||||
protection.submit(route, {
|
||||
preserveScroll: true,
|
||||
onSuccess: () => {
|
||||
form.resetAndClearErrors();
|
||||
emit('close');
|
||||
},
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Dialog :open="target !== null" @update:open="close">
|
||||
<DialogContent
|
||||
:show-close-button="!form.processing"
|
||||
@escape-key-down="form.processing && $event.preventDefault()"
|
||||
@interact-outside="form.processing && $event.preventDefault()"
|
||||
>
|
||||
<DialogHeader>
|
||||
<DialogTitle>{{ title }}</DialogTitle>
|
||||
<DialogDescription class="break-words">{{
|
||||
description
|
||||
}}</DialogDescription>
|
||||
</DialogHeader>
|
||||
<form
|
||||
class="gap-column grid min-w-0"
|
||||
:aria-busy="form.processing"
|
||||
@submit.prevent="submit"
|
||||
>
|
||||
<FormFeedback :state="protection.state.value" @retry="submit" />
|
||||
<InputError
|
||||
v-for="message in otherErrors"
|
||||
:key="message"
|
||||
:message="message"
|
||||
/>
|
||||
<fieldset
|
||||
v-if="!deleting"
|
||||
:disabled="form.processing"
|
||||
class="grid min-w-0 gap-4"
|
||||
>
|
||||
<div class="grid gap-2">
|
||||
<Label for="workflow-name">{{
|
||||
t(
|
||||
target?.kind === 'column'
|
||||
? 'workflow.columnName'
|
||||
: 'workflow.statusName',
|
||||
)
|
||||
}}</Label>
|
||||
<Input
|
||||
id="workflow-name"
|
||||
v-model="form.name"
|
||||
name="name"
|
||||
required
|
||||
maxlength="255"
|
||||
:aria-invalid="!!form.errors.name"
|
||||
:aria-describedby="
|
||||
form.errors.name
|
||||
? 'workflow-name-error'
|
||||
: undefined
|
||||
"
|
||||
/>
|
||||
<InputError
|
||||
id="workflow-name-error"
|
||||
:message="form.errors.name"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
v-if="
|
||||
target?.kind === 'column' &&
|
||||
target.action === 'edit'
|
||||
"
|
||||
class="grid gap-2"
|
||||
>
|
||||
<Label for="workflow-position">{{
|
||||
t('workflow.position')
|
||||
}}</Label>
|
||||
<Input
|
||||
id="workflow-position"
|
||||
v-model="form.position"
|
||||
name="position"
|
||||
type="number"
|
||||
min="1"
|
||||
:max="columnCount"
|
||||
step="1"
|
||||
required
|
||||
:aria-invalid="!!form.errors.position"
|
||||
aria-describedby="workflow-position-help workflow-position-error"
|
||||
/>
|
||||
<p
|
||||
id="workflow-position-help"
|
||||
class="text-caption text-muted-foreground"
|
||||
>
|
||||
{{
|
||||
t('workflow.positionHelp', {
|
||||
count: columnCount,
|
||||
})
|
||||
}}
|
||||
</p>
|
||||
<InputError
|
||||
id="workflow-position-error"
|
||||
:message="form.errors.position"
|
||||
/>
|
||||
</div>
|
||||
</fieldset>
|
||||
<DialogFooter>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
:disabled="form.processing"
|
||||
@click="close(false)"
|
||||
>{{ t('common.cancel') }}</Button
|
||||
>
|
||||
<Button
|
||||
type="submit"
|
||||
:variant="deleting ? 'destructive' : 'default'"
|
||||
:loading="form.processing"
|
||||
>{{
|
||||
deleting
|
||||
? t('workflow.confirmDelete')
|
||||
: target?.action === 'create'
|
||||
? title
|
||||
: t('common.save')
|
||||
}}</Button
|
||||
>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</template>
|
||||
@@ -0,0 +1,106 @@
|
||||
<script setup lang="ts">
|
||||
import { Pencil, Plus, Trash2 } from 'lucide-vue-next';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useLocalization } from '@/composables/useLocalization';
|
||||
import type { BoardColumnModel } from '@/types/models/board-column-model';
|
||||
import type { TicketStatusModel } from '@/types/models/ticket-status-model';
|
||||
import type { WorkflowEditorTarget } from '@/types/project-workflow';
|
||||
|
||||
defineProps<{
|
||||
column: BoardColumnModel | null;
|
||||
statuses: TicketStatusModel[];
|
||||
}>();
|
||||
defineEmits<{ edit: [target: WorkflowEditorTarget] }>();
|
||||
const { t } = useLocalization();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="grid min-w-0 gap-3">
|
||||
<ul
|
||||
class="divide-y"
|
||||
:aria-label="
|
||||
t('workflow.statusesIn', {
|
||||
context: column?.name ?? t('workflow.backlog'),
|
||||
})
|
||||
"
|
||||
>
|
||||
<li
|
||||
v-for="status in statuses"
|
||||
:key="status.id"
|
||||
class="flex min-w-0 flex-wrap items-center justify-between gap-2 py-3 first:pt-0"
|
||||
>
|
||||
<span
|
||||
class="min-w-0 flex-1 basis-28 break-words text-sm font-medium"
|
||||
>{{ status.name }}</span
|
||||
>
|
||||
<div class="flex shrink-0 gap-1">
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
:aria-label="
|
||||
t('workflow.renameStatus', { name: status.name })
|
||||
"
|
||||
@click="
|
||||
$emit('edit', {
|
||||
kind: 'status',
|
||||
action: 'edit',
|
||||
column,
|
||||
status,
|
||||
})
|
||||
"
|
||||
><Pencil class="size-4" aria-hidden="true"
|
||||
/></Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
class="text-destructive"
|
||||
:disabled="statuses.length <= 1"
|
||||
:aria-label="
|
||||
t('workflow.removeStatus', { name: status.name })
|
||||
"
|
||||
:aria-describedby="
|
||||
statuses.length <= 1
|
||||
? `status-protection-${column?.id ?? 'backlog'}`
|
||||
: undefined
|
||||
"
|
||||
@click="
|
||||
$emit('edit', {
|
||||
kind: 'status',
|
||||
action: 'delete',
|
||||
column,
|
||||
status,
|
||||
replacement: statuses.find(
|
||||
(item) => item.id !== status.id,
|
||||
),
|
||||
})
|
||||
"
|
||||
><Trash2 class="size-4" aria-hidden="true"
|
||||
/></Button>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<p
|
||||
v-if="statuses.length <= 1"
|
||||
:id="`status-protection-${column?.id ?? 'backlog'}`"
|
||||
class="text-caption text-muted-foreground"
|
||||
>
|
||||
{{ t('workflow.lastStatus') }}
|
||||
</p>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
class="w-full sm:w-fit"
|
||||
:aria-label="
|
||||
t('workflow.addStatusTo', {
|
||||
context: column?.name ?? t('workflow.backlog'),
|
||||
})
|
||||
"
|
||||
@click="$emit('edit', { kind: 'status', action: 'create', column })"
|
||||
><Plus class="size-4" aria-hidden="true" />{{
|
||||
t('workflow.addStatus')
|
||||
}}</Button
|
||||
>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,91 @@
|
||||
<script setup lang="ts">
|
||||
import { Form } from '@inertiajs/vue3';
|
||||
import { updateStatusTransitions } from '@/actions/App/Http/Controllers/ProjectBoardSettingsController';
|
||||
import InputError from '@/components/InputError.vue';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useLocalization } from '@/composables/useLocalization';
|
||||
import { ticketStatusLabel } from '@/lib/tickets';
|
||||
import type { TicketStatusModel } from '@/types/models/ticket-status-model';
|
||||
|
||||
defineProps<{ projectId: number; statuses: TicketStatusModel[] }>();
|
||||
const { t } = useLocalization();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<details class="bg-card min-w-0 rounded-xl border">
|
||||
<summary
|
||||
class="focus-visible:ring-ring/40 cursor-pointer rounded-xl p-5 font-semibold outline-none focus-visible:ring-2 sm:p-6"
|
||||
>
|
||||
{{ t('workflow.transitions') }}
|
||||
</summary>
|
||||
<div class="grid min-w-0 gap-4 border-t p-5 sm:p-6">
|
||||
<p class="text-muted-foreground text-sm">
|
||||
{{ t('workflow.transitionsDescription') }}
|
||||
</p>
|
||||
<Form
|
||||
v-for="source in statuses"
|
||||
:key="source.id"
|
||||
v-bind="updateStatusTransitions.form([projectId, source.id])"
|
||||
preserve-scroll
|
||||
set-defaults-on-success
|
||||
class="grid min-w-0 gap-3 rounded-lg border p-4"
|
||||
v-slot="{ errors, processing, recentlySuccessful }"
|
||||
>
|
||||
<fieldset :disabled="processing" class="grid min-w-0 gap-3">
|
||||
<legend class="mb-3 break-words font-medium">
|
||||
{{ ticketStatusLabel(source, '') }}
|
||||
</legend>
|
||||
<p
|
||||
v-if="statuses.length <= 1"
|
||||
class="text-muted-foreground text-sm"
|
||||
>
|
||||
{{ t('workflow.noTargets') }}
|
||||
</p>
|
||||
<div v-else class="grid min-w-0 gap-2 sm:grid-cols-2">
|
||||
<label
|
||||
v-for="target in statuses.filter(
|
||||
(item) => item.id !== source.id,
|
||||
)"
|
||||
:key="target.id"
|
||||
class="border-input flex min-h-11 min-w-0 items-center gap-3 rounded-lg border px-3 py-2 text-sm"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
name="allowed_ticket_status_ids[]"
|
||||
:value="target.id"
|
||||
:checked="
|
||||
source.allowed_target_statuses?.some(
|
||||
(item) => item.id === target.id,
|
||||
) ?? false
|
||||
"
|
||||
class="border-input accent-primary focus-visible:ring-ring/40 size-4 shrink-0 rounded focus-visible:ring-2"
|
||||
/>
|
||||
<span class="min-w-0 break-words">{{
|
||||
ticketStatusLabel(target, '')
|
||||
}}</span>
|
||||
</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
<InputError
|
||||
v-for="(message, key) in errors"
|
||||
:key="key"
|
||||
:message="message"
|
||||
/>
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Button
|
||||
type="submit"
|
||||
variant="outline"
|
||||
:loading="processing"
|
||||
>{{ t('common.save') }}</Button
|
||||
>
|
||||
<span
|
||||
v-if="recentlySuccessful"
|
||||
role="status"
|
||||
class="text-primary text-sm"
|
||||
>{{ t('feedback.saved') }}</span
|
||||
>
|
||||
</div>
|
||||
</Form>
|
||||
</div>
|
||||
</details>
|
||||
</template>
|
||||
Reference in New Issue
Block a user