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

fix: allow reset options on clear search #991

Open
wants to merge 3 commits 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
5 changes: 5 additions & 0 deletions .changeset/four-apples-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ensembleui/react-runtime": patch
---

Allow reset options on clear search in multiselect and search
15 changes: 5 additions & 10 deletions apps/kitchen-sink/src/ensemble/screens/home.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -460,17 +460,12 @@ View:
placeholder: "Search or Select From Groups"
labelKey: name
valueKey: email
data: ${ensemble.storage.get('products')}
data: "${getProducts.body.users?.map((i) => ({ ...i, name: i.firstName + ' ' + i.lastName })) || []}"
onSearch:
executeCode: |
ensemble.invokeAPI('getProducts', { search: search }).then((res) => {
const users = res?.body?.users || [];
console.log(users , "users");
const newUsers = users.map((i) => ({ ...i, label: i.firstName + ' ' + i.lastName, name: i.firstName + ' ' + i.lastName, value: i.email }));
console.log(newUsers , "newUsers");
ensemble.storage.set('products', newUsers);
});
console.log("onSearch values: ", search);
invokeAPI:
name: getProducts
inputs:
search: ${search}
onChange:
executeCode: |
console.log("onChange values: ", search);
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime/src/widgets/Form/MultiSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from "@ensembleui/react-framework";
import { PlusCircleOutlined } from "@ant-design/icons";
import { Select as SelectComponent, Space, Form } from "antd";
import { get, isArray, isEmpty, isEqual, isObject, isString } from "lodash-es";
import { get, isArray, isEqual, isObject, isString } from "lodash-es";
import { useDebounce } from "react-use";
import { WidgetRegistry } from "../../registry";
import { useEnsembleAction } from "../../runtime/hooks/useEnsembleAction";
Expand Down Expand Up @@ -170,7 +170,7 @@ const MultiSelect: React.FC<MultiSelectProps> = (props) => {

useDebounce(
() => {
if (onSearchAction?.callback && !isEmpty(searchValue)) {
if (onSearchAction?.callback) {
onSearchAction.callback({ search: searchValue });
}
},
Expand Down
12 changes: 12 additions & 0 deletions packages/runtime/src/widgets/Form/__tests__/MultiSelect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,18 @@ describe("MultiSelect Widget", () => {
expect(screen.queryByText("Option 3")).not.toBeInTheDocument();
expect(screen.queryByText("Option 44", { selector })).toBeVisible();
});

// clear search value to show all options
userEvent.clear(document.querySelector("input") as HTMLElement);

// Wait for the combobox to reflect the selected values
await waitFor(() => {
expect(screen.getByText("Option 4", { selector })).toBeVisible();
expect(screen.queryByText("Option 1", { selector })).toBeVisible();
expect(screen.queryByText("Option 2", { selector })).toBeVisible();
expect(screen.queryByText("Option 3", { selector })).toBeVisible();
expect(screen.queryByText("Option 44", { selector })).toBeVisible();
});
});
});
/* eslint-enable react/no-children-prop */
Loading