feat(kanban): use total task count from the api instead of manually calculating it per bucket
continuous-integration/drone/push Build is passing Details

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
Signed by: konrad
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[]
isDoneBucket: boolean
position: number
count: number
createdBy: IUser
created: Date

View File

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

View File

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

View File

@ -52,10 +52,10 @@
:contenteditable="(bucketTitleEditable && canWrite && !collapsedBuckets[bucket.id]) ? true : undefined"
:spellcheck="false">{{ bucket.title }}</h2>
<span
:class="{'is-max': bucket.tasks.length >= bucket.limit}"
:class="{'is-max': bucket.count >= bucket.limit}"
class="limit"
v-if="bucket.limit > 0">
{{ bucket.tasks.length }}/{{ bucket.limit }}
{{ bucket.count }}/{{ bucket.limit }}
</span>
<dropdown
class="is-right options"
@ -433,6 +433,19 @@ async function updateTaskPosition(e) {
) {
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 {
await taskStore.update(newTask)
@ -580,7 +593,7 @@ function shouldAcceptDrop(bucket: IBucket) {
// If there is no limit set, dragging & dropping should always work
bucket.limit === 0 ||
// Disallow dropping to buckets which have their limit reached
bucket.tasks.length < bucket.limit
bucket.count < bucket.limit
)
}