@pushwoosh/smart-components-kit 2.3.0 → 2.4.1
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,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Spinner } from '@pushwoosh/dumb-components';
|
|
3
3
|
import { Horizontal, useAsync } from '@pushwoosh/kit-helpers';
|
|
4
|
-
import { useSPAContext } from '@pushwoosh/spa-context';
|
|
4
|
+
import { useSession, useSPAContext } from '@pushwoosh/spa-context';
|
|
5
5
|
import { collectPaginatedData } from '../asyncHelpers';
|
|
6
6
|
import { langCodes } from './constants';
|
|
7
7
|
import { LanguagesSelectForm } from './LanguagesSelectForm';
|
|
@@ -18,30 +18,34 @@ export const LanguagesSelectFormLoader = ({
|
|
|
18
18
|
const {
|
|
19
19
|
rpcGateway
|
|
20
20
|
} = useSPAContext();
|
|
21
|
+
const withLocales = useSession()?.restrictions?.allowUseLocaleTag ?? false;
|
|
21
22
|
const langAsync = useAsync(async () => {
|
|
22
23
|
// GetTagValues caps an unpaged request at 100 values, and apps hold more languages than that
|
|
23
|
-
const
|
|
24
|
+
const fetchTagValues = name => collectPaginatedData(1000, async (perPage, page) => {
|
|
24
25
|
const res = await rpcGateway.tags.GetTagValues({
|
|
25
26
|
application,
|
|
26
|
-
name
|
|
27
|
+
name,
|
|
27
28
|
platforms,
|
|
28
29
|
page,
|
|
29
30
|
perPage
|
|
30
31
|
});
|
|
31
32
|
return res.values;
|
|
32
33
|
});
|
|
34
|
+
const [values, localeValues] = await Promise.all([fetchTagValues('Language'), withLocales ? fetchTagValues('Locale').catch(() => []) : Promise.resolve([])]);
|
|
33
35
|
const valuesLangCodes = values.map(v => canonicalizeLangCode(v.value));
|
|
34
36
|
const allLangCodes = Array.from(new Set([...valuesLangCodes, ...langCodes.map(canonicalizeLangCode)]).values());
|
|
35
|
-
|
|
37
|
+
const localeCodes = localeValues.map(v => canonicalizeLangCode(v.value)).filter(code => !allLangCodes.includes(code));
|
|
38
|
+
const subscribersOf = code => [...values, ...localeValues].find(val => canonicalizeLangCode(val.value) === code)?.count || 0;
|
|
39
|
+
return [...allLangCodes, ...localeCodes].sort((a, b) => {
|
|
36
40
|
return a.localeCompare(b, systemLanguage, {
|
|
37
41
|
sensitivity: 'base'
|
|
38
42
|
});
|
|
39
43
|
}).map(code => ({
|
|
40
44
|
code,
|
|
41
45
|
name: getLangName(code),
|
|
42
|
-
subscribers:
|
|
46
|
+
subscribers: subscribersOf(code)
|
|
43
47
|
}));
|
|
44
|
-
}, [application, getLangName, systemLanguage, platforms]);
|
|
48
|
+
}, [application, getLangName, systemLanguage, platforms, withLocales]);
|
|
45
49
|
if (langAsync.loading) {
|
|
46
50
|
return _jsx(Horizontal, {
|
|
47
51
|
"$placeItems": "center",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pushwoosh/smart-components-kit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"description": "Stateful, data-connected React components shared by Pushwoosh micro-frontends",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@pushwoosh/kit-helpers": "^4.16.1",
|
|
23
23
|
"@pushwoosh/kit-icons": "^2.3.15",
|
|
24
24
|
"@pushwoosh/kit-typography": "^2.0.0",
|
|
25
|
-
"@pushwoosh/rpc-v2-http-api-data": "^0.2.
|
|
25
|
+
"@pushwoosh/rpc-v2-http-api-data": "^0.2.505",
|
|
26
26
|
"jwt-decode": "^4.0.0",
|
|
27
27
|
"react-hook-form": "^7.68.0"
|
|
28
28
|
},
|