@k-int/stripes-kint-components 1.3.0 → 1.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.
@@ -29,5 +29,43 @@ import { generateKiwtQuery } from '@k-int/stripes-kint-components'
29
29
  ### Props
30
30
  Name | Type | Description | default | required
31
31
  --- | --- | --- | --- | ---
32
- options | object | An object with keys: `searchKey`, `filterKeys`, `sortKeys` and `stats`, which maps the incoming nsValues objects to a KIWT query. | | ✓ |
32
+ options | object | An object with keys: `searchKey`, `filterKeys`, `sortKeys` and `stats`, which maps the incoming nsValues objects to a KIWT query. You can also pass arbitrary `key`/`value` pairs to append `key==value` onto the query. | | ✓ |
33
+ nsValues | object | An object containing the actual query parameters to become the mapped KIWT query | | ✓ |
34
+
35
+ ## generateKiwtQueryParams
36
+ A util function for generating an array of "KIWT" (K-Int Web-Toolkit) style backend query parameters from a SASQ query object
37
+ ### Basic usage
38
+ ```
39
+ import { generateKiwtQueryParams } from '@k-int/stripes-kint-components'
40
+ ...
41
+ const nsValues = {
42
+ query: 'test',
43
+ filters: 'requestStatus.completed,journalVolume.test1,startDate.startDate>=2021-10-28'
44
+ }
45
+
46
+ const options = {
47
+ searchKey: 'request.name',
48
+ filterKeys: {
49
+ requestStatus: 'requestStatus.value,
50
+ journalVolume: 'journalVolume'
51
+ }
52
+ }
53
+
54
+ const queryArray = generateKiwtQueryParams(options, nsValues)
55
+
56
+ // We'd expect queryArray === [
57
+ "match=request.name",
58
+ "term=test",
59
+ "filters=requestStatus.value==completed",
60
+ "filters=journalVolume==test1",
61
+ "filters=startDate%3E=2021-10-28",
62
+ "stats=true"
63
+ ]
64
+ ...
65
+ ```
66
+
67
+ ### Props
68
+ Name | Type | Description | default | required
69
+ --- | --- | --- | --- | ---
70
+ options | object | An object with keys: `searchKey`, `filterKeys`, `sortKeys` and `stats`, which maps the incoming nsValues objects to an KIWT query array. You can also pass arbitrary `key`/`value` pairs to append `key==value` onto the query. | | ✓ |
33
71
  nsValues | object | An object containing the actual query parameters to become the mapped KIWT query | | ✓ |
@@ -1,66 +1,7 @@
1
- const generateKiwtQuery = (options, nsValues) => {
2
- const { query, filters, sort } = nsValues;
3
- const {
4
- searchKey = '',
5
- /* Assumtion made that if no filterKey is provided then the given filterValues for that key are standalaone, ie require no comparator or key */
6
- filterKeys = {},
7
- sortKeys = {},
8
- stats = true,
9
- ...rest
10
- } = options;
11
-
12
- const paramsArray = [];
13
-
14
- if (query) {
15
- paramsArray.push(...searchKey.split(',')?.map(m => `match=${m}`));
16
- paramsArray.push(`term=${query}`);
17
- }
18
-
19
- if (filters) {
20
- const filterMap = {};
21
- filters.split(',').forEach(filter => {
22
- const [filterName, ...rest] = filter.split('.');
23
- const filterValue = rest.join('.');
24
-
25
- if (filterMap[filterName] === undefined) filterMap[filterName] = [];
26
- filterMap[filterName].push(filterValue);
27
- });
28
-
29
- // We now have a filterMap of shape { status: ['active', 'cancelled'], type: ['local'] }
30
- Object.entries(filterMap).forEach(([filterName, filterValues]) => {
31
- const filterKey = filterKeys[filterName];
32
-
33
- if (!filterKey) {
34
- // These filters have no key mapping so we just pass the values to the backend as-is.
35
- paramsArray.push(...filterValues?.map(f => `filters=${f}`));
36
- } else {
37
- const filterString = filterValues.map(v => `${filterKey}==${v}`).join('||');
38
- paramsArray.push(`filters=${filterString}`);
39
- }
40
- });
41
- }
42
-
43
- if (sort) {
44
- paramsArray.push(...sort.split(',').map(sortKey => {
45
- const descending = sortKey.startsWith('-');
46
- let term = sortKey.replace('-', '');
47
-
48
- if (term in sortKeys) {
49
- term = term.replace(term, sortKeys[term]);
50
- }
51
-
52
- return `sort=${term};${descending ? 'desc' : 'asc'}`;
53
- }));
54
- }
55
-
56
- if (stats) {
57
- paramsArray.push('stats=true');
58
- }
59
-
60
- for (const [key, value] of Object.entries(rest)) {
61
- paramsArray.push(`${key}=${value}`);
62
- }
1
+ import generateKiwtQueryParams from './generateKiwtQueryParams';
63
2
 
3
+ const generateKiwtQuery = (options, nsValues) => {
4
+ const paramsArray = generateKiwtQueryParams(options, nsValues);
64
5
  return paramsArray.length ? '?' + paramsArray.map(p => encodeURI(p)).join('&') : '';
65
6
  };
66
7
 
@@ -0,0 +1,67 @@
1
+ const generateKiwtQueryParams = (options, nsValues) => {
2
+ const { qindex, query, filters, sort } = nsValues;
3
+ const {
4
+ searchKey = '',
5
+ /* Assumtion made that if no filterKey is provided then the given filterValues for that key are standalaone, ie require no comparator or key */
6
+ filterKeys = {},
7
+ sortKeys = {},
8
+ stats = true,
9
+ ...rest
10
+ } = options;
11
+
12
+ const paramsArray = [];
13
+
14
+ if (query) {
15
+ paramsArray.push(...(qindex || searchKey).split(',')?.map(m => `match=${m}`));
16
+ paramsArray.push(`term=${query}`);
17
+ }
18
+
19
+ if (filters) {
20
+ const filterMap = {};
21
+ filters.split(',').forEach(filter => {
22
+ const [filterName, ...filterRest] = filter.split('.');
23
+ const filterValue = filterRest.join('.');
24
+
25
+ if (filterMap[filterName] === undefined) filterMap[filterName] = [];
26
+ filterMap[filterName].push(filterValue);
27
+ });
28
+
29
+ // We now have a filterMap of shape { status: ['active', 'cancelled'], type: ['local'] }
30
+ Object.entries(filterMap).forEach(([filterName, filterValues]) => {
31
+ const filterKey = filterKeys[filterName];
32
+
33
+ if (!filterKey) {
34
+ // These filters have no key mapping so we just pass the values to the backend as-is.
35
+ paramsArray.push(...filterValues?.map(f => `filters=${f}`));
36
+ } else {
37
+ const filterString = filterValues.map(v => `${filterKey}==${v}`).join('||');
38
+ paramsArray.push(`filters=${filterString}`);
39
+ }
40
+ });
41
+ }
42
+
43
+ if (sort) {
44
+ paramsArray.push(...sort.split(',').map(sortKey => {
45
+ const descending = sortKey.startsWith('-');
46
+ let term = sortKey.replace('-', '');
47
+
48
+ if (term in sortKeys) {
49
+ term = term.replace(term, sortKeys[term]);
50
+ }
51
+
52
+ return `sort=${term};${descending ? 'desc' : 'asc'}`;
53
+ }));
54
+ }
55
+
56
+ if (stats) {
57
+ paramsArray.push('stats=true');
58
+ }
59
+
60
+ for (const [key, value] of Object.entries(rest)) {
61
+ paramsArray.push(`${key}=${value}`);
62
+ }
63
+
64
+ return paramsArray;
65
+ };
66
+
67
+ export default generateKiwtQueryParams;
@@ -1,2 +1,5 @@
1
1
  export { default as generateKiwtQuery } from './generateKiwtQuery';
2
+ export { default as generateKiwtQueryParams } from './generateKiwtQueryParams';
3
+ export { default as selectorSafe } from './selectorSafe';
4
+
2
5
  export { default as buildUrl } from './buildUrl';
@@ -0,0 +1,38 @@
1
+ /**
2
+ * No Results Message
3
+ */
4
+
5
+ @import '@folio/stripes-components/lib/variables.css';
6
+
7
+ /* Empty Message */
8
+ .noResultsMessage {
9
+ padding: 15px;
10
+ color: var(--color-text-p2);
11
+ position: absolute;
12
+ top: 0;
13
+ bottom: 0;
14
+ left: 0;
15
+ right: 0;
16
+ background: var(--color-fill);
17
+ flex-direction: column;
18
+ }
19
+
20
+ .noResultsMessage,
21
+ .noResultsMessageLabelWrap {
22
+ display: flex;
23
+ align-items: center;
24
+ justify-content: center;
25
+ }
26
+
27
+ .noResultsMessageLabelWrap {
28
+ font-size: var(--font-size-large);
29
+ }
30
+
31
+ .noResultsMessageIcon,
32
+ .noResultsMessageLabel {
33
+ margin: 0 4px;
34
+ }
35
+
36
+ .noResultsMessageButton {
37
+ margin-top: 15px;
38
+ }
@@ -15,5 +15,7 @@
15
15
  "editableRefdataList.label": "Label",
16
16
  "editableRefdataList.value": "Value",
17
17
 
18
- "sasqLookupComponent.mainPane.found": "{total} records found"
18
+ "sasqLookupComponent.mainPane.found": "{total} records found",
19
+
20
+ "noResultsMessage.showFilters": "Show filters"
19
21
  }