Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

dropdown with id #192

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
29 changes: 26 additions & 3 deletions src/components/vanilla/controls/Dropdown/Dropdown.emb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,24 @@ export const meta = {
type: 'dataset',
label: 'Dataset',
description: 'Dataset',
required: true,
category: 'Dropdown values'
},
{
name: 'property',
type: 'dimension',
label: 'Property',
required: true,
config: {
dataset: 'ds'
},
category: 'Dropdown values'
},
{
name: 'id',
type: 'dimension',
label: 'Id',
required: false,
config: {
dataset: 'ds'
},
Expand Down Expand Up @@ -61,6 +73,10 @@ export const meta = {
{
name: 'value',
type: 'string'
},
{
name: 'id',
type: 'string'
}
]
}
Expand All @@ -72,6 +88,12 @@ export const meta = {
defaultValue: Value.noFilter(),
inputs: ['defaultValue'],
events: [{ name: 'onChange', property: 'value' }]
},
{
name: 'dropdown id',
type: 'string',
defaultValue: Value.noFilter(),
events: [{ name: 'onChange', property: 'id' }]
}
]
} as const satisfies EmbeddedComponentMeta;
Expand All @@ -88,7 +110,7 @@ export default defineComponent<Props, typeof meta, { search: string }>(Component
...inputs,
options: loadData({
from: inputs.ds,
dimensions: inputs.property ? [inputs.property] : [],
dimensions: inputs.id ? [inputs.property, inputs.id] : [inputs.property],
limit: inputs.limit || 1000,
filters:
embState?.search && inputs.property
Expand All @@ -104,9 +126,10 @@ export default defineComponent<Props, typeof meta, { search: string }>(Component
};
},
events: {
onChange: (value) => {
onChange: (e) => {
return {
value: value || Value.noFilter()
value: e.value || Value.noFilter(),
id: e.id || Value.noFilter()
};
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/components/vanilla/controls/Dropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
onChange: (v: string) => void;
searchProperty?: string;
minDropdownWidth?: number;
property?: { name: string; title: string; nativeType: string; __type__: string };
property: { name: string; title: string; nativeType: string; __type__: string };
id?: { name: string; title: string; nativeType: string; __type__: string };
title?: string;
defaultValue?: string;
placeholder?: string;
Expand Down Expand Up @@ -63,12 +64,12 @@
);

const set = useCallback(
(value: string) => {
(value: string, id: string) => {
performSearch('');

setValue(value);

props.onChange(value);
props.onChange({ value, id });

Check failure on line 72 in src/components/vanilla/controls/Dropdown/index.tsx

View workflow job for this annotation

GitHub Actions / Test application (ubuntu-latest, 20)

Argument of type '{ value: string; id: string; }' is not assignable to parameter of type 'string'.

clearTimeout(debounce);
},
Expand All @@ -95,7 +96,10 @@
onClick={() => {
setFocus(false);
setTriggerBlur(false);
set(o[props.property?.name || ''] || '');
set(
o[props.property?.name || ''] || '',
o[props.id?.name || ''] || ''
);
}}
className={`flex items-center min-h-[36px] px-3 py-2 hover:bg-black/5 cursor-pointer font-normal ${
value === o[props.property?.name || ''] ? 'bg-black/5' : ''
Expand Down Expand Up @@ -165,7 +169,7 @@
{!props.unclearable && !!value && (
<div
onClick={() => {
set('');

Check failure on line 172 in src/components/vanilla/controls/Dropdown/index.tsx

View workflow job for this annotation

GitHub Actions / Test application (ubuntu-latest, 20)

Expected 2 arguments, but got 1.
}}
className="absolute right-10 top-0 h-10 flex items-center z-10 cursor-pointer"
>
Expand Down
Loading