fix(task): pass a list specified via quick add magic down to all subtasks created via indention

Resolves vikunja/frontend#2771
This commit is contained in:
kolaente 2022-12-02 18:39:52 +01:00
parent 83fb8c3ded
commit b2da4fd126
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
5 changed files with 44 additions and 4 deletions

View File

@ -98,14 +98,20 @@ async function addTask() {
// by quick add magic.
const createdTasks: { [key: ITask['title']]: ITask } = {}
const tasksToCreate = parseSubtasksViaIndention(newTaskTitle.value)
const newTasks = tasksToCreate.map(async ({title}) => {
const newTasks = tasksToCreate.map(async ({title, list}) => {
if (title === '') {
return
}
// If the task has a list specified, make sure to use it
let listId = null
if (list !== null) {
listId = await taskStore.findListId({list, listId: 0})
}
const task = await taskStore.createNewTask({
title,
listId: authStore.settings.defaultListId,
listId: listId || authStore.settings.defaultListId,
position: props.defaultPosition,
})
createdTasks[title] = task

View File

@ -106,4 +106,15 @@ task two`)
expect(tasks).to.have.length(1)
expect(tasks[0].parent).toBeNull()
})
it('Should add the list of the parent task as list for all sub tasks', () => {
const tasks = parseSubtasksViaIndention(
`parent task +list
sub task 1
sub task 2`)
expect(tasks).to.have.length(3)
expect(tasks[0].list).to.eq('list')
expect(tasks[1].list).to.eq('list')
expect(tasks[2].list).to.eq('list')
})
})

View File

@ -1,6 +1,9 @@
import {getListFromPrefix} from '@/modules/parseTaskText'
export interface TaskWithParent {
title: string,
parent: string | null,
list: string | null,
}
function cleanupTitle(title: string) {
@ -20,8 +23,11 @@ export function parseSubtasksViaIndention(taskTitles: string): TaskWithParent[]
const task: TaskWithParent = {
title: cleanupTitle(title),
parent: null,
list: null,
}
task.list = getListFromPrefix(task.title)
if (index === 0) {
return task
}
@ -41,6 +47,10 @@ export function parseSubtasksViaIndention(taskTitles: string): TaskWithParent[]
} while (parentSpaces >= matchedSpaces)
task.title = cleanupTitle(title.replace(spaceRegex, ''))
task.parent = task.parent.replace(spaceRegex, '')
if (task.list === null) {
// This allows to specify a list once for the parent task and inherit it to all subtasks
task.list = getListFromPrefix(task.parent)
}
}
return task

View File

@ -1,6 +1,7 @@
import {parseDate} from '../helpers/time/parseDate'
import {PRIORITIES} from '@/constants/priorities'
import {REPEAT_TYPES, type IRepeatAfter, type IRepeatType} from '@/types/IRepeatAfter'
import {getQuickAddMagicMode} from '@/helpers/quickAddMagicMode'
const VIKUNJA_PREFIXES: Prefixes = {
label: '*',
@ -74,8 +75,7 @@ export const parseTaskText = (text: string, prefixesMode: PrefixMode = PrefixMod
result.labels = getItemsFromPrefix(text, prefixes.label)
result.text = cleanupItemText(result.text, result.labels, prefixes.label)
const lists: string[] = getItemsFromPrefix(result.text, prefixes.list)
result.list = lists.length > 0 ? lists[0] : null
result.list = getListFromPrefix(result.text, prefixes.list)
result.text = result.list !== null ? cleanupItemText(result.text, [result.list], prefixes.list) : result.text
result.priority = getPriority(result.text, prefixes.priority)
@ -130,6 +130,18 @@ const getItemsFromPrefix = (text: string, prefix: string): string[] => {
return Array.from(new Set(items))
}
export const getListFromPrefix = (text: string, listPrefix: string | null = null): string | null => {
if (listPrefix === null) {
const prefixes = PREFIXES[getQuickAddMagicMode()]
if (prefixes === undefined) {
return null
}
listPrefix = prefixes.list
}
const lists: string[] = getItemsFromPrefix(text, listPrefix)
return lists.length > 0 ? lists[0] : null
}
const getPriority = (text: string, prefix: string): number | null => {
const ps = getItemsFromPrefix(text, prefix)
if (ps.length === 0) {

View File

@ -437,6 +437,7 @@ export const useTaskStore = defineStore('task', () => {
addLabelsToTask,
createNewTask,
setCoverImage,
findListId,
}
})