UBERF-10376: Allow todos filtering (#8729)

This commit is contained in:
Andrey Sobolev 2025-04-28 19:54:58 +07:00 committed by GitHub
parent 54df8dcf4b
commit 3bf36c524a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 42 additions and 28 deletions

View File

@ -298,7 +298,7 @@ class Connection implements ClientConnection {
return return
} }
if (resp.rateLimit !== undefined) { if (resp.rateLimit !== undefined && resp.rateLimit.remaining < 10) {
console.log( console.log(
'Rate limits:', 'Rate limits:',
resp.rateLimit.remaining, resp.rateLimit.remaining,

View File

@ -10,7 +10,7 @@
import { Analytics } from '@hcengineering/analytics' import { Analytics } from '@hcengineering/analytics'
export let fullSize: boolean = false export let fullSize: boolean = false
let value: string = '' export let value: string = ''
let disabled: boolean = false let disabled: boolean = false
const client = getClient() const client = getClient()
@ -53,12 +53,12 @@
clear() clear()
} }
function clear () { function clear (): void {
value = '' value = ''
} }
function openPopup () { function openPopup (): void {
showPopup(CreateToDoPopup, {}, 'top') showPopup(CreateToDoPopup, { value }, 'top')
} }
</script> </script>

View File

@ -32,13 +32,14 @@
import Workslots from './Workslots.svelte' import Workslots from './Workslots.svelte'
export let object: Doc | undefined export let object: Doc | undefined
export let value: string = ''
const me = getCurrentEmployee() const me = getCurrentEmployee()
const myAccount = getCurrentAccount() const myAccount = getCurrentAccount()
const todo: AttachedData<ToDo> = { const todo: AttachedData<ToDo> = {
workslots: 0, workslots: 0,
title: '', title: value,
description: '', description: '',
priority: ToDoPriority.NoPriority, priority: ToDoPriority.NoPriority,
attachedSpace: object?.space, attachedSpace: object?.space,

View File

@ -14,34 +14,34 @@
--> -->
<script lang="ts"> <script lang="ts">
import type { DocumentQuery, Ref, WithLookup, IdMap } from '@hcengineering/core'
import type { ToDo, WorkSlot } from '@hcengineering/time'
import { getCurrentEmployee } from '@hcengineering/contact' import { getCurrentEmployee } from '@hcengineering/contact'
import type { DocumentQuery, IdMap, Ref, WithLookup } from '@hcengineering/core'
import { SortingOrder, toIdMap } from '@hcengineering/core'
import type { IntlString } from '@hcengineering/platform' import type { IntlString } from '@hcengineering/platform'
import { createQuery } from '@hcengineering/presentation'
import type { TagElement } from '@hcengineering/tags' import type { TagElement } from '@hcengineering/tags'
import tags from '@hcengineering/tags'
import type { ToDo, WorkSlot } from '@hcengineering/time'
import type { Project } from '@hcengineering/tracker' import type { Project } from '@hcengineering/tracker'
import type { ToDosMode } from '..' import tracker from '@hcengineering/tracker'
import { import {
ButtonIcon,
Header,
IconMenuClose,
IconMenuOpen,
Label,
Scroller, Scroller,
areDatesEqual, areDatesEqual,
todosSP,
defaultSP, defaultSP,
Header, deviceOptionsStore as deviceInfo,
ButtonIcon, todosSP
Label,
IconMenuOpen,
IconMenuClose,
deviceOptionsStore as deviceInfo
} from '@hcengineering/ui' } from '@hcengineering/ui'
import { toIdMap, SortingOrder } from '@hcengineering/core'
import { createQuery } from '@hcengineering/presentation'
import tracker from '@hcengineering/tracker'
import tags from '@hcengineering/tags'
import view from '@hcengineering/view-resources/src/plugin' import view from '@hcengineering/view-resources/src/plugin'
import type { ToDosMode } from '..'
import time from '../plugin'
import { getNearest } from '../utils' import { getNearest } from '../utils'
import CreateToDo from './CreateToDo.svelte' import CreateToDo from './CreateToDo.svelte'
import ToDoGroup from './ToDoGroup.svelte' import ToDoGroup from './ToDoGroup.svelte'
import time from '../plugin'
export let mode: ToDosMode export let mode: ToDosMode
export let tag: Ref<TagElement> | undefined export let tag: Ref<TagElement> | undefined
@ -197,9 +197,11 @@
let inbox: WithLookup<ToDo>[] = [] let inbox: WithLookup<ToDo>[] = []
let done: WithLookup<ToDo>[] = [] let done: WithLookup<ToDo>[] = []
let rawActive: WithLookup<ToDo>[] = [] let rawActive: WithLookup<ToDo>[] = []
let todoValue: string = ''
$: active = filterActive(mode, rawActive, currentDate) $: active = filterActive(mode, rawActive, currentDate)
$: groups = group(inbox, done, active) $: groups = group(inbox, done, active, todoValue)
function filterActive (mode: ToDosMode, raw: WithLookup<ToDo>[], currentDate: Date): WithLookup<ToDo>[] { function filterActive (mode: ToDosMode, raw: WithLookup<ToDo>[], currentDate: Date): WithLookup<ToDo>[] {
if (mode === 'planned') { if (mode === 'planned') {
@ -233,13 +235,18 @@
function group ( function group (
unplanned: WithLookup<ToDo>[], unplanned: WithLookup<ToDo>[],
done: WithLookup<ToDo>[], done: WithLookup<ToDo>[],
active: WithLookup<ToDo>[] active: WithLookup<ToDo>[],
filterValue: string
): [IntlString, WithLookup<ToDo>[]][] { ): [IntlString, WithLookup<ToDo>[]][] {
const trimFilter = filterValue.trim().toLowerCase()
const filterOp = (it: WithLookup<ToDo>) => trimFilter === '' || it.title.toLowerCase().includes(trimFilter)
const groups = new Map<IntlString, WithLookup<ToDo>[]>([ const groups = new Map<IntlString, WithLookup<ToDo>[]>([
[time.string.Scheduled, []], [time.string.Scheduled, []],
[time.string.Unplanned, unplanned], [time.string.Unplanned, unplanned.filter(filterOp)],
[time.string.ToDos, []], [time.string.ToDos, []],
[time.string.Done, done] [time.string.Done, done.filter(filterOp)]
]) ])
const now = Date.now() const now = Date.now()
const todos: { const todos: {
@ -250,7 +257,7 @@
nearest: WorkSlot | undefined nearest: WorkSlot | undefined
todo: WithLookup<ToDo> todo: WithLookup<ToDo>
}[] = [] }[] = []
for (const todo of active) { for (const todo of active.filter(filterOp)) {
if (todo.$lookup?.workslots !== undefined) { if (todo.$lookup?.workslots !== undefined) {
todo.$lookup.workslots = getWorkslots(todo).sort((a, b) => a.date - b.date) todo.$lookup.workslots = getWorkslots(todo).sort((a, b) => a.date - b.date)
} }
@ -275,6 +282,13 @@
time.string.Scheduled, time.string.Scheduled,
scheduled.map((p) => p.todo) scheduled.map((p) => p.todo)
) )
if (trimFilter.length > 0) {
for (const [k, v] of groups) {
if (v.length === 0) {
groups.delete(k)
}
}
}
return Array.from(groups) return Array.from(groups)
} }
const getDateStr = (date: Date): string => { const getDateStr = (date: Date): string => {
@ -313,8 +327,7 @@
{/if} {/if}
</div> </div>
</Header> </Header>
<CreateToDo fullSize /> <CreateToDo fullSize bind:value={todoValue} />
<Scroller fade={filteredGroups.length > 1 ? todosSP : defaultSP} noStretch> <Scroller fade={filteredGroups.length > 1 ? todosSP : defaultSP} noStretch>
{#each filteredGroups as group} {#each filteredGroups as group}
<ToDoGroup <ToDoGroup