|
1 | 1 | <script lang="ts">
|
2 | 2 | import Button from '$lib/holocene/button.svelte';
|
| 3 | + import ChipInput from '$lib/holocene/input/chip-input.svelte'; |
| 4 | + import Input from '$lib/holocene/input/input.svelte'; |
| 5 | + import NumberInput from '$lib/holocene/input/number-input.svelte'; |
3 | 6 | import Option from '$lib/holocene/select/option.svelte';
|
4 | 7 | import Select from '$lib/holocene/select/select.svelte';
|
5 | 8 | import { translate } from '$lib/i18n/translate';
|
|
11 | 14 | import { SEARCH_ATTRIBUTE_TYPE } from '$lib/types/workflows';
|
12 | 15 |
|
13 | 16 | import DatetimeInput from './datetime-input.svelte';
|
14 |
| - import ListInput from './list-input.svelte'; |
15 |
| - import NumberInput from './number-input.svelte'; |
16 |
| - import TextInput from './text-input.svelte'; |
17 | 17 |
|
18 | 18 | export let attributesToAdd: SearchAttributeInput[] = [];
|
19 | 19 | export let attribute: SearchAttributeInput;
|
20 | 20 | export let onRemove: (attribute: string) => void;
|
21 | 21 |
|
22 |
| - $: type = $customSearchAttributes[attribute.attribute]; |
23 | 22 | $: isDisabled = (value: string) => {
|
24 |
| - return !!attributesToAdd.find((a) => a.attribute === value); |
| 23 | + return !!attributesToAdd.find((a) => a.label === value); |
25 | 24 | };
|
26 | 25 |
|
| 26 | + const getType = (attr: string) => $customSearchAttributes[attr]; |
| 27 | +
|
27 | 28 | const handleAttributeChange = (attr: string) => {
|
28 |
| - if (type !== $customSearchAttributes[attr]) { |
| 29 | + const type = getType(attr); |
| 30 | +
|
| 31 | + if (type === SEARCH_ATTRIBUTE_TYPE.KEYWORDLIST) { |
| 32 | + attribute.value = []; |
| 33 | + } else if (attribute.type !== type) { |
29 | 34 | attribute.value = null;
|
30 | 35 | }
|
| 36 | +
|
| 37 | + attribute.type = type; |
31 | 38 | };
|
32 | 39 | </script>
|
33 | 40 |
|
|
38 | 45 | label={translate('workflows.custom-search-attribute')}
|
39 | 46 | class="w-full"
|
40 | 47 | placeholder={translate('workflows.select-attribute')}
|
41 |
| - bind:value={attribute.attribute} |
| 48 | + bind:value={attribute.label} |
42 | 49 | onChange={handleAttributeChange}
|
43 | 50 | >
|
44 | 51 | {#each $customSearchAttributeOptions as { value, label, type }}
|
|
48 | 55 | {/each}
|
49 | 56 | </Select>
|
50 | 57 | </div>
|
51 |
| - {#if type === SEARCH_ATTRIBUTE_TYPE.BOOL} |
| 58 | + {#if attribute.type === SEARCH_ATTRIBUTE_TYPE.BOOL} |
52 | 59 | <Select
|
53 | 60 | label={translate('common.value')}
|
54 | 61 | id="attribute-value"
|
|
57 | 64 | <Option value={true}>{translate('common.true')}</Option>
|
58 | 65 | <Option value={false}>{translate('common.false')}</Option>
|
59 | 66 | </Select>
|
60 |
| - {:else if type === SEARCH_ATTRIBUTE_TYPE.DATETIME} |
| 67 | + {:else if attribute.type === SEARCH_ATTRIBUTE_TYPE.DATETIME} |
61 | 68 | <DatetimeInput bind:value={attribute.value} />
|
62 |
| - {:else if type === SEARCH_ATTRIBUTE_TYPE.INT || type === SEARCH_ATTRIBUTE_TYPE.DOUBLE} |
63 |
| - <NumberInput bind:value={attribute.value} /> |
64 |
| - {:else if type === SEARCH_ATTRIBUTE_TYPE.KEYWORDLIST} |
65 |
| - <ListInput bind:value={attribute.value} /> |
| 69 | + {:else if attribute.type === SEARCH_ATTRIBUTE_TYPE.INT || attribute.type === SEARCH_ATTRIBUTE_TYPE.DOUBLE} |
| 70 | + <NumberInput |
| 71 | + label={translate('common.value')} |
| 72 | + id="attribute-value" |
| 73 | + bind:value={attribute.value} |
| 74 | + /> |
| 75 | + {:else if attribute.type === SEARCH_ATTRIBUTE_TYPE.KEYWORDLIST} |
| 76 | + <ChipInput |
| 77 | + label={translate('common.value')} |
| 78 | + id="attribute-value" |
| 79 | + bind:chips={attribute.value} |
| 80 | + class="w-full" |
| 81 | + removeChipButtonLabel={(chip) => |
| 82 | + translate('workflows.remove-keyword-label', { keyword: chip })} |
| 83 | + /> |
| 84 | + {:else if attribute.type === SEARCH_ATTRIBUTE_TYPE.TEXT || attribute.type === SEARCH_ATTRIBUTE_TYPE.KEYWORD || attribute.type === SEARCH_ATTRIBUTE_TYPE.UNSPECIFIED} |
| 85 | + <Input |
| 86 | + label={translate('common.value')} |
| 87 | + id="attribute-value" |
| 88 | + class="grow" |
| 89 | + bind:value={attribute.value} |
| 90 | + /> |
66 | 91 | {:else}
|
67 |
| - <TextInput bind:value={attribute.value} /> |
| 92 | + <Input |
| 93 | + label={translate('common.value')} |
| 94 | + id="attribute-value" |
| 95 | + class="grow" |
| 96 | + placeholder={translate('workflows.unsupported-attribute')} |
| 97 | + error |
| 98 | + disabled |
| 99 | + value="" |
| 100 | + /> |
68 | 101 | {/if}
|
69 | 102 | <Button
|
70 | 103 | variant="ghost"
|
71 | 104 | leadingIcon="close"
|
72 | 105 | class="mt-6 w-10 rounded-full"
|
73 |
| - on:click={() => onRemove(attribute.attribute)} |
| 106 | + on:click={() => onRemove(attribute.label)} |
74 | 107 | />
|
75 | 108 | </div>
|
0 commit comments