@akinon/akifilter 0.5.4 → 1.0.1

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.
Files changed (160) hide show
  1. package/README.md +44 -0
  2. package/dist/cjs/akifilter.d.ts +53 -0
  3. package/dist/cjs/akifilter.d.ts.map +1 -0
  4. package/dist/cjs/akifilter.js +360 -0
  5. package/dist/cjs/common/storage.d.ts +10 -0
  6. package/dist/cjs/common/storage.d.ts.map +1 -0
  7. package/dist/cjs/common/storage.js +124 -0
  8. package/dist/cjs/common/theme-overrides.d.ts +3 -0
  9. package/dist/cjs/common/theme-overrides.d.ts.map +1 -0
  10. package/dist/cjs/common/theme-overrides.js +6 -0
  11. package/dist/cjs/components/applied-filters.d.ts +14 -0
  12. package/dist/cjs/components/applied-filters.d.ts.map +1 -0
  13. package/dist/cjs/components/applied-filters.js +26 -0
  14. package/dist/cjs/components/filter-toolbar.d.ts +11 -0
  15. package/dist/cjs/components/filter-toolbar.d.ts.map +1 -0
  16. package/dist/cjs/components/filter-toolbar.js +17 -0
  17. package/dist/cjs/components/visibility-modal.d.ts +19 -0
  18. package/dist/cjs/components/visibility-modal.d.ts.map +1 -0
  19. package/dist/cjs/components/visibility-modal.js +30 -0
  20. package/dist/cjs/constants.d.ts +4 -0
  21. package/dist/cjs/constants.d.ts.map +1 -0
  22. package/dist/cjs/constants.js +6 -0
  23. package/dist/cjs/hooks/use-debounced-value.d.ts +2 -0
  24. package/dist/cjs/hooks/use-debounced-value.d.ts.map +1 -0
  25. package/dist/cjs/hooks/use-debounced-value.js +17 -0
  26. package/dist/cjs/i18n/index.d.ts +2 -4
  27. package/dist/cjs/i18n/index.d.ts.map +1 -1
  28. package/dist/cjs/i18n/index.js +1 -1
  29. package/dist/cjs/i18n/translations/en.d.ts +33 -3
  30. package/dist/cjs/i18n/translations/en.d.ts.map +1 -1
  31. package/dist/cjs/i18n/translations/en.js +33 -3
  32. package/dist/cjs/i18n/translations/tr.d.ts +33 -3
  33. package/dist/cjs/i18n/translations/tr.d.ts.map +1 -1
  34. package/dist/cjs/i18n/translations/tr.js +33 -3
  35. package/dist/cjs/index.d.ts +3 -14
  36. package/dist/cjs/index.d.ts.map +1 -1
  37. package/dist/cjs/index.js +17 -32
  38. package/dist/cjs/styles.css +179 -0
  39. package/dist/cjs/types.d.ts +11 -0
  40. package/dist/cjs/types.d.ts.map +1 -0
  41. package/dist/cjs/types.js +2 -0
  42. package/dist/cjs/utils/schema.d.ts +9 -0
  43. package/dist/cjs/utils/schema.d.ts.map +1 -0
  44. package/dist/cjs/utils/schema.js +61 -0
  45. package/dist/cjs/utils/values.d.ts +5 -0
  46. package/dist/cjs/utils/values.d.ts.map +1 -0
  47. package/dist/cjs/utils/values.js +44 -0
  48. package/dist/esm/akifilter.d.ts +53 -0
  49. package/dist/esm/akifilter.d.ts.map +1 -0
  50. package/dist/esm/akifilter.js +356 -0
  51. package/dist/esm/common/storage.d.ts +10 -0
  52. package/dist/esm/common/storage.d.ts.map +1 -0
  53. package/dist/esm/common/storage.js +114 -0
  54. package/dist/esm/common/theme-overrides.d.ts +3 -0
  55. package/dist/esm/common/theme-overrides.d.ts.map +1 -0
  56. package/dist/esm/common/theme-overrides.js +3 -0
  57. package/dist/esm/components/applied-filters.d.ts +14 -0
  58. package/dist/esm/components/applied-filters.d.ts.map +1 -0
  59. package/dist/esm/components/applied-filters.js +22 -0
  60. package/dist/esm/components/filter-toolbar.d.ts +11 -0
  61. package/dist/esm/components/filter-toolbar.d.ts.map +1 -0
  62. package/dist/esm/components/filter-toolbar.js +13 -0
  63. package/dist/esm/components/visibility-modal.d.ts +19 -0
  64. package/dist/esm/components/visibility-modal.d.ts.map +1 -0
  65. package/dist/esm/components/visibility-modal.js +26 -0
  66. package/dist/esm/constants.d.ts +4 -0
  67. package/dist/esm/constants.d.ts.map +1 -0
  68. package/dist/esm/constants.js +3 -0
  69. package/dist/esm/hooks/use-debounced-value.d.ts +2 -0
  70. package/dist/esm/hooks/use-debounced-value.d.ts.map +1 -0
  71. package/dist/esm/hooks/use-debounced-value.js +13 -0
  72. package/dist/esm/i18n/index.d.ts +2 -4
  73. package/dist/esm/i18n/index.d.ts.map +1 -1
  74. package/dist/esm/i18n/index.js +5 -5
  75. package/dist/esm/i18n/translations/en.d.ts +33 -3
  76. package/dist/esm/i18n/translations/en.d.ts.map +1 -1
  77. package/dist/esm/i18n/translations/en.js +33 -3
  78. package/dist/esm/i18n/translations/tr.d.ts +33 -3
  79. package/dist/esm/i18n/translations/tr.d.ts.map +1 -1
  80. package/dist/esm/i18n/translations/tr.js +33 -3
  81. package/dist/esm/index.d.ts +3 -14
  82. package/dist/esm/index.d.ts.map +1 -1
  83. package/dist/esm/index.js +3 -30
  84. package/dist/esm/styles.css +179 -0
  85. package/dist/esm/types.d.ts +11 -0
  86. package/dist/esm/types.d.ts.map +1 -0
  87. package/dist/esm/types.js +1 -0
  88. package/dist/esm/utils/schema.d.ts +9 -0
  89. package/dist/esm/utils/schema.d.ts.map +1 -0
  90. package/dist/esm/utils/schema.js +52 -0
  91. package/dist/esm/utils/values.d.ts +5 -0
  92. package/dist/esm/utils/values.d.ts.map +1 -0
  93. package/dist/esm/utils/values.js +39 -0
  94. package/package.json +39 -33
  95. package/dist/cjs/components/AppliedFilters/AppliedFilterItem.d.ts +0 -12
  96. package/dist/cjs/components/AppliedFilters/AppliedFilterItem.d.ts.map +0 -1
  97. package/dist/cjs/components/AppliedFilters/AppliedFilterItem.js +0 -62
  98. package/dist/cjs/components/AppliedFilters/common.d.ts +0 -6
  99. package/dist/cjs/components/AppliedFilters/common.d.ts.map +0 -1
  100. package/dist/cjs/components/AppliedFilters/common.js +0 -34
  101. package/dist/cjs/components/AppliedFilters/index.d.ts +0 -4
  102. package/dist/cjs/components/AppliedFilters/index.d.ts.map +0 -1
  103. package/dist/cjs/components/AppliedFilters/index.js +0 -26
  104. package/dist/cjs/components/AppliedFilters/styles.css +0 -65
  105. package/dist/cjs/components/ConditionalFilters/index.d.ts +0 -3
  106. package/dist/cjs/components/ConditionalFilters/index.d.ts.map +0 -1
  107. package/dist/cjs/components/ConditionalFilters/index.js +0 -32
  108. package/dist/cjs/components/FilterContext/index.d.ts +0 -45
  109. package/dist/cjs/components/FilterContext/index.d.ts.map +0 -1
  110. package/dist/cjs/components/FilterContext/index.js +0 -85
  111. package/dist/cjs/components/SelectShownFilters/index.d.ts +0 -7
  112. package/dist/cjs/components/SelectShownFilters/index.d.ts.map +0 -1
  113. package/dist/cjs/components/SelectShownFilters/index.js +0 -111
  114. package/dist/cjs/components/SelectShownFilters/styles.css +0 -99
  115. package/dist/cjs/components/ShownFilters/index.d.ts +0 -3
  116. package/dist/cjs/components/ShownFilters/index.d.ts.map +0 -1
  117. package/dist/cjs/components/ShownFilters/index.js +0 -45
  118. package/dist/cjs/components/index.d.ts +0 -6
  119. package/dist/cjs/components/index.d.ts.map +0 -1
  120. package/dist/cjs/components/index.js +0 -21
  121. package/dist/cjs/constants/index.d.ts +0 -56
  122. package/dist/cjs/constants/index.d.ts.map +0 -1
  123. package/dist/cjs/constants/index.js +0 -58
  124. package/dist/cjs/index.css +0 -67
  125. package/dist/cjs/utils/index.d.ts +0 -25
  126. package/dist/cjs/utils/index.d.ts.map +0 -1
  127. package/dist/cjs/utils/index.js +0 -40
  128. package/dist/esm/components/AppliedFilters/AppliedFilterItem.d.ts +0 -12
  129. package/dist/esm/components/AppliedFilters/AppliedFilterItem.d.ts.map +0 -1
  130. package/dist/esm/components/AppliedFilters/AppliedFilterItem.js +0 -58
  131. package/dist/esm/components/AppliedFilters/common.d.ts +0 -6
  132. package/dist/esm/components/AppliedFilters/common.d.ts.map +0 -1
  133. package/dist/esm/components/AppliedFilters/common.js +0 -29
  134. package/dist/esm/components/AppliedFilters/index.d.ts +0 -4
  135. package/dist/esm/components/AppliedFilters/index.d.ts.map +0 -1
  136. package/dist/esm/components/AppliedFilters/index.js +0 -22
  137. package/dist/esm/components/AppliedFilters/styles.css +0 -65
  138. package/dist/esm/components/ConditionalFilters/index.d.ts +0 -3
  139. package/dist/esm/components/ConditionalFilters/index.d.ts.map +0 -1
  140. package/dist/esm/components/ConditionalFilters/index.js +0 -28
  141. package/dist/esm/components/FilterContext/index.d.ts +0 -45
  142. package/dist/esm/components/FilterContext/index.d.ts.map +0 -1
  143. package/dist/esm/components/FilterContext/index.js +0 -80
  144. package/dist/esm/components/SelectShownFilters/index.d.ts +0 -7
  145. package/dist/esm/components/SelectShownFilters/index.d.ts.map +0 -1
  146. package/dist/esm/components/SelectShownFilters/index.js +0 -107
  147. package/dist/esm/components/SelectShownFilters/styles.css +0 -99
  148. package/dist/esm/components/ShownFilters/index.d.ts +0 -3
  149. package/dist/esm/components/ShownFilters/index.d.ts.map +0 -1
  150. package/dist/esm/components/ShownFilters/index.js +0 -41
  151. package/dist/esm/components/index.d.ts +0 -6
  152. package/dist/esm/components/index.d.ts.map +0 -1
  153. package/dist/esm/components/index.js +0 -5
  154. package/dist/esm/constants/index.d.ts +0 -56
  155. package/dist/esm/constants/index.d.ts.map +0 -1
  156. package/dist/esm/constants/index.js +0 -55
  157. package/dist/esm/index.css +0 -67
  158. package/dist/esm/utils/index.d.ts +0 -25
  159. package/dist/esm/utils/index.d.ts.map +0 -1
  160. package/dist/esm/utils/index.js +0 -35
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/utils/schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAGnD,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhE,eAAO,MAAM,eAAe,GAAI,YAAY,SAAS,WAAW,GAAG,WAAW,EAC5E,OAAO,cAAc,CAAC,YAAY,CAAC,KAClC,MAEF,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,YAAY,SAAS,WAAW,GAAG,WAAW,EAE9C,OAAO,cAAc,CAAC,YAAY,CAAC,KAClC,MAEF,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,YAAY,SAAS,WAAW,GAAG,WAAW,EAE9C,QAAQ,eAAe,CAAC,YAAY,CAAC,EACrC,MAAM,MAAM,EAAE,KACb,MAAM,EAGR,CAAC;AAEF,eAAO,MAAM,wBAAwB,GACnC,YAAY,SAAS,WAAW,GAAG,WAAW,EAE9C,QAAQ,eAAe,CAAC,YAAY,CAAC,KACpC,MAAM,EAUR,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAC/B,YAAY,SAAS,WAAW,GAAG,WAAW,EAE9C,QAAQ,eAAe,CAAC,YAAY,CAAC,KACpC,OAAO,CAAC,YAAY,CAQtB,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAClC,YAAY,SAAS,WAAW,GAAG,WAAW,EAE9C,QAAQ,eAAe,CAAC,YAAY,CAAC,EACrC,SAAS,OAAO,CAAC,YAAY,CAAC,KAC7B,OAAO,CAAC,YAAY,CA+BtB,CAAC"}
@@ -0,0 +1,52 @@
1
+ import { akidate } from '@akinon/akidate';
2
+ import { DEFAULT_VISIBLE_COUNT } from '../constants';
3
+ export const getDisplayLabel = (field) => {
4
+ return field.label || field.placeholder || String(field.key);
5
+ };
6
+ export const getFieldAriaLabel = (field) => {
7
+ return field.label || field.placeholder || String(field.key);
8
+ };
9
+ export const ensureSchemaOrder = (schema, keys) => {
10
+ const keySet = new Set(keys.map(String));
11
+ return schema.map(field => String(field.key)).filter(key => keySet.has(key));
12
+ };
13
+ export const deriveDefaultVisibleKeys = (schema) => {
14
+ const explicitKeys = schema
15
+ .filter(field => field.isVisible)
16
+ .map(field => String(field.key));
17
+ if (explicitKeys.length > 0) {
18
+ return ensureSchemaOrder(schema, Array.from(new Set(explicitKeys)));
19
+ }
20
+ return schema.slice(0, DEFAULT_VISIBLE_COUNT).map(field => String(field.key));
21
+ };
22
+ export const extractDefaultValues = (schema) => {
23
+ return schema.reduce((acc, field) => {
24
+ if (field.defaultValue !== undefined) {
25
+ const key = field.key;
26
+ acc[key] = field.defaultValue;
27
+ }
28
+ return acc;
29
+ }, {});
30
+ };
31
+ export const normaliseValuesBySchema = (schema, values) => {
32
+ if (!values) {
33
+ return {};
34
+ }
35
+ return Object.keys(values).reduce((acc, key) => {
36
+ const field = schema.find(schemaField => String(schemaField.key) === String(key));
37
+ if (!field) {
38
+ acc[key] = values[key];
39
+ return acc;
40
+ }
41
+ const currentValue = values[key];
42
+ if (field.type === 'date') {
43
+ const parsed = akidate.parse(currentValue);
44
+ if (parsed) {
45
+ acc[key] = parsed;
46
+ return acc;
47
+ }
48
+ }
49
+ acc[key] = currentValue;
50
+ return acc;
51
+ }, {});
52
+ };
@@ -0,0 +1,5 @@
1
+ import type { FieldValues } from '@akinon/akiform';
2
+ import type { AkifilterField, AkifilterSchema } from '../types';
3
+ export declare const shouldPersistValue: <TFieldValues extends FieldValues = FieldValues>(field: AkifilterField<TFieldValues> | undefined, value: unknown) => boolean;
4
+ export declare const normaliseOutputValues: <TFieldValues extends FieldValues = FieldValues>(schema: AkifilterSchema<TFieldValues>, values?: Partial<TFieldValues> | FieldValues) => Partial<TFieldValues>;
5
+ //# sourceMappingURL=values.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"values.d.ts","sourceRoot":"","sources":["../../../src/utils/values.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhE,eAAO,MAAM,kBAAkB,GAC7B,YAAY,SAAS,WAAW,GAAG,WAAW,EAE9C,OAAO,cAAc,CAAC,YAAY,CAAC,GAAG,SAAS,EAC/C,OAAO,OAAO,KACb,OAkBF,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAChC,YAAY,SAAS,WAAW,GAAG,WAAW,EAE9C,QAAQ,eAAe,CAAC,YAAY,CAAC,EACrC,SAAS,OAAO,CAAC,YAAY,CAAC,GAAG,WAAW,KAC3C,OAAO,CAAC,YAAY,CA8BtB,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { akidate } from '@akinon/akidate';
2
+ export const shouldPersistValue = (field, value) => {
3
+ if (value === undefined || value === null) {
4
+ return false;
5
+ }
6
+ if (typeof value === 'string' && value.trim() === '') {
7
+ return false;
8
+ }
9
+ if (Array.isArray(value) && value.length === 0) {
10
+ return false;
11
+ }
12
+ if ((field === null || field === void 0 ? void 0 : field.type) === 'checkbox' && value !== true) {
13
+ return false;
14
+ }
15
+ return true;
16
+ };
17
+ export const normaliseOutputValues = (schema, values) => {
18
+ if (!values) {
19
+ return {};
20
+ }
21
+ const entries = Object.entries(values);
22
+ return entries.reduce((acc, [key, rawValue]) => {
23
+ const field = schema.find(schemaField => String(schemaField.key) === String(key));
24
+ if (!shouldPersistValue(field, rawValue)) {
25
+ return acc;
26
+ }
27
+ let normalisedValue = rawValue;
28
+ if ((field === null || field === void 0 ? void 0 : field.type) === 'date') {
29
+ const normalised = akidate.toIsoDate(rawValue);
30
+ if (!normalised) {
31
+ return acc;
32
+ }
33
+ normalisedValue = akidate.formatIsoDate(normalised, 'YYYY-MM-DD');
34
+ }
35
+ acc[key] =
36
+ normalisedValue;
37
+ return acc;
38
+ }, {});
39
+ };
package/package.json CHANGED
@@ -1,6 +1,8 @@
1
1
  {
2
2
  "name": "@akinon/akifilter",
3
- "version": "0.5.4",
3
+ "version": "1.0.1",
4
+ "private": false,
5
+ "description": "Akifilter is a filtering library for Akinon frontend applications.",
4
6
  "type": "module",
5
7
  "main": "dist/esm/index.js",
6
8
  "module": "dist/esm/index.js",
@@ -8,41 +10,40 @@
8
10
  "dist"
9
11
  ],
10
12
  "dependencies": {
11
- "@types/lodash": "^4.14.202",
12
- "antd": "5.17.0",
13
- "dayjs": "1.11.10",
14
- "lodash": "^4.17.21",
15
- "react-hook-form": "7.48.2",
16
- "react-hook-form-antd": "1.0.1",
17
- "use-immer": "^0.9.0",
18
- "@akinon/akiform-builder": "^0.6.0",
19
- "@akinon/ui-divider": "0.3.0",
20
- "@akinon/icons": "^0.4.0",
21
- "@akinon/ui-input": "0.4.0",
22
- "@akinon/ui-pagination": "0.3.0",
23
- "@akinon/ui-layout": "0.4.0",
24
- "@akinon/ui-modal": "0.3.0",
25
- "@akinon/ui-space": "0.3.0",
26
- "@akinon/ui-tree-select": "0.3.0",
27
- "@akinon/akilocale": "^0.12.0",
28
- "@akinon/ui-typography": "0.3.0"
13
+ "antd": "^5.27.0",
14
+ "react-error-boundary": "^6.0.0",
15
+ "@akinon/akiform": "1.1.1",
16
+ "@akinon/icons": "1.1.0",
17
+ "@akinon/akidate": "1.1.1",
18
+ "@akinon/akilocale": "1.2.0",
19
+ "@akinon/ui-button": "1.3.0",
20
+ "@akinon/ui-card": "1.1.0",
21
+ "@akinon/ui-checkbox": "1.3.0",
22
+ "@akinon/ui-input": "1.1.0",
23
+ "@akinon/ui-date-picker": "1.3.0",
24
+ "@akinon/ui-modal": "1.1.0",
25
+ "@akinon/ui-input-number": "1.3.0",
26
+ "@akinon/ui-space": "1.3.0",
27
+ "@akinon/ui-pagination": "1.3.1",
28
+ "@akinon/ui-select": "1.3.1",
29
+ "@akinon/ui-typography": "1.1.0"
29
30
  },
30
31
  "devDependencies": {
31
32
  "clean-package": "2.2.0",
32
33
  "copyfiles": "^2.4.1",
33
34
  "rimraf": "^5.0.5",
34
- "typescript": "^5.2.2",
35
- "@akinon/vite-config": "0.4.0",
36
- "@akinon/eslint-config": "0.1.0",
37
- "@akinon/typescript-config": "0.2.0"
35
+ "typescript": "*",
36
+ "@akinon/akiform-builder": "1.3.2",
37
+ "@akinon/typescript-config": "1.1.0",
38
+ "@akinon/ui-theme": "1.1.0",
39
+ "@akinon/utils": "1.1.1",
40
+ "@akinon/vitest-config": "1.1.0"
38
41
  },
39
42
  "peerDependencies": {
40
- "react": ">=18",
41
- "react-dom": ">=18",
42
- "react-router": ">=6.17.0",
43
- "react-router-dom": ">=6.17.0"
43
+ "react": "^18 || ^19",
44
+ "react-dom": "^18 || ^19"
44
45
  },
45
- "clean-package": "../../../clean-package.config.json",
46
+ "clean-package": "./clean-package.config.json",
46
47
  "types": "dist/esm/index.d.ts",
47
48
  "exports": {
48
49
  ".": {
@@ -50,18 +51,23 @@
50
51
  "import": "./dist/esm/index.js",
51
52
  "require": "./dist/cjs/index.js"
52
53
  },
54
+ "./devtools": {
55
+ "types": "./dist/esm/devtools.d.ts",
56
+ "import": "./dist/esm/devtools.js",
57
+ "require": "./dist/cjs/devtools.js"
58
+ },
53
59
  "./package.json": "./package.json"
54
60
  },
55
61
  "scripts": {
56
62
  "build": "pnpm run build:esm && pnpm run build:commonjs && pnpm run copy:files",
57
- "build:esm": "tsc --outDir dist/esm",
58
63
  "build:commonjs": "tsc --module commonjs --outDir dist/cjs",
59
- "copy:files": "copyfiles -u 1 src/*.css dist/esm && copyfiles -u 1 src/*.css dist/cjs && copyfiles -u 1 src/**/*.css dist/esm && copyfiles -u 1 src/**/*.css dist/cjs",
60
- "lint": "eslint *.ts*",
61
- "test": "vitest run",
64
+ "build:esm": "tsc --outDir dist/esm",
65
+ "clean": "rimraf dist/",
66
+ "copy:files": "copyfiles -u 1 \"src/**/*.!(ts|tsx)\" dist/esm && copyfiles -u 1 \"src/**/*.!(ts|tsx)\" dist/cjs",
67
+ "test": "vitest",
62
68
  "test:coverage": "vitest run --coverage",
69
+ "test:run": "vitest run",
63
70
  "test:ui": "vitest --ui",
64
- "test:watch": "vitest watch",
65
71
  "typecheck": "tsc --noEmit"
66
72
  }
67
73
  }
@@ -1,12 +0,0 @@
1
- import './styles.css';
2
- import React from 'react';
3
- import type { FilterState } from '../FilterContext';
4
- type AppliedFilterItemProps = {
5
- filterKeyValue: [
6
- string,
7
- (FilterState['appliedFilters'][string] | FilterState['appliedFilters'][string][])
8
- ];
9
- };
10
- export declare const AppliedFilterItem: ({ filterKeyValue }: AppliedFilterItemProps) => React.JSX.Element | null;
11
- export {};
12
- //# sourceMappingURL=AppliedFilterItem.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AppliedFilterItem.d.ts","sourceRoot":"","sources":["../../../../src/components/AppliedFilters/AppliedFilterItem.tsx"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AAKtB,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAMpD,KAAK,sBAAsB,GAAG;IAC5B,cAAc,EAAE;QACd,MAAM;QACN,CACI,WAAW,CAAC,gBAAgB,CAAC,CAAC,MAAM,CAAC,GACrC,WAAW,CAAC,gBAAgB,CAAC,CAAC,MAAM,CAAC,EAAE,CAC1C;KACF,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,iBAAiB,uBAE3B,sBAAsB,6BAuGxB,CAAC"}
@@ -1,62 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AppliedFilterItem = void 0;
4
- require("./styles.css");
5
- const icons_1 = require("@akinon/icons");
6
- const ui_space_1 = require("@akinon/ui-space");
7
- const ui_typography_1 = require("@akinon/ui-typography");
8
- const react_1 = require("react");
9
- const dayjs_1 = require("dayjs");
10
- const FilterContext_1 = require("../FilterContext");
11
- const lodash_1 = require("lodash");
12
- const AppliedFilterItem = ({ filterKeyValue }) => {
13
- const [filterKey, filterValue] = filterKeyValue;
14
- const { state: { applicableFilters, appliedFilters }, dispatch, conditionalFiltersSchema } = (0, FilterContext_1.useFilterContext)();
15
- // find filterItem for placeholder, etc from filterKey
16
- const filterItem = [
17
- ...applicableFilters,
18
- ...(conditionalFiltersSchema || [])
19
- ].find(i => i.key === filterKey);
20
- if (!filterItem) {
21
- console.warn(`filterItem with key ${filterKey} not found`);
22
- return null;
23
- }
24
- // TODO getModifiedFilterValue doesn't need filterValue. It can obtain it from filterItem
25
- // TODO explain why you need to modify the filter value
26
- // const modifiedFilterValue = getModifiedFilterValue({
27
- // filterItem,
28
- // filterValue
29
- // });
30
- // const shouldShowActiveFilter =
31
- // !isEmpty(filterItem) && !isEmpty(modifiedFilterValue);
32
- const handleRemoveFilter = (removedFilterKey) => {
33
- // TODO write test for below comment
34
- // you should mark the key as undefined instead of deleting it for antd form item to pick up the change
35
- const newFilters = Object.assign(Object.assign({}, appliedFilters), { [removedFilterKey]: undefined });
36
- dispatch({
37
- type: 'SET_APPLIED_FILTERS',
38
- payload: { appliedFilters: newFilters }
39
- });
40
- };
41
- const inputField = filterItem;
42
- const renderFilterValue = (value) => {
43
- if (value instanceof Date) {
44
- return (0, dayjs_1.default)(value).format('YYYY-MM-DD');
45
- }
46
- if ((0, lodash_1.isBoolean)(value)) {
47
- return value.toString();
48
- }
49
- if ((0, lodash_1.isArray)(value)) {
50
- return value.join(', ');
51
- }
52
- return String(value);
53
- };
54
- return (react_1.default.createElement(react_1.default.Fragment, null,
55
- react_1.default.createElement(ui_space_1.Space, { key: filterKey, align: "center", className: "active-filter-item" },
56
- react_1.default.createElement(ui_typography_1.Text, { className: "active-filter-item__label" }, inputField === null || inputField === void 0 ? void 0 :
57
- inputField.placeholder,
58
- ":"),
59
- react_1.default.createElement(ui_typography_1.Text, { className: "active-filter-item__value" }, renderFilterValue(filterValue)),
60
- react_1.default.createElement(icons_1.Icon, { icon: "close", size: 20, className: "active-filter-item__remove-filter-icon", onClick: () => handleRemoveFilter(filterKey) }))));
61
- };
62
- exports.AppliedFilterItem = AppliedFilterItem;
@@ -1,6 +0,0 @@
1
- export declare const isFileObject: (value: any) => boolean;
2
- export declare const getModifiedFilterValue: ({ filterItem, filterValue }: {
3
- filterItem: any;
4
- filterValue: any['value'];
5
- }) => any;
6
- //# sourceMappingURL=common.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../src/components/AppliedFilters/common.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,YAAY,UAAW,GAAG,YAAuC,CAAC;AAE/E,eAAO,MAAM,sBAAsB,gCAGhC;IACD,UAAU,EAAE,GAAG,CAAC;IAChB,WAAW,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;CAC3B,QA8BA,CAAC"}
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getModifiedFilterValue = exports.isFileObject = void 0;
4
- /* eslint-disable */
5
- const ui_tree_select_1 = require("@akinon/ui-tree-select");
6
- const constants_1 = require("../../constants");
7
- const utils_1 = require("../../utils");
8
- const isFileObject = (value) => (value === null || value === void 0 ? void 0 : value.originFileObj) !== undefined;
9
- exports.isFileObject = isFileObject;
10
- const getModifiedFilterValue = ({ filterItem, filterValue }) => {
11
- var _a, _b, _c;
12
- switch (filterItem === null || filterItem === void 0 ? void 0 : filterItem.widget) {
13
- case 'select':
14
- if (((_a = filterItem === null || filterItem === void 0 ? void 0 : filterItem.widgetProps) === null || _a === void 0 ? void 0 : _a.mode) === 'multiple') {
15
- return filterValue === null || filterValue === void 0 ? void 0 : filterValue.map((value) => {
16
- const optionObject = filterItem.options.find((option) => option.value === value);
17
- return (optionObject === null || optionObject === void 0 ? void 0 : optionObject.label) || value;
18
- }).join(', ');
19
- }
20
- const optionObject = filterItem.options.find((option) => option.value === filterValue);
21
- return (optionObject === null || optionObject === void 0 ? void 0 : optionObject.label) || filterValue;
22
- case 'date-picker':
23
- return filterValue === null || filterValue === void 0 ? void 0 : filterValue.format(constants_1.overallDateFormat);
24
- case 'checkbox-group':
25
- return filterValue === null || filterValue === void 0 ? void 0 : filterValue.map(() => 'Yes').join(', ');
26
- case ui_tree_select_1.TreeSelect:
27
- const tree = (_b = filterItem === null || filterItem === void 0 ? void 0 : filterItem.widgetProps) === null || _b === void 0 ? void 0 : _b.treeData;
28
- const label = (_c = (0, utils_1.getTreeNodeByValue)({ tree, nodeValue: filterValue })) === null || _c === void 0 ? void 0 : _c.value;
29
- return label || filterValue;
30
- default:
31
- return filterValue;
32
- }
33
- };
34
- exports.getModifiedFilterValue = getModifiedFilterValue;
@@ -1,4 +0,0 @@
1
- import './styles.css';
2
- import React from 'react';
3
- export declare const AppliedFilters: () => React.JSX.Element;
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/AppliedFilters/index.tsx"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AAMtB,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,eAAO,MAAM,cAAc,yBAyC1B,CAAC"}
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AppliedFilters = void 0;
4
- require("./styles.css");
5
- const icons_1 = require("@akinon/icons");
6
- const ui_layout_1 = require("@akinon/ui-layout");
7
- const ui_space_1 = require("@akinon/ui-space");
8
- const ui_typography_1 = require("@akinon/ui-typography");
9
- const react_1 = require("react");
10
- const FilterContext_1 = require("../FilterContext");
11
- const AppliedFilterItem_1 = require("./AppliedFilterItem");
12
- const AppliedFilters = () => {
13
- var _a;
14
- const { state: { appliedFilters }, dispatch } = (0, FilterContext_1.useFilterContext)();
15
- const handleOnResetFilters = () => {
16
- dispatch({ type: 'SET_APPLIED_FILTERS', payload: { appliedFilters: {} } });
17
- };
18
- return (react_1.default.createElement(ui_layout_1.Row, { align: "middle", className: "applied_filters" },
19
- react_1.default.createElement(ui_layout_1.Col, { className: "applied_filters__list" },
20
- react_1.default.createElement(ui_space_1.Space, null,
21
- react_1.default.createElement(ui_typography_1.Text, { className: "applied_filters__label" }, "Active filters:"),
22
- react_1.default.createElement(ui_space_1.Space, { className: "applied_filters__items", "data-testid": "appliedFilters" }, (_a = Object.entries(appliedFilters)) === null || _a === void 0 ? void 0 : _a.map(([filterKey, filterValue], i) => filterValue !== undefined && (react_1.default.createElement(AppliedFilterItem_1.AppliedFilterItem, { filterKeyValue: [filterKey, filterValue], key: i })))))),
23
- react_1.default.createElement(ui_layout_1.Col, { className: "applied_filters__clear-filters" },
24
- react_1.default.createElement(icons_1.Icon, { icon: "bin", size: 35, className: "applied_filters__reset-filters-icon", onClick: handleOnResetFilters }))));
25
- };
26
- exports.AppliedFilters = AppliedFilters;
@@ -1,65 +0,0 @@
1
- .akinon-filter .applied_filters {
2
- padding: 5px 6px;
3
- background-color: #2b344c;
4
- border-radius: 5px;
5
- }
6
-
7
- .applied_filters .applied_filters__list {
8
- flex: 1;
9
- background-color: #1e1e2d;
10
- padding: 6px 16px;
11
- border-radius: 3px;
12
- }
13
-
14
- .applied_filters .applied_filters__label.akinon-typography {
15
- color: white;
16
- font-size: 14px;
17
- font-weight: 600;
18
- }
19
-
20
- .applied_filters .applied_filters__reset-filters-icon {
21
- cursor: pointer;
22
- color: white;
23
- font-size: 20px;
24
- padding: 6px;
25
- margin: 6px;
26
- }
27
-
28
- .applied_filters .applied_filters__items {
29
- flex-wrap: wrap;
30
- }
31
-
32
- .akinon-filter .active-filter-item {
33
- font-size: 14px;
34
- background-color: white;
35
- padding: 1px 4px;
36
- border-radius: 3px;
37
- line-height: 1rem;
38
- }
39
-
40
- .active-filter-item .akinon-space-item {
41
- display: flex;
42
- justify-content: center;
43
- }
44
-
45
- .active-filter-item .active-filter-item__label.akinon-typography,
46
- .active-filter-item .active-filter-item__value.akinon-typography {
47
- color: #4a4a4a;
48
- }
49
-
50
- .active-filter-item .active-filter-item__label.akinon-typography {
51
- font-weight: 600;
52
- }
53
-
54
- .active-filter-item .active-filter-item__value.akinon-typography {
55
- font-weight: 500;
56
- }
57
-
58
- .active-filter-item .active-filter-item__remove-filter-icon {
59
- cursor: pointer;
60
- background-color: #4482ff;
61
- color: white;
62
- font-size: 5px;
63
- padding: 5px;
64
- border-radius: 99px;
65
- }
@@ -1,3 +0,0 @@
1
- import React from 'react';
2
- export declare const ConditionalFilters: () => React.JSX.Element | null;
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionalFilters/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,eAAO,MAAM,kBAAkB,gCAyC9B,CAAC"}
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConditionalFilters = void 0;
4
- const akiform_builder_1 = require("@akinon/akiform-builder");
5
- const ui_typography_1 = require("@akinon/ui-typography");
6
- const react_1 = require("react");
7
- const FilterContext_1 = require("../FilterContext");
8
- const ConditionalFilters = () => {
9
- const { dispatch, state, conditionalFiltersSchema } = (0, FilterContext_1.useFilterContext)();
10
- const { appliedFilters } = state;
11
- const [formResetCount, setFormResetCount] = react_1.default.useState(0);
12
- // reset form state when conditionalFiltersSchema changes
13
- react_1.default.useEffect(() => {
14
- setFormResetCount(formResetCount + 1);
15
- }, [conditionalFiltersSchema]);
16
- // second form created just to reset antd form state when conditionalFiltersSchema changes.
17
- const handleFormChange = (allValues) => {
18
- dispatch({
19
- type: 'SET_APPLIED_FILTERS',
20
- payload: {
21
- appliedFilters: Object.assign(Object.assign({}, appliedFilters), allValues)
22
- }
23
- });
24
- };
25
- if (!conditionalFiltersSchema)
26
- return null;
27
- return (react_1.default.createElement(react_1.default.Fragment, null,
28
- react_1.default.createElement(ui_typography_1.Paragraph, { className: "akinon-filter__header" }, "COMMON PARAMETER FILTERS"),
29
- react_1.default.createElement("div", null,
30
- react_1.default.createElement(akiform_builder_1.FormBuilderWatch, { builderFields: conditionalFiltersSchema, handleChange: handleFormChange, key: formResetCount, isDebounced: true }))));
31
- };
32
- exports.ConditionalFilters = ConditionalFilters;
@@ -1,45 +0,0 @@
1
- import { FormField } from '@akinon/akiform-builder';
2
- import React, { Dispatch } from 'react';
3
- import type { FilterProps } from '../..';
4
- export type FilterState = {
5
- mainPath: string;
6
- appliedFilters: {
7
- [key: string]: string | number | boolean | undefined;
8
- };
9
- applicableFilters: FormField[];
10
- shownFilters: string[];
11
- recreateShownFiltersCount: number;
12
- };
13
- export type FilterAction = {
14
- type: 'SET_APPLIED_FILTERS';
15
- payload: {
16
- appliedFilters: FilterState['appliedFilters'];
17
- };
18
- } | {
19
- type: 'SET_APPLICABLE_FILTERS';
20
- payload: {
21
- applicableFilters: FilterState['applicableFilters'];
22
- };
23
- } | {
24
- type: 'SET_SHOWN_FILTERS';
25
- payload: {
26
- shownFilters: FilterState['shownFilters'];
27
- };
28
- };
29
- export type FilterContext = {
30
- state: FilterState;
31
- dispatch: Dispatch<FilterAction>;
32
- conditionalFiltersSchema: FilterProps['conditionalFiltersSchema'];
33
- };
34
- type FilterContextProviderProps = FilterProps & {
35
- children: React.ReactNode;
36
- };
37
- /**
38
- * FilterContextProvider manages both filter context and antd form state.
39
- * Reason for not separating antd form state from filter context is that antd
40
- * form state is tightly coupled with filter context state.
41
- */
42
- export declare const FilterContextProvider: ({ children, filterSchema, customMainPath, useAppliedFilters, conditionalFiltersSchema }: FilterContextProviderProps) => React.JSX.Element;
43
- export declare function useFilterContext(): FilterContext;
44
- export {};
45
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/FilterContext/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,EAAE,EAAiB,QAAQ,EAAyB,MAAM,OAAO,CAAC;AAI9E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAGzC,MAAM,MAAM,WAAW,GAAG;IAExB,QAAQ,EAAE,MAAM,CAAC;IAEjB,cAAc,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAA;KAAE,CAAC;IAEzE,iBAAiB,EAAE,SAAS,EAAE,CAAC;IAE/B,YAAY,EAAE,MAAM,EAAE,CAAC;IAEvB,yBAAyB,EAAE,MAAM,CAAC;CACnC,CAAC;AAQF,MAAM,MAAM,YAAY,GACpB;IACE,IAAI,EAAE,qBAAqB,CAAC;IAC5B,OAAO,EAAE;QAAE,cAAc,EAAE,WAAW,CAAC,gBAAgB,CAAC,CAAA;KAAE,CAAC;CAC5D,GACD;IACE,IAAI,EAAE,wBAAwB,CAAC;IAC/B,OAAO,EAAE;QAAE,iBAAiB,EAAE,WAAW,CAAC,mBAAmB,CAAC,CAAA;KAAE,CAAC;CAClE,GACD;IACE,IAAI,EAAE,mBAAmB,CAAC;IAC1B,OAAO,EAAE;QAAE,YAAY,EAAE,WAAW,CAAC,cAAc,CAAC,CAAA;KAAE,CAAC;CACxD,CAAC;AAEN,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACjC,wBAAwB,EAAE,WAAW,CAAC,0BAA0B,CAAC,CAAC;CACnE,CAAC;AAEF,KAAK,0BAA0B,GAAG,WAAW,GAAG;IAC9C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAAC;AAIF;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,4FAM/B,0BAA0B,sBA2F5B,CAAC;AAEF,wBAAgB,gBAAgB,kBAM/B"}
@@ -1,85 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useFilterContext = exports.FilterContextProvider = void 0;
4
- const react_1 = require("react");
5
- const react_router_dom_1 = require("react-router-dom");
6
- const use_immer_1 = require("use-immer");
7
- const utils_1 = require("../../utils");
8
- const FilterContext = (0, react_1.createContext)(undefined);
9
- /**
10
- * FilterContextProvider manages both filter context and antd form state.
11
- * Reason for not separating antd form state from filter context is that antd
12
- * form state is tightly coupled with filter context state.
13
- */
14
- const FilterContextProvider = ({ children, filterSchema, customMainPath, useAppliedFilters, conditionalFiltersSchema }) => {
15
- const { pathname } = (0, react_router_dom_1.useLocation)();
16
- const mainPath = customMainPath
17
- ? customMainPath
18
- : (0, utils_1.getPathFragments)(pathname).mainPath;
19
- if (!mainPath) {
20
- throw new Error('mainPath is not defined');
21
- }
22
- // load appliedFilters from local storage
23
- const localAppliedFilters = JSON.parse(localStorage.getItem(`appliedFilters-${mainPath}`) || '{}');
24
- // get applied filters from parent component
25
- const parentAppliedFilters = useAppliedFilters[0];
26
- // load shownFilters from local storage
27
- const localShownFilters = JSON.parse(localStorage.getItem(`shownFilters-${mainPath}`) || '[]');
28
- const initialState = {
29
- mainPath,
30
- // if parentAppliedFilters is not empty, use it. Otherwise, use localAppliedFilters. don't merge them to prevent conflicts since you want parent to have the control
31
- appliedFilters: Object.keys(parentAppliedFilters).length > 0
32
- ? parentAppliedFilters
33
- : localAppliedFilters,
34
- applicableFilters: filterSchema,
35
- // if localShownFilters is not defined, only show first 8 filters
36
- shownFilters: localShownFilters.length
37
- ? localShownFilters
38
- : filterSchema.map(filter => filter.key).slice(0, 8),
39
- recreateShownFiltersCount: 0
40
- };
41
- const [state, dispatch] = (0, use_immer_1.useImmerReducer)((draft, action) => {
42
- switch (action.type) {
43
- case 'SET_APPLIED_FILTERS':
44
- // console.log('SET_APPLIED_FILTERS', action.payload.appliedFilters);
45
- draft.appliedFilters = action.payload.appliedFilters;
46
- return;
47
- case 'SET_APPLICABLE_FILTERS':
48
- // console.log('SET_APPLICABLE_FILTERS');
49
- draft.applicableFilters = action.payload.applicableFilters;
50
- return;
51
- case 'SET_SHOWN_FILTERS':
52
- // console.log('SET_SHOWN_FILTERS', action.payload.shownFilters);
53
- draft.shownFilters = action.payload.shownFilters;
54
- draft.recreateShownFiltersCount = draft.recreateShownFiltersCount + 1;
55
- return;
56
- }
57
- }, initialState);
58
- (0, react_1.useEffect)(() => {
59
- // send applied filters to parent component
60
- useAppliedFilters[1](state.appliedFilters);
61
- // save current appliedFilters to local storage to persist them
62
- localStorage.setItem(`appliedFilters-${mainPath}`, JSON.stringify(state.appliedFilters));
63
- }, [state.appliedFilters]);
64
- // save current shownFilters to local storage to persist them
65
- (0, react_1.useEffect)(() => {
66
- localStorage.setItem(`shownFilters-${mainPath}`, JSON.stringify(state.shownFilters));
67
- }, [state.shownFilters]);
68
- (0, react_1.useEffect)(() => {
69
- dispatch({
70
- type: 'SET_APPLICABLE_FILTERS',
71
- payload: { applicableFilters: filterSchema }
72
- });
73
- }, [filterSchema]);
74
- // console.log('form state', state);
75
- return (react_1.default.createElement(FilterContext.Provider, { value: { state, dispatch, conditionalFiltersSchema } }, children));
76
- };
77
- exports.FilterContextProvider = FilterContextProvider;
78
- function useFilterContext() {
79
- const context = (0, react_1.useContext)(FilterContext);
80
- if (context === undefined) {
81
- throw new Error('useFilterContext must be used within a FilterProvider');
82
- }
83
- return context;
84
- }
85
- exports.useFilterContext = useFilterContext;
@@ -1,7 +0,0 @@
1
- import './styles.css';
2
- import React from 'react';
3
- /**
4
- * Via this component, user can select which filters to show in the UI from applicableFilters.
5
- */
6
- export declare const SelectShownFilters: () => React.JSX.Element;
7
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/SelectShownFilters/index.tsx"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AActB,OAAO,KAAmB,MAAM,OAAO,CAAC;AAWxC;;GAEG;AACH,eAAO,MAAM,kBAAkB,yBA+J9B,CAAC"}