@k-int/stripes-kint-components 5.9.0 → 5.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/es/index.js +12 -0
- package/es/lib/Tags/Tags.js +143 -0
- package/es/lib/Tags/Tags.test.js +80 -0
- package/es/lib/Tags/hooks/index.js +28 -0
- package/es/lib/Tags/hooks/useTags.js +15 -0
- package/es/lib/Tags/hooks/useTagsEnabled.js +25 -0
- package/es/lib/Tags/index.js +40 -0
- package/es/lib/Tags/tagsConfig.js +10 -0
- package/es/lib/Typedown/Typedown.js +12 -2
- package/es/lib/hooks/typedownHooks/useTypedown.js +15 -2
- package/es/lib/hooks/useHelperApp.js +18 -15
- package/package.json +3 -2
- package/src/index.js +2 -0
- package/src/lib/FormModal/README.md +91 -0
- package/src/lib/Tags/Tags.js +145 -0
- package/src/lib/Tags/Tags.test.js +77 -0
- package/src/lib/Tags/hooks/index.js +2 -0
- package/src/lib/Tags/hooks/useTags.js +16 -0
- package/src/lib/Tags/hooks/useTagsEnabled.js +19 -0
- package/src/lib/Tags/index.js +4 -0
- package/src/lib/Tags/tagsConfig.js +16 -0
- package/src/lib/Typedown/README.md +21 -19
- package/src/lib/Typedown/Typedown.js +16 -3
- package/src/lib/hooks/typedownHooks/useTypedown.js +17 -3
- package/src/lib/hooks/useHelperApp.js +21 -13
- package/src/lib/utils/README.md +126 -56
- package/test/helpers/test-implementor-translations.json +4 -1
package/src/lib/utils/README.md
CHANGED
|
@@ -1,73 +1,143 @@
|
|
|
1
|
-
#
|
|
2
|
-
A collection of useful util functions
|
|
1
|
+
# Utility Functions
|
|
3
2
|
|
|
4
3
|
## generateKiwtQuery
|
|
5
|
-
A util function for generating a "KIWT" (K-Int Web-Toolkit) style backend query from a SASQ query object
|
|
6
|
-
### Basic usage
|
|
7
|
-
```
|
|
8
|
-
import { generateKiwtQuery } from '@k-int/stripes-kint-components'
|
|
9
|
-
...
|
|
10
|
-
const nsValues = {
|
|
11
|
-
query: 'test',
|
|
12
|
-
filters: 'requestStatus.completed,journalVolume.test1,startDate.startDate>=2021-10-28'
|
|
13
|
-
}
|
|
14
4
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
5
|
+
The `generateKiwtQuery` function generates a URL query string in "KIWT" (K-Int Web Toolkit) style from a SASQ (Search and Sort Query) object. It handles search terms, filters, sorting, and other parameters, making it easy to construct complex query strings for backend APIs.
|
|
6
|
+
|
|
7
|
+
### Basic Usage
|
|
8
|
+
|
|
9
|
+
```javascript
|
|
10
|
+
import { generateKiwtQuery } from '@k-int/stripes-kint-components';
|
|
11
|
+
|
|
12
|
+
const nsValues = {
|
|
13
|
+
query: 'test',
|
|
14
|
+
filters: 'requestStatus.completed,journalVolume.test1,startDate.startDate>=2021-10-28',
|
|
15
|
+
sort: '-title' // Example of sorting by title in descending order
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const options = {
|
|
19
|
+
searchKey: 'request.name',
|
|
20
|
+
filterKeys: {
|
|
21
|
+
requestStatus: 'requestStatus.value',
|
|
22
|
+
journalVolume: 'journalVolume'
|
|
23
|
+
},
|
|
24
|
+
sortKeys: {
|
|
25
|
+
title: 'item.title' // Example of mapping 'title' to 'item.title' for sorting
|
|
21
26
|
}
|
|
27
|
+
};
|
|
22
28
|
|
|
23
|
-
|
|
29
|
+
const queryString = generateKiwtQuery(options, nsValues);
|
|
24
30
|
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
// queryString will be:
|
|
32
|
+
//?match=request.name&term=test&filters=requestStatus.value==completed&filters=journalVolume==test1&filters=startDate%3E=2021-10-28&sort=item.title;desc&stats=true
|
|
27
33
|
```
|
|
28
34
|
|
|
29
35
|
### Props
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
|
|
37
|
+
| Name | Type | Description | Default | Required |
|
|
38
|
+
|---|---|---|---|---|
|
|
39
|
+
| options | object | An object with keys: `searchKey`, `filterKeys`, `sortKeys`, and `stats`, which maps the incoming `nsValues` object to a KIWT query. You can also pass arbitrary `key`/`value` pairs to append `key==value` onto the query. | | ✓ |
|
|
40
|
+
| nsValues | object | An object containing the query parameters. Can contain `query`, `filters`, and `sort`, as well as any other arbitrary parameters. | | ✓ |
|
|
41
|
+
| encode | boolean | A boolean indicating whether to URL-encode the values. | `true` | ✕ |
|
|
35
42
|
|
|
36
43
|
## generateKiwtQueryParams
|
|
37
|
-
A util function for generating an array of "KIWT" (K-Int Web-Toolkit) style backend query parameters from a SASQ query object
|
|
38
|
-
### Basic usage
|
|
39
|
-
```
|
|
40
|
-
import { generateKiwtQueryParams } from '@k-int/stripes-kint-components'
|
|
41
|
-
...
|
|
42
|
-
const nsValues = {
|
|
43
|
-
query: 'test',
|
|
44
|
-
filters: 'requestStatus.completed,journalVolume.test1,startDate.startDate>=2021-10-28'
|
|
45
|
-
}
|
|
46
44
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
45
|
+
The `generateKiwtQueryParams` function is similar to `generateKiwtQuery`, but instead of returning a string, it returns an array of query parameters. This can be useful for more advanced use cases where you need to manipulate the parameters before constructing the final query string.
|
|
46
|
+
|
|
47
|
+
### Basic Usage
|
|
48
|
+
|
|
49
|
+
```javascript
|
|
50
|
+
import { generateKiwtQueryParams } from '@k-int/stripes-kint-components';
|
|
51
|
+
|
|
52
|
+
const nsValues = {
|
|
53
|
+
query: 'test',
|
|
54
|
+
filters: 'requestStatus.completed,journalVolume.test1,startDate.startDate>=2021-10-28'
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const options = {
|
|
58
|
+
searchKey: 'request.name',
|
|
59
|
+
filterKeys: {
|
|
60
|
+
requestStatus: 'requestStatus.value',
|
|
61
|
+
journalVolume: 'journalVolume'
|
|
53
62
|
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const queryArray = generateKiwtQueryParams(options, nsValues);
|
|
54
66
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
]
|
|
65
|
-
...
|
|
67
|
+
// queryArray will be:
|
|
68
|
+
// [
|
|
69
|
+
// "match=request.name",
|
|
70
|
+
// "term=test",
|
|
71
|
+
// "filters=requestStatus.value==completed",
|
|
72
|
+
// "filters=journalVolume==test1",
|
|
73
|
+
// "filters=startDate%3E=2021-10-28",
|
|
74
|
+
// "stats=true"
|
|
75
|
+
// ]
|
|
66
76
|
```
|
|
67
77
|
|
|
68
78
|
### Props
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
79
|
+
|
|
80
|
+
| Name | Type | Description | Default | Required |
|
|
81
|
+
|---|---|---|---|---|
|
|
82
|
+
| options | object | An object with keys: `searchKey`, `filterKeys`, `sortKeys`, and `stats`, which maps the incoming `nsValues` object to a KIWT query array. You can also pass arbitrary `key`/`value` pairs to append `key==value` onto the query. | | ✓ |
|
|
83
|
+
| nsValues | object | An object containing the query parameters. Can contain `query`, `filters`, and `sort`, as well as any other arbitrary parameters. | | ✓ |
|
|
84
|
+
| encode | boolean | A boolean indicating whether to URL-encode the values. | `true` | ✕ |
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
### Options Parameter Structure
|
|
88
|
+
|
|
89
|
+
The `options` parameter is a powerful tool for customizing the query string generation. It has the following key elements:
|
|
90
|
+
|
|
91
|
+
* **Search:**
|
|
92
|
+
* `searchKey`: Specifies the field to search on. If using SASQ, the corresponding value in `nsValues.query` will be used as the search term. Otherwise, you can directly specify the search term using the `term` key in `options`.
|
|
93
|
+
* **Filters:** See the "Filters Object Structure" section below for details.
|
|
94
|
+
* **Sorting:**
|
|
95
|
+
* `sortKeys`: An object mapping sort field names from `nsValues.sort` to their corresponding backend keys.
|
|
96
|
+
* `sort`: An array of sort objects. Each object can have `path` (field to sort on) and `direction` (`asc` or `desc`).
|
|
97
|
+
* **Statistics:**
|
|
98
|
+
* `stats`: A boolean value indicating whether to include the `stats=true` parameter.
|
|
99
|
+
* **Other parameters:** Any other key-value pairs in the `options` object will be directly added as query parameters.
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
### Filters Object Structure
|
|
103
|
+
|
|
104
|
+
The `filters` option in the `options` parameter allows you to define complex filter expressions using an array of filter objects. Each filter object can have the following properties:
|
|
105
|
+
|
|
106
|
+
* **path:** The path to the field to filter on (e.g., `item.title`).
|
|
107
|
+
* **comparator:** *(Optional)* The comparator to use for the filter (e.g., `==`, `!=`, `>`, `<`). Defaults to `==`.
|
|
108
|
+
* **value:** A single value to filter on.
|
|
109
|
+
* **values:** An array of values to filter on. If present, this property takes precedence over `value`, and an `OR` condition is implied between the values.
|
|
110
|
+
* **groupValues:** An object defining nested filter groups with `AND` or `OR` logic. This property allows for building complex nested filters. See the explanation below.
|
|
111
|
+
|
|
112
|
+
#### Nested Filter Groups (`groupValues`)
|
|
113
|
+
|
|
114
|
+
The `groupValues` property enables the creation of nested filter expressions with `AND` and `OR` logic. It is an object with either `AND` or `OR` properties (or both, with `AND` taking precedence). The value of these properties should be an array of filter objects, allowing for recursive nesting.
|
|
115
|
+
|
|
116
|
+
```javascript
|
|
117
|
+
// Example: (status==active AND type==local) OR (status==pending)
|
|
118
|
+
const filters = [
|
|
119
|
+
{
|
|
120
|
+
groupValues: {
|
|
121
|
+
OR: [
|
|
122
|
+
{
|
|
123
|
+
groupValues: {
|
|
124
|
+
AND: [
|
|
125
|
+
{ path: 'item.status', value: 'active' },
|
|
126
|
+
{ path: 'item.type', value: 'local' },
|
|
127
|
+
],
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
{ path: 'item.status', value: 'pending' },
|
|
131
|
+
]
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
];
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
This structure allows you to express complex filter logic in a clear and organized way.
|
|
138
|
+
|
|
139
|
+
### Key Takeaways
|
|
140
|
+
|
|
141
|
+
* `generateKiwtQuery` provides a flexible way to construct URL query strings for backend APIs, especially when working with Stripes SASQ.
|
|
142
|
+
* The `options` parameter offers fine-grained control over the query generation process, allowing for complex filtering, sorting, and other customizations.
|
|
143
|
+
* `generateKiwtQueryParams` is useful for advanced use cases where you need to manipulate the parameters before constructing the final query string.
|