@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.
- package/CHANGELOG.md +9 -1
- package/es/index.js +26 -0
- package/es/lib/NoResultsMessage/NoResultsMessage.js +89 -0
- package/es/lib/NoResultsMessage/index.js +15 -0
- package/es/lib/SASQLookupComponent/SASQLookupComponent.js +17 -0
- package/es/lib/hooks/index.js +8 -0
- package/es/lib/hooks/useHelperApp.js +7 -1
- package/es/lib/hooks/useKiwtSASQuery.js +22 -1
- package/es/lib/hooks/useQIndex.js +75 -0
- package/es/lib/hooks/useRefdata.js +23 -6
- package/es/lib/utils/generateKiwtQuery.js +3 -109
- package/es/lib/utils/generateKiwtQueryParams.js +125 -0
- package/es/lib/utils/index.js +16 -0
- package/package.json +1 -1
- package/src/index.js +7 -1
- package/src/lib/NoResultsMessage/NoResultsMessage.js +78 -0
- package/src/lib/NoResultsMessage/index.js +1 -0
- package/src/lib/SASQLookupComponent/SASQLookupComponent.js +30 -8
- package/src/lib/SASQRoute/README.md +1 -1
- package/src/lib/TypeDown/README.md +1 -115
- package/src/lib/hooks/README.md +34 -0
- package/src/lib/hooks/index.js +2 -0
- package/src/lib/hooks/useHelperApp.js +5 -1
- package/src/lib/hooks/useKiwtSASQuery.js +9 -1
- package/src/lib/hooks/useQIndex.js +41 -0
- package/src/lib/hooks/useRefdata.js +23 -6
- package/src/lib/utils/README.md +39 -1
- package/src/lib/utils/generateKiwtQuery.js +3 -62
- package/src/lib/utils/generateKiwtQueryParams.js +67 -0
- package/src/lib/utils/index.js +3 -0
- package/styles/NoResultsMessage.css +38 -0
- package/translations/stripes-kint-components/en.json +3 -1
package/src/lib/utils/README.md
CHANGED
|
@@ -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
|
-
|
|
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;
|
package/src/lib/utils/index.js
CHANGED
|
@@ -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
|
}
|