Add checklist acceptance criteria
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { useForm } from '@inertiajs/vue3';
|
||||
import { computed, ref } from 'vue';
|
||||
import ProjectTicketController from '@/actions/App/Http/Controllers/ProjectTicketController';
|
||||
import InputError from '@/components/InputError.vue';
|
||||
import TicketPriorityIcon from '@/components/TicketPriorityIcon.vue';
|
||||
@@ -23,6 +24,11 @@ import {
|
||||
SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import {
|
||||
acceptanceCriteriaToEditorState,
|
||||
buildAcceptanceCriteria,
|
||||
parseChecklistLines,
|
||||
} from '@/lib/acceptance-criteria';
|
||||
import {
|
||||
fieldLabelClass,
|
||||
frostedCardClass,
|
||||
@@ -53,8 +59,17 @@ const props = defineProps<{
|
||||
users: UserModel[];
|
||||
}>();
|
||||
|
||||
const acceptanceCriteriaEditorState = acceptanceCriteriaToEditorState(
|
||||
props.ticket.acceptance_criteria,
|
||||
);
|
||||
const acceptanceCriteriaSummary = ref(acceptanceCriteriaEditorState.summary);
|
||||
const acceptanceCriteriaChecklist = ref(acceptanceCriteriaEditorState.checklist);
|
||||
|
||||
const form = useForm({
|
||||
acceptance_criteria: props.ticket.acceptance_criteria ?? '',
|
||||
acceptance_criteria: buildAcceptanceCriteria(
|
||||
acceptanceCriteriaSummary.value,
|
||||
acceptanceCriteriaChecklist.value,
|
||||
),
|
||||
assignee_user_id: props.ticket.assignee_user_id ?? '',
|
||||
author_user_id: props.ticket.author_user_id ?? '',
|
||||
blocked_comment: props.ticket.blocked_comment ?? '',
|
||||
@@ -80,11 +95,32 @@ const form = useForm({
|
||||
story_points: props.ticket.story_points,
|
||||
});
|
||||
|
||||
const acceptanceCriteriaPreviewItems = computed(() =>
|
||||
parseChecklistLines(acceptanceCriteriaChecklist.value),
|
||||
);
|
||||
|
||||
const acceptanceCriteriaError = computed(() => {
|
||||
return (
|
||||
form.errors.acceptance_criteria ??
|
||||
form.errors['acceptance_criteria.summary'] ??
|
||||
form.errors['acceptance_criteria.items'] ??
|
||||
Object.entries(form.errors).find(([key]) =>
|
||||
key.startsWith('acceptance_criteria.items.'),
|
||||
)?.[1] ??
|
||||
''
|
||||
);
|
||||
});
|
||||
|
||||
const submit = (): void => {
|
||||
if (!props.canEditTicket) {
|
||||
return;
|
||||
}
|
||||
|
||||
form.acceptance_criteria = buildAcceptanceCriteria(
|
||||
acceptanceCriteriaSummary.value,
|
||||
acceptanceCriteriaChecklist.value,
|
||||
);
|
||||
|
||||
form.submit(
|
||||
ProjectTicketController.update({
|
||||
project: props.project.id,
|
||||
@@ -286,17 +322,92 @@ const submit = (): void => {
|
||||
<InputError :message="form.errors.description" />
|
||||
</div>
|
||||
|
||||
<div class="grid gap-2">
|
||||
<Label for="acceptance_criteria" :class="fieldLabelClass">
|
||||
Acceptance criteria
|
||||
</Label>
|
||||
<Textarea
|
||||
id="acceptance_criteria"
|
||||
v-model="form.acceptance_criteria"
|
||||
:disabled="!canEditTicket || form.processing"
|
||||
:class="textareaClass"
|
||||
/>
|
||||
<InputError :message="form.errors.acceptance_criteria" />
|
||||
<div class="grid gap-4">
|
||||
<div class="grid gap-2">
|
||||
<Label
|
||||
for="acceptance_criteria_summary"
|
||||
:class="fieldLabelClass"
|
||||
>
|
||||
Acceptance criteria summary
|
||||
</Label>
|
||||
<Input
|
||||
id="acceptance_criteria_summary"
|
||||
v-model="acceptanceCriteriaSummary"
|
||||
:disabled="!canEditTicket || form.processing"
|
||||
placeholder="In one sentence, what defines done?"
|
||||
:class="inputClass"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-2">
|
||||
<Label
|
||||
for="acceptance_criteria_checklist"
|
||||
:class="fieldLabelClass"
|
||||
>
|
||||
Acceptance checklist
|
||||
</Label>
|
||||
<Textarea
|
||||
id="acceptance_criteria_checklist"
|
||||
v-model="acceptanceCriteriaChecklist"
|
||||
:disabled="!canEditTicket || form.processing"
|
||||
placeholder="[ ] User can sign in\n[ ] Errors are shown inline\n [x] Nested checks use two-space indent"
|
||||
:class="textareaClass"
|
||||
/>
|
||||
<p class="text-muted-foreground text-xs leading-5">
|
||||
Each line is a checklist item. Prefix with
|
||||
<span class="font-semibold">[x]</span> for checked
|
||||
items and indent with two spaces for nested items.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<InputError :message="acceptanceCriteriaError" />
|
||||
|
||||
<div
|
||||
class="dark:bg-muted/25 grid gap-3 rounded-[1.25rem] border border-dashed border-[#adb3b5]/35 bg-[#f8f9fa]/70 p-4 dark:border-white/10"
|
||||
>
|
||||
<p
|
||||
class="text-[0.72rem] font-semibold uppercase tracking-[0.18em] text-[#5a6062]"
|
||||
>
|
||||
Checklist preview
|
||||
</p>
|
||||
|
||||
<div
|
||||
v-if="acceptanceCriteriaPreviewItems.length === 0"
|
||||
class="text-muted-foreground rounded-xl border border-dashed px-3 py-3 text-sm"
|
||||
>
|
||||
Add checklist lines to preview nested items.
|
||||
</div>
|
||||
|
||||
<div v-else class="space-y-2">
|
||||
<div
|
||||
v-for="(
|
||||
checklistItem,
|
||||
checklistItemIndex
|
||||
) in acceptanceCriteriaPreviewItems"
|
||||
:key="checklistItemIndex"
|
||||
class="flex items-start gap-3"
|
||||
:style="{
|
||||
marginLeft: `${checklistItem.indent * 1.25}rem`,
|
||||
}"
|
||||
>
|
||||
<Checkbox
|
||||
:checked="checklistItem.checked"
|
||||
disabled
|
||||
class="mt-0.5"
|
||||
/>
|
||||
<span
|
||||
class="text-sm"
|
||||
:class="
|
||||
checklistItem.checked
|
||||
? 'text-muted-foreground line-through'
|
||||
: 'text-foreground'
|
||||
"
|
||||
>
|
||||
{{ checklistItem.text }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
|
||||
Reference in New Issue
Block a user