Skip to content

Commit b49bf27

Browse files
authored
Improve UpdateCard editor (#8479)
1 parent 507078d commit b49bf27

File tree

4 files changed

+84
-10
lines changed

4 files changed

+84
-10
lines changed

plugins/process-resources/src/components/ParamsEditor.svelte

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
export let state: State
2323
export let _class: Ref<Class<Doc>>
2424
export let params: MethodParams<Doc>
25+
export let allowRemove: boolean = false
2526
export let keys: string[] = []
2627
2728
const dispatch = createEventDispatcher()
@@ -45,10 +46,12 @@
4546
{state}
4647
{_class}
4748
{key}
49+
{allowRemove}
4850
object={params}
4951
on:update={(e) => {
5052
change(e, key)
5153
}}
54+
on:remove
5255
/>
5356
{/each}
5457
</div>

plugins/process-resources/src/components/ProcessAttribute.svelte

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,16 @@
1515
<script lang="ts">
1616
import { AnyAttribute, Class, Doc, Ref } from '@hcengineering/core'
1717
import { Context, parseContext, SelectedContext } from '@hcengineering/process'
18-
import { AnySvelteComponent, Button, eventToHTMLElement, IconAdd, Label, showPopup, tooltip } from '@hcengineering/ui'
18+
import {
19+
AnySvelteComponent,
20+
Button,
21+
eventToHTMLElement,
22+
IconAdd,
23+
IconClose,
24+
Label,
25+
showPopup,
26+
tooltip
27+
} from '@hcengineering/ui'
1928
import { AttributeCategory } from '@hcengineering/view'
2029
import { createEventDispatcher } from 'svelte'
2130
import ContextSelectorPopup from './attributeEditors/ContextSelectorPopup.svelte'
@@ -29,6 +38,7 @@
2938
}
3039
export let attribute: AnyAttribute
3140
export let editor: AnySvelteComponent | undefined
41+
export let allowRemove: boolean = false
3242
3343
const dispatch = createEventDispatcher()
3444
@@ -94,14 +104,23 @@
94104
/>
95105
</div>
96106
{/if}
97-
<div class="button">
107+
<div class="button flex-row-center">
98108
<Button
99109
icon={IconAdd}
100110
kind="ghost"
101111
on:click={(e) => {
102112
selectContext(e)
103113
}}
104114
/>
115+
{#if allowRemove}
116+
<Button
117+
icon={IconClose}
118+
kind="ghost"
119+
on:click={() => {
120+
dispatch('remove', { key: attribute.name })
121+
}}
122+
/>
123+
{/if}
105124
</div>
106125
</div>
107126
{/if}

plugins/process-resources/src/components/ProcessAttributeEditor.svelte

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
export let _class: Ref<Class<Doc>>
2626
export let key: string
2727
export let object: Record<string, any>
28+
export let allowRemove: boolean = false
2829
2930
const client = getClient()
3031
const hierarchy = client.getHierarchy()
@@ -61,6 +62,8 @@
6162
{attribute}
6263
{presenterClass}
6364
{value}
65+
{allowRemove}
66+
on:remove
6467
on:change={(e) => {
6568
onChange(e.detail)
6669
}}

plugins/process-resources/src/components/UpdateCardEditor.svelte

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
-->
1515
<script lang="ts">
1616
import { Card, MasterTag } from '@hcengineering/card'
17-
import core, { Class, Ref } from '@hcengineering/core'
18-
import { getClient } from '@hcengineering/presentation'
17+
import core, { AnyAttribute, Class, Ref } from '@hcengineering/core'
18+
import presentation, { getClient } from '@hcengineering/presentation'
1919
import { Process, State, Step } from '@hcengineering/process'
2020
import { createEventDispatcher } from 'svelte'
2121
import ParamsEditor from './ParamsEditor.svelte'
22+
import { Button, eventToHTMLElement, SelectPopup, showPopup } from '@hcengineering/ui'
2223
2324
export let process: Process
2425
export let state: State
@@ -39,20 +40,68 @@
3940
}
4041
}
4142
42-
function getKeys (_class: Ref<Class<MasterTag>>): string[] {
43+
function getKeys (_class: Ref<Class<MasterTag>>): AnyAttribute[] {
4344
const ignoreKeys = ['_class', 'content', 'parent', 'attachments', 'todos']
4445
const attributes = hierarchy.getAllAttributes(_class, core.class.Doc)
45-
const res: string[] = []
46+
const res: AnyAttribute[] = []
4647
for (const [key, attr] of attributes) {
4748
if (attr.hidden === true) continue
48-
if (attr.readonly === true) continue
4949
if (ignoreKeys.includes(key)) continue
50-
res.push(key)
50+
res.push(attr)
5151
}
5252
return res
5353
}
5454
55-
$: keys = getKeys(process.masterTag)
55+
let keys = Object.keys(params)
56+
57+
$: allAttrs = getKeys(process.masterTag)
58+
$: possibleAttrs = allAttrs.filter((attr) => !keys.includes(attr.name))
59+
60+
function addKey (key: string): void {
61+
keys = [...keys, key]
62+
}
63+
64+
function onAdd (e: MouseEvent): void {
65+
showPopup(
66+
SelectPopup,
67+
{
68+
value: possibleAttrs.map((p) => {
69+
return { id: p.name, label: p.label }
70+
})
71+
},
72+
eventToHTMLElement(e),
73+
(res) => {
74+
if (res != null) {
75+
addKey(res)
76+
}
77+
}
78+
)
79+
}
80+
81+
function remove (e: CustomEvent<any>): void {
82+
if (e.detail !== undefined) {
83+
const key = e.detail.key
84+
keys = keys.filter((k) => k !== key)
85+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
86+
delete (params as any)[key]
87+
;(step.params as any) = params
88+
dispatch('change', step)
89+
}
90+
}
5691
</script>
5792

58-
<ParamsEditor _class={process.masterTag} {process} {state} {keys} {params} on:change={change} />
93+
<ParamsEditor
94+
_class={process.masterTag}
95+
{process}
96+
{state}
97+
{keys}
98+
{params}
99+
allowRemove
100+
on:remove={remove}
101+
on:change={change}
102+
/>
103+
{#if possibleAttrs.length > 0}
104+
<div class="flex-center mt-4">
105+
<Button label={presentation.string.Add} width={'100%'} kind={'link-bordered'} size={'large'} on:click={onAdd} />
106+
</div>
107+
{/if}

0 commit comments

Comments
 (0)