@k-int/stripes-kint-components 5.18.0 → 5.19.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 +7 -0
- package/es/index.js +8 -0
- package/es/lib/SASQLookupComponent/SASQLookupComponent.js +5 -1
- package/es/lib/SearchKeyControl/SearchKeyControl.js +95 -0
- package/es/lib/SearchKeyControl/SearchKeyControl.test.js +177 -0
- package/es/lib/SearchKeyControl/index.js +13 -0
- package/es/lib/hooks/__mocks__/index.js +2 -2
- package/es/lib/hooks/index.js +33 -21
- package/es/lib/hooks/intlHooks/index.js +27 -0
- package/es/lib/hooks/intlHooks/useIntlKey/index.js +13 -0
- package/es/lib/hooks/{useIntlKey.js → intlHooks/useIntlKey/useIntlKey.js} +1 -1
- package/es/lib/hooks/intlHooks/useIntlKeyStore/index.js +13 -0
- package/es/lib/hooks/intlHooks/useKintIntl/index.js +13 -0
- package/es/lib/hooks/{useKintIntl.js → intlHooks/useKintIntl/useKintIntl.js} +1 -1
- package/es/lib/hooks/useInvalidateRefdata/index.js +13 -0
- package/es/lib/hooks/{useInvalidateRefdata.js → useInvalidateRefdata/useInvalidateRefdata.js} +1 -1
- package/es/lib/hooks/useMutateCustomProperties/index.js +13 -0
- package/es/lib/hooks/{useMutateCustomProperties.js → useMutateCustomProperties/useMutateCustomProperties.js} +1 -1
- package/es/lib/hooks/useMutateGeneric/index.js +13 -0
- package/es/lib/hooks/useMutateRefdataCategory/index.js +13 -0
- package/es/lib/hooks/{useMutateRefdataCategory.js → useMutateRefdataCategory/useMutateRefdataCategory.js} +2 -2
- package/es/lib/hooks/useMutateRefdataValue/index.js +13 -0
- package/es/lib/hooks/{useMutateRefdataValue.js → useMutateRefdataValue/useMutateRefdataValue.js} +2 -2
- package/es/lib/utils/refdataQueryKey/index.js +13 -0
- package/package.json +1 -1
- package/src/index.js +4 -0
- package/src/lib/NumberField/README.md +134 -0
- package/src/lib/SASQLookupComponent/README.md +172 -0
- package/src/lib/SASQLookupComponent/SASQLookupComponent.js +6 -1
- package/src/lib/SASQLookupComponent/TableBody/README.md +113 -0
- package/src/lib/SASQRoute/README.md +49 -18
- package/src/lib/SASQViewComponent/README.md +132 -0
- package/src/lib/SearchKeyControl/README.md +70 -0
- package/src/lib/SearchKeyControl/SearchKeyControl.js +98 -0
- package/src/lib/SearchKeyControl/SearchKeyControl.test.js +165 -0
- package/src/lib/SearchKeyControl/index.js +1 -0
- package/src/lib/hooks/README.md +26 -121
- package/src/lib/hooks/__mocks__/index.js +2 -2
- package/src/lib/hooks/index.js +2 -3
- package/src/lib/hooks/intlHooks/README.md +31 -0
- package/src/lib/hooks/intlHooks/index.js +3 -0
- package/src/lib/hooks/intlHooks/useIntlKey/README.md +23 -0
- package/src/lib/hooks/intlHooks/useIntlKey/index.js +1 -0
- package/src/lib/hooks/{useIntlKey.js → intlHooks/useIntlKey/useIntlKey.js} +1 -1
- package/src/lib/hooks/intlHooks/useIntlKeyStore/README.md +32 -0
- package/src/lib/hooks/intlHooks/useIntlKeyStore/index.js +1 -0
- package/src/lib/hooks/intlHooks/useKintIntl/README.md +42 -0
- package/src/lib/hooks/intlHooks/useKintIntl/index.js +1 -0
- package/src/lib/hooks/{useKintIntl.js → intlHooks/useKintIntl/useKintIntl.js} +1 -1
- package/src/lib/hooks/useInvalidateRefdata/README.md +72 -0
- package/src/lib/hooks/useInvalidateRefdata/index.js +1 -0
- package/src/lib/hooks/{useInvalidateRefdata.js → useInvalidateRefdata/useInvalidateRefdata.js} +1 -1
- package/src/lib/hooks/useMutateCustomProperties/README.md +88 -0
- package/src/lib/hooks/useMutateCustomProperties/index.js +1 -0
- package/src/lib/hooks/{useMutateCustomProperties.js → useMutateCustomProperties/useMutateCustomProperties.js} +1 -1
- package/src/lib/hooks/useMutateGeneric/README.md +187 -0
- package/src/lib/hooks/useMutateGeneric/index.js +1 -0
- package/src/lib/hooks/useMutateRefdataCategory/README.md +85 -0
- package/src/lib/hooks/useMutateRefdataCategory/index.js +1 -0
- package/src/lib/hooks/{useMutateRefdataCategory.js → useMutateRefdataCategory/useMutateRefdataCategory.js} +2 -2
- package/src/lib/hooks/useMutateRefdataValue/README.md +154 -0
- package/src/lib/hooks/useMutateRefdataValue/index.js +1 -0
- package/src/lib/hooks/{useMutateRefdataValue.js → useMutateRefdataValue/useMutateRefdataValue.js} +2 -2
- package/src/lib/settingsHooks/useAppSettings/README.md +24 -0
- package/src/lib/utils/refdataQueryKey/README.md +38 -0
- package/src/lib/utils/refdataQueryKey/index.js +1 -0
- package/styles/SearchKeyControl.css +14 -0
- /package/es/lib/hooks/{useIntlKeyStore.js → intlHooks/useIntlKeyStore/useIntlKeyStore.js} +0 -0
- /package/es/lib/hooks/{useMutateGeneric.js → useMutateGeneric/useMutateGeneric.js} +0 -0
- /package/es/lib/utils/{refdataQueryKey.js → refdataQueryKey/refdataQueryKey.js} +0 -0
- /package/src/lib/hooks/{useIntlKeyStore.js → intlHooks/useIntlKeyStore/useIntlKeyStore.js} +0 -0
- /package/src/lib/hooks/{useMutateGeneric.js → useMutateGeneric/useMutateGeneric.js} +0 -0
- /package/src/lib/utils/{refdataQueryKey.js → refdataQueryKey/refdataQueryKey.js} +0 -0
package/src/lib/hooks/README.md
CHANGED
|
@@ -15,85 +15,14 @@ const data = useRefdata({
|
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
### Props
|
|
18
|
-
Name
|
|
19
|
-
|
|
20
|
-
endpoint
|
|
21
|
-
desc
|
|
22
|
-
queryParams
|
|
23
|
-
returnQueryObject | bool
|
|
24
|
-
options
|
|
18
|
+
| Name | Type | Description | default | required |
|
|
19
|
+
|-------------------|--------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------|----------|
|
|
20
|
+
| endpoint | string | The endpoint to fetch refdataValues from | | ✓ |
|
|
21
|
+
| desc | string | The refdataCategory (usually of the form `DomainClass.Field`) | | ✕ |
|
|
22
|
+
| queryParams | object | A set of queryParameters to hand to react-query's `useQuery` | | ✕ |
|
|
23
|
+
| returnQueryObject | bool | A switch to return the entirety of the queryObject from useQuery. If `false`, the data will be destructured, if `true` the return will be the full object returned by react-query's `useQuery` | false | ✕ |
|
|
24
|
+
| options | object | An object of the shape SASQ_MAP (See generateKiwtQuery) to pass to the generateKiwtQuery inside. Any passed desc "d" will be passed as a filter `DescKey.${d}`, with DescKey acting as FilterName, assuming `filterKeys: { DescKey: "desc" }` in options, so `desc==${d}` is passed directly to the backend. | `{filterKeys: {DescKey: "desc" }, stats: false, max: 100}` | ✕ |
|
|
25
25
|
|
|
26
|
-
## useMutateRefdataValue
|
|
27
|
-
A hook for mutations (Create/Delete/Edit) of refdataValues.
|
|
28
|
-
|
|
29
|
-
### Basic Usage
|
|
30
|
-
```javascript
|
|
31
|
-
import { useMutateRefdataValue } from '@k-int/stripes-kint-components'
|
|
32
|
-
...
|
|
33
|
-
const { delete } = useMutateRefdataValue({
|
|
34
|
-
endpoint: 'oa/refdata',
|
|
35
|
-
id: '1234-abcd-5678',
|
|
36
|
-
});
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
### Props
|
|
40
|
-
Name | Type | Description | default | required
|
|
41
|
-
--- | --- | --- | --- | ---
|
|
42
|
-
afterQueryCalls | object | An object of the form `{delete: func1, put: func2}` where `func1`/`func2` are functions to be called after the `delete`/`put`. This is for ease of use, you can alternatively manually use a `.then()` on the functions returned from this hook. | | ✓ |
|
|
43
|
-
catchQueryCalls | object | An object of the form `{delete: func1, put: func2}` where `func1`/`func2` are functions to be called with a HTTPError object when the `delete`/`put` calls fail. This is for ease of use, you can alternatively manually use a `.catch()` on the functions returned from this hook. | | ✕ |
|
|
44
|
-
endpoint | string | The refdata endpoint | | ✕ |
|
|
45
|
-
id | string | The id of the refdata whose values are to be mutated | | ✕ |
|
|
46
|
-
queryParams | object | An object of the form `{delete: obj1, put: obj2}`, where `obj1`/`obj2` are set of queryParameters to hand to react-query's `useMutation` for the delete/put operations respectively | | ✕ |
|
|
47
|
-
returnQueryObject | object | An object of the form `{delete: bool1, put: bool2}` containing switches to return the entirety of the queryObject from useMutation for `delete` and `put` respectively. If `false`, the mutateAsync function will be destructured, if `true` the return will be the full object returned by react-query's `useMutation` | {put: false, delete: false} | ✕ |
|
|
48
|
-
|
|
49
|
-
### Example
|
|
50
|
-
```javascript
|
|
51
|
-
...
|
|
52
|
-
const { delete, put } = useMutateRefdataValue({
|
|
53
|
-
afterQueryCalls: {
|
|
54
|
-
delete: json => setContentData(json?.values ?? []),
|
|
55
|
-
put: json => setContentData(json?.values ?? [])
|
|
56
|
-
},
|
|
57
|
-
endpoint: 'oa/refdata',
|
|
58
|
-
id: refdata?.id,
|
|
59
|
-
queryParams: {
|
|
60
|
-
delete: {
|
|
61
|
-
enabled: !!refdata
|
|
62
|
-
},
|
|
63
|
-
put: {
|
|
64
|
-
enabled: !!refdata
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
...
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
This block will destructure two `mutateAsync` functions, `delete` and `put`. After a call to either of them the `json` returned will be used in a function call `setContentData`.
|
|
72
|
-
|
|
73
|
-
The calls will only be enabled if `refdata` is truthy.
|
|
74
|
-
|
|
75
|
-
`put` will return a function `put(data)` and will make a `put` call to add the `data` to the values of the given refdata id. In practice this means calling `put` as follows:
|
|
76
|
-
```javascript
|
|
77
|
-
put({
|
|
78
|
-
value: 'testValue'
|
|
79
|
-
label: 'testLabel'
|
|
80
|
-
})
|
|
81
|
-
```
|
|
82
|
-
for a new refdataValue, or
|
|
83
|
-
```javascript
|
|
84
|
-
put({
|
|
85
|
-
id: <id of the refdataValue to edit>
|
|
86
|
-
value: 'testValue2'
|
|
87
|
-
label: 'testLabel 2'
|
|
88
|
-
})
|
|
89
|
-
```
|
|
90
|
-
to edit an existing value.
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
`delete` will return a function `delete(data)` and will make a `put` call to glue `_delete: true` to the given value. In practice this means calling `delete` as follows:
|
|
94
|
-
```javascript
|
|
95
|
-
delete(<ID of refdata value to remove>)
|
|
96
|
-
```
|
|
97
26
|
|
|
98
27
|
## useActiveElement
|
|
99
28
|
A hook which returns the currently focused element in the document, `active`, as well as a function `hasParent`.
|
|
@@ -145,9 +74,9 @@ return (
|
|
|
145
74
|
```
|
|
146
75
|
|
|
147
76
|
### Props
|
|
148
|
-
Name
|
|
149
|
-
|
|
150
|
-
helpers | object | An object of the form `{helperKey1: Component1, helperKey2: Component1}` where `Component1`/`Component1` are components to be rendered when the url contains query `helper=helperKey1` or `helper=helperKey2` respectively |
|
|
77
|
+
| Name | Type | Description | default | required |
|
|
78
|
+
|---------|--------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|----------|
|
|
79
|
+
| helpers | object | An object of the form `{helperKey1: Component1, helperKey2: Component1}` where `Component1`/`Component1` are components to be rendered when the url contains query `helper=helperKey1` or `helper=helperKey2` respectively | | ✓ |
|
|
151
80
|
|
|
152
81
|
## useKiwtSASQuery
|
|
153
82
|
A hook which sets up a basic queryGetter and querySetter for use with SASQ, as well as setting up the query object itself. Will often be used with the `generateKiwtQuery` function from `utils`.
|
|
@@ -285,34 +214,10 @@ export default Test
|
|
|
285
214
|
```
|
|
286
215
|
|
|
287
216
|
### Props
|
|
288
|
-
Name
|
|
289
|
-
|
|
290
|
-
name
|
|
291
|
-
submitWholeDeletedObject | bool
|
|
292
|
-
|
|
293
|
-
## useAppSettings
|
|
294
|
-
A hook for fetching AppSetting values
|
|
295
|
-
### Basic usage
|
|
296
|
-
```javascript
|
|
297
|
-
import { useAppSettings } from '@k-int/stripes-kint-components'
|
|
298
|
-
...
|
|
299
|
-
const data = useAppSettings({
|
|
300
|
-
endpoint: 'oa/settings/appSettings'
|
|
301
|
-
});
|
|
302
|
-
...
|
|
303
|
-
```
|
|
304
|
-
|
|
305
|
-
This will return a list of AppSettings. If a `keyName` is passed, this will instead return a single AppSetting object.
|
|
306
|
-
|
|
307
|
-
### Props
|
|
308
|
-
Name | Type | Description | default | required
|
|
309
|
-
--- | --- | --- | --- | ---
|
|
310
|
-
endpoint | string | The endpoint to fetch AppSettings from | | ✓ |
|
|
311
|
-
sectionName | string | A string representing a section of AppSettings to filter on | | ✕ |
|
|
312
|
-
keyName | string | A string representing an individual key of an AppSettings to filter on. The presence of this prop will change the output shape from Array to Object. It is not strictly necessary to use `keyName` in conjunction with `sectionName`, but keys are not guaranteed to be unique between sections. In addition it may marginally improve performance to use both, even if a key is unique, so it is recommended. | | ✕ |
|
|
313
|
-
queryParams | object | A set of queryParameters to hand to react-query's `useQuery` | | ✕ |
|
|
314
|
-
returnQueryObject | bool | A switch to return the entirety of the queryObject from useQuery. If `false`, the data will be destructured, if `true` the return will be the full object returned by react-query's `useQuery` | false | ✕ |
|
|
315
|
-
options | object | An object of the shape SASQ_MAP (See generateKiwtQuery) to pass to the generateKiwtQuery inside. The default | `{perPage: 100, stats: false, filters: [{path: 'section', value: sectionName }, {path: 'key', value: keyName }]}` | ✕ |
|
|
217
|
+
| Name | Type | Description | default | required |
|
|
218
|
+
|--------------------------|--------|---------------------------------------------------------------------------------------------------------|---------|----------|
|
|
219
|
+
| name | String | The name of the fieldArray, used to hook into the final form state for that field. | | ✓ |
|
|
220
|
+
| submitWholeDeletedObject | bool | a boolean flag to ensure that a deleted object is sent whole to the backend, rather than just as an id. | false | ✕ |
|
|
316
221
|
|
|
317
222
|
## useMutateGeneric
|
|
318
223
|
|
|
@@ -336,15 +241,15 @@ updateObject({ id: 456, name: 'Updated Object' }) // Updates the object with id
|
|
|
336
241
|
|
|
337
242
|
### Props
|
|
338
243
|
|
|
339
|
-
| Name
|
|
340
|
-
|
|
341
|
-
| afterQueryCalls
|
|
342
|
-
| catchQueryCalls
|
|
343
|
-
| endpoint
|
|
344
|
-
| endpointMutators
|
|
345
|
-
| payloadMutators
|
|
346
|
-
| promiseReturns
|
|
347
|
-
| queryKey
|
|
348
|
-
| queryKeyMutators
|
|
349
|
-
| queryParams
|
|
350
|
-
| returnQueryObject | object | An object of the form `{ delete: bool1, post: bool2, put: bool3 }` containing switches to return the entire query object from `useMutation` for each operation. If `false` (the default), the `mutateAsync` function will be returned; if `true`, the full object (including `mutate`, `isLoading`, `error`, etc.) will be returned.
|
|
244
|
+
| Name | Type | Description | Default | Required |
|
|
245
|
+
|-------------------|--------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|----------|
|
|
246
|
+
| afterQueryCalls | object | An object of the form `{ delete: func1, post: func2, put: func3 }` where `func1(responseData)`, `func2(responseData)`, and `func3(responseData)` are functions to be called *after* the corresponding mutation is successful. `responseData` is the data returned by the API call. | `{}` | ✕ |
|
|
247
|
+
| catchQueryCalls | object | An object of the form `{ delete: func1, post: func2, put: func3 }` where `func1(error)`, `func2(error)`, and `func3(error)` are functions to be called *if* the corresponding mutation fails. `error` is the HTTPError object. | `{}` | ✕ |
|
|
248
|
+
| endpoint | string | The base endpoint for the API calls. | | ✓ |
|
|
249
|
+
| endpointMutators | object | An object of the form `{ delete: func1, post: func2, put: func3 }` where `func1(id)`, `func2()`, and `func3(data)` are functions that modify the endpoint for each operation. Defaults to appending the id for `delete` and `put`, and using the base endpoint for `post`. | `{ delete: (id) => "${endpoint}/${id}", post: () => endpoint, put: (data) => "${endpoint}/${data.id}" }` | ✕ |
|
|
250
|
+
| payloadMutators | object | An object of the form `{ post: func1, put: func2 }` where `func1(data)` and `func2(data)` are functions that modify the payload for the `post` and `put` operations. Defaults to wrapping the data in a `json` object. | `{ post: (data) => ({ json: data }), put: (data) => ({ json: data }) }` | ✕ |
|
|
251
|
+
| promiseReturns | object | An object of the form `{ delete: func1, post: func2, put: func3 }` where `func1(id, ky)`, `func2(data, ky)`, and `func3(data, ky)` are functions that define the promise return for each operation. Allows full control over the `ky` call. `id` is the id for delete, `data` is the data being sent for post/put, and `ky` is the `ky` instance. | `{ delete: (id, ky) => ky.delete(...).json(), post: (data, ky) => ky.post(...).json(), put: (data, ky) => ky.put(...).json() }` | ✕ |
|
|
252
|
+
| queryKey | array | The query key to be used with `react-query`. **Must be an array.** | `[]` | ✓ |
|
|
253
|
+
| queryKeyMutators | object | An object of the form `{ delete: func1, post: func2, put: func3 }` where `func1()`, `func2()`, and `func3()` are functions that return the query key for each mutation. | `{ delete: () => [...queryKey, 'delete'], post: () => [...queryKey, 'create'], put: () => [...queryKey, 'edit'] }` | ✕ |
|
|
254
|
+
| queryParams | object | An object of the form `{ delete: obj1, post: obj2, put: obj3 }` where `obj1`, `obj2`, and `obj3` are the query parameters for each operation. | `{}` | ✕ |
|
|
255
|
+
| returnQueryObject | object | An object of the form `{ delete: bool1, post: bool2, put: bool3 }` containing switches to return the entire query object from `useMutation` for each operation. If `false` (the default), the `mutateAsync` function will be returned; if `true`, the full object (including `mutate`, `isLoading`, `error`, etc.) will be returned. | `{ delete: false, post: false, put: false }` | ✕ |
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import refdata from '../../../../test/jest/refdata';
|
|
2
2
|
import customProperties from '../../../../test/jest/customProperties';
|
|
3
3
|
|
|
4
|
-
import useKintIntl from '../useKintIntl';
|
|
4
|
+
import useKintIntl from '../intlHooks/useKintIntl';
|
|
5
5
|
|
|
6
6
|
/* EXAMPLE Grab actual hooks for anything not mocked here */
|
|
7
7
|
const hooks = jest.requireActual('../index');
|
|
8
8
|
|
|
9
9
|
// We have to do this up here too so that our passed useKintIntl
|
|
10
10
|
// ALSO has a mocked useIntlKeyStore... I think anyway
|
|
11
|
-
jest.mock('../useIntlKeyStore', () => () => () => 'ui-test-implementor');
|
|
11
|
+
jest.mock('../intlHooks/useIntlKeyStore', () => () => () => 'ui-test-implementor');
|
|
12
12
|
|
|
13
13
|
module.exports = {
|
|
14
14
|
...hooks,
|
package/src/lib/hooks/index.js
CHANGED
|
@@ -8,9 +8,6 @@ export { default as useQIndex } from './useQIndex';
|
|
|
8
8
|
export { default as useKiwtFieldArray } from './useKiwtFieldArray';
|
|
9
9
|
export { default as useCustomProperties } from './useCustomProperties';
|
|
10
10
|
export { default as useInvalidateRefdata } from './useInvalidateRefdata';
|
|
11
|
-
export { default as useKintIntl } from './useKintIntl';
|
|
12
|
-
export { default as useIntlKeyStore } from './useIntlKeyStore';
|
|
13
|
-
export { default as useIntlKey } from './useIntlKey';
|
|
14
11
|
export { default as useSASQQueryMeta } from './useSASQQueryMeta';
|
|
15
12
|
export { default as useModConfigEntries } from './useModConfigEntries';
|
|
16
13
|
export { default as useActionListRef } from './useActionListRef';
|
|
@@ -22,3 +19,5 @@ export { default as useMutateCustomProperties } from './useMutateCustomPropertie
|
|
|
22
19
|
export { default as useMutateModConfigEntry } from './useMutateModConfigEntry';
|
|
23
20
|
|
|
24
21
|
export { default as usePrevNextPagination } from './usePrevNextPagination';
|
|
22
|
+
|
|
23
|
+
export * from './intlHooks';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Internationalization (intl) Hooks
|
|
2
|
+
|
|
3
|
+
This suite of hooks provides a standardized way to handle internationalization across components while respecting module boundaries. The system allows:
|
|
4
|
+
|
|
5
|
+
1. **Root Module Configuration** - Set default intl keys/namespaces at application root
|
|
6
|
+
2. **Component-Level Overrides** - Customize translations per-component via `intlKey`/`intlNS` props
|
|
7
|
+
3. **Automatic Key Resolution** - Components automatically find translations without hardcoded paths
|
|
8
|
+
|
|
9
|
+
## Key Components
|
|
10
|
+
|
|
11
|
+
1. **[useIntlKeyStore](./useIntlKeyStore/README.md)** - Global store for managing intl keys
|
|
12
|
+
2. **[useIntlKey](./useIntlKey/README.md)** - Hook for resolving intl keys
|
|
13
|
+
3. **[useKintIntl](./useKintIntl/README.md)** - Enhanced intl formatting hook
|
|
14
|
+
|
|
15
|
+
## Core Principles
|
|
16
|
+
|
|
17
|
+
- **No Library Translations** - Parent modules provide all translations
|
|
18
|
+
- **Explicit Key Management** - Required key configuration prevents silent failures
|
|
19
|
+
- **Namespace Isolation** - Prevents key collisions between modules
|
|
20
|
+
- **Override Support** - Components can bypass default keys when needed
|
|
21
|
+
|
|
22
|
+
## Implementation Benefits
|
|
23
|
+
|
|
24
|
+
- ✅ Avoids duplicated translation efforts
|
|
25
|
+
- ✅ Maintains Lokalise compatibility
|
|
26
|
+
- ✅ Enables component reuse across modules
|
|
27
|
+
- ✅ Provides clear error messaging for missing config
|
|
28
|
+
- ✅ Supports both simple and complex i18n scenarios
|
|
29
|
+
|
|
30
|
+
## Developer note
|
|
31
|
+
This clearly isn't an ideal solution, but it is the best one we could come up with at the time. Each module implementing kint-components can either set up a global key store telling kint-components where to look for their intl keys in general, or set this on a component by component case via the `intlKey` and `intlNS` props used throughout kint-components
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# useIntlKey
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
Resolves internationalization keys with fallback logic.
|
|
5
|
+
|
|
6
|
+
## Resolution Order
|
|
7
|
+
1. Directly passed `intlKey` prop
|
|
8
|
+
2. Namespace lookup via `intlNS` prop
|
|
9
|
+
3. Default namespace from `useNamespace`
|
|
10
|
+
|
|
11
|
+
## Error Handling
|
|
12
|
+
Throws error if:
|
|
13
|
+
- No key passed directly
|
|
14
|
+
- No key found in registry
|
|
15
|
+
- Namespace not registered
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
```jsx
|
|
19
|
+
const Component = ({ intlKey, intlNS }) => {
|
|
20
|
+
const resolvedKey = useIntlKey(intlKey, intlNS);
|
|
21
|
+
// Uses resolved key for translations
|
|
22
|
+
};
|
|
23
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './useIntlKey';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# useIntlKeyStore
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
Global state management for internationalization keys using Zustand.
|
|
5
|
+
|
|
6
|
+
## Key Features
|
|
7
|
+
- Namespace-key pair storage
|
|
8
|
+
- Automatic namespace resolution
|
|
9
|
+
- Hook-safe operations
|
|
10
|
+
|
|
11
|
+
## Initial Setup
|
|
12
|
+
```jsx
|
|
13
|
+
// App root component
|
|
14
|
+
import useIntlKeyStore from './useIntlKeyStore';
|
|
15
|
+
|
|
16
|
+
const App = () => {
|
|
17
|
+
const { addKey } = useIntlKeyStore();
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
addKey('moduleBaseKey', 'myModuleNamespace');
|
|
21
|
+
}, [addKey]);
|
|
22
|
+
|
|
23
|
+
return (...);
|
|
24
|
+
};
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Store Methods
|
|
28
|
+
| Method | Parameters | Description |
|
|
29
|
+
|--------------|---------------------|--------------------------------------|
|
|
30
|
+
| `addKey` | `(key, namespace)` | Registers namespace-key pair |
|
|
31
|
+
| `removeKey` | `(namespace)` | Removes namespace registration |
|
|
32
|
+
| `getKey` | `(namespace)` | Retrieves key for namespace |
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './useIntlKeyStore';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# useKintIntl
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
Enhanced internationalization hook that extends `react-intl`'s `useIntl` with automatic key resolution and override support.
|
|
5
|
+
|
|
6
|
+
## Key Features
|
|
7
|
+
- Automatic key prefixing with module-specific base path
|
|
8
|
+
- Fallback message support
|
|
9
|
+
- Type-safe override validation
|
|
10
|
+
- Message existence checking
|
|
11
|
+
|
|
12
|
+
## Basic Usage
|
|
13
|
+
```jsx
|
|
14
|
+
const MyComponent = () => {
|
|
15
|
+
const { formatKintMessage } = useKintIntl('myComponent', 'myModule');
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<div>
|
|
19
|
+
{formatKintMessage({ id: 'greeting' })}
|
|
20
|
+
</div>
|
|
21
|
+
);
|
|
22
|
+
};
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Override Behavior
|
|
26
|
+
Component-level overrides take precedence:
|
|
27
|
+
```jsx
|
|
28
|
+
<MyComponent
|
|
29
|
+
intlKey="customKey"
|
|
30
|
+
intlNS="customNamespace"
|
|
31
|
+
/>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Methods
|
|
35
|
+
### `formatKintMessage(options, values)`
|
|
36
|
+
- `options.id`: Relative translation key (auto-prefixed)
|
|
37
|
+
- `options.overrideValue`: Direct string or alternate translation key
|
|
38
|
+
- `options.fallbackMessage`: Fallback text if translation missing
|
|
39
|
+
- `values`: Injection values for placeholders
|
|
40
|
+
|
|
41
|
+
### `messageExists(key)`
|
|
42
|
+
Checks if translation exists for resolved key
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './useKintIntl';
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# useInvalidateRefdata
|
|
2
|
+
|
|
3
|
+
## Reference Data Cache Management Hook
|
|
4
|
+
A specialized utility for maintaining reference data consistency across the application.
|
|
5
|
+
Part of the reference data management ecosystem, designed to work with [`useMutateRefdataCategory`](../useMutateRefdataCategory/README.md) and [`useMutateRefdataValue`](../useMutateRefdataValue/README.md).
|
|
6
|
+
|
|
7
|
+
## Basic Usage
|
|
8
|
+
```jsx
|
|
9
|
+
const RefdataUpdater = () => {
|
|
10
|
+
const invalidate = useInvalidateRefdata('license_types');
|
|
11
|
+
|
|
12
|
+
const handleUpdate = async () => {
|
|
13
|
+
await updateLicenseTypes();
|
|
14
|
+
invalidate(); // Triggers cache refresh
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
return <Button onClick={handleUpdate}>Refresh Data</Button>;
|
|
18
|
+
};
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### 2. Query Key Structure
|
|
22
|
+
Uses centralized key generator [`refdataQueryKey`](../../utils/refdataQueryKey/README.md):
|
|
23
|
+
```js
|
|
24
|
+
refdataQueryKey('media_formats') => ['stripes-kint-components', 'refdata', 'media_formats']
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Parameters
|
|
28
|
+
| Parameter | Type | Required | Default | Description |
|
|
29
|
+
|-----------|------|----------|---------|-------------|
|
|
30
|
+
| `desc` | string | ✕ | - | Reference data category descriptor |
|
|
31
|
+
|
|
32
|
+
## Advanced Usage
|
|
33
|
+
|
|
34
|
+
### Batch Invalidation
|
|
35
|
+
```jsx
|
|
36
|
+
const invalidateMedia = useInvalidateRefdata('media_types');
|
|
37
|
+
const invalidateLicenses = useInvalidateRefdata('license_types');
|
|
38
|
+
|
|
39
|
+
const handleGlobalRefresh = async () => {
|
|
40
|
+
await Promise.all([
|
|
41
|
+
invalidateMedia(),
|
|
42
|
+
invalidateLicenses()
|
|
43
|
+
]);
|
|
44
|
+
};
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Conditional Invalidation
|
|
48
|
+
```jsx
|
|
49
|
+
const RefdataForm = ({ category }) => {
|
|
50
|
+
const invalidate = useInvalidateRefdata(category?.type);
|
|
51
|
+
|
|
52
|
+
const handleSubmit = async (data) => {
|
|
53
|
+
await saveCategory(data);
|
|
54
|
+
if (category) invalidate();
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Integration Notes
|
|
60
|
+
|
|
61
|
+
### Performance Considerations
|
|
62
|
+
- Prefer targeted invalidations over global refresh
|
|
63
|
+
- Combine with mutation hooks for automatic invalidation
|
|
64
|
+
- Avoid in tight loops - debounce if needed
|
|
65
|
+
|
|
66
|
+
### Error Handling
|
|
67
|
+
- Safe to call multiple times
|
|
68
|
+
- Fails silently if no active queries match
|
|
69
|
+
- Returns promise for error chaining:
|
|
70
|
+
```js
|
|
71
|
+
invalidate().catch(error => logger.error('Refresh failed', error));
|
|
72
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './useInvalidateRefdata';
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# useMutateCustomProperties
|
|
2
|
+
|
|
3
|
+
## Purpose-Specific Mutation Hook
|
|
4
|
+
A specialized abstraction of [`useMutateGeneric`](./useMutateGeneric.md) optimized for managing custom properties configurations in FOLIO. Designed for operations targeting specific resource identifiers with enforced endpoint structure.
|
|
5
|
+
|
|
6
|
+
```mermaid
|
|
7
|
+
graph TD
|
|
8
|
+
A[useMutateCustomProperties] --> B[useMutateGeneric]
|
|
9
|
+
B --> C[Pre-configured Endpoints]
|
|
10
|
+
B --> D[Standardized Query Keys]
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## When to Use
|
|
14
|
+
- Managing custom properties for **single-resource endpoints**
|
|
15
|
+
- Operations requiring fixed ID in URL paths
|
|
16
|
+
- Standardizing cache keys for property-related mutations
|
|
17
|
+
|
|
18
|
+
## Key Differentiators
|
|
19
|
+
|| useMutateGeneric | useMutateCustomProperties |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| **Endpoint Structure** | Configurable | Enforced `/endpoint/{id}` |
|
|
22
|
+
| **Query Key** | Customizable | Auto-generated hierarchy |
|
|
23
|
+
| **ID Handling** | Manual in calls | Built into configuration |
|
|
24
|
+
|
|
25
|
+
## Usage Example
|
|
26
|
+
```jsx
|
|
27
|
+
const CustomPropertiesEditor = ({ recordId }) => {
|
|
28
|
+
const { post, put } = useMutateCustomProperties({
|
|
29
|
+
endpoint: 'configurations/custom-properties',
|
|
30
|
+
id: recordId
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const saveProperty = (property) =>
|
|
34
|
+
property.id ? put(property) : post(property);
|
|
35
|
+
|
|
36
|
+
return <PropertyForm onSubmit={saveProperty} />;
|
|
37
|
+
};
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Required Props
|
|
41
|
+
| Prop | Type | Description |
|
|
42
|
+
|------|------|-------------|
|
|
43
|
+
| `endpoint` | string | Base API path (e.g., `'license/custom-properties'`) |
|
|
44
|
+
| `id` | string | Unique resource identifier for URL construction |
|
|
45
|
+
|
|
46
|
+
## Default Behavior
|
|
47
|
+
1. **Endpoint Construction**
|
|
48
|
+
```js
|
|
49
|
+
// PUT/DELETE endpoints
|
|
50
|
+
`${endpoint}/${id}`
|
|
51
|
+
```
|
|
52
|
+
2. **Query Key Structure**
|
|
53
|
+
```js
|
|
54
|
+
['stripes-kint-components', 'useMutateCustomProperties', id]
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Customization
|
|
58
|
+
While providing opinionated defaults, maintains full compatibility with [`useMutateGeneric`](./useMutateGeneric.md) configuration:
|
|
59
|
+
|
|
60
|
+
```jsx
|
|
61
|
+
// Override delete endpoint while keeping other defaults
|
|
62
|
+
useMutateCustomProperties({
|
|
63
|
+
endpoint: 'inventory/types',
|
|
64
|
+
id: 'BOOK',
|
|
65
|
+
endpointMutators: {
|
|
66
|
+
delete: () => `inventory/legacy-types/${id}?version=2`
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Error Handling
|
|
72
|
+
Inherits the [error handling characteristics](./useMutateGeneric.md#error-handling-philosophy) of the base hook. Recommended pattern:
|
|
73
|
+
|
|
74
|
+
```jsx
|
|
75
|
+
useMutateCustomProperties({
|
|
76
|
+
catchQueryCalls: {
|
|
77
|
+
post: (error) => {
|
|
78
|
+
logger.error('Custom property creation failed', error);
|
|
79
|
+
throw error; // Propagate to error boundary
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Performance Notes
|
|
86
|
+
- Cache keys automatically include the `id` parameter
|
|
87
|
+
- Memoize configurations when using multiple instances
|
|
88
|
+
- Prefer single instance per resource ID lifecycle
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './useMutateCustomProperties';
|