@akinon/akifilter 0.3.0 → 0.4.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 → cjs/components}/AppliedFilters/AppliedFilterItem.d.ts +1 -0
- package/dist/cjs/components/AppliedFilters/AppliedFilterItem.d.ts.map +1 -0
- package/dist/cjs/components/AppliedFilters/AppliedFilterItem.js +53 -0
- package/dist/cjs/components/AppliedFilters/common.d.ts +6 -0
- package/dist/cjs/components/AppliedFilters/common.d.ts.map +1 -0
- package/dist/cjs/components/AppliedFilters/common.js +33 -0
- package/dist/{components → cjs/components}/AppliedFilters/index.d.ts +1 -0
- package/dist/cjs/components/AppliedFilters/index.d.ts.map +1 -0
- package/dist/cjs/components/AppliedFilters/index.js +26 -0
- package/dist/cjs/components/AppliedFilters/styles.css +65 -0
- package/dist/cjs/components/ConditionalFilters/index.d.ts.map +1 -0
- package/dist/cjs/components/ConditionalFilters/index.js +32 -0
- package/dist/cjs/components/FilterContext/index.d.ts.map +1 -0
- package/dist/cjs/components/FilterContext/index.js +85 -0
- package/dist/{components → cjs/components}/SelectShownFilters/index.d.ts +1 -0
- package/dist/cjs/components/SelectShownFilters/index.d.ts.map +1 -0
- package/dist/cjs/components/SelectShownFilters/index.js +111 -0
- package/dist/cjs/components/SelectShownFilters/styles.css +99 -0
- package/dist/cjs/components/ShownFilters/index.d.ts.map +1 -0
- package/dist/cjs/components/ShownFilters/index.js +46 -0
- package/dist/cjs/components/index.d.ts.map +1 -0
- package/dist/cjs/components/index.js +21 -0
- package/dist/cjs/constants/index.d.ts.map +1 -0
- package/dist/cjs/constants/index.js +58 -0
- package/dist/cjs/i18n/index.d.ts.map +1 -0
- package/dist/cjs/i18n/index.js +14 -0
- package/dist/cjs/i18n/translations/en.d.ts.map +1 -0
- package/dist/cjs/i18n/translations/en.js +6 -0
- package/dist/cjs/i18n/translations/tr.d.ts.map +1 -0
- package/dist/cjs/i18n/translations/tr.js +6 -0
- package/dist/cjs/index.css +67 -0
- package/dist/{index.d.ts → cjs/index.d.ts} +1 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +34 -0
- package/dist/cjs/utils/index.d.ts.map +1 -0
- package/dist/cjs/utils/index.js +40 -0
- package/dist/esm/components/AppliedFilters/AppliedFilterItem.d.ts +12 -0
- package/dist/esm/components/AppliedFilters/AppliedFilterItem.d.ts.map +1 -0
- package/dist/esm/components/AppliedFilters/AppliedFilterItem.js +49 -0
- package/dist/esm/components/AppliedFilters/common.d.ts +6 -0
- package/dist/esm/components/AppliedFilters/common.d.ts.map +1 -0
- package/dist/esm/components/AppliedFilters/common.js +28 -0
- package/dist/esm/components/AppliedFilters/index.d.ts +4 -0
- package/dist/esm/components/AppliedFilters/index.d.ts.map +1 -0
- package/dist/esm/components/AppliedFilters/index.js +22 -0
- package/dist/esm/components/AppliedFilters/styles.css +65 -0
- package/dist/esm/components/ConditionalFilters/index.d.ts +3 -0
- package/dist/esm/components/ConditionalFilters/index.d.ts.map +1 -0
- package/dist/esm/components/ConditionalFilters/index.js +28 -0
- package/dist/esm/components/FilterContext/index.d.ts +45 -0
- package/dist/esm/components/FilterContext/index.d.ts.map +1 -0
- package/dist/esm/components/FilterContext/index.js +80 -0
- package/dist/esm/components/SelectShownFilters/index.d.ts +7 -0
- package/dist/esm/components/SelectShownFilters/index.d.ts.map +1 -0
- package/dist/esm/components/SelectShownFilters/index.js +107 -0
- package/dist/esm/components/SelectShownFilters/styles.css +99 -0
- package/dist/esm/components/ShownFilters/index.d.ts +3 -0
- package/dist/esm/components/ShownFilters/index.d.ts.map +1 -0
- package/dist/esm/components/ShownFilters/index.js +42 -0
- package/dist/esm/components/index.d.ts +6 -0
- package/dist/esm/components/index.d.ts.map +1 -0
- package/dist/esm/components/index.js +5 -0
- package/dist/esm/constants/index.d.ts +56 -0
- package/dist/esm/constants/index.d.ts.map +1 -0
- package/dist/esm/constants/index.js +55 -0
- package/dist/esm/i18n/index.d.ts +5 -0
- package/dist/esm/i18n/index.d.ts.map +1 -0
- package/dist/esm/i18n/index.js +11 -0
- package/dist/esm/i18n/translations/en.d.ts +5 -0
- package/dist/esm/i18n/translations/en.d.ts.map +1 -0
- package/dist/esm/i18n/translations/en.js +4 -0
- package/dist/esm/i18n/translations/tr.d.ts +5 -0
- package/dist/esm/i18n/translations/tr.d.ts.map +1 -0
- package/dist/esm/i18n/translations/tr.js +4 -0
- package/dist/esm/index.css +67 -0
- package/dist/esm/index.d.ts +15 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +30 -0
- package/dist/esm/utils/index.d.ts +25 -0
- package/dist/esm/utils/index.d.ts.map +1 -0
- package/dist/esm/utils/index.js +35 -0
- package/package.json +18 -7
- package/dist/Utils/index.d.ts.map +0 -1
- package/dist/components/AppliedFilters/AppliedFilterItem.d.ts.map +0 -1
- package/dist/components/AppliedFilters/common.d.ts +0 -7
- package/dist/components/AppliedFilters/common.d.ts.map +0 -1
- package/dist/components/AppliedFilters/index.d.ts.map +0 -1
- package/dist/components/ConditionalFilters/index.d.ts.map +0 -1
- package/dist/components/FilterContext/index.d.ts.map +0 -1
- package/dist/components/SelectShownFilters/index.d.ts.map +0 -1
- package/dist/components/ShownFilters/index.d.ts.map +0 -1
- package/dist/components/index.d.ts.map +0 -1
- package/dist/constants/index.d.ts.map +0 -1
- package/dist/i18n/index.d.ts.map +0 -1
- package/dist/i18n/translations/en.d.ts.map +0 -1
- package/dist/i18n/translations/tr.d.ts.map +0 -1
- package/dist/index.cjs +0 -31
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -16212
- /package/dist/{components → cjs/components}/ConditionalFilters/index.d.ts +0 -0
- /package/dist/{components → cjs/components}/FilterContext/index.d.ts +0 -0
- /package/dist/{components → cjs/components}/ShownFilters/index.d.ts +0 -0
- /package/dist/{components → cjs/components}/index.d.ts +0 -0
- /package/dist/{constants → cjs/constants}/index.d.ts +0 -0
- /package/dist/{i18n → cjs/i18n}/index.d.ts +0 -0
- /package/dist/{i18n → cjs/i18n}/translations/en.d.ts +0 -0
- /package/dist/{i18n → cjs/i18n}/translations/tr.d.ts +0 -0
- /package/dist/{Utils → cjs/utils}/index.d.ts +0 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultBreakpoints = exports.Breakpoint = exports.defaultRowKey = exports.sampleDate = exports.dateManipulationKeys = exports.omsDashboardStorageKeyName = exports.allowedHtmlTypes = exports.allowedImageTypes = exports.allowedFileTypesAndXlsx = exports.allowedFileTypes = exports.contextChannel = exports.platformLanguage = exports.readResponseMessageKey = exports.permissionSlugSuffix = exports.googleMapApiKey = exports.tokenStorageKey = exports.tokenHeaderKEY = exports.dateTimeFormat = exports.defaultDateTimeFormatWithTimeZone = exports.defaultDateTimeFormatIntl = exports.defaultDateTimeFormat = exports.defaultDateTimeValueFormat = exports.fullDateTimeWithZoneFormat = exports.dateTimeLocalSecondsFormat = exports.overallDateFormat = exports.dateWithMonthNameAndYear = exports.dateWithMonthName = exports.timeFormatWithDateAndTime = exports.timeFormatWithTimeZone = exports.defaultTimeFormatWithTimeZone = exports.defaultTimeFormatWithSeconds = exports.defaultTimeFormat = exports.defaultDateValueFormat = exports.defaultDateFormat = void 0;
|
|
4
|
+
exports.defaultDateFormat = 'DD/MM/YYYY';
|
|
5
|
+
exports.defaultDateValueFormat = 'YYYY-MM-DD';
|
|
6
|
+
exports.defaultTimeFormat = 'HH:mm';
|
|
7
|
+
exports.defaultTimeFormatWithSeconds = 'HH:mm:ss';
|
|
8
|
+
exports.defaultTimeFormatWithTimeZone = 'HH:mm:ssZZ';
|
|
9
|
+
exports.timeFormatWithTimeZone = 'HH:mmZ';
|
|
10
|
+
exports.timeFormatWithDateAndTime = 'LLL';
|
|
11
|
+
exports.dateWithMonthName = 'DD MMMM';
|
|
12
|
+
exports.dateWithMonthNameAndYear = 'DD MMMM YYYY';
|
|
13
|
+
exports.overallDateFormat = 'DD-MM-YYYY HH:mm:ss';
|
|
14
|
+
exports.dateTimeLocalSecondsFormat = 'YYYY-MM-DDTHH:mm:ss.SSS';
|
|
15
|
+
exports.fullDateTimeWithZoneFormat = 'YYYY-MM-DDTHH:mm:ss.SSS\\Z';
|
|
16
|
+
exports.defaultDateTimeValueFormat = `${exports.defaultDateValueFormat} ${exports.defaultTimeFormatWithSeconds}`;
|
|
17
|
+
exports.defaultDateTimeFormat = `${exports.defaultDateFormat} ${exports.defaultTimeFormat}`;
|
|
18
|
+
exports.defaultDateTimeFormatIntl = {
|
|
19
|
+
year: 'numeric',
|
|
20
|
+
month: 'numeric',
|
|
21
|
+
day: 'numeric',
|
|
22
|
+
hour: 'numeric',
|
|
23
|
+
minute: 'numeric',
|
|
24
|
+
hour12: false
|
|
25
|
+
};
|
|
26
|
+
exports.defaultDateTimeFormatWithTimeZone = `${exports.defaultDateValueFormat} ${exports.timeFormatWithTimeZone}`;
|
|
27
|
+
exports.dateTimeFormat = `${exports.defaultDateValueFormat} ${exports.defaultTimeFormat}`;
|
|
28
|
+
exports.tokenHeaderKEY = 'Bearer';
|
|
29
|
+
exports.tokenStorageKey = 'tkn';
|
|
30
|
+
exports.googleMapApiKey = 'AIzaSyB7GLs4svXGax91fiW-gH1wInjmde7cEHk';
|
|
31
|
+
exports.permissionSlugSuffix = '-v2';
|
|
32
|
+
exports.readResponseMessageKey = 'readResponseMessages';
|
|
33
|
+
exports.platformLanguage = 'platform_language';
|
|
34
|
+
exports.contextChannel = 'contextChannel';
|
|
35
|
+
exports.allowedFileTypes = '.xls, .csv';
|
|
36
|
+
exports.allowedFileTypesAndXlsx = exports.allowedFileTypes + ', .xlsx';
|
|
37
|
+
exports.allowedImageTypes = '.png,.jpeg,.jpg,.bmp';
|
|
38
|
+
exports.allowedHtmlTypes = '.html';
|
|
39
|
+
exports.omsDashboardStorageKeyName = 'oms_dashboardFilters';
|
|
40
|
+
exports.dateManipulationKeys = {
|
|
41
|
+
END_OF: 'endOf',
|
|
42
|
+
SUBTRACT: 'subtract',
|
|
43
|
+
ADD: 'add'
|
|
44
|
+
};
|
|
45
|
+
exports.sampleDate = '2022-01-01';
|
|
46
|
+
exports.defaultRowKey = 'id';
|
|
47
|
+
exports.Breakpoint = {
|
|
48
|
+
MOBILE: 'MOBILE',
|
|
49
|
+
TABLET: 'TABLET',
|
|
50
|
+
DESKTOP: 'DESKTOP',
|
|
51
|
+
LARGE_DESKTOP: 'LARGE_DESKTOP'
|
|
52
|
+
};
|
|
53
|
+
exports.defaultBreakpoints = {
|
|
54
|
+
MOBILE: 576,
|
|
55
|
+
TABLET: 768,
|
|
56
|
+
DESKTOP: 992,
|
|
57
|
+
LARGE_DESKTOP: 1200
|
|
58
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/i18n/index.tsx"],"names":[],"mappings":"AAKA,eAAO,MAAM,IAAI;;;CAOf,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.i18n = void 0;
|
|
4
|
+
const akilocale_1 = require("@akinon/akilocale");
|
|
5
|
+
const en_1 = require("./translations/en");
|
|
6
|
+
const tr_1 = require("./translations/tr");
|
|
7
|
+
exports.i18n = akilocale_1.Akilocale.createInstance({
|
|
8
|
+
debug: true,
|
|
9
|
+
fallbackLng: 'en',
|
|
10
|
+
translations: {
|
|
11
|
+
en: en_1.default,
|
|
12
|
+
tr: tr_1.default
|
|
13
|
+
}
|
|
14
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"en.d.ts","sourceRoot":"","sources":["../../../../src/i18n/translations/en.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,MAAM;;CAEF,CAAC;AAEX,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tr.d.ts","sourceRoot":"","sources":["../../../../src/i18n/translations/tr.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,MAAM;;CAEF,CAAC;AAEX,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
.akinon-filter {
|
|
2
|
+
background-color: var(--color-ebonyClay-400);
|
|
3
|
+
padding: 1.25rem 1.5rem 1.5rem;
|
|
4
|
+
border-radius: 10px;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.akinon-filter .akinon-filter__title {
|
|
8
|
+
margin: 0;
|
|
9
|
+
font-weight: 500 !important;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.akinon-filter .akinon-filter__top {
|
|
13
|
+
display: flex;
|
|
14
|
+
justify-content: space-between;
|
|
15
|
+
align-items: center;
|
|
16
|
+
margin-bottom: 1rem;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.akinon-filter .akinon-filter__header {
|
|
20
|
+
color: var(--color-gray-500);
|
|
21
|
+
margin: 1.25rem 0 0.5rem !important;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/* Overriding this here is questionable? */
|
|
25
|
+
.akinon-filter .akinon-form {
|
|
26
|
+
display: grid;
|
|
27
|
+
grid-template-columns: 1fr 1fr 1fr 1fr;
|
|
28
|
+
gap: 0.5rem 0.75rem;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.akinon-filter .akinon-checkbox-wrapper {
|
|
32
|
+
box-sizing: border-box;
|
|
33
|
+
margin: 0;
|
|
34
|
+
padding: 3px 10px;
|
|
35
|
+
font-size: 14px;
|
|
36
|
+
list-style: none;
|
|
37
|
+
position: relative;
|
|
38
|
+
width: 100%;
|
|
39
|
+
min-width: 0;
|
|
40
|
+
background-color: #2b344c;
|
|
41
|
+
background-image: none;
|
|
42
|
+
border-width: 2px;
|
|
43
|
+
border-style: solid;
|
|
44
|
+
border-color: #262e47;
|
|
45
|
+
border-radius: 6px;
|
|
46
|
+
span {
|
|
47
|
+
color: var(--color-gray-500) !important;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.akinon-filter .akinon-picker {
|
|
52
|
+
background-color: var(--color-ebonyClay-475);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.akinon-filter .akinon-picker,
|
|
56
|
+
.akinon-filter .akinon-input-number,
|
|
57
|
+
[class^='antd-item'] {
|
|
58
|
+
width: 100%;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.akinon-filter .akinon-form-item-control-input-content > * {
|
|
62
|
+
align-items: center;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.akinon-filter .shown-filters * {
|
|
66
|
+
font-weight: 700 !important;
|
|
67
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAC;AAErB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAWzD,OAAO,KAAK,MAAM,OAAO,CAAC;AAS1B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAY9D,MAAM,MAAM,WAAW,GAAG;IAExB,YAAY,EAAE,SAAS,EAAE,CAAC;IAG1B,iBAAiB,EAAE;QACjB,WAAW,CAAC,gBAAgB,CAAC;QAC7B,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC,CAAC;KACpE,CAAC;IAEF,wBAAwB,CAAC,EAAE,SAAS,EAAE,CAAC;IAEvC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,SAAS,kFAKnB,WAAW,sBAqBb,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Akifilter = void 0;
|
|
4
|
+
require("./index.css");
|
|
5
|
+
const ui_typography_1 = require("@akinon/ui-typography");
|
|
6
|
+
const dayjs_1 = require("dayjs");
|
|
7
|
+
const advancedFormat_1 = require("dayjs/plugin/advancedFormat");
|
|
8
|
+
const customParseFormat_1 = require("dayjs/plugin/customParseFormat");
|
|
9
|
+
const localeData_1 = require("dayjs/plugin/localeData");
|
|
10
|
+
const weekday_1 = require("dayjs/plugin/weekday");
|
|
11
|
+
const weekOfYear_1 = require("dayjs/plugin/weekOfYear");
|
|
12
|
+
const weekYear_1 = require("dayjs/plugin/weekYear");
|
|
13
|
+
const react_1 = require("react");
|
|
14
|
+
const components_1 = require("./components");
|
|
15
|
+
const i18n_1 = require("./i18n");
|
|
16
|
+
// TODO: Whats this dayjs block doing here?
|
|
17
|
+
// extend dayjs with plugins so datepicker value can be set outside
|
|
18
|
+
dayjs_1.default.extend(customParseFormat_1.default);
|
|
19
|
+
dayjs_1.default.extend(advancedFormat_1.default);
|
|
20
|
+
dayjs_1.default.extend(weekday_1.default);
|
|
21
|
+
dayjs_1.default.extend(localeData_1.default);
|
|
22
|
+
dayjs_1.default.extend(weekOfYear_1.default);
|
|
23
|
+
dayjs_1.default.extend(weekYear_1.default);
|
|
24
|
+
const Akifilter = ({ filterSchema, useAppliedFilters, customMainPath, conditionalFiltersSchema }) => {
|
|
25
|
+
return (react_1.default.createElement("div", { className: "akinon-filter" },
|
|
26
|
+
react_1.default.createElement(components_1.FilterContextProvider, { filterSchema: filterSchema, customMainPath: customMainPath, useAppliedFilters: useAppliedFilters, conditionalFiltersSchema: conditionalFiltersSchema },
|
|
27
|
+
react_1.default.createElement("div", { className: "akinon-filter__top" },
|
|
28
|
+
react_1.default.createElement(ui_typography_1.Title, { className: "akinon-filter__title", level: 4 }, i18n_1.i18n.t('title')),
|
|
29
|
+
react_1.default.createElement(components_1.SelectShownFilters, null)),
|
|
30
|
+
react_1.default.createElement(components_1.AppliedFilters, null),
|
|
31
|
+
react_1.default.createElement(components_1.ShownFilters, null),
|
|
32
|
+
react_1.default.createElement(components_1.ConditionalFilters, null))));
|
|
33
|
+
};
|
|
34
|
+
exports.Akifilter = Akifilter;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.tsx"],"names":[],"mappings":"AAEA,UAAU,QAAQ;IAChB,KAAK,EAAE,GAAG,CAAC;IACX,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC;CACvB;AAED,UAAU,MAAM;IACd,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB,SAAS,EAAE,GAAG,CAAC;CAChB;AAED,wBAAgB,kBAAkB,CAAC,EACjC,IAAI,EACJ,SAAS,EACV,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAiB1B;AAED;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,SAAU,GAAG;;;;;;CAUzC,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPathFragments = exports.getTreeNodeByValue = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
function getTreeNodeByValue({ tree, nodeValue }) {
|
|
6
|
+
if ((0, lodash_1.isEmpty)(tree) || (0, lodash_1.isEmpty)(nodeValue)) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
for (const node of tree) {
|
|
10
|
+
if (node.value === nodeValue) {
|
|
11
|
+
return node;
|
|
12
|
+
}
|
|
13
|
+
if (node.children) {
|
|
14
|
+
const childNode = getTreeNodeByValue({ tree: node.children, nodeValue });
|
|
15
|
+
if (childNode) {
|
|
16
|
+
return childNode;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
exports.getTreeNodeByValue = getTreeNodeByValue;
|
|
23
|
+
/**
|
|
24
|
+
* To understand this fragmentation, you need to know that the path is built as follows:
|
|
25
|
+
*
|
|
26
|
+
* `appPath = /{appLanguage}/{apiLanguage}/{rootPath}/{subPath}`
|
|
27
|
+
*
|
|
28
|
+
* `mainPath = rootPath + subPath`
|
|
29
|
+
*/
|
|
30
|
+
const getPathFragments = (path) => {
|
|
31
|
+
const pathSlices = path.split('/');
|
|
32
|
+
return {
|
|
33
|
+
appLanguage: pathSlices[1],
|
|
34
|
+
apiLanguage: pathSlices[2],
|
|
35
|
+
rootPath: `/${pathSlices[3]}`,
|
|
36
|
+
subPath: `/${pathSlices.slice(4).join('/')}`,
|
|
37
|
+
mainPath: `/${pathSlices.slice(3).join('/')}`
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
exports.getPathFragments = getPathFragments;
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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;AAE1B,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,6BA8FxB,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import './styles.css';
|
|
2
|
+
import { Icon } from '@akinon/icons';
|
|
3
|
+
import { Space } from '@akinon/ui-space';
|
|
4
|
+
import { Text } from '@akinon/ui-typography';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { useFilterContext } from '../FilterContext';
|
|
7
|
+
import { isArray, isBoolean } from 'lodash';
|
|
8
|
+
export const AppliedFilterItem = ({ filterKeyValue }) => {
|
|
9
|
+
const [filterKey, filterValue] = filterKeyValue;
|
|
10
|
+
const { state: { applicableFilters, appliedFilters }, dispatch, conditionalFiltersSchema } = useFilterContext();
|
|
11
|
+
// find filterItem for placeholder, etc from filterKey
|
|
12
|
+
const filterItem = [
|
|
13
|
+
...applicableFilters,
|
|
14
|
+
...(conditionalFiltersSchema || [])
|
|
15
|
+
].find(i => i.key === filterKey);
|
|
16
|
+
if (!filterItem) {
|
|
17
|
+
console.warn(`filterItem with key ${filterKey} not found`);
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
// TODO getModifiedFilterValue doesn't need filterValue. It can obtain it from filterItem
|
|
21
|
+
// TODO explain why you need to modify the filter value
|
|
22
|
+
// const modifiedFilterValue = getModifiedFilterValue({
|
|
23
|
+
// filterItem,
|
|
24
|
+
// filterValue
|
|
25
|
+
// });
|
|
26
|
+
// const shouldShowActiveFilter =
|
|
27
|
+
// !isEmpty(filterItem) && !isEmpty(modifiedFilterValue);
|
|
28
|
+
const handleRemoveFilter = (removedFilterKey) => {
|
|
29
|
+
// TODO write test for below comment
|
|
30
|
+
// you should mark the key as undefined instead of deleting it for antd form item to pick up the change
|
|
31
|
+
const newFilters = Object.assign(Object.assign({}, appliedFilters), { [removedFilterKey]: undefined });
|
|
32
|
+
dispatch({
|
|
33
|
+
type: 'SET_APPLIED_FILTERS',
|
|
34
|
+
payload: { appliedFilters: newFilters }
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
const inputField = filterItem;
|
|
38
|
+
return (React.createElement(React.Fragment, null,
|
|
39
|
+
React.createElement(Space, { key: filterKey, align: "center", className: "active-filter-item" },
|
|
40
|
+
React.createElement(Text, { className: "active-filter-item__label" }, inputField === null || inputField === void 0 ? void 0 :
|
|
41
|
+
inputField.placeholder,
|
|
42
|
+
":"),
|
|
43
|
+
React.createElement(Text, { className: "active-filter-item__value" }, isBoolean(filterValue)
|
|
44
|
+
? filterValue.toString()
|
|
45
|
+
: isArray(filterValue)
|
|
46
|
+
? filterValue.join(', ')
|
|
47
|
+
: filterValue),
|
|
48
|
+
React.createElement(Icon, { icon: "close", size: 20, className: "active-filter-item__remove-filter-icon", onClick: () => handleRemoveFilter(filterKey) }))));
|
|
49
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../src/components/AppliedFilters/common.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,YAAY,UAAW,GAAG,YAAuC,CAAC;AAE/E,eAAO,MAAM,sBAAsB;gBAIrB,GAAG;iBACF,GAAG,CAAC,OAAO,CAAC;SA+B1B,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { TreeSelect } from '@akinon/ui-tree-select';
|
|
2
|
+
import { overallDateFormat } from '../../constants';
|
|
3
|
+
import { getTreeNodeByValue } from '../../utils';
|
|
4
|
+
export const isFileObject = (value) => (value === null || value === void 0 ? void 0 : value.originFileObj) !== undefined;
|
|
5
|
+
export const getModifiedFilterValue = ({ filterItem, filterValue }) => {
|
|
6
|
+
var _a, _b, _c;
|
|
7
|
+
switch (filterItem === null || filterItem === void 0 ? void 0 : filterItem.widget) {
|
|
8
|
+
case 'select':
|
|
9
|
+
if (((_a = filterItem === null || filterItem === void 0 ? void 0 : filterItem.widgetProps) === null || _a === void 0 ? void 0 : _a.mode) === 'multiple') {
|
|
10
|
+
return filterValue === null || filterValue === void 0 ? void 0 : filterValue.map((value) => {
|
|
11
|
+
const optionObject = filterItem.options.find((option) => option.value === value);
|
|
12
|
+
return (optionObject === null || optionObject === void 0 ? void 0 : optionObject.label) || value;
|
|
13
|
+
}).join(', ');
|
|
14
|
+
}
|
|
15
|
+
const optionObject = filterItem.options.find((option) => option.value === filterValue);
|
|
16
|
+
return (optionObject === null || optionObject === void 0 ? void 0 : optionObject.label) || filterValue;
|
|
17
|
+
case 'date-picker':
|
|
18
|
+
return filterValue === null || filterValue === void 0 ? void 0 : filterValue.format(overallDateFormat);
|
|
19
|
+
case 'checkbox-group':
|
|
20
|
+
return filterValue === null || filterValue === void 0 ? void 0 : filterValue.map(() => 'Yes').join(', ');
|
|
21
|
+
case TreeSelect:
|
|
22
|
+
const tree = (_b = filterItem === null || filterItem === void 0 ? void 0 : filterItem.widgetProps) === null || _b === void 0 ? void 0 : _b.treeData;
|
|
23
|
+
const label = (_c = getTreeNodeByValue({ tree, nodeValue: filterValue })) === null || _c === void 0 ? void 0 : _c.value;
|
|
24
|
+
return label || filterValue;
|
|
25
|
+
default:
|
|
26
|
+
return filterValue;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import './styles.css';
|
|
2
|
+
import { Icon } from '@akinon/icons';
|
|
3
|
+
import { Col, Row } from '@akinon/ui-layout';
|
|
4
|
+
import { Space } from '@akinon/ui-space';
|
|
5
|
+
import { Text } from '@akinon/ui-typography';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import { useFilterContext } from '../FilterContext';
|
|
8
|
+
import { AppliedFilterItem } from './AppliedFilterItem';
|
|
9
|
+
export const AppliedFilters = () => {
|
|
10
|
+
var _a;
|
|
11
|
+
const { state: { appliedFilters }, dispatch } = useFilterContext();
|
|
12
|
+
const handleOnResetFilters = () => {
|
|
13
|
+
dispatch({ type: 'SET_APPLIED_FILTERS', payload: { appliedFilters: {} } });
|
|
14
|
+
};
|
|
15
|
+
return (React.createElement(Row, { align: "middle", className: "applied_filters" },
|
|
16
|
+
React.createElement(Col, { className: "applied_filters__list" },
|
|
17
|
+
React.createElement(Space, null,
|
|
18
|
+
React.createElement(Text, { className: "applied_filters__label" }, "Active filters:"),
|
|
19
|
+
React.createElement(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.createElement(AppliedFilterItem, { filterKeyValue: [filterKey, filterValue], key: i })))))),
|
|
20
|
+
React.createElement(Col, { className: "applied_filters__clear-filters" },
|
|
21
|
+
React.createElement(Icon, { icon: "bin", size: 35, className: "applied_filters__reset-filters-icon", onClick: handleOnResetFilters }))));
|
|
22
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { FormBuilderWatch } from '@akinon/akiform-builder';
|
|
2
|
+
import { Paragraph } from '@akinon/ui-typography';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { useFilterContext } from '../FilterContext';
|
|
5
|
+
export const ConditionalFilters = () => {
|
|
6
|
+
const { dispatch, state, conditionalFiltersSchema } = useFilterContext();
|
|
7
|
+
const { appliedFilters } = state;
|
|
8
|
+
const [formResetCount, setFormResetCount] = React.useState(0);
|
|
9
|
+
// reset form state when conditionalFiltersSchema changes
|
|
10
|
+
React.useEffect(() => {
|
|
11
|
+
setFormResetCount(formResetCount + 1);
|
|
12
|
+
}, [conditionalFiltersSchema]);
|
|
13
|
+
// second form created just to reset antd form state when conditionalFiltersSchema changes.
|
|
14
|
+
const handleFormChange = (allValues) => {
|
|
15
|
+
dispatch({
|
|
16
|
+
type: 'SET_APPLIED_FILTERS',
|
|
17
|
+
payload: {
|
|
18
|
+
appliedFilters: Object.assign(Object.assign({}, appliedFilters), allValues)
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
if (!conditionalFiltersSchema)
|
|
23
|
+
return null;
|
|
24
|
+
return (React.createElement(React.Fragment, null,
|
|
25
|
+
React.createElement(Paragraph, { className: "akinon-filter__header" }, "COMMON PARAMETER FILTERS"),
|
|
26
|
+
React.createElement("div", null,
|
|
27
|
+
React.createElement(FormBuilderWatch, { builderFields: conditionalFiltersSchema, handleChange: handleFormChange, key: formResetCount, isDebounced: true }))));
|
|
28
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import React, { createContext, useContext, useEffect } from 'react';
|
|
2
|
+
import { useLocation } from 'react-router-dom';
|
|
3
|
+
import { useImmerReducer } from 'use-immer';
|
|
4
|
+
import { getPathFragments } from '../../utils';
|
|
5
|
+
const FilterContext = createContext(undefined);
|
|
6
|
+
/**
|
|
7
|
+
* FilterContextProvider manages both filter context and antd form state.
|
|
8
|
+
* Reason for not separating antd form state from filter context is that antd
|
|
9
|
+
* form state is tightly coupled with filter context state.
|
|
10
|
+
*/
|
|
11
|
+
export const FilterContextProvider = ({ children, filterSchema, customMainPath, useAppliedFilters, conditionalFiltersSchema }) => {
|
|
12
|
+
const { pathname } = useLocation();
|
|
13
|
+
const mainPath = customMainPath
|
|
14
|
+
? customMainPath
|
|
15
|
+
: getPathFragments(pathname).mainPath;
|
|
16
|
+
if (!mainPath) {
|
|
17
|
+
throw new Error('mainPath is not defined');
|
|
18
|
+
}
|
|
19
|
+
// load appliedFilters from local storage
|
|
20
|
+
const localAppliedFilters = JSON.parse(localStorage.getItem(`appliedFilters-${mainPath}`) || '{}');
|
|
21
|
+
// get applied filters from parent component
|
|
22
|
+
const parentAppliedFilters = useAppliedFilters[0];
|
|
23
|
+
// load shownFilters from local storage
|
|
24
|
+
const localShownFilters = JSON.parse(localStorage.getItem(`shownFilters-${mainPath}`) || '[]');
|
|
25
|
+
const initialState = {
|
|
26
|
+
mainPath,
|
|
27
|
+
// 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
|
|
28
|
+
appliedFilters: Object.keys(parentAppliedFilters).length > 0
|
|
29
|
+
? parentAppliedFilters
|
|
30
|
+
: localAppliedFilters,
|
|
31
|
+
applicableFilters: filterSchema,
|
|
32
|
+
// if localShownFilters is not defined, only show first 8 filters
|
|
33
|
+
shownFilters: localShownFilters.length
|
|
34
|
+
? localShownFilters
|
|
35
|
+
: filterSchema.map(filter => filter.key).slice(0, 8),
|
|
36
|
+
recreateShownFiltersCount: 0
|
|
37
|
+
};
|
|
38
|
+
const [state, dispatch] = useImmerReducer((draft, action) => {
|
|
39
|
+
switch (action.type) {
|
|
40
|
+
case 'SET_APPLIED_FILTERS':
|
|
41
|
+
// console.log('SET_APPLIED_FILTERS', action.payload.appliedFilters);
|
|
42
|
+
draft.appliedFilters = action.payload.appliedFilters;
|
|
43
|
+
return;
|
|
44
|
+
case 'SET_APPLICABLE_FILTERS':
|
|
45
|
+
// console.log('SET_APPLICABLE_FILTERS');
|
|
46
|
+
draft.applicableFilters = action.payload.applicableFilters;
|
|
47
|
+
return;
|
|
48
|
+
case 'SET_SHOWN_FILTERS':
|
|
49
|
+
// console.log('SET_SHOWN_FILTERS', action.payload.shownFilters);
|
|
50
|
+
draft.shownFilters = action.payload.shownFilters;
|
|
51
|
+
draft.recreateShownFiltersCount = draft.recreateShownFiltersCount + 1;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
}, initialState);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
// send applied filters to parent component
|
|
57
|
+
useAppliedFilters[1](state.appliedFilters);
|
|
58
|
+
// save current appliedFilters to local storage to persist them
|
|
59
|
+
localStorage.setItem(`appliedFilters-${mainPath}`, JSON.stringify(state.appliedFilters));
|
|
60
|
+
}, [state.appliedFilters]);
|
|
61
|
+
// save current shownFilters to local storage to persist them
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
localStorage.setItem(`shownFilters-${mainPath}`, JSON.stringify(state.shownFilters));
|
|
64
|
+
}, [state.shownFilters]);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
dispatch({
|
|
67
|
+
type: 'SET_APPLICABLE_FILTERS',
|
|
68
|
+
payload: { applicableFilters: filterSchema }
|
|
69
|
+
});
|
|
70
|
+
}, [filterSchema]);
|
|
71
|
+
// console.log('form state', state);
|
|
72
|
+
return (React.createElement(FilterContext.Provider, { value: { state, dispatch, conditionalFiltersSchema } }, children));
|
|
73
|
+
};
|
|
74
|
+
export function useFilterContext() {
|
|
75
|
+
const context = useContext(FilterContext);
|
|
76
|
+
if (context === undefined) {
|
|
77
|
+
throw new Error('useFilterContext must be used within a FilterProvider');
|
|
78
|
+
}
|
|
79
|
+
return context;
|
|
80
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|