Skip to content

Commit 0f80bfd

Browse files
authored
Process const context (#9996)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
1 parent 22f1ba6 commit 0f80bfd

File tree

12 files changed

+131
-25
lines changed

12 files changed

+131
-25
lines changed

packages/ui/src/components/EditBox.svelte

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,9 @@
6666
if (minValue !== undefined && maxValue !== undefined && maxValue < minValue) return
6767
if (minValue !== undefined && val < minValue) value = minValue
6868
if (maxValue !== undefined && val > maxValue) value = maxValue
69-
dispatch('change')
69+
dispatch('value', value)
7070
}
7171
72-
$: setValue(value, maxValue, minValue)
73-
7472
$: translateCB(placeholder, placeholderParam ?? {}, $themeStore.language, (res) => {
7573
phTranslate = res
7674
})
@@ -196,11 +194,17 @@
196194
type="number"
197195
bind:value
198196
placeholder={phTranslate}
197+
min={minValue}
198+
max={maxValue}
199199
on:input={handleInput}
200-
on:change
200+
on:change={() => {
201+
setValue(value, maxValue, minValue)
202+
dispatch('change', value)
203+
}}
201204
on:keydown
202205
on:keypress
203206
on:blur={() => {
207+
setValue(value, maxValue, minValue)
204208
dispatch('blur', value)
205209
}}
206210
/>

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
{#if contextValue}
8787
<ContextValue
8888
{process}
89-
{masterTag}
9089
{contextValue}
9190
{context}
9291
{attribute}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!--
2+
// Copyright © 2025 Hardcore Engineering Inc.
3+
//
4+
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License. You may
6+
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
//
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
-->
15+
<script lang="ts">
16+
import { getClient } from '@hcengineering/presentation'
17+
import type { Process, SelectedConst } from '@hcengineering/process'
18+
import { AnyComponent, Component } from '@hcengineering/ui'
19+
import { findAttributePresenter } from '@hcengineering/view-resources'
20+
import { readonly } from 'svelte/store'
21+
22+
export let contextValue: SelectedConst
23+
export let process: Process
24+
25+
const client = getClient()
26+
let presenter: AnyComponent | undefined = undefined
27+
$: presenter = findAttributePresenter(client, process.masterTag, contextValue.key)
28+
</script>
29+
30+
{#if presenter !== undefined}
31+
<Component is={presenter} props={{ value: contextValue.value, readonly }} disabled />
32+
{/if}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<!--
2+
// Copyright © 2025 Hardcore Engineering Inc.
3+
//
4+
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License. You may
6+
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
//
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
-->
15+
<script lang="ts">
16+
import { AnyAttribute } from '@hcengineering/core'
17+
import { Card, findAttributeEditor, getClient } from '@hcengineering/presentation'
18+
import { Component } from '@hcengineering/ui'
19+
import { createEventDispatcher } from 'svelte'
20+
21+
export let attribute: AnyAttribute
22+
23+
const client = getClient()
24+
$: editor = findAttributeEditor(client, attribute.attributeOf, attribute.name)
25+
26+
const dispatch = createEventDispatcher()
27+
28+
function save (): void {
29+
dispatch('close', value)
30+
}
31+
32+
function onChange (val: any): void {
33+
value = val
34+
}
35+
36+
let value: any | undefined = undefined
37+
</script>
38+
39+
<Card width={'menu'} label={attribute.label} canSave={value != null} on:close okAction={save}>
40+
{value}
41+
{#if editor != null}
42+
<Component
43+
is={editor}
44+
props={{
45+
attribute,
46+
showNavigate: false,
47+
onChange,
48+
label: attribute.label,
49+
placeholder: attribute?.label,
50+
kind: 'ghost',
51+
size: 'large',
52+
width: '100%',
53+
justify: 'left',
54+
type: attribute?.type
55+
}}
56+
/>
57+
{/if}
58+
</Card>

plugins/process-resources/src/components/attributeEditors/ContextSelectorPopup.svelte

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424
RelatedContext,
2525
SelectedContext
2626
} from '@hcengineering/process'
27-
import { Label, resizeObserver, Scroller, Submenu } from '@hcengineering/ui'
27+
import { eventToHTMLElement, Label, resizeObserver, Scroller, showPopup, Submenu } from '@hcengineering/ui'
2828
import { createEventDispatcher } from 'svelte'
2929
import plugin from '../../plugin'
3030
import { generateContextId, getRelationObjectReduceFunc, getValueReduceFunc } from '../../utils'
3131
import ExecutionContextPresenter from './ExecutionContextPresenter.svelte'
32+
import ConstValuePopup from './ConstValuePopup.svelte'
3233
3334
export let process: Process
3435
export let masterTag: Ref<MasterTag | Tag>
@@ -44,11 +45,6 @@
4445
dispatch('close')
4546
}
4647
47-
function onCustom (): void {
48-
onSelect(null)
49-
dispatch('close')
50-
}
51-
5248
function onAttribute (val: AnyAttribute): void {
5349
const valueFunc = getValueReduceFunc(val, attribute)
5450
onClick({
@@ -108,6 +104,19 @@
108104
})
109105
dispatch('close')
110106
}
107+
108+
function onConst (e: MouseEvent): void {
109+
showPopup(ConstValuePopup, { attribute }, eventToHTMLElement(e), (res) => {
110+
if (res != null) {
111+
onSelect({
112+
type: 'const',
113+
key: attribute.name,
114+
value: res
115+
})
116+
}
117+
dispatch('close')
118+
})
119+
}
111120
</script>
112121

113122
<div class="selectPopup" use:resizeObserver={() => dispatch('changeContent')}>
@@ -241,13 +250,7 @@
241250
<div class="menu-separator" />
242251
{/if}
243252
{#if !forbidValue}
244-
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
245-
<button
246-
on:click={() => {
247-
onCustom()
248-
}}
249-
class="menu-item"
250-
>
253+
<button on:click={onConst} class="menu-item">
251254
<span class="overflow-label pr-1">
252255
<Label label={plugin.string.CustomValue} />
253256
</span>

plugins/process-resources/src/components/attributeEditors/ContextValue.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// limitations under the License.
1414
-->
1515
<script lang="ts">
16-
import { MasterTag, Tag } from '@hcengineering/card'
1716
import { AnyAttribute, Class, Doc, Ref } from '@hcengineering/core'
1817
import { Context, Process, SelectedContext } from '@hcengineering/process'
1918
import { Button, eventToHTMLElement, showPopup } from '@hcengineering/ui'
@@ -23,7 +22,6 @@
2322
import ContextValuePresenter from './ContextValuePresenter.svelte'
2423
2524
export let process: Process
26-
export let masterTag: Ref<MasterTag | Tag>
2725
export let contextValue: SelectedContext
2826
export let context: Context
2927
export let attribute: AnyAttribute

plugins/process-resources/src/components/attributeEditors/ContextValuePresenter.svelte

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import RelContextPresenter from './RelContextPresenter.svelte'
2222
import FunctionContextPresenter from './FunctionContextPresenter.svelte'
2323
import ExecutionContextPresenter from './ExecutionContextPresenter.svelte'
24+
import ConstContextPresenter from './ConstContextPresenter.svelte'
2425
import FunctionPresenter from './FunctionPresenter.svelte'
2526
2627
export let process: Process
@@ -42,6 +43,8 @@
4243
<FunctionContextPresenter {contextValue} {context} {process} />
4344
{:else if contextValue.type === 'context'}
4445
<ExecutionContextPresenter {contextValue} {process} />
46+
{:else if contextValue.type === 'const'}
47+
<ConstContextPresenter {contextValue} {process} />
4548
{/if}
4649
</div>
4750
{#if contextValue.sourceFunction}

plugins/process-resources/src/components/criterias/ArraySizeCriteria.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
{#if contextValue}
6666
<ContextValue
6767
{process}
68-
masterTag={process.masterTag}
6968
{contextValue}
7069
{context}
7170
{attribute}

plugins/process-resources/src/components/criterias/BaseCriteriaEditor.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
{#if contextValue}
6969
<ContextValue
7070
{process}
71-
masterTag={process.masterTag}
7271
{contextValue}
7372
{context}
7473
{attribute}

plugins/process-resources/src/components/criterias/RangeCriteria.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090
{#if firstContextValue}
9191
<ContextValue
9292
{process}
93-
masterTag={process.masterTag}
9493
contextValue={firstContextValue}
9594
{context}
9695
{attribute}
@@ -136,7 +135,6 @@
136135
{#if secondContextValue}
137136
<ContextValue
138137
{process}
139-
masterTag={process.masterTag}
140138
contextValue={secondContextValue}
141139
{context}
142140
{attribute}

0 commit comments

Comments
 (0)