Skip to content

Conversation

@kevinleeTCA
Copy link

create a custom component based on the existing one, then during the loadData step I'd get both names and IDs and combine them into a single object, then use that in index.ts to do the rendering and set the option values with the ID.

Comment on lines +30 to +38
{
name: 'id',
type: 'dimension',
label: 'ID',
config: {
dataset: 'ds'
},
category: 'Dropdown ids'
},
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where we add the id dimension that later will be linked to a variable to filter other charts data using id (built in index)

Comment on lines +45 to +51
// {
// name: 'defaultValue',
// type: 'string',
// array: true,
// label: 'Default value',
// category: 'Pre-configured variables'
// },
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Temporarily comment this out due to a type inconsistent issue.
Screenshot 2025-01-09 at 2 01 36 pm
Screenshot 2025-01-09 at 2 01 42 pm

...inputs,
options: loadData({
from: inputs.ds,
dimensions: inputs.property ? [inputs.property, inputs.id] : [],
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where we can query the id field when doing the dropdown search:
Screenshot 2025-01-09 at 1 44 04 pm

Comment on lines +134 to +137
return {
value: value.length ? value : Value.noFilter(),
id: id.length ? id : Value.noFilter()
};
Copy link
Author

@kevinleeTCA kevinleeTCA Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where we would like to capture an object (instead of value string) to be able to assign the id to a variable used for filters

Comment on lines +20 to +23
export type EventPayload = {
value: string;
id: string;
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the event payload should have an object type instead of string

className?: string;
options: DataResponse;
unclearable?: boolean;
onChange: (v: EventPayload[]) => void;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and onChange should capture event payload containing both value and id

Comment on lines +70 to +89
const set = useCallback(
(newValue: EventPayload) => {
performSearch('');

let newValues: EventPayload[] = [];

if (newValue.value !== '') {
newValues = value || [];
if (newValues?.includes(newValue)) {
newValues = newValues.filter((v) => v.value !== newValue.value);
} else {
newValues = [...newValues, newValue];
}
}

props.onChange(newValues);
setValue(newValues);
setServerSearch((s) => ({ ...s, [props.searchProperty || 'search']: '' }));
clearTimeout(debounce);
},
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change in the index to support an object set from old to new. But I am still encountering issues in the preview mode when select any item from dropdown:
Screenshot 2025-01-09 at 1 44 34 pm

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR introduces a new MultiSelectDropdownWithIds component that extends the existing dropdown functionality to support both display values and corresponding IDs, enabling more complex data relationships in selections.

  • The EventPayload type in /src/components/vanilla/controls/MultiSelectDropdownWithIds/index.tsx needs proper handling in the set() function for ID field management
  • Global debounce variable in /src/components/vanilla/controls/MultiSelectDropdownWithIds/index.tsx should be moved into component scope to prevent cross-instance interference
  • The includes() check in the list rendering logic needs to be updated to properly compare objects with both value and ID fields
  • The component adds new id dimension input in .emb.ts to load corresponding IDs alongside property values

💡 (1/5) You can manually trigger the bot by mentioning @greptileai in a comment!

2 file(s) reviewed, 5 comment(s)
Edit PR Review Bot Settings | Greptile

...inputs,
options: loadData({
from: inputs.ds,
dimensions: inputs.property ? [inputs.property, inputs.id] : [],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: No check for inputs.id before including it in dimensions array. Could cause runtime issues if id field not configured.

Suggested change
dimensions: inputs.property ? [inputs.property, inputs.id] : [],
dimensions: inputs.property && inputs.id ? [inputs.property, inputs.id] : [],

options: loadData({
from: inputs.ds,
dimensions: inputs.property ? [inputs.property, inputs.id] : [],
limit: inputs.limit || 1000,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Default limit of 1000 differs from meta default of 100. Should be consistent.

Comment on lines +78 to +79
if (newValues?.includes(newValue)) {
newValues = newValues.filter((v) => v.value !== newValue.value);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Array.includes() won't work correctly for object comparison. Need to use array.find() with proper value/id comparison

Suggested change
if (newValues?.includes(newValue)) {
newValues = newValues.filter((v) => v.value !== newValue.value);
if (newValues?.find(v => v.value === newValue.value && v.id === newValue.id)) {
newValues = newValues.filter((v) => v.value !== newValue.value);

key={i}
onClick={() => {
setTriggerBlur(false);
set(o[props.property?.name || ''] || '');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Missing ID field in set() call. Should be set({value: o[props.property?.name || ''], id: o.id}) to properly handle both value and ID

Suggested change
set(o[props.property?.name || ''] || '');
set({value: o[props.property?.name || ''] || '', id: o.id});


type Record = { [p: string]: string };

let debounce: number | undefined = undefined;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Global debounce variable will cause issues with multiple component instances. Move inside component using useRef

Suggested change
let debounce: number | undefined = undefined;
const debounce = useRef<number>();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant