Skip to content

UBER-298: Add readonly users option to the UserBoxItems component #3481

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions plugins/contact-resources/src/components/UserBoxItems.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
// Copyright © 2022 Hardcore Engineering Inc.
// Copyright © 2022-2023 Hardcore Engineering Inc.
//
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
Expand All @@ -14,7 +14,7 @@
-->
<script lang="ts">
import contact, { Employee } from '@hcengineering/contact'
import type { Class, DocumentQuery, Ref } from '@hcengineering/core'
import type { Class, DocumentQuery, IdMap, Ref } from '@hcengineering/core'
import type { IntlString } from '@hcengineering/platform'
import { Label, showPopup, ActionIcon, IconClose, IconAdd, Icon } from '@hcengineering/ui'
import type { IconSize } from '@hcengineering/ui'
Expand All @@ -25,6 +25,7 @@
import UsersPopup from './UsersPopup.svelte'

export let items: Ref<Employee>[] = []
export let readonlyItems: Ref<Employee>[] = []
export let _class: Ref<Class<Employee>> = contact.class.Employee
export let docQuery: DocumentQuery<Employee> | undefined = {
active: true
Expand All @@ -36,8 +37,10 @@
export let width: string | undefined = undefined
export let readonly: boolean = false

let persons: Employee[] = items.map((p) => $employeeByIdStore.get(p)).filter((p) => p !== undefined) as Employee[]
$: persons = items.map((p) => $employeeByIdStore.get(p)).filter((p) => p !== undefined) as Employee[]
let persons: Employee[] = getPersons(items, $employeeByIdStore)
$: persons = getPersons(items, $employeeByIdStore)
let readonlyPersons: Employee[] = getPersons(readonlyItems, $employeeByIdStore)
$: readonlyPersons = getPersons(readonlyItems, $employeeByIdStore)

const dispatch = createEventDispatcher()

Expand All @@ -51,6 +54,7 @@
multiSelect: true,
allowDeselect: false,
selectedUsers: items,
ignoreUsers: readonlyItems,
readonly
},
evt.target as HTMLElement,
Expand All @@ -64,6 +68,10 @@
)
}

function getPersons (employees: Ref<Employee>[], employeeById: IdMap<Employee>) {
return employees.map((p) => employeeById.get(p)).filter((p) => p !== undefined) as Employee[]
}

const removePerson = (removed: Employee) => {
const newItems = items.filter((it) => it !== removed._id)
dispatch('update', newItems)
Expand All @@ -72,6 +80,11 @@

<div class="flex-col" style:width={width ?? 'auto'}>
<div class="flex-row-center flex-wrap">
{#each readonlyPersons as person}
<div class="usertag-container gap-1-5">
<UserInfo value={person} {size} />
</div>
{/each}
{#each persons as person}
<div class="usertag-container gap-1-5">
<UserInfo value={person} {size} />
Expand Down
3 changes: 0 additions & 3 deletions plugins/contact-resources/src/components/UsersPopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@
{@const cl = hierarchy.getClass(person._class)}
<div class="menu-group__header">
<span class="overflow-label">
<!-- {#if cl.icon}
<Icon icon={cl.icon} size={'small'} />
{/if} -->
<Label label={cl.label} />
</span>
</div>
Expand Down