@tsed/react-formio 1.10.14 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/table/filters/selectColumnFilter.component.spec.d.ts +1 -0
- package/dist/index.js +14 -3
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +7 -1
- package/dist/index.modern.js.map +1 -1
- package/package.json +4 -4
- package/src/components/table/filters/selectColumnFilter.component.spec.tsx +54 -0
- package/src/components/table/filters/selectColumnFilter.component.tsx +8 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/react-formio",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"description": "Provide a react formio wrapper. Written in TypeScript.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.modern.js",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"prettier": "prettier '{src,test}/**/*.{ts,tsx}' --write"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@tsed/redux-utils": "1.
|
|
17
|
+
"@tsed/redux-utils": "1.11.0",
|
|
18
18
|
"eventemitter2": "^6.4.3",
|
|
19
19
|
"prop-types": "^15.7.2"
|
|
20
20
|
},
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"tooltip.js": ">=1.3.3"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@tsed/tailwind": "1.
|
|
33
|
-
"@tsed/tailwind-formio": "1.
|
|
32
|
+
"@tsed/tailwind": "1.11.0",
|
|
33
|
+
"@tsed/tailwind-formio": "1.11.0",
|
|
34
34
|
"eslint-plugin-jsx-a11y": "^6.5.1"
|
|
35
35
|
},
|
|
36
36
|
"repository": "https://github.com/TypedProject/tsed-formio",
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import "@testing-library/jest-dom/extend-expect";
|
|
2
|
+
import { render } from "@testing-library/react";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { SelectColumnFilter } from "./selectColumnFilter.component";
|
|
5
|
+
|
|
6
|
+
describe("SelectColumnFilter", () => {
|
|
7
|
+
it("should display select with choices", async () => {
|
|
8
|
+
const mockSetFilter = jest.fn();
|
|
9
|
+
const props = {
|
|
10
|
+
name: "data.id",
|
|
11
|
+
setFilter: mockSetFilter,
|
|
12
|
+
column: {
|
|
13
|
+
id: "id",
|
|
14
|
+
preFilteredRows: [
|
|
15
|
+
{ values: { id: "select-choice-1" } },
|
|
16
|
+
{ values: { id: "select-choice-2" } }
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const { getByText } = render(
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
<SelectColumnFilter {...props} />
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
expect(getByText("select-choice-1")).toBeDefined();
|
|
28
|
+
expect(getByText("select-choice-2")).toBeDefined();
|
|
29
|
+
});
|
|
30
|
+
it("should display select with custom choices", async () => {
|
|
31
|
+
const mockSetFilter = jest.fn();
|
|
32
|
+
const props = {
|
|
33
|
+
name: "data.id",
|
|
34
|
+
setFilter: mockSetFilter,
|
|
35
|
+
column: {
|
|
36
|
+
id: "id",
|
|
37
|
+
preFilteredRows: [
|
|
38
|
+
{ values: { id: "select-choice-1" } },
|
|
39
|
+
{ values: { id: "select-choice-2" } }
|
|
40
|
+
],
|
|
41
|
+
choices: [{ label: "fake-choice", value: "fake-choice" }]
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const { queryByText, getByText } = render(
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
<SelectColumnFilter {...props} />
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
expect(queryByText("select-choice-1")).toBeNull();
|
|
52
|
+
expect(getByText("fake-choice")).toBeDefined();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -5,8 +5,14 @@ import { Select } from "../../select/select.component";
|
|
|
5
5
|
export function SelectColumnFilter<D extends Record<string, unknown> = {}>({
|
|
6
6
|
column
|
|
7
7
|
}: FilterProps<D>) {
|
|
8
|
-
const { filterValue, setFilter } = column;
|
|
9
|
-
const { choices
|
|
8
|
+
const { id, preFilteredRows, filterValue, setFilter } = column;
|
|
9
|
+
const { choices: customChoices } = column as any;
|
|
10
|
+
|
|
11
|
+
const choices =
|
|
12
|
+
customChoices ||
|
|
13
|
+
[...new Set(preFilteredRows.map((row) => row.values[id]))]
|
|
14
|
+
.filter((value) => value)
|
|
15
|
+
.map((value) => ({ label: value, value }));
|
|
10
16
|
|
|
11
17
|
return (
|
|
12
18
|
<Select
|