1
0

feat(kanban): use total task count from the api instead of manually calculating it per bucket

This fixes an ux issue where the total count would show a wrong number of total tasks because that was the number of tasks which were loaded at the time. In combination with bucket limits, this caused error messages when the user would attempt to drag tasks into a bucket which appeared not full but was.
This commit is contained in:
kolaente 2023-06-08 16:57:58 +02:00
parent c7a989d7dc
commit ad27f588a2
No known key found for this signature in database
GPG Key ID: F40E70337AB24C9B
4 changed files with 19 additions and 3 deletions

View File

@ -10,6 +10,7 @@ export interface IBucket extends IAbstract {
tasks: ITask[] tasks: ITask[]
isDoneBucket: boolean isDoneBucket: boolean
position: number position: number
count: number
createdBy: IUser createdBy: IUser
created: Date created: Date

View File

@ -14,6 +14,7 @@ export default class BucketModel extends AbstractModel<IBucket> implements IBuck
tasks: ITask[] = [] tasks: ITask[] = []
isDoneBucket = false isDoneBucket = false
position = 0 position = 0
count = 0
createdBy: IUser = null createdBy: IUser = null
created: Date = null created: Date = null

View File

@ -167,6 +167,7 @@ export const useKanbanStore = defineStore('kanban', () => {
const oldBucket = buckets.value[bucketIndex] const oldBucket = buckets.value[bucketIndex]
const newBucket = { const newBucket = {
...oldBucket, ...oldBucket,
count: oldBucket.count + 1,
tasks: [ tasks: [
...oldBucket.tasks, ...oldBucket.tasks,
task, task,

View File

@ -52,10 +52,10 @@
:contenteditable="(bucketTitleEditable && canWrite && !collapsedBuckets[bucket.id]) ? true : undefined" :contenteditable="(bucketTitleEditable && canWrite && !collapsedBuckets[bucket.id]) ? true : undefined"
:spellcheck="false">{{ bucket.title }}</h2> :spellcheck="false">{{ bucket.title }}</h2>
<span <span
:class="{'is-max': bucket.tasks.length >= bucket.limit}" :class="{'is-max': bucket.count >= bucket.limit}"
class="limit" class="limit"
v-if="bucket.limit > 0"> v-if="bucket.limit > 0">
{{ bucket.tasks.length }}/{{ bucket.limit }} {{ bucket.count }}/{{ bucket.limit }}
</span> </span>
<dropdown <dropdown
class="is-right options" class="is-right options"
@ -433,6 +433,19 @@ async function updateTaskPosition(e) {
) { ) {
newTask.done = newBucket.isDoneBucket newTask.done = newBucket.isDoneBucket
} }
if (
oldBucket !== undefined && // This shouldn't actually be `undefined`, but let's play it safe.
newBucket.id !== oldBucket.id
) {
kanbanStore.setBucketById({
...oldBucket,
count: oldBucket.count - 1,
})
kanbanStore.setBucketById({
...newBucket,
count: newBucket.count + 1,
})
}
try { try {
await taskStore.update(newTask) await taskStore.update(newTask)
@ -580,7 +593,7 @@ function shouldAcceptDrop(bucket: IBucket) {
// If there is no limit set, dragging & dropping should always work // If there is no limit set, dragging & dropping should always work
bucket.limit === 0 || bucket.limit === 0 ||
// Disallow dropping to buckets which have their limit reached // Disallow dropping to buckets which have their limit reached
bucket.tasks.length < bucket.limit bucket.count < bucket.limit
) )
} }