@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.
@@ -1,73 +1,143 @@
1
- # util
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
- const options = {
16
- searchKey: 'request.name',
17
- filterKeys: {
18
- requestStatus: 'requestStatus.value,
19
- journalVolume: 'journalVolume'
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
- const queryString = generateKiwtQuery(options, nsValues)
29
+ const queryString = generateKiwtQuery(options, nsValues);
24
30
 
25
- // We'd expect queryString === "?match=request.name&term=test&filters=requestStatus.value==completed&filters=journalVolume==test1&filters=startDate%3E=2021-10-28&stats=true"
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
- Name | Type | Description | default | required
31
- --- | --- | --- | --- | ---
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
- encode | boolean | A boolean prop which determines if each query param chunk will be encoded using encodeURIComponent or not | true | |
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
- const options = {
48
- searchKey: 'request.name',
49
- filterKeys: {
50
- requestStatus: 'requestStatus.value,
51
- journalVolume: 'journalVolume'
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
- const queryArray = generateKiwtQueryParams(options, nsValues)
56
-
57
- // We'd expect queryArray === [
58
- "match=request.name",
59
- "term=test",
60
- "filters=requestStatus.value==completed",
61
- "filters=journalVolume==test1",
62
- "filters=startDate%3E=2021-10-28",
63
- "stats=true"
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
- Name | Type | Description | default | required
70
- --- | --- | --- | --- | ---
71
- 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. | | ✓ |
72
- nsValues | object | An object containing the actual query parameters to become the mapped KIWT query | | ✓ |
73
- encode | boolean | A boolean prop which determines if each query param chunk will be encoded using encodeURIComponent or not | true | |
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.
@@ -76,5 +76,8 @@
76
76
  "edit": "Edit",
77
77
  "save": "Save",
78
78
  "cancel": "Cancel",
79
- "apply": "Apply"
79
+ "apply": "Apply",
80
+ "tags": "Tags",
81
+ "numberOfTags": "{count, number} {count, plural, one {Tag} other {Tags}}",
82
+ "newTagCreated": "New tag created"
80
83
  }