Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions alfy-bot-frontend/src/features/projects/ui/BacklogStoryRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { releaseLabel } from '../lib/release'
import { useReleaseStore } from '../model/release-store'
import { useGroupDetail } from '../model/use-group-detail'
import BacklogTaskRow from './BacklogTaskRow.vue'
import InlineTitleInput from './InlineTitleInput.vue'
import ReleasePickerContent from './ReleasePickerContent.vue'

const props = defineProps<{
Expand All @@ -21,15 +20,14 @@ const props = defineProps<{
}>()

const emit = defineEmits<{
createTask: [groupId: string, title: string]
createTask: [groupId: string]
openTask: [task: Task]
toggleTask: [id: string]
moveTask: [taskId: string, sprintId: string | null]
moveStory: [storyId: string, sprintId: string | null]
}>()

const expanded = ref(false)
const addingTask = ref(false)
const releaseOpen = ref(false)
const savingRelease = ref(false)
const errorMessage = ref<string | null>(null)
Expand All @@ -39,14 +37,9 @@ const story = computed(() => props.entry.story)
const label = computed(() => releaseLabel(releaseStore.releasesOf(story.value.projectId), story.value.releaseId))
const released = computed(() => releaseStore.releasesOf(story.value.projectId).some(r => r.id === story.value.releaseId && r.status === 'released'))

function createTask(title: string) {
emit('createTask', story.value.id, title)
addingTask.value = false
}

function startAddingTask() {
expanded.value = true
addingTask.value = true
emit('createTask', story.value.id)
}

async function setRelease(releaseId: string | null) {
Expand Down Expand Up @@ -136,11 +129,7 @@ function handleChange(event: { added?: { element: Task } }) {
</template>
</draggable>
<div class="px-3 pb-2">
<p v-if="addingTask && released" class="py-1 text-xs text-muted-foreground">
Новая задача будет без релиза. Релиз можно выбрать в её карточке.
</p>
<InlineTitleInput v-if="addingTask" placeholder="Название задачи в истории" @submit="createTask" @cancel="addingTask = false" />
<button v-else class="flex cursor-pointer items-center gap-1 py-1 text-xs text-muted-foreground hover:text-foreground" @click="startAddingTask">
<button class="flex cursor-pointer items-center gap-1 py-1 text-xs text-muted-foreground hover:text-foreground" @click="startAddingTask">
<Plus :size="13" /> Задача в истории
</button>
</div>
Expand Down
24 changes: 5 additions & 19 deletions alfy-bot-frontend/src/features/projects/ui/SprintBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { useGroupStore } from '../model/group-store'
import { useSprintStore } from '../model/sprint-store'
import BacklogStoryRow from './BacklogStoryRow.vue'
import BacklogTaskRow from './BacklogTaskRow.vue'
import InlineTitleInput from './InlineTitleInput.vue'

/**
* Блок вкладки «Бэклог»: один спринт проекта или сам бэклог (`sprint = null`).
Expand Down Expand Up @@ -64,10 +63,10 @@ const emit = defineEmits<{
/** Задача перенесена в этот блок или выбрана в меню «В спринт…»: id задачи и id спринта (`null` — бэклог). */
moveTask: [taskId: string, sprintId: string | null]
moveStory: [storyId: string, sprintId: string | null]
/** Введено название новой задачи. */
createTask: [title: string]
/** Запрошено создание задачи в текущем блоке. */
createTask: []
/** Создание задачи с группой истории в спринте текущего блока. */
createStoryTask: [groupId: string, title: string]
createStoryTask: [groupId: string]
/** Клик по строке задачи. */
openTask: [task: Task]
/** Смена отметки выполнения задачи. */
Expand All @@ -83,7 +82,6 @@ const planningTasks = computed(() => taskStore.tasks.filter(t => t.projectId ===
const stories = computed(() => backlogStories(tree.value, props.tasks, planningTasks.value, props.sprint?.id ?? null, props.epicFilter, props.showCompleted))
const standaloneTasks = computed(() => standaloneBacklogTasks(props.tasks, tree.value))

const addingTask = ref(false)
const keepFocusOnClose = ref(false)

const showStart = computed(() =>
Expand Down Expand Up @@ -135,11 +133,6 @@ function onCloseAutoFocus(event: Event) {
keepFocusOnClose.value = false
event.preventDefault()
}

function handleCreateTask(taskTitle: string) {
addingTask.value = false
emit('createTask', taskTitle)
}
</script>

<template>
Expand Down Expand Up @@ -204,7 +197,7 @@ function handleCreateTask(taskTitle: string) {
:entry="entry"
:sprint-id="sprint?.id ?? null"
:sprints="moveTargets"
@create-task="(groupId, taskTitle) => emit('createStoryTask', groupId, taskTitle)"
@create-task="groupId => emit('createStoryTask', groupId)"
@open-task="emit('openTask', $event)"
@toggle-task="emit('toggleTask', $event)"
@move-task="(taskId, sprintId) => emit('moveTask', taskId, sprintId)"
Expand Down Expand Up @@ -246,19 +239,12 @@ function handleCreateTask(taskTitle: string) {

<div class="border-t border-border px-3 py-2">
<button
v-if="!addingTask"
class="flex cursor-pointer items-center gap-1.5 text-xs font-medium text-muted-foreground transition-colors hover:text-foreground"
@click="addingTask = true"
@click="emit('createTask')"
>
<Plus :size="14" />
задача
</button>
<InlineTitleInput
v-else
placeholder="Название задачи"
@submit="handleCreateTask"
@cancel="addingTask = false"
/>
</div>
</section>
</template>
78 changes: 66 additions & 12 deletions alfy-bot-frontend/src/views/ProjectBacklogView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { computed, inject, onMounted, ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import AppHeader from '@/components/AppHeader.vue'
import { Button } from '@/components/ui/button'
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog'
import { useConfirm } from '@/composables/useConfirm'
import { apiErrorMessage } from '@/features/projects/lib/api-error'
import { matchesEpic } from '@/features/projects/lib/backlog-stories'
Expand All @@ -28,6 +29,7 @@ import { useShowCompleted } from '@/features/tasks/lib/use-show-completed'
import { useTaskDetailHandlers } from '@/features/tasks/lib/use-task-detail-handlers'
import { useTaskStore } from '@/features/tasks/model/task-store'
import TaskDetailDialog from '@/features/tasks/ui/TaskDetailDialog.vue'
import TaskForm from '@/features/tasks/ui/TaskForm.vue'
import TaskListOptionsMenu from '@/features/tasks/ui/TaskListOptionsMenu.vue'

const openSidebar = inject<() => void>('openSidebar')
Expand Down Expand Up @@ -101,15 +103,51 @@ async function handleMoveStory(storyId: string, sprintId: string | null) {
}
}

async function handleCreateTask(sprintId: string | null, title: string, groupId?: string) {
actionError.value = null
const creationTarget = ref<{ projectId: string, sprintId: string | null, groupId?: string } | null>(null)
const isCreatingTask = ref(false)
const taskCreationError = ref<string | null>(null)
const creationStory = computed(() => creationTarget.value?.groupId
? findGroup(groupStore.groupsOf(creationTarget.value.projectId), creationTarget.value.groupId)
: null)
const isReleasedStory = computed(() => !!creationTarget.value && releaseStore.releasesOf(creationTarget.value.projectId)
.some(release => release.id === creationStory.value?.releaseId && release.status === 'released'))
const creationLabel = computed(() => {
const target = creationTarget.value
if (!target)
return ''
const sprint = sprintStore.lists[target.projectId]?.find(item => item.id === target.sprintId)
return [project.value?.title, sprint?.name ?? 'Бэклог', creationStory.value?.title].filter(Boolean).join(' · ')
})

function openTaskCreation(sprintId: string | null, groupId?: string) {
if (isCreatingTask.value)
return
taskCreationError.value = null
creationTarget.value = { projectId: projectId.value, sprintId, groupId }
}

function closeTaskCreation(open: boolean) {
if (!open && !isCreatingTask.value)
creationTarget.value = null
}

async function handleCreateTask(data: Omit<Task, 'id' | 'completed' | 'pomodoroCompleted'>) {
const target = creationTarget.value
if (!target || isCreatingTask.value)
return
isCreatingTask.value = true
taskCreationError.value = null
try {
const story = groupId ? findGroup(groupStore.groupsOf(projectId.value), groupId) : null
const releasedStory = releaseStore.releasesOf(projectId.value).some(r => r.id === story?.releaseId && r.status === 'released')
await taskStore.createTask({ title, completed: false, projectId: projectId.value, sprintId, ...(groupId ? { groupId } : {}), ...(releasedStory ? { releaseId: null } : {}) })
await taskStore.createTask({ ...data, completed: false, projectId: target.projectId, sprintId: target.sprintId, groupId: target.groupId ?? null, ...(isReleasedStory.value ? { releaseId: null } : {}) })
if (creationTarget.value === target)
creationTarget.value = null
}
catch (err) {
actionError.value = apiErrorMessage(err, 'Не удалось создать задачу')
if (creationTarget.value === target)
taskCreationError.value = apiErrorMessage(err, 'Не удалось создать задачу')
}
finally {
isCreatingTask.value = false
}
}

Expand Down Expand Up @@ -173,6 +211,7 @@ onMounted(() => {
watch(projectId, (id) => {
epicFilter.value = 'all'
actionError.value = null
creationTarget.value = null
if (id)
loadProjectData(id)
})
Expand Down Expand Up @@ -230,8 +269,8 @@ watch([projectId, isAgileProject], ([id, isAgile]) => {
@complete="completeTarget = activeSprint"
@move-task="handleMoveTask"
@move-story="handleMoveStory"
@create-task="handleCreateTask(activeSprint.id, $event)"
@create-story-task="(groupId, title) => handleCreateTask(activeSprint!.id, title, groupId)"
@create-task="openTaskCreation(activeSprint.id)"
@create-story-task="groupId => openTaskCreation(activeSprint!.id, groupId)"
@open-task="handleOpenTask"
@toggle-task="handleToggleTask"
/>
Expand All @@ -251,8 +290,8 @@ watch([projectId, isAgileProject], ([id, isAgile]) => {
@delete="handleDeleteSprint(sprint)"
@move-task="handleMoveTask"
@move-story="handleMoveStory"
@create-task="handleCreateTask(sprint.id, $event)"
@create-story-task="(groupId, title) => handleCreateTask(sprint.id, title, groupId)"
@create-task="openTaskCreation(sprint.id)"
@create-story-task="groupId => openTaskCreation(sprint.id, groupId)"
@open-task="handleOpenTask"
@toggle-task="handleToggleTask"
/>
Expand All @@ -271,15 +310,30 @@ watch([projectId, isAgileProject], ([id, isAgile]) => {
:has-active-sprint="!!activeSprint"
@move-task="handleMoveTask"
@move-story="handleMoveStory"
@create-task="handleCreateTask(null, $event)"
@create-story-task="(groupId, title) => handleCreateTask(null, title, groupId)"
@create-task="openTaskCreation(null)"
@create-story-task="groupId => openTaskCreation(null, groupId)"
@open-task="handleOpenTask"
@toggle-task="handleToggleTask"
/>
</div>
</div>
</template>
</div>
<Dialog :open="!!creationTarget" @update:open="closeTaskCreation">
<DialogContent class="max-h-[90dvh] overflow-y-auto sm:max-w-xl" @interact-outside.prevent @escape-key-down="isCreatingTask && $event.preventDefault()">
<DialogHeader>
<DialogTitle>Новая задача</DialogTitle>
<DialogDescription>{{ creationLabel }}</DialogDescription>
</DialogHeader>
<p v-if="isReleasedStory" class="text-sm text-muted-foreground">
Новая задача будет без релиза. Релиз можно выбрать в её карточке.
</p>
<TaskForm v-if="creationTarget" modal :loading="isCreatingTask" @submit="handleCreateTask" @cancel="closeTaskCreation(false)" />
<p v-if="taskCreationError" role="alert" class="text-sm text-destructive">
{{ taskCreationError }}
</p>
</DialogContent>
</Dialog>
<SprintFormDialog
v-if="formTarget"
:open="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ describe('строка истории', () => {
expect(row.find('[data-task-id]').exists()).toBe(false)
await row.get('button[aria-label="Добавить задачу в историю Оплата"]').trigger('click')
expect(row.find('[data-task-id="task"]').exists()).toBe(true)
await row.get('input[placeholder="Название задачи в истории"]').setValue('Проверка оплаты')
await row.get('input[placeholder="Название задачи в истории"]').trigger('keydown.enter')
expect(row.emitted('createTask')).toEqual([['story', 'Проверка оплаты']])
expect(row.find('input[placeholder="Название задачи в истории"]').exists()).toBe(false)
expect(row.emitted('createTask')).toEqual([['story']])
row.unmount()
})

Expand Down
14 changes: 5 additions & 9 deletions alfy-bot-frontend/tests/features/projects/ui/SprintBlock.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,27 +98,23 @@ describe('sprintBlock', () => {
backlog.unmount()
})

it('«+ задача» в блоке спринта эмитит createTask с названием', async () => {
it('«+ задача» в блоке спринта запрашивает модалку создания', async () => {
const wrapper = mountBlock({ sprint: makeSprint() })

await buttonByText(wrapper, 'задача')!.trigger('click')
const input = wrapper.find('input')
await input.setValue('Новая')
await input.trigger('keydown.enter')
expect(wrapper.find('input').exists()).toBe(false)

expect(wrapper.emitted('createTask')).toEqual([['Новая']])
expect(wrapper.emitted('createTask')).toEqual([[]])
wrapper.unmount()
})

it('«+ задача» в бэклоге тоже эмитит createTask', async () => {
const wrapper = mountBlock({ sprint: null })

await buttonByText(wrapper, 'задача')!.trigger('click')
const input = wrapper.find('input')
await input.setValue('В бэклог')
await input.trigger('keydown.enter')
expect(wrapper.find('input').exists()).toBe(false)

expect(wrapper.emitted('createTask')).toEqual([['В бэклог']])
expect(wrapper.emitted('createTask')).toEqual([[]])
wrapper.unmount()
})

Expand Down
Loading
Loading