UBER-267: Fix created selection (#3269)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2023-05-29 16:10:27 +07:00 committed by GitHub
parent 2d8779a06f
commit 24f3c161d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 8 deletions

View File

@ -26,6 +26,7 @@
"Edit": "Edit", "Edit": "Edit",
"DocumentPreview": "Preview", "DocumentPreview": "Preview",
"MakePrivate": "Make private", "MakePrivate": "Make private",
"MakePrivateDescription": "Only members can see it" "MakePrivateDescription": "Only members can see it",
"Created": "Created"
} }
} }

View File

@ -26,6 +26,7 @@
"Edit": "Редактировать", "Edit": "Редактировать",
"DocumentPreview": "Предпросмотр", "DocumentPreview": "Предпросмотр",
"MakePrivate": "Сделать личным", "MakePrivate": "Сделать личным",
"MakePrivateDescription": "Только пользователи могут видеть это" "MakePrivateDescription": "Только пользователи могут видеть это",
"Created": "Созданные"
} }
} }

View File

@ -24,12 +24,12 @@
IconCheck, IconCheck,
IconSearch, IconSearch,
ListView, ListView,
closeTooltip,
createFocusManager, createFocusManager,
deviceOptionsStore, deviceOptionsStore,
resizeObserver, resizeObserver,
showPopup, showPopup,
tooltip, tooltip
closeTooltip
} from '@hcengineering/ui' } from '@hcengineering/ui'
import { createEventDispatcher } from 'svelte' import { createEventDispatcher } from 'svelte'
import presentation from '..' import presentation from '..'
@ -58,6 +58,7 @@
export let create: ObjectCreate | undefined = undefined export let create: ObjectCreate | undefined = undefined
export let readonly = false export let readonly = false
export let disallowDeselect: Ref<Doc>[] | undefined = undefined export let disallowDeselect: Ref<Doc>[] | undefined = undefined
export let created: Doc[] = []
let search: string = '' let search: string = ''
@ -66,6 +67,7 @@
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
$: showCategories = $: showCategories =
created.length > 0 ||
objects.map((it) => (it as any)[groupBy]).filter((it, index, arr) => arr.indexOf(it) === index).length > 1 objects.map((it) => (it as any)[groupBy]).filter((it, index, arr) => arr.indexOf(it) === index).length > 1
const checkSelected = (item: Doc): void => { const checkSelected = (item: Doc): void => {
@ -130,6 +132,7 @@
const newPerson = await client.findOne(_class, { _id: res }) const newPerson = await client.findOne(_class, { _id: res })
if (newPerson !== undefined) { if (newPerson !== undefined) {
search = c.update?.(newPerson) ?? '' search = c.update?.(newPerson) ?? ''
dispatch('created', newPerson)
dispatch('search', search) dispatch('search', search)
} }
} }
@ -177,6 +180,13 @@
$: updateLocation(scrollDiv, selectedDiv, objects, selected) $: updateLocation(scrollDiv, selectedDiv, objects, selected)
const forbiddenDeselectItemIds = new Set(disallowDeselect) const forbiddenDeselectItemIds = new Set(disallowDeselect)
function getGroup (doc: Doc, groupBy: any): any {
if (created.find((it) => it._id === doc._id) !== undefined) {
return '_created'
}
return toAny(doc)[groupBy]
}
</script> </script>
<FocusHandler {manager} /> <FocusHandler {manager} />
@ -225,7 +235,7 @@
<svelte:fragment slot="category" let:item> <svelte:fragment slot="category" let:item>
{#if showCategories} {#if showCategories}
{@const obj = toAny(objects[item])} {@const obj = toAny(objects[item])}
{#if item === 0 || (item > 0 && toAny(objects[item - 1])[groupBy] !== obj[groupBy])} {#if item === 0 || (item > 0 && getGroup(objects[item - 1], groupBy) !== getGroup(obj, groupBy))}
<!--Category for first item--> <!--Category for first item-->
{#if item > 0}<div class="menu-separator" />{/if} {#if item > 0}<div class="menu-separator" />{/if}
<div class="category-box"> <div class="category-box">

View File

@ -15,6 +15,7 @@
<script lang="ts"> <script lang="ts">
import type { Class, Doc, DocumentQuery, FindOptions, Ref } from '@hcengineering/core' import type { Class, Doc, DocumentQuery, FindOptions, Ref } from '@hcengineering/core'
import type { IntlString } from '@hcengineering/platform' import type { IntlString } from '@hcengineering/platform'
import { Label } from '@hcengineering/ui'
import presentation from '..' import presentation from '..'
import { ObjectCreate } from '../types' import { ObjectCreate } from '../types'
import { createQuery } from '../utils' import { createQuery } from '../utils'
@ -45,6 +46,8 @@
export let readonly = false export let readonly = false
export let disallowDeselect: Ref<Doc>[] | undefined = undefined export let disallowDeselect: Ref<Doc>[] | undefined = undefined
const created: Doc[] = []
let search: string = '' let search: string = ''
let objects: Doc[] = [] let objects: Doc[] = []
@ -68,7 +71,12 @@
const bval: string = `${(b as any)[groupBy]}` const bval: string = `${(b as any)[groupBy]}`
return aval.localeCompare(bval) return aval.localeCompare(bval)
}) })
objects = result if (created.length > 0) {
const cmap = new Set(created.map((it) => it._id))
objects = [...created, ...result.filter((d) => !cmap.has(d._id))]
} else {
objects = result
}
}, },
{ ...(options ?? {}), limit: 200 } { ...(options ?? {}), limit: 200 }
) )
@ -98,6 +106,8 @@
on:close on:close
on:changeContent on:changeContent
on:search={(e) => (search = e.detail)} on:search={(e) => (search = e.detail)}
on:created={(doc) => created.push(doc.detail)}
{created}
> >
<svelte:fragment slot="item" let:item> <svelte:fragment slot="item" let:item>
{#if $$slots.item} {#if $$slots.item}
@ -105,7 +115,13 @@
{/if} {/if}
</svelte:fragment> </svelte:fragment>
<svelte:fragment slot="category" let:item> <svelte:fragment slot="category" let:item>
{#if $$slots.category} {#if created.length > 0 && created.find((it) => it._id === item._id) !== undefined}
<div class="menu-group__header">
<span class="overflow-label">
<Label label={presentation.string.Created} />
</span>
</div>
{:else if $$slots.category}
<slot name="category" {item} /> <slot name="category" {item} />
{/if} {/if}
</svelte:fragment> </svelte:fragment>

View File

@ -57,7 +57,8 @@ export default plugin(presentationId, {
DocumentPreview: '' as IntlString, DocumentPreview: '' as IntlString,
MakePrivate: '' as IntlString, MakePrivate: '' as IntlString,
MakePrivateDescription: '' as IntlString, MakePrivateDescription: '' as IntlString,
OpenInANewTab: '' as IntlString OpenInANewTab: '' as IntlString,
Created: '' as IntlString
}, },
metadata: { metadata: {
RequiredVersion: '' as Metadata<string>, RequiredVersion: '' as Metadata<string>,