@evergis/common 0.0.3

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Kirill Protasov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # @evergis/common
2
+
3
+ ## Commands
4
+
5
+ ```
6
+ npm start # or yarn start
7
+ ```
8
+
9
+ This builds to `/dist` and runs the project in watch mode so any edits you save inside `src` causes a rebuild to `/dist`.
10
+
11
+ Then run either example playground or storybook:
12
+
13
+ ### Storybook
14
+
15
+ Run inside another terminal:
16
+
17
+ ```
18
+ yarn storybook
19
+ ```
20
+
21
+ This loads the stories from `./stories`.
22
+
23
+ > NOTE: Stories should reference the components as if using the library. This means importing from the root project directory. This has been aliased in the tsconfig and the storybook webpack config as a helper.
24
+
25
+ ### Tests
26
+
27
+ Jest tests are set up to run with `npm test` or `yarn test`. This runs the test watcher (Jest) in an interactive mode. By default, runs tests related to files changed since the last commit.
28
+
29
+ > TODO: MOVE style to separate @evergis/style
@@ -0,0 +1,7 @@
1
+ import { Api } from '@evergis/api';
2
+ import { FC } from 'react';
3
+ export declare type ApiContextProps = {
4
+ api?: Api;
5
+ };
6
+ export declare const ApiProvider: FC<ApiContextProps>;
7
+ export declare const useApi: () => ApiContextProps;
@@ -0,0 +1,291 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
+
7
+ var api = require('@evergis/api');
8
+ var react = require('@evergis/react');
9
+ var React = require('react');
10
+ var React__default = _interopDefault(React);
11
+ var reactI18next = require('react-i18next');
12
+ var reactFetching = require('@evergis/react-fetching');
13
+ var ui = require('@evergis/ui');
14
+ var styled = _interopDefault(require('styled-components'));
15
+
16
+ const ApiContext = /*#__PURE__*/React.createContext({});
17
+ const ApiProvider = (_ref) => {
18
+ let {
19
+ api,
20
+ children
21
+ } = _ref;
22
+ return React__default.createElement(ApiContext.Provider, {
23
+ value: {
24
+ api
25
+ }
26
+ }, children);
27
+ };
28
+ const useApi = () => {
29
+ return React.useContext(ApiContext);
30
+ };
31
+
32
+ let resource;
33
+ const checkLimits = evergisApi => {
34
+ if (!resource) {
35
+ resource = reactFetching.createResource(params => async api => ({
36
+ data: await api.resourceCatalog.checkLimits(params)
37
+ }), {
38
+ injected: evergisApi
39
+ });
40
+ }
41
+
42
+ return resource;
43
+ };
44
+
45
+ const usePolitics = (username, onError) => {
46
+ const {
47
+ t
48
+ } = reactI18next.useTranslation('politics');
49
+ const {
50
+ api: api$1
51
+ } = useApi();
52
+ const {
53
+ data: limits,
54
+ refetch,
55
+ error
56
+ } = checkLimits(api$1).use({
57
+ input: {
58
+ userName: username
59
+ },
60
+ waitInput: true
61
+ });
62
+ React.useEffect(() => {
63
+ if (error) {
64
+ onError(error);
65
+ }
66
+ }, [error, onError]);
67
+ const politics = React.useMemo(() => {
68
+ return limits ? [{
69
+ name: t('maps'),
70
+ used: limits.currentProjectCount,
71
+ max: limits.maxProjectsCount,
72
+ type: api.PolicyType.CreateProject,
73
+ icon: 'map'
74
+ }, {
75
+ name: t('layers'),
76
+ used: limits.currentServiceCount,
77
+ max: limits.maxServicesCount,
78
+ type: api.PolicyType.CreateLayer,
79
+ icon: 'layers'
80
+ }, {
81
+ name: t('tables'),
82
+ used: limits.currentTableCount,
83
+ max: limits.maxTablesCount,
84
+ type: api.PolicyType.CreateTable,
85
+ icon: 'table'
86
+ }, {
87
+ name: t('maxFeaturesInLayerLimit'),
88
+ max: limits.maxFeaturesInOneTable,
89
+ type: api.PolicyType.MaxFeaturesInOneTable,
90
+ icon: 'points'
91
+ }, {
92
+ name: t('maxFileSize'),
93
+ max: limits.maxUploadContentSize,
94
+ // @ts-ignore
95
+ type: api.PolicyType.MaxUploadContentSize,
96
+ icon: 'textfile'
97
+ }] : [];
98
+ }, [t, limits]);
99
+ const updatePolicy = React.useCallback(async (value, type) => {
100
+ await api$1.security.setPolicy({
101
+ value,
102
+ type,
103
+ role: "__" + username
104
+ });
105
+ await refetch();
106
+ }, [api$1]);
107
+ return [politics, updatePolicy];
108
+ };
109
+
110
+ const numberWithSpaces = function numberWithSpaces(input, maximumFractionDigits) {
111
+ if (maximumFractionDigits === void 0) {
112
+ maximumFractionDigits = 10;
113
+ }
114
+
115
+ if (input === null || input === undefined) {
116
+ return '';
117
+ }
118
+
119
+ return parseFloat((typeof input === 'string' ? parseFloat(input) : input).toString()).toLocaleString('ru-RU', {
120
+ maximumFractionDigits
121
+ });
122
+ };
123
+
124
+ function _taggedTemplateLiteralLoose(strings, raw) {
125
+ if (!raw) {
126
+ raw = strings.slice(0);
127
+ }
128
+
129
+ strings.raw = raw;
130
+ return strings;
131
+ }
132
+
133
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11;
134
+ const PoliticsContainer = /*#__PURE__*/styled(ui.Flex)(_templateObject || (_templateObject = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-top: 3rem;\n flex-direction: column;\n"])));
135
+ const PoliticsTitle = /*#__PURE__*/styled(ui.H2)(_templateObject2 || (_templateObject2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin: 0;\n"])));
136
+ const PoliticsItems = /*#__PURE__*/styled(ui.Flex)(_templateObject3 || (_templateObject3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n flex-wrap: wrap;\n margin-top: 0.5rem;\n margin-bottom: 0.75rem;\n"])));
137
+ const PoliticsItemContainer = /*#__PURE__*/styled(ui.Flex)(_templateObject4 || (_templateObject4 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-top: 1rem;\n margin-right: 1rem;\n width: 14.5rem;\n border-radius: 2px;\n background-color: #f6f6f6;\n flex-direction: column;\n"])));
138
+ const PoliticsItemContent = /*#__PURE__*/styled(ui.Flex)(_templateObject5 || (_templateObject5 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n flex-direction: column;\n align-items: center;\n padding: 1rem 1rem 0;\n width: 100%;\n box-sizing: border-box;\n"])));
139
+ const PoliticsItemIcon = /*#__PURE__*/styled(ui.Icon)(_templateObject6 || (_templateObject6 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n opacity: 0.28;\n"])));
140
+ const PoliticsItemLimit = /*#__PURE__*/styled.span(_templateObject7 || (_templateObject7 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n font-size: 18px;\n font-weight: bold;\n margin-top: 0.75rem;\n"])));
141
+ const PoliticsItemType = /*#__PURE__*/styled.span(_templateObject8 || (_templateObject8 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n font-size: 12px;\n color: ", ";\n"])), (_ref) => {
142
+ let {
143
+ theme: {
144
+ palette
145
+ }
146
+ } = _ref;
147
+ return palette.textSecondary;
148
+ });
149
+ const PoliticsRatioContainer = /*#__PURE__*/styled.div(_templateObject9 || (_templateObject9 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin: 0.75rem 0 0;\n height: 0.5rem;\n width: 100%;\n"])));
150
+ const PoliticsRatio = /*#__PURE__*/styled(ui.RatioLine)(_templateObject10 || (_templateObject10 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n width: 100%;\n margin: 0;\n"])));
151
+ const PoliticsLimit = /*#__PURE__*/styled(ui.Flex)(_templateObject11 || (_templateObject11 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n flex-direction: column;\n width: 100%;\n margin-top: 0.75rem;\n background: white;\n"])));
152
+
153
+ const WARN_ENTITY_COUNT_THRESHOLD = 75;
154
+ const ERROR_ENTITY_COUNT_THRESHOLD = 90;
155
+
156
+ function getRatioLineVariant(used, max) {
157
+ const ratioUsed = used / max * 100;
158
+
159
+ if (ratioUsed >= ERROR_ENTITY_COUNT_THRESHOLD) {
160
+ return {
161
+ error: true
162
+ };
163
+ }
164
+
165
+ if (ratioUsed >= WARN_ENTITY_COUNT_THRESHOLD) {
166
+ return {
167
+ secondary: true
168
+ };
169
+ }
170
+
171
+ return {
172
+ primary: true
173
+ };
174
+ }
175
+
176
+ const PolicyItem = (_ref) => {
177
+ let {
178
+ item,
179
+ updatePolicyItem,
180
+ canUpdate
181
+ } = _ref;
182
+ const {
183
+ t
184
+ } = reactI18next.useTranslation('politics');
185
+ const {
186
+ name,
187
+ used,
188
+ max,
189
+ type,
190
+ disabled,
191
+ icon
192
+ } = item;
193
+ const onMaxLimitChange = React.useCallback(value => {
194
+ updatePolicyItem(value || 0, type);
195
+ }, [updatePolicyItem]);
196
+ const maxValue = // @ts-ignore
197
+ type === api.PolicyType.MaxUploadContentSize ? (max / (1024 * 1024)).toFixed(6) : max;
198
+ const formattedMaxValue = numberWithSpaces(maxValue, 6);
199
+ return React__default.createElement(PoliticsItemContainer, {
200
+ key: name
201
+ }, React__default.createElement(PoliticsItemContent, null, React__default.createElement(PoliticsItemIcon, {
202
+ kind: icon
203
+ }), React__default.createElement(PoliticsItemLimit, null, used !== undefined ? used + " " + t('from') + " " + (max === -1 ? '∞' : formattedMaxValue) : (max === -1 ? '∞' : formattedMaxValue) + " " + ( // @ts-ignore
204
+ type === api.PolicyType.MaxUploadContentSize ? 'mb' : '')), React__default.createElement(PoliticsItemType, null, name), canUpdate && React__default.createElement(PoliticsLimit, null, React__default.createElement(ui.NumberInput, {
205
+ required: true,
206
+ disabled: disabled,
207
+ counter: false,
208
+ width: '100%',
209
+ value: +maxValue,
210
+ onChange: onMaxLimitChange
211
+ }))), React__default.createElement(PoliticsRatioContainer, null, used !== undefined && React__default.createElement(PoliticsRatio, Object.assign({
212
+ ratio: used / max * 100
213
+ }, getRatioLineVariant(used, max)))));
214
+ };
215
+
216
+ const Politics = (_ref) => {
217
+ let {
218
+ username,
219
+ canUpdate,
220
+ title,
221
+ className,
222
+ onError
223
+ } = _ref;
224
+ const [politics, updatePolicy] = usePolitics(username, onError);
225
+ const debounce = react.useDebouncedCallback(500);
226
+ const updatePolicyItem = React.useCallback((value, type) => {
227
+ debounce(async () => {
228
+ const fixedValue = // max file size in mb
229
+ // @ts-ignore
230
+ type === api.PolicyType.MaxUploadContentSize ? value * 1024 * 1024 : value;
231
+ await updatePolicy(fixedValue, type);
232
+ });
233
+ }, [username]);
234
+ return React__default.createElement(PoliticsContainer, {
235
+ className: className
236
+ }, title && React__default.createElement(PoliticsTitle, null, title), React__default.createElement(PoliticsItems, null, politics.map(item => React__default.createElement(PolicyItem, {
237
+ key: item.name,
238
+ canUpdate: canUpdate,
239
+ item: item,
240
+ updatePolicyItem: updatePolicyItem
241
+ }))));
242
+ };
243
+
244
+ var maps = "Maps";
245
+ var layers = "Layers";
246
+ var maxFeaturesInLayerLimit = "Max objects count in layer";
247
+ var maxFileSize = "Max file size";
248
+ var tables = "Tables";
249
+ var from = "from";
250
+ var politics_en = {
251
+ maps: maps,
252
+ layers: layers,
253
+ maxFeaturesInLayerLimit: maxFeaturesInLayerLimit,
254
+ maxFileSize: maxFileSize,
255
+ tables: tables,
256
+ "in": "in",
257
+ from: from
258
+ };
259
+
260
+ var maps$1 = "Карты";
261
+ var layers$1 = "Слои";
262
+ var maxFeaturesInLayerLimit$1 = "Макс. количество объектов в слое";
263
+ var maxFileSize$1 = "Макс. размер файла";
264
+ var tables$1 = "Таблицы";
265
+ var from$1 = "из";
266
+ var politics_ru = {
267
+ maps: maps$1,
268
+ layers: layers$1,
269
+ maxFeaturesInLayerLimit: maxFeaturesInLayerLimit$1,
270
+ maxFileSize: maxFileSize$1,
271
+ tables: tables$1,
272
+ "in": "в",
273
+ from: from$1
274
+ };
275
+
276
+ const resources = {
277
+ en: {
278
+ politics: politics_en
279
+ },
280
+ ru: {
281
+ politics: politics_ru
282
+ }
283
+ };
284
+
285
+ exports.ApiProvider = ApiProvider;
286
+ exports.Politics = Politics;
287
+ exports.checkLimits = checkLimits;
288
+ exports.numberWithSpaces = numberWithSpaces;
289
+ exports.resources = resources;
290
+ exports.useApi = useApi;
291
+ //# sourceMappingURL=common.cjs.development.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.cjs.development.js","sources":["../src/ApiProvider.tsx","../src/resources/limits.ts","../src/components/Politics/hooks/usePolitics.ts","../src/utils/formatNumber.ts","../src/components/Politics/styled.ts","../src/components/Politics/PolicyItem.tsx","../src/components/Politics/index.tsx","../src/i18n/index.ts"],"sourcesContent":["import { Api } from '@evergis/api';\nimport React, { createContext, FC, useContext } from 'react';\n\nexport type ApiContextProps = {\n api?: Api;\n};\n\nconst ApiContext = createContext<ApiContextProps>({});\n\nexport const ApiProvider: FC<ApiContextProps> = ({ api, children }) => {\n return <ApiContext.Provider value={{ api }}>{children}</ApiContext.Provider>;\n};\n\nexport const useApi = (): ApiContextProps => {\n return useContext(ApiContext);\n};\n","import { Api, CheckLimitsParams } from '@evergis/api';\nimport { createResource } from '@evergis/react-fetching';\n\nlet resource: any;\n\nexport const checkLimits = (evergisApi: Api) => {\n if (!resource) {\n resource = createResource(\n (params: CheckLimitsParams) => async api => ({\n data: await api.resourceCatalog.checkLimits(params),\n }),\n { injected: evergisApi }\n );\n }\n\n return resource;\n};\n","import { Api, PolicyType } from '@evergis/api';\nimport { useCallback, useEffect, useMemo } from 'react';\nimport { useTranslation } from 'react-i18next';\nimport { useApi } from '../../../ApiProvider';\nimport { checkLimits } from '../../../resources/limits';\nimport { PoliticsItem, UpdatePolicy } from '../types';\n\nexport const usePolitics = (\n username?: string,\n onError?: (error: any) => void\n): [PoliticsItem[], UpdatePolicy] => {\n const { t } = useTranslation('politics');\n const { api } = useApi();\n\n const { data: limits, refetch, error } = checkLimits(api as Api).use({\n input: { userName: username },\n waitInput: true,\n });\n\n useEffect(() => {\n if (error) {\n onError(error);\n }\n }, [error, onError]);\n\n const politics = useMemo<PoliticsItem[]>(() => {\n return limits\n ? [\n {\n name: t('maps'),\n used: limits.currentProjectCount as number,\n max: limits.maxProjectsCount as number,\n type: PolicyType.CreateProject,\n icon: 'map',\n },\n {\n name: t('layers'),\n used: limits.currentServiceCount as number,\n max: limits.maxServicesCount as number,\n type: PolicyType.CreateLayer,\n icon: 'layers',\n },\n {\n name: t('tables'),\n used: limits.currentTableCount as number,\n max: limits.maxTablesCount as number,\n type: PolicyType.CreateTable,\n icon: 'table',\n },\n {\n name: t('maxFeaturesInLayerLimit'),\n max: limits.maxFeaturesInOneTable as number,\n type: PolicyType.MaxFeaturesInOneTable,\n icon: 'points',\n },\n {\n name: t('maxFileSize'),\n max: limits.maxUploadContentSize as number,\n // @ts-ignore\n type: PolicyType.MaxUploadContentSize,\n icon: 'textfile',\n },\n ]\n : [];\n }, [t, limits]);\n\n const updatePolicy: UpdatePolicy = useCallback(\n async (value, type) => {\n await (api as Api).security.setPolicy({\n value,\n type,\n role: `__${username}`,\n });\n\n await refetch();\n },\n [api]\n );\n\n return [politics, updatePolicy];\n};\n","export const numberWithSpaces = (\n input: number | string | null,\n maximumFractionDigits = 10\n): string => {\n if (input === null || input === undefined) {\n return '';\n }\n\n return parseFloat(\n (typeof input === 'string' ? parseFloat(input) : input).toString()\n ).toLocaleString('ru-RU', {\n maximumFractionDigits,\n });\n};\n","import { Flex, H2, Icon, RatioLine } from '@evergis/ui';\nimport styled from 'styled-components';\n\nexport const PoliticsContainer = styled(Flex)`\n margin-top: 3rem;\n flex-direction: column;\n`;\n\nexport const PoliticsTitle = styled(H2)`\n margin: 0;\n`;\n\nexport const PoliticsItems = styled(Flex)`\n flex-wrap: wrap;\n margin-top: 0.5rem;\n margin-bottom: 0.75rem;\n`;\n\nexport const PoliticsItemContainer = styled(Flex)`\n margin-top: 1rem;\n margin-right: 1rem;\n width: 14.5rem;\n border-radius: 2px;\n background-color: #f6f6f6;\n flex-direction: column;\n`;\n\nexport const PoliticsItemContent = styled(Flex)`\n flex-direction: column;\n align-items: center;\n padding: 1rem 1rem 0;\n width: 100%;\n box-sizing: border-box;\n`;\n\nexport const PoliticsItemIcon = styled(Icon)`\n opacity: 0.28;\n`;\n\nexport const PoliticsItemLimit = styled.span`\n font-size: 18px;\n font-weight: bold;\n margin-top: 0.75rem;\n`;\n\nexport const PoliticsItemType = styled.span`\n font-size: 12px;\n color: ${({ theme: { palette } }) => palette.textSecondary};\n`;\n\nexport const PoliticsRatioContainer = styled.div`\n margin: 0.75rem 0 0;\n height: 0.5rem;\n width: 100%;\n`;\n\nexport const PoliticsRatio = styled(RatioLine)`\n width: 100%;\n margin: 0;\n`;\n\nexport const PoliticsLimit = styled(Flex)`\n flex-direction: column;\n width: 100%;\n margin-top: 0.75rem;\n background: white;\n`;\n","import { PolicyType } from '@evergis/api';\nimport { NumberInput } from '@evergis/ui';\nimport React, { FC, useCallback } from 'react';\nimport { useTranslation } from 'react-i18next';\nimport { numberWithSpaces } from '../../utils';\nimport {\n PoliticsItemContainer,\n PoliticsItemContent,\n PoliticsItemIcon,\n PoliticsItemLimit,\n PoliticsItemType,\n PoliticsLimit,\n PoliticsRatio,\n PoliticsRatioContainer,\n} from './styled';\nimport { PolicyItemProps } from './types';\n\ntype RatioLineVariant = Partial<\n Record<'primary' | 'secondary' | 'error', boolean>\n>;\n\nconst WARN_ENTITY_COUNT_THRESHOLD = 75;\nconst ERROR_ENTITY_COUNT_THRESHOLD = 90;\n\nfunction getRatioLineVariant(used: number, max: number): RatioLineVariant {\n const ratioUsed = (used / max) * 100;\n\n if (ratioUsed >= ERROR_ENTITY_COUNT_THRESHOLD) {\n return { error: true };\n }\n\n if (ratioUsed >= WARN_ENTITY_COUNT_THRESHOLD) {\n return { secondary: true };\n }\n\n return { primary: true };\n}\n\nexport const PolicyItem: FC<PolicyItemProps> = ({\n item,\n updatePolicyItem,\n canUpdate,\n}) => {\n const { t } = useTranslation('politics');\n const { name, used, max, type, disabled, icon } = item;\n const onMaxLimitChange = useCallback(\n (value: number | null) => {\n updatePolicyItem(value || 0, type);\n },\n [updatePolicyItem]\n );\n\n const maxValue =\n // @ts-ignore\n type === PolicyType.MaxUploadContentSize\n ? (max / (1024 * 1024)).toFixed(6)\n : max;\n const formattedMaxValue = numberWithSpaces(maxValue, 6);\n\n return (\n <PoliticsItemContainer key={name}>\n <PoliticsItemContent>\n <PoliticsItemIcon kind={icon} />\n <PoliticsItemLimit>\n {used !== undefined\n ? `${used} ${t('from')} ${max === -1 ? '∞' : formattedMaxValue}`\n : `${max === -1 ? '∞' : formattedMaxValue} ${\n // @ts-ignore\n type === PolicyType.MaxUploadContentSize ? 'mb' : ''\n }`}\n </PoliticsItemLimit>\n <PoliticsItemType>{name}</PoliticsItemType>\n {canUpdate && (\n <PoliticsLimit>\n <NumberInput\n required\n disabled={disabled}\n counter={false}\n width={'100%'}\n value={+maxValue}\n onChange={onMaxLimitChange}\n />\n </PoliticsLimit>\n )}\n </PoliticsItemContent>\n <PoliticsRatioContainer>\n {used !== undefined && (\n <PoliticsRatio\n ratio={(used / max) * 100}\n {...getRatioLineVariant(used, max)}\n />\n )}\n </PoliticsRatioContainer>\n </PoliticsItemContainer>\n );\n};\n","import { PolicyType } from '@evergis/api';\nimport { useDebouncedCallback } from '@evergis/react';\nimport React, { FC, useCallback } from 'react';\nimport { usePolitics } from './hooks/usePolitics';\nimport { PolicyItem } from './PolicyItem';\nimport { PoliticsContainer, PoliticsItems, PoliticsTitle } from './styled';\nimport { PoliticsProps } from './types';\n\nexport const Politics: FC<PoliticsProps> = ({\n username,\n canUpdate,\n title,\n className,\n onError,\n}) => {\n const [politics, updatePolicy] = usePolitics(username, onError);\n const debounce = useDebouncedCallback(500);\n const updatePolicyItem = useCallback(\n (value: number, type: PolicyType) => {\n debounce(async () => {\n const fixedValue =\n // max file size in mb\n // @ts-ignore\n type === PolicyType.MaxUploadContentSize\n ? value * 1024 * 1024\n : value;\n\n await updatePolicy(fixedValue, type);\n });\n },\n [username]\n );\n\n return (\n <PoliticsContainer className={className}>\n {title && <PoliticsTitle>{title}</PoliticsTitle>}\n <PoliticsItems>\n {politics.map(item => (\n <PolicyItem\n key={item.name}\n canUpdate={canUpdate}\n item={item}\n updatePolicyItem={updatePolicyItem}\n />\n ))}\n </PoliticsItems>\n </PoliticsContainer>\n );\n};\n","import politics_en from './en/politics.json';\nimport politics_ru from './ru/politics.json';\n\nexport const resources = {\n en: {\n politics: politics_en,\n },\n ru: {\n politics: politics_ru,\n },\n} as const;\n"],"names":["ApiContext","createContext","ApiProvider","api","children","React","Provider","value","useApi","useContext","resource","checkLimits","evergisApi","createResource","params","data","resourceCatalog","injected","usePolitics","username","onError","t","useTranslation","limits","refetch","error","use","input","userName","waitInput","useEffect","politics","useMemo","name","used","currentProjectCount","max","maxProjectsCount","type","PolicyType","CreateProject","icon","currentServiceCount","maxServicesCount","CreateLayer","currentTableCount","maxTablesCount","CreateTable","maxFeaturesInOneTable","MaxFeaturesInOneTable","maxUploadContentSize","MaxUploadContentSize","updatePolicy","useCallback","security","setPolicy","role","numberWithSpaces","maximumFractionDigits","undefined","parseFloat","toString","toLocaleString","PoliticsContainer","styled","Flex","PoliticsTitle","H2","PoliticsItems","PoliticsItemContainer","PoliticsItemContent","PoliticsItemIcon","Icon","PoliticsItemLimit","span","PoliticsItemType","theme","palette","textSecondary","PoliticsRatioContainer","div","PoliticsRatio","RatioLine","PoliticsLimit","WARN_ENTITY_COUNT_THRESHOLD","ERROR_ENTITY_COUNT_THRESHOLD","getRatioLineVariant","ratioUsed","secondary","primary","PolicyItem","item","updatePolicyItem","canUpdate","disabled","onMaxLimitChange","maxValue","toFixed","formattedMaxValue","key","kind","NumberInput","required","counter","width","onChange","ratio","Politics","title","className","debounce","useDebouncedCallback","fixedValue","map","resources","en","politics_en","ru","politics_ru"],"mappings":";;;;;;;;;;;;;;;AAOA,MAAMA,UAAU,gBAAGC,mBAAa,CAAkB,EAAlB,CAAhC;MAEaC,WAAW,GAAwB;MAAC;AAAEC,IAAAA,GAAF;AAAOC,IAAAA;AAAP;AAC/C,SAAOC,4BAAA,CAACL,UAAU,CAACM,QAAZ;AAAqBC,IAAAA,KAAK,EAAE;AAAEJ,MAAAA;AAAF;GAA5B,EAAsCC,QAAtC,CAAP;AACD;MAEYI,MAAM,GAAG;AACpB,SAAOC,gBAAU,CAACT,UAAD,CAAjB;AACD;;ACZD,IAAIU,QAAJ;AAEA,MAAaC,WAAW,GAAIC,UAAD;AACzB,MAAI,CAACF,QAAL,EAAe;AACbA,IAAAA,QAAQ,GAAGG,4BAAc,CACtBC,MAAD,IAA+B,MAAMX,GAAN,KAAc;AAC3CY,MAAAA,IAAI,EAAE,MAAMZ,GAAG,CAACa,eAAJ,CAAoBL,WAApB,CAAgCG,MAAhC;AAD+B,KAAd,CADR,EAIvB;AAAEG,MAAAA,QAAQ,EAAEL;AAAZ,KAJuB,CAAzB;AAMD;;AAED,SAAOF,QAAP;AACD,CAXM;;ACEA,MAAMQ,WAAW,GAAG,CACzBC,QADyB,EAEzBC,OAFyB;AAIzB,QAAM;AAAEC,IAAAA;AAAF,MAAQC,2BAAc,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AAlB;AACD,KATO,CAAR;AAUD,GAZiC,EAalC,CAACnB,QAAD,CAbkC,CAApC;AAgBA,SACEd,4BAAA,CAAC0D,iBAAD;AAAmB8C,IAAAA,SAAS,EAAEA;GAA9B,EACGD,KAAK,IAAIvG,4BAAA,CAAC6D,aAAD,MAAA,EAAgB0C,KAAhB,CADZ,EAEEvG,4BAAA,CAAC+D,aAAD,MAAA,EACGrC,QAAQ,CAACkF,GAAT,CAAatB,IAAI,IAChBtF,4BAAA,CAACqF,UAAD;AACES,IAAAA,GAAG,EAAER,IAAI,CAAC1D;AACV4D,IAAAA,SAAS,EAAEA;AACXF,IAAAA,IAAI,EAAEA;AACNC,IAAAA,gBAAgB,EAAEA;GAJpB,CADD,CADH,CAFF,CADF;AAeD,CAxCM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MCLMsB,SAAS,GAAG;AACvBC,EAAAA,EAAE,EAAE;AACFpF,IAAAA,QAAQ,EAAEqF;AADR,GADmB;AAIvBC,EAAAA,EAAE,EAAE;AACFtF,IAAAA,QAAQ,EAAEuF;AADR;AAJmB,CAAlB;;;;;;;;;"}
@@ -0,0 +1,2 @@
1
+ "use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@evergis/api"),n=require("@evergis/react"),a=require("react"),r=e(a),i=require("react-i18next"),o=require("@evergis/react-fetching"),l=require("@evergis/ui"),c=e(require("styled-components"));const s=a.createContext({}),m=()=>a.useContext(s);let u;const p=e=>(u||(u=o.createResource(e=>async t=>({data:await t.resourceCatalog.checkLimits(e)}),{injected:e})),u),d=function(e,t){return void 0===t&&(t=10),null==e?"":parseFloat(("string"==typeof e?parseFloat(e):e).toString()).toLocaleString("ru-RU",{maximumFractionDigits:t})};function x(e,t){return t||(t=e.slice(0)),e.raw=t,e}var y,b,f,g,C,h,v,P,F,w,E;const T=c(l.Flex)(y||(y=x(["\n margin-top: 3rem;\n flex-direction: column;\n"]))),S=c(l.H2)(b||(b=x(["\n margin: 0;\n"]))),z=c(l.Flex)(f||(f=x(["\n flex-wrap: wrap;\n margin-top: 0.5rem;\n margin-bottom: 0.75rem;\n"]))),L=c(l.Flex)(g||(g=x(["\n margin-top: 1rem;\n margin-right: 1rem;\n width: 14.5rem;\n border-radius: 2px;\n background-color: #f6f6f6;\n flex-direction: column;\n"]))),k=c(l.Flex)(C||(C=x(["\n flex-direction: column;\n align-items: center;\n padding: 1rem 1rem 0;\n width: 100%;\n box-sizing: border-box;\n"]))),I=c(l.Icon)(h||(h=x(["\n opacity: 0.28;\n"]))),M=c.span(v||(v=x(["\n font-size: 18px;\n font-weight: bold;\n margin-top: 0.75rem;\n"]))),U=c.span(P||(P=x(["\n font-size: 12px;\n color: ",";\n"])),e=>{let{theme:{palette:t}}=e;return t.textSecondary}),j=c.div(F||(F=x(["\n margin: 0.75rem 0 0;\n height: 0.5rem;\n width: 100%;\n"]))),q=c(l.RatioLine)(w||(w=x(["\n width: 100%;\n margin: 0;\n"]))),N=c(l.Flex)(E||(E=x(["\n flex-direction: column;\n width: 100%;\n margin-top: 0.75rem;\n background: white;\n"]))),O=e=>{let{item:n,updatePolicyItem:o,canUpdate:c}=e;const{t:s}=i.useTranslation("politics"),{name:m,used:u,max:p,type:x,disabled:y,icon:b}=n,f=a.useCallback(e=>{o(e||0,x)},[o]),g=x===t.PolicyType.MaxUploadContentSize?(p/1048576).toFixed(6):p,C=d(g,6);return r.createElement(L,{key:m},r.createElement(k,null,r.createElement(I,{kind:b}),r.createElement(M,null,void 0!==u?u+" "+s("from")+" "+(-1===p?"∞":C):(-1===p?"∞":C)+" "+(x===t.PolicyType.MaxUploadContentSize?"mb":"")),r.createElement(U,null,m),c&&r.createElement(N,null,r.createElement(l.NumberInput,{required:!0,disabled:y,counter:!1,width:"100%",value:+g,onChange:f}))),r.createElement(j,null,void 0!==u&&r.createElement(q,Object.assign({ratio:u/p*100},function(e,t){const n=e/t*100;return n>=90?{error:!0}:n>=75?{secondary:!0}:{primary:!0}}(u,p)))))};exports.ApiProvider=e=>{let{api:t,children:n}=e;return r.createElement(s.Provider,{value:{api:t}},n)},exports.Politics=e=>{let{username:o,canUpdate:l,title:c,className:s,onError:u}=e;const[d,x]=((e,n)=>{const{t:r}=i.useTranslation("politics"),{api:o}=m(),{data:l,refetch:c,error:s}=p(o).use({input:{userName:e},waitInput:!0});return a.useEffect(()=>{s&&n(s)},[s,n]),[a.useMemo(()=>l?[{name:r("maps"),used:l.currentProjectCount,max:l.maxProjectsCount,type:t.PolicyType.CreateProject,icon:"map"},{name:r("layers"),used:l.currentServiceCount,max:l.maxServicesCount,type:t.PolicyType.CreateLayer,icon:"layers"},{name:r("tables"),used:l.currentTableCount,max:l.maxTablesCount,type:t.PolicyType.CreateTable,icon:"table"},{name:r("maxFeaturesInLayerLimit"),max:l.maxFeaturesInOneTable,type:t.PolicyType.MaxFeaturesInOneTable,icon:"points"},{name:r("maxFileSize"),max:l.maxUploadContentSize,type:t.PolicyType.MaxUploadContentSize,icon:"textfile"}]:[],[r,l]),a.useCallback(async(t,n)=>{await o.security.setPolicy({value:t,type:n,role:"__"+e}),await c()},[o])]})(o,u),y=n.useDebouncedCallback(500),b=a.useCallback((e,n)=>{y(async()=>{const a=n===t.PolicyType.MaxUploadContentSize?1024*e*1024:e;await x(a,n)})},[o]);return r.createElement(T,{className:s},c&&r.createElement(S,null,c),r.createElement(z,null,d.map(e=>r.createElement(O,{key:e.name,canUpdate:l,item:e,updatePolicyItem:b}))))},exports.checkLimits=p,exports.numberWithSpaces=d,exports.resources={en:{politics:{maps:"Maps",layers:"Layers",maxFeaturesInLayerLimit:"Max objects count in layer",maxFileSize:"Max file size",tables:"Tables",in:"in",from:"from"}},ru:{politics:{maps:"Карты",layers:"Слои",maxFeaturesInLayerLimit:"Макс. количество объектов в слое",maxFileSize:"Макс. размер файла",tables:"Таблицы",in:"в",from:"из"}}},exports.useApi=m;
2
+ //# sourceMappingURL=common.cjs.production.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.cjs.production.min.js","sources":["../src/ApiProvider.tsx","../src/resources/limits.ts","../src/utils/formatNumber.ts","../src/components/Politics/styled.ts","../src/components/Politics/PolicyItem.tsx","../src/components/Politics/index.tsx","../src/components/Politics/hooks/usePolitics.ts","../src/i18n/index.ts"],"sourcesContent":["import { Api } from '@evergis/api';\nimport React, { createContext, FC, useContext } from 'react';\n\nexport type ApiContextProps = {\n api?: Api;\n};\n\nconst ApiContext = createContext<ApiContextProps>({});\n\nexport const ApiProvider: FC<ApiContextProps> = ({ api, children }) => {\n return <ApiContext.Provider value={{ api }}>{children}</ApiContext.Provider>;\n};\n\nexport const useApi = (): ApiContextProps => {\n return useContext(ApiContext);\n};\n","import { Api, CheckLimitsParams } from '@evergis/api';\nimport { createResource } from '@evergis/react-fetching';\n\nlet resource: any;\n\nexport const checkLimits = (evergisApi: Api) => {\n if (!resource) {\n resource = createResource(\n (params: CheckLimitsParams) => async api => ({\n data: await api.resourceCatalog.checkLimits(params),\n }),\n { injected: evergisApi }\n );\n }\n\n return resource;\n};\n","export const numberWithSpaces = (\n input: number | string | null,\n maximumFractionDigits = 10\n): string => {\n if (input === null || input === undefined) {\n return '';\n }\n\n return parseFloat(\n (typeof input === 'string' ? parseFloat(input) : input).toString()\n ).toLocaleString('ru-RU', {\n maximumFractionDigits,\n });\n};\n","import { Flex, H2, Icon, RatioLine } from '@evergis/ui';\nimport styled from 'styled-components';\n\nexport const PoliticsContainer = styled(Flex)`\n margin-top: 3rem;\n flex-direction: column;\n`;\n\nexport const PoliticsTitle = styled(H2)`\n margin: 0;\n`;\n\nexport const PoliticsItems = styled(Flex)`\n flex-wrap: wrap;\n margin-top: 0.5rem;\n margin-bottom: 0.75rem;\n`;\n\nexport const PoliticsItemContainer = styled(Flex)`\n margin-top: 1rem;\n margin-right: 1rem;\n width: 14.5rem;\n border-radius: 2px;\n background-color: #f6f6f6;\n flex-direction: column;\n`;\n\nexport const PoliticsItemContent = styled(Flex)`\n flex-direction: column;\n align-items: center;\n padding: 1rem 1rem 0;\n width: 100%;\n box-sizing: border-box;\n`;\n\nexport const PoliticsItemIcon = styled(Icon)`\n opacity: 0.28;\n`;\n\nexport const PoliticsItemLimit = styled.span`\n font-size: 18px;\n font-weight: bold;\n margin-top: 0.75rem;\n`;\n\nexport const PoliticsItemType = styled.span`\n font-size: 12px;\n color: ${({ theme: { palette } }) => palette.textSecondary};\n`;\n\nexport const PoliticsRatioContainer = styled.div`\n margin: 0.75rem 0 0;\n height: 0.5rem;\n width: 100%;\n`;\n\nexport const PoliticsRatio = styled(RatioLine)`\n width: 100%;\n margin: 0;\n`;\n\nexport const PoliticsLimit = styled(Flex)`\n flex-direction: column;\n width: 100%;\n margin-top: 0.75rem;\n background: white;\n`;\n","import { PolicyType } from '@evergis/api';\nimport { NumberInput } from '@evergis/ui';\nimport React, { FC, useCallback } from 'react';\nimport { useTranslation } from 'react-i18next';\nimport { numberWithSpaces } from '../../utils';\nimport {\n PoliticsItemContainer,\n PoliticsItemContent,\n PoliticsItemIcon,\n PoliticsItemLimit,\n PoliticsItemType,\n PoliticsLimit,\n PoliticsRatio,\n PoliticsRatioContainer,\n} from './styled';\nimport { PolicyItemProps } from './types';\n\ntype RatioLineVariant = Partial<\n Record<'primary' | 'secondary' | 'error', boolean>\n>;\n\nconst WARN_ENTITY_COUNT_THRESHOLD = 75;\nconst ERROR_ENTITY_COUNT_THRESHOLD = 90;\n\nfunction getRatioLineVariant(used: number, max: number): RatioLineVariant {\n const ratioUsed = (used / max) * 100;\n\n if (ratioUsed >= ERROR_ENTITY_COUNT_THRESHOLD) {\n return { error: true };\n }\n\n if (ratioUsed >= WARN_ENTITY_COUNT_THRESHOLD) {\n return { secondary: true };\n }\n\n return { primary: true };\n}\n\nexport const PolicyItem: FC<PolicyItemProps> = ({\n item,\n updatePolicyItem,\n canUpdate,\n}) => {\n const { t } = useTranslation('politics');\n const { name, used, max, type, disabled, icon } = item;\n const onMaxLimitChange = useCallback(\n (value: number | null) => {\n updatePolicyItem(value || 0, type);\n },\n [updatePolicyItem]\n );\n\n const maxValue =\n // @ts-ignore\n type === PolicyType.MaxUploadContentSize\n ? (max / (1024 * 1024)).toFixed(6)\n : max;\n const formattedMaxValue = numberWithSpaces(maxValue, 6);\n\n return (\n <PoliticsItemContainer key={name}>\n <PoliticsItemContent>\n <PoliticsItemIcon kind={icon} />\n <PoliticsItemLimit>\n {used !== undefined\n ? `${used} ${t('from')} ${max === -1 ? '∞' : formattedMaxValue}`\n : `${max === -1 ? '∞' : formattedMaxValue} ${\n // @ts-ignore\n type === PolicyType.MaxUploadContentSize ? 'mb' : ''\n }`}\n </PoliticsItemLimit>\n <PoliticsItemType>{name}</PoliticsItemType>\n {canUpdate && (\n <PoliticsLimit>\n <NumberInput\n required\n disabled={disabled}\n counter={false}\n width={'100%'}\n value={+maxValue}\n onChange={onMaxLimitChange}\n />\n </PoliticsLimit>\n )}\n </PoliticsItemContent>\n <PoliticsRatioContainer>\n {used !== undefined && (\n <PoliticsRatio\n ratio={(used / max) * 100}\n {...getRatioLineVariant(used, max)}\n />\n )}\n </PoliticsRatioContainer>\n </PoliticsItemContainer>\n );\n};\n","import { PolicyType } from '@evergis/api';\nimport { useDebouncedCallback } from '@evergis/react';\nimport React, { FC, useCallback } from 'react';\nimport { usePolitics } from './hooks/usePolitics';\nimport { PolicyItem } from './PolicyItem';\nimport { PoliticsContainer, PoliticsItems, PoliticsTitle } from './styled';\nimport { PoliticsProps } from './types';\n\nexport const Politics: FC<PoliticsProps> = ({\n username,\n canUpdate,\n title,\n className,\n onError,\n}) => {\n const [politics, updatePolicy] = usePolitics(username, onError);\n const debounce = useDebouncedCallback(500);\n const updatePolicyItem = useCallback(\n (value: number, type: PolicyType) => {\n debounce(async () => {\n const fixedValue =\n // max file size in mb\n // @ts-ignore\n type === PolicyType.MaxUploadContentSize\n ? value * 1024 * 1024\n : value;\n\n await updatePolicy(fixedValue, type);\n });\n },\n [username]\n );\n\n return (\n <PoliticsContainer className={className}>\n {title && <PoliticsTitle>{title}</PoliticsTitle>}\n <PoliticsItems>\n {politics.map(item => (\n <PolicyItem\n key={item.name}\n canUpdate={canUpdate}\n item={item}\n updatePolicyItem={updatePolicyItem}\n />\n ))}\n </PoliticsItems>\n </PoliticsContainer>\n );\n};\n","import { Api, PolicyType } from '@evergis/api';\nimport { useCallback, useEffect, useMemo } from 'react';\nimport { useTranslation } from 'react-i18next';\nimport { useApi } from '../../../ApiProvider';\nimport { checkLimits } from '../../../resources/limits';\nimport { PoliticsItem, UpdatePolicy } from '../types';\n\nexport const usePolitics = (\n username?: string,\n onError?: (error: any) => void\n): [PoliticsItem[], UpdatePolicy] => {\n const { t } = useTranslation('politics');\n const { api } = useApi();\n\n const { data: limits, refetch, error } = checkLimits(api as Api).use({\n input: { userName: username },\n waitInput: true,\n });\n\n useEffect(() => {\n if (error) {\n onError(error);\n }\n }, [error, onError]);\n\n const politics = useMemo<PoliticsItem[]>(() => {\n return limits\n ? [\n {\n name: t('maps'),\n used: limits.currentProjectCount as number,\n max: limits.maxProjectsCount as number,\n type: PolicyType.CreateProject,\n icon: 'map',\n },\n {\n name: t('layers'),\n used: limits.currentServiceCount as number,\n max: limits.maxServicesCount as number,\n type: PolicyType.CreateLayer,\n icon: 'layers',\n },\n {\n name: t('tables'),\n used: limits.currentTableCount as number,\n max: limits.maxTablesCount as number,\n type: PolicyType.CreateTable,\n icon: 'table',\n },\n {\n name: t('maxFeaturesInLayerLimit'),\n max: limits.maxFeaturesInOneTable as number,\n type: PolicyType.MaxFeaturesInOneTable,\n icon: 'points',\n },\n {\n name: t('maxFileSize'),\n max: limits.maxUploadContentSize as number,\n // @ts-ignore\n type: PolicyType.MaxUploadContentSize,\n icon: 'textfile',\n },\n ]\n : [];\n }, [t, limits]);\n\n const updatePolicy: UpdatePolicy = useCallback(\n async (value, type) => {\n await (api as Api).security.setPolicy({\n value,\n type,\n role: `__${username}`,\n });\n\n await refetch();\n },\n [api]\n );\n\n return [politics, updatePolicy];\n};\n","import politics_en from './en/politics.json';\nimport politics_ru from './ru/politics.json';\n\nexport const resources = {\n en: {\n politics: politics_en,\n },\n ru: {\n politics: politics_ru,\n },\n} as const;\n"],"names":["ApiContext","createContext","useApi","useContext","resource","checkLimits","evergisApi","createResource","params","async","data","api","resourceCatalog","injected","numberWithSpaces","input","maximumFractionDigits","parseFloat","toString","toLocaleString","PoliticsContainer","styled","Flex","PoliticsTitle","H2","PoliticsItems","PoliticsItemContainer","PoliticsItemContent","PoliticsItemIcon","Icon","PoliticsItemLimit","span","PoliticsItemType","theme","palette","textSecondary","PoliticsRatioContainer","div","PoliticsRatio","RatioLine","PoliticsLimit","PolicyItem","item","updatePolicyItem","canUpdate","t","useTranslation","name","used","max","type","disabled","icon","onMaxLimitChange","useCallback","value","maxValue","PolicyType","MaxUploadContentSize","toFixed","formattedMaxValue","React","key","kind","undefined","NumberInput","required","counter","width","onChange","ratio","ratioUsed","error","secondary","primary","getRatioLineVariant","children","Provider","username","title","className","onError","politics","updatePolicy","limits","refetch","use","userName","waitInput","useEffect","useMemo","currentProjectCount","maxProjectsCount","CreateProject","currentServiceCount","maxServicesCount","CreateLayer","currentTableCount","maxTablesCount","CreateTable","maxFeaturesInOneTable","MaxFeaturesInOneTable","maxUploadContentSize","security","setPolicy","role","usePolitics","debounce","useDebouncedCallback","fixedValue","map","en","ru"],"mappings":"yVAOA,MAAMA,EAAaC,gBAA+B,IAMrCC,EAAS,IACbC,aAAWH,GCXpB,IAAII,QAESC,EAAeC,IACrBF,IACHA,EAAWG,iBACRC,GAA8BC,MAAAA,KAC7BC,WAAYC,EAAIC,gBAAgBP,YAAYG,KAE9C,CAAEK,SAAUP,KAITF,GCfIU,EAAmB,SAC9BC,EACAC,mBAAAA,IAAAA,EAAwB,IAEpBD,MAAAA,EACK,GAGFE,YACa,iBAAVF,EAAqBE,WAAWF,GAASA,GAAOG,YACxDC,eAAe,QAAS,CACxBH,sBAAAA,wFCRSI,EAAoBC,EAAOC,OAAPD,m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EAAWC,uBAAqB,KAChCjE,EAAmBW,cACvB,CAACC,EAAeL,KACdyD,EAASlG,gBACDoG,EAGJ3D,IAASO,aAAWC,qBACR,KAARH,EAAe,KACfA,QAEA4B,EAAa0B,EAAY3D,MAGnC,CAAC4B,WAIDjB,gBAACzC,GAAkB4D,UAAWA,GAC3BD,GAASlB,gBAACtC,OAAewD,GAC1BlB,gBAACpC,OACEyD,EAAS4B,IAAIpE,GACZmB,gBAACpB,GACCqB,IAAKpB,EAAKK,KACVH,UAAWA,EACXF,KAAMA,EACNC,iBAAkBA,2EEvCL,CACvBoE,GAAI,CACF7B,6JAEF8B,GAAI,CACF9B"}
@@ -0,0 +1,279 @@
1
+ import { PolicyType } from '@evergis/api';
2
+ import { useDebouncedCallback } from '@evergis/react';
3
+ import React, { useContext, createContext, useEffect, useMemo, useCallback } from 'react';
4
+ import { useTranslation } from 'react-i18next';
5
+ import { createResource } from '@evergis/react-fetching';
6
+ import { Flex, H2, Icon, RatioLine, NumberInput } from '@evergis/ui';
7
+ import styled from 'styled-components';
8
+
9
+ const ApiContext = /*#__PURE__*/createContext({});
10
+ const ApiProvider = (_ref) => {
11
+ let {
12
+ api,
13
+ children
14
+ } = _ref;
15
+ return React.createElement(ApiContext.Provider, {
16
+ value: {
17
+ api
18
+ }
19
+ }, children);
20
+ };
21
+ const useApi = () => {
22
+ return useContext(ApiContext);
23
+ };
24
+
25
+ let resource;
26
+ const checkLimits = evergisApi => {
27
+ if (!resource) {
28
+ resource = createResource(params => async api => ({
29
+ data: await api.resourceCatalog.checkLimits(params)
30
+ }), {
31
+ injected: evergisApi
32
+ });
33
+ }
34
+
35
+ return resource;
36
+ };
37
+
38
+ const usePolitics = (username, onError) => {
39
+ const {
40
+ t
41
+ } = useTranslation('politics');
42
+ const {
43
+ api
44
+ } = useApi();
45
+ const {
46
+ data: limits,
47
+ refetch,
48
+ error
49
+ } = checkLimits(api).use({
50
+ input: {
51
+ userName: username
52
+ },
53
+ waitInput: true
54
+ });
55
+ useEffect(() => {
56
+ if (error) {
57
+ onError(error);
58
+ }
59
+ }, [error, onError]);
60
+ const politics = useMemo(() => {
61
+ return limits ? [{
62
+ name: t('maps'),
63
+ used: limits.currentProjectCount,
64
+ max: limits.maxProjectsCount,
65
+ type: PolicyType.CreateProject,
66
+ icon: 'map'
67
+ }, {
68
+ name: t('layers'),
69
+ used: limits.currentServiceCount,
70
+ max: limits.maxServicesCount,
71
+ type: PolicyType.CreateLayer,
72
+ icon: 'layers'
73
+ }, {
74
+ name: t('tables'),
75
+ used: limits.currentTableCount,
76
+ max: limits.maxTablesCount,
77
+ type: PolicyType.CreateTable,
78
+ icon: 'table'
79
+ }, {
80
+ name: t('maxFeaturesInLayerLimit'),
81
+ max: limits.maxFeaturesInOneTable,
82
+ type: PolicyType.MaxFeaturesInOneTable,
83
+ icon: 'points'
84
+ }, {
85
+ name: t('maxFileSize'),
86
+ max: limits.maxUploadContentSize,
87
+ // @ts-ignore
88
+ type: PolicyType.MaxUploadContentSize,
89
+ icon: 'textfile'
90
+ }] : [];
91
+ }, [t, limits]);
92
+ const updatePolicy = useCallback(async (value, type) => {
93
+ await api.security.setPolicy({
94
+ value,
95
+ type,
96
+ role: "__" + username
97
+ });
98
+ await refetch();
99
+ }, [api]);
100
+ return [politics, updatePolicy];
101
+ };
102
+
103
+ const numberWithSpaces = function numberWithSpaces(input, maximumFractionDigits) {
104
+ if (maximumFractionDigits === void 0) {
105
+ maximumFractionDigits = 10;
106
+ }
107
+
108
+ if (input === null || input === undefined) {
109
+ return '';
110
+ }
111
+
112
+ return parseFloat((typeof input === 'string' ? parseFloat(input) : input).toString()).toLocaleString('ru-RU', {
113
+ maximumFractionDigits
114
+ });
115
+ };
116
+
117
+ function _taggedTemplateLiteralLoose(strings, raw) {
118
+ if (!raw) {
119
+ raw = strings.slice(0);
120
+ }
121
+
122
+ strings.raw = raw;
123
+ return strings;
124
+ }
125
+
126
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11;
127
+ const PoliticsContainer = /*#__PURE__*/styled(Flex)(_templateObject || (_templateObject = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-top: 3rem;\n flex-direction: column;\n"])));
128
+ const PoliticsTitle = /*#__PURE__*/styled(H2)(_templateObject2 || (_templateObject2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin: 0;\n"])));
129
+ const PoliticsItems = /*#__PURE__*/styled(Flex)(_templateObject3 || (_templateObject3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n flex-wrap: wrap;\n margin-top: 0.5rem;\n margin-bottom: 0.75rem;\n"])));
130
+ const PoliticsItemContainer = /*#__PURE__*/styled(Flex)(_templateObject4 || (_templateObject4 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-top: 1rem;\n margin-right: 1rem;\n width: 14.5rem;\n border-radius: 2px;\n background-color: #f6f6f6;\n flex-direction: column;\n"])));
131
+ const PoliticsItemContent = /*#__PURE__*/styled(Flex)(_templateObject5 || (_templateObject5 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n flex-direction: column;\n align-items: center;\n padding: 1rem 1rem 0;\n width: 100%;\n box-sizing: border-box;\n"])));
132
+ const PoliticsItemIcon = /*#__PURE__*/styled(Icon)(_templateObject6 || (_templateObject6 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n opacity: 0.28;\n"])));
133
+ const PoliticsItemLimit = /*#__PURE__*/styled.span(_templateObject7 || (_templateObject7 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n font-size: 18px;\n font-weight: bold;\n margin-top: 0.75rem;\n"])));
134
+ const PoliticsItemType = /*#__PURE__*/styled.span(_templateObject8 || (_templateObject8 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n font-size: 12px;\n color: ", ";\n"])), (_ref) => {
135
+ let {
136
+ theme: {
137
+ palette
138
+ }
139
+ } = _ref;
140
+ return palette.textSecondary;
141
+ });
142
+ const PoliticsRatioContainer = /*#__PURE__*/styled.div(_templateObject9 || (_templateObject9 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin: 0.75rem 0 0;\n height: 0.5rem;\n width: 100%;\n"])));
143
+ const PoliticsRatio = /*#__PURE__*/styled(RatioLine)(_templateObject10 || (_templateObject10 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n width: 100%;\n margin: 0;\n"])));
144
+ const PoliticsLimit = /*#__PURE__*/styled(Flex)(_templateObject11 || (_templateObject11 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n flex-direction: column;\n width: 100%;\n margin-top: 0.75rem;\n background: white;\n"])));
145
+
146
+ const WARN_ENTITY_COUNT_THRESHOLD = 75;
147
+ const ERROR_ENTITY_COUNT_THRESHOLD = 90;
148
+
149
+ function getRatioLineVariant(used, max) {
150
+ const ratioUsed = used / max * 100;
151
+
152
+ if (ratioUsed >= ERROR_ENTITY_COUNT_THRESHOLD) {
153
+ return {
154
+ error: true
155
+ };
156
+ }
157
+
158
+ if (ratioUsed >= WARN_ENTITY_COUNT_THRESHOLD) {
159
+ return {
160
+ secondary: true
161
+ };
162
+ }
163
+
164
+ return {
165
+ primary: true
166
+ };
167
+ }
168
+
169
+ const PolicyItem = (_ref) => {
170
+ let {
171
+ item,
172
+ updatePolicyItem,
173
+ canUpdate
174
+ } = _ref;
175
+ const {
176
+ t
177
+ } = useTranslation('politics');
178
+ const {
179
+ name,
180
+ used,
181
+ max,
182
+ type,
183
+ disabled,
184
+ icon
185
+ } = item;
186
+ const onMaxLimitChange = useCallback(value => {
187
+ updatePolicyItem(value || 0, type);
188
+ }, [updatePolicyItem]);
189
+ const maxValue = // @ts-ignore
190
+ type === PolicyType.MaxUploadContentSize ? (max / (1024 * 1024)).toFixed(6) : max;
191
+ const formattedMaxValue = numberWithSpaces(maxValue, 6);
192
+ return React.createElement(PoliticsItemContainer, {
193
+ key: name
194
+ }, React.createElement(PoliticsItemContent, null, React.createElement(PoliticsItemIcon, {
195
+ kind: icon
196
+ }), React.createElement(PoliticsItemLimit, null, used !== undefined ? used + " " + t('from') + " " + (max === -1 ? '∞' : formattedMaxValue) : (max === -1 ? '∞' : formattedMaxValue) + " " + ( // @ts-ignore
197
+ type === PolicyType.MaxUploadContentSize ? 'mb' : '')), React.createElement(PoliticsItemType, null, name), canUpdate && React.createElement(PoliticsLimit, null, React.createElement(NumberInput, {
198
+ required: true,
199
+ disabled: disabled,
200
+ counter: false,
201
+ width: '100%',
202
+ value: +maxValue,
203
+ onChange: onMaxLimitChange
204
+ }))), React.createElement(PoliticsRatioContainer, null, used !== undefined && React.createElement(PoliticsRatio, Object.assign({
205
+ ratio: used / max * 100
206
+ }, getRatioLineVariant(used, max)))));
207
+ };
208
+
209
+ const Politics = (_ref) => {
210
+ let {
211
+ username,
212
+ canUpdate,
213
+ title,
214
+ className,
215
+ onError
216
+ } = _ref;
217
+ const [politics, updatePolicy] = usePolitics(username, onError);
218
+ const debounce = useDebouncedCallback(500);
219
+ const updatePolicyItem = useCallback((value, type) => {
220
+ debounce(async () => {
221
+ const fixedValue = // max file size in mb
222
+ // @ts-ignore
223
+ type === PolicyType.MaxUploadContentSize ? value * 1024 * 1024 : value;
224
+ await updatePolicy(fixedValue, type);
225
+ });
226
+ }, [username]);
227
+ return React.createElement(PoliticsContainer, {
228
+ className: className
229
+ }, title && React.createElement(PoliticsTitle, null, title), React.createElement(PoliticsItems, null, politics.map(item => React.createElement(PolicyItem, {
230
+ key: item.name,
231
+ canUpdate: canUpdate,
232
+ item: item,
233
+ updatePolicyItem: updatePolicyItem
234
+ }))));
235
+ };
236
+
237
+ var maps = "Maps";
238
+ var layers = "Layers";
239
+ var maxFeaturesInLayerLimit = "Max objects count in layer";
240
+ var maxFileSize = "Max file size";
241
+ var tables = "Tables";
242
+ var from = "from";
243
+ var politics_en = {
244
+ maps: maps,
245
+ layers: layers,
246
+ maxFeaturesInLayerLimit: maxFeaturesInLayerLimit,
247
+ maxFileSize: maxFileSize,
248
+ tables: tables,
249
+ "in": "in",
250
+ from: from
251
+ };
252
+
253
+ var maps$1 = "Карты";
254
+ var layers$1 = "Слои";
255
+ var maxFeaturesInLayerLimit$1 = "Макс. количество объектов в слое";
256
+ var maxFileSize$1 = "Макс. размер файла";
257
+ var tables$1 = "Таблицы";
258
+ var from$1 = "из";
259
+ var politics_ru = {
260
+ maps: maps$1,
261
+ layers: layers$1,
262
+ maxFeaturesInLayerLimit: maxFeaturesInLayerLimit$1,
263
+ maxFileSize: maxFileSize$1,
264
+ tables: tables$1,
265
+ "in": "в",
266
+ from: from$1
267
+ };
268
+
269
+ const resources = {
270
+ en: {
271
+ politics: politics_en
272
+ },
273
+ ru: {
274
+ politics: politics_ru
275
+ }
276
+ };
277
+
278
+ export { ApiProvider, Politics, checkLimits, numberWithSpaces, resources, useApi };
279
+ //# sourceMappingURL=common.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.esm.js","sources":["../src/ApiProvider.tsx","../src/resources/limits.ts","../src/components/Politics/hooks/usePolitics.ts","../src/utils/formatNumber.ts","../src/components/Politics/styled.ts","../src/components/Politics/PolicyItem.tsx","../src/components/Politics/index.tsx","../src/i18n/index.ts"],"sourcesContent":["import { Api } from '@evergis/api';\nimport React, { createContext, FC, useContext } from 'react';\n\nexport type ApiContextProps = {\n api?: Api;\n};\n\nconst ApiContext = createContext<ApiContextProps>({});\n\nexport const ApiProvider: FC<ApiContextProps> = ({ api, children }) => {\n return <ApiContext.Provider value={{ api }}>{children}</ApiContext.Provider>;\n};\n\nexport const useApi = (): ApiContextProps => {\n return useContext(ApiContext);\n};\n","import { Api, CheckLimitsParams } from '@evergis/api';\nimport { createResource } from '@evergis/react-fetching';\n\nlet resource: any;\n\nexport const checkLimits = (evergisApi: Api) => {\n if (!resource) {\n resource = createResource(\n (params: CheckLimitsParams) => async api => ({\n data: await api.resourceCatalog.checkLimits(params),\n }),\n { injected: evergisApi }\n );\n }\n\n return resource;\n};\n","import { Api, PolicyType } from '@evergis/api';\nimport { useCallback, useEffect, useMemo } from 'react';\nimport { useTranslation } from 'react-i18next';\nimport { useApi } from '../../../ApiProvider';\nimport { checkLimits } from '../../../resources/limits';\nimport { PoliticsItem, UpdatePolicy } from '../types';\n\nexport const usePolitics = (\n username?: string,\n onError?: (error: any) => void\n): [PoliticsItem[], UpdatePolicy] => {\n const { t } = useTranslation('politics');\n const { api } = useApi();\n\n const { data: limits, refetch, error } = checkLimits(api as Api).use({\n input: { userName: username },\n waitInput: true,\n });\n\n useEffect(() => {\n if (error) {\n onError(error);\n }\n }, [error, onError]);\n\n const politics = useMemo<PoliticsItem[]>(() => {\n return limits\n ? [\n {\n name: t('maps'),\n used: limits.currentProjectCount as number,\n max: limits.maxProjectsCount as number,\n type: PolicyType.CreateProject,\n icon: 'map',\n },\n {\n name: t('layers'),\n used: limits.currentServiceCount as number,\n max: limits.maxServicesCount as number,\n type: PolicyType.CreateLayer,\n icon: 'layers',\n },\n {\n name: t('tables'),\n used: limits.currentTableCount as number,\n max: limits.maxTablesCount as number,\n type: PolicyType.CreateTable,\n icon: 'table',\n },\n {\n name: t('maxFeaturesInLayerLimit'),\n max: limits.maxFeaturesInOneTable as number,\n type: PolicyType.MaxFeaturesInOneTable,\n icon: 'points',\n },\n {\n name: t('maxFileSize'),\n max: limits.maxUploadContentSize as number,\n // @ts-ignore\n type: PolicyType.MaxUploadContentSize,\n icon: 'textfile',\n },\n ]\n : [];\n }, [t, limits]);\n\n const updatePolicy: UpdatePolicy = useCallback(\n async (value, type) => {\n await (api as Api).security.setPolicy({\n value,\n type,\n role: `__${username}`,\n });\n\n await refetch();\n },\n [api]\n );\n\n return [politics, updatePolicy];\n};\n","export const numberWithSpaces = (\n input: number | string | null,\n maximumFractionDigits = 10\n): string => {\n if (input === null || input === undefined) {\n return '';\n }\n\n return parseFloat(\n (typeof input === 'string' ? parseFloat(input) : input).toString()\n ).toLocaleString('ru-RU', {\n maximumFractionDigits,\n });\n};\n","import { Flex, H2, Icon, RatioLine } from '@evergis/ui';\nimport styled from 'styled-components';\n\nexport const PoliticsContainer = styled(Flex)`\n margin-top: 3rem;\n flex-direction: column;\n`;\n\nexport const PoliticsTitle = styled(H2)`\n margin: 0;\n`;\n\nexport const PoliticsItems = styled(Flex)`\n flex-wrap: wrap;\n margin-top: 0.5rem;\n margin-bottom: 0.75rem;\n`;\n\nexport const PoliticsItemContainer = styled(Flex)`\n margin-top: 1rem;\n margin-right: 1rem;\n width: 14.5rem;\n border-radius: 2px;\n background-color: #f6f6f6;\n flex-direction: column;\n`;\n\nexport const PoliticsItemContent = styled(Flex)`\n flex-direction: column;\n align-items: center;\n padding: 1rem 1rem 0;\n width: 100%;\n box-sizing: border-box;\n`;\n\nexport const PoliticsItemIcon = styled(Icon)`\n opacity: 0.28;\n`;\n\nexport const PoliticsItemLimit = styled.span`\n font-size: 18px;\n font-weight: bold;\n margin-top: 0.75rem;\n`;\n\nexport const PoliticsItemType = styled.span`\n font-size: 12px;\n color: ${({ theme: { palette } }) => palette.textSecondary};\n`;\n\nexport const PoliticsRatioContainer = styled.div`\n margin: 0.75rem 0 0;\n height: 0.5rem;\n width: 100%;\n`;\n\nexport const PoliticsRatio = styled(RatioLine)`\n width: 100%;\n margin: 0;\n`;\n\nexport const PoliticsLimit = styled(Flex)`\n flex-direction: column;\n width: 100%;\n margin-top: 0.75rem;\n background: white;\n`;\n","import { PolicyType } from '@evergis/api';\nimport { NumberInput } from '@evergis/ui';\nimport React, { FC, useCallback } from 'react';\nimport { useTranslation } from 'react-i18next';\nimport { numberWithSpaces } from '../../utils';\nimport {\n PoliticsItemContainer,\n PoliticsItemContent,\n PoliticsItemIcon,\n PoliticsItemLimit,\n PoliticsItemType,\n PoliticsLimit,\n PoliticsRatio,\n PoliticsRatioContainer,\n} from './styled';\nimport { PolicyItemProps } from './types';\n\ntype RatioLineVariant = Partial<\n Record<'primary' | 'secondary' | 'error', boolean>\n>;\n\nconst WARN_ENTITY_COUNT_THRESHOLD = 75;\nconst ERROR_ENTITY_COUNT_THRESHOLD = 90;\n\nfunction getRatioLineVariant(used: number, max: number): RatioLineVariant {\n const ratioUsed = (used / max) * 100;\n\n if (ratioUsed >= ERROR_ENTITY_COUNT_THRESHOLD) {\n return { error: true };\n }\n\n if (ratioUsed >= WARN_ENTITY_COUNT_THRESHOLD) {\n return { secondary: true };\n }\n\n return { primary: true };\n}\n\nexport const PolicyItem: FC<PolicyItemProps> = ({\n item,\n updatePolicyItem,\n canUpdate,\n}) => {\n const { t } = useTranslation('politics');\n const { name, used, max, type, disabled, icon } = item;\n const onMaxLimitChange = useCallback(\n (value: number | null) => {\n updatePolicyItem(value || 0, type);\n },\n [updatePolicyItem]\n );\n\n const maxValue =\n // @ts-ignore\n type === PolicyType.MaxUploadContentSize\n ? (max / (1024 * 1024)).toFixed(6)\n : max;\n const formattedMaxValue = numberWithSpaces(maxValue, 6);\n\n return (\n <PoliticsItemContainer key={name}>\n <PoliticsItemContent>\n <PoliticsItemIcon kind={icon} />\n <PoliticsItemLimit>\n {used !== undefined\n ? `${used} ${t('from')} ${max === -1 ? '∞' : formattedMaxValue}`\n : `${max === -1 ? '∞' : formattedMaxValue} ${\n // @ts-ignore\n type === PolicyType.MaxUploadContentSize ? 'mb' : ''\n }`}\n </PoliticsItemLimit>\n <PoliticsItemType>{name}</PoliticsItemType>\n {canUpdate && (\n <PoliticsLimit>\n <NumberInput\n required\n disabled={disabled}\n counter={false}\n width={'100%'}\n value={+maxValue}\n onChange={onMaxLimitChange}\n />\n </PoliticsLimit>\n )}\n </PoliticsItemContent>\n <PoliticsRatioContainer>\n {used !== undefined && (\n <PoliticsRatio\n ratio={(used / max) * 100}\n {...getRatioLineVariant(used, max)}\n />\n )}\n </PoliticsRatioContainer>\n </PoliticsItemContainer>\n );\n};\n","import { PolicyType } from '@evergis/api';\nimport { useDebouncedCallback } from '@evergis/react';\nimport React, { FC, useCallback } from 'react';\nimport { usePolitics } from './hooks/usePolitics';\nimport { PolicyItem } from './PolicyItem';\nimport { PoliticsContainer, PoliticsItems, PoliticsTitle } from './styled';\nimport { PoliticsProps } from './types';\n\nexport const Politics: FC<PoliticsProps> = ({\n username,\n canUpdate,\n title,\n className,\n onError,\n}) => {\n const [politics, updatePolicy] = usePolitics(username, onError);\n const debounce = useDebouncedCallback(500);\n const updatePolicyItem = useCallback(\n (value: number, type: PolicyType) => {\n debounce(async () => {\n const fixedValue =\n // max file size in mb\n // @ts-ignore\n type === PolicyType.MaxUploadContentSize\n ? value * 1024 * 1024\n : value;\n\n await updatePolicy(fixedValue, type);\n });\n },\n [username]\n );\n\n return (\n <PoliticsContainer className={className}>\n {title && <PoliticsTitle>{title}</PoliticsTitle>}\n <PoliticsItems>\n {politics.map(item => (\n <PolicyItem\n key={item.name}\n canUpdate={canUpdate}\n item={item}\n updatePolicyItem={updatePolicyItem}\n />\n ))}\n </PoliticsItems>\n </PoliticsContainer>\n );\n};\n","import politics_en from './en/politics.json';\nimport politics_ru from './ru/politics.json';\n\nexport const resources = {\n en: {\n politics: politics_en,\n },\n ru: {\n politics: politics_ru,\n },\n} as const;\n"],"names":["ApiContext","createContext","ApiProvider","api","children","React","Provider","value","useApi","useContext","resource","checkLimits","evergisApi","createResource","params","data","resourceCatalog","injected","usePolitics","username","onError","t","useTranslation","limits","refetch","error","use","input","userName","waitInput","useEffect","politics","useMemo","name","used","currentProjectCount","max","maxProjectsCount","type","PolicyType","CreateProject","icon","currentServiceCount","maxServicesCount","CreateLayer","currentTableCount","maxTablesCount","CreateTable","maxFeaturesInOneTable","MaxFeaturesInOneTable","maxUploadContentSize","MaxUploadContentSize","updatePolicy","useCallback","security","setPolicy","role","numberWithSpaces","maximumFractionDigits","undefined","parseFloat","toString","toLocaleString","PoliticsContainer","styled","Flex","PoliticsTitle","H2","PoliticsItems","PoliticsItemContainer","PoliticsItemContent","PoliticsItemIcon","Icon","PoliticsItemLimit","span","PoliticsItemType","theme","palette","textSecondary","PoliticsRatioContainer","div","PoliticsRatio","RatioLine","PoliticsLimit","WARN_ENTITY_COUNT_THRESHOLD","ERROR_ENTITY_COUNT_THRESHOLD","getRatioLineVariant","ratioUsed","secondary","primary","PolicyItem","item","updatePolicyItem","canUpdate","disabled","onMaxLimitChange","maxValue","toFixed","formattedMaxValue","key","kind","NumberInput","required","counter","width","onChange","ratio","Politics","title","className","debounce","useDebouncedCallback","fixedValue","map","resources","en","politics_en","ru","politics_ru"],"mappings":";;;;;;;;AAOA,MAAMA,UAAU,gBAAGC,aAAa,CAAkB,EAAlB,CAAhC;MAEaC,WAAW,GAAwB;MAAC;AAAEC,IAAAA,GAAF;AAAOC,IAAAA;AAAP;AAC/C,SAAOC,mBAAA,CAACL,UAAU,CAACM,QAAZ;AAAqBC,IAAAA,KAAK,EAAE;AAAEJ,MAAAA;AAAF;GAA5B,EAAsCC,QAAtC,CAAP;AACD;MAEYI,MAAM,GAAG;AACpB,SAAOC,UAAU,CAACT,UAAD,CAAjB;AACD;;ACZD,IAAIU,QAAJ;AAEA,MAAaC,WAAW,GAAIC,UAAD;AACzB,MAAI,CAACF,QAAL,EAAe;AACbA,IAAAA,QAAQ,GAAGG,cAAc,CACtBC,MAAD,IAA+B,MAAMX,GAAN,KAAc;AAC3CY,MAAAA,IAAI,EAAE,MAAMZ,GAAG,CAACa,eAAJ,CAAoBL,WAApB,CAAgCG,MAAhC;AAD+B,KAAd,CADR,EAIvB;AAAEG,MAAAA,QAAQ,EAAEL;AAAZ,KAJuB,CAAzB;AAMD;;AAED,SAAOF,QAAP;AACD,CAXM;;ACEA,MAAMQ,WAAW,GAAG,CACzBC,QADyB,EAEzBC,OAFyB;AAIzB,QAAM;AAAEC,IAAAA;AAAF,MAAQC,cAAc,CAAC,UAAD,CAA5B;AACA,QAAM;AAAEnB,IAAAA;AAAF,MAAUK,MAAM,EAAtB;AAEA,QAAM;AAAEO,IAAAA,IAAI,EAAEQ,MAAR;AAAgBC,IAAAA,OAAhB;AAAyBC,IAAAA;AAAzB,MAAmCd,WAAW,CAACR,GAAD,CAAX,CAAwBuB,GAAxB,C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mBAAA,CAAC+D,aAAD,MAAA,EACGrC,QAAQ,CAACkF,GAAT,CAAatB,IAAI,IAChBtF,mBAAA,CAACqF,UAAD;AACES,IAAAA,GAAG,EAAER,IAAI,CAAC1D;AACV4D,IAAAA,SAAS,EAAEA;AACXF,IAAAA,IAAI,EAAEA;AACNC,IAAAA,gBAAgB,EAAEA;GAJpB,CADD,CADH,CAFF,CADF;AAeD,CAxCM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MCLMsB,SAAS,GAAG;AACvBC,EAAAA,EAAE,EAAE;AACFpF,IAAAA,QAAQ,EAAEqF;AADR,GADmB;AAIvBC,EAAAA,EAAE,EAAE;AACFtF,IAAAA,QAAQ,EAAEuF;AADR;AAJmB,CAAlB;;;;"}
@@ -0,0 +1,3 @@
1
+ import { FC } from 'react';
2
+ import { PolicyItemProps } from './types';
3
+ export declare const PolicyItem: FC<PolicyItemProps>;
@@ -0,0 +1,2 @@
1
+ import { PoliticsItem, UpdatePolicy } from '../types';
2
+ export declare const usePolitics: (username?: string, onError?: (error: any) => void) => [PoliticsItem[], UpdatePolicy];
@@ -0,0 +1,3 @@
1
+ import { FC } from 'react';
2
+ import { PoliticsProps } from './types';
3
+ export declare const Politics: FC<PoliticsProps>;
@@ -0,0 +1,11 @@
1
+ export declare const PoliticsContainer: import("styled-components").StyledComponent<"div", any, import("@evergis/ui").IFlexProps, never>;
2
+ export declare const PoliticsTitle: import("styled-components").StyledComponent<"h2", any, {}, never>;
3
+ export declare const PoliticsItems: import("styled-components").StyledComponent<"div", any, import("@evergis/ui").IFlexProps, never>;
4
+ export declare const PoliticsItemContainer: import("styled-components").StyledComponent<"div", any, import("@evergis/ui").IFlexProps, never>;
5
+ export declare const PoliticsItemContent: import("styled-components").StyledComponent<"div", any, import("@evergis/ui").IFlexProps, never>;
6
+ export declare const PoliticsItemIcon: import("styled-components").StyledComponent<"span", any, import("@evergis/ui").IIconProps, never>;
7
+ export declare const PoliticsItemLimit: import("styled-components").StyledComponent<"span", any, {}, never>;
8
+ export declare const PoliticsItemType: import("styled-components").StyledComponent<"span", any, {}, never>;
9
+ export declare const PoliticsRatioContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
10
+ export declare const PoliticsRatio: import("styled-components").StyledComponent<import("react").FC<import("@evergis/ui").RatioLineProps>, any, {}, never>;
11
+ export declare const PoliticsLimit: import("styled-components").StyledComponent<"div", any, import("@evergis/ui").IFlexProps, never>;
@@ -0,0 +1,23 @@
1
+ import { PolicyType } from '@evergis/api';
2
+ import { IconTypesKeys } from '@evergis/ui';
3
+ export declare type PoliticsItem = {
4
+ name: string;
5
+ used?: number;
6
+ max: number;
7
+ type: PolicyType;
8
+ disabled?: boolean;
9
+ icon: IconTypesKeys;
10
+ };
11
+ export declare type PoliticsProps = {
12
+ username?: string;
13
+ canUpdate: boolean;
14
+ title?: string;
15
+ className?: string;
16
+ onError?: (error: any) => void;
17
+ };
18
+ export declare type UpdatePolicy = (value: number, type: PolicyType) => void;
19
+ export declare type PolicyItemProps = {
20
+ item: PoliticsItem;
21
+ updatePolicyItem: UpdatePolicy;
22
+ canUpdate: boolean;
23
+ };
@@ -0,0 +1 @@
1
+ export * from './Politics';
@@ -0,0 +1,24 @@
1
+ export declare const resources: {
2
+ readonly en: {
3
+ readonly politics: {
4
+ maps: string;
5
+ layers: string;
6
+ maxFeaturesInLayerLimit: string;
7
+ maxFileSize: string;
8
+ tables: string;
9
+ in: string;
10
+ from: string;
11
+ };
12
+ };
13
+ readonly ru: {
14
+ readonly politics: {
15
+ maps: string;
16
+ layers: string;
17
+ maxFeaturesInLayerLimit: string;
18
+ maxFileSize: string;
19
+ tables: string;
20
+ in: string;
21
+ from: string;
22
+ };
23
+ };
24
+ };
@@ -0,0 +1,5 @@
1
+ export * from './components';
2
+ export * from './resources';
3
+ export * from './utils';
4
+ export * from './i18n';
5
+ export * from './ApiProvider';
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+
2
+ 'use strict'
3
+
4
+ if (process.env.NODE_ENV === 'production') {
5
+ module.exports = require('./common.cjs.production.min.js')
6
+ } else {
7
+ module.exports = require('./common.cjs.development.js')
8
+ }
@@ -0,0 +1 @@
1
+ export * from './limits';
@@ -0,0 +1,2 @@
1
+ import { Api } from '@evergis/api';
2
+ export declare const checkLimits: (evergisApi: Api) => any;
@@ -0,0 +1 @@
1
+ export declare const numberWithSpaces: (input: number | string | null, maximumFractionDigits?: number) => string;
@@ -0,0 +1 @@
1
+ export * from './formatNumber';
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "version": "0.0.3",
3
+ "license": "MIT",
4
+ "main": "dist/index.js",
5
+ "typings": "dist/index.d.ts",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "engines": {
10
+ "node": ">=10"
11
+ },
12
+ "scripts": {
13
+ "start": "tsdx watch",
14
+ "build": "tsdx build",
15
+ "test": "tsdx test --passWithNoTests",
16
+ "lint": "tsdx lint",
17
+ "lint:fix": "tsdx lint --fix",
18
+ "prepare": "tsdx build"
19
+ },
20
+ "peerDependencies": {
21
+ "@evergis/api": ">=3.0.104",
22
+ "@evergis/react-fetching": ">=0.1.8",
23
+ "@evergis/sgis": ">=0.5.0",
24
+ "@evergis/ui": ">=2.0.116",
25
+ "react": ">=17",
26
+ "react-dom": ">=17",
27
+ "react-i18next": ">=11"
28
+ },
29
+ "husky": {
30
+ "hooks": {
31
+ "pre-push": "tsdx lint"
32
+ }
33
+ },
34
+ "prettier": {
35
+ "printWidth": 80,
36
+ "semi": true,
37
+ "singleQuote": true,
38
+ "trailingComma": "es5"
39
+ },
40
+ "name": "@evergis/common",
41
+ "author": "Everpoint",
42
+ "module": "dist/common.esm.js",
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "devDependencies": {
47
+ "@babel/core": "^7.17.5",
48
+ "@babel/plugin-transform-classes": "^7.16.7",
49
+ "@babel/preset-env": "^7.16.11",
50
+ "@evergis/api": "^3.0.105",
51
+ "@evergis/react-fetching": "0.1.8",
52
+ "@evergis/sgis": "0.5.0-alpha.21",
53
+ "@evergis/ui": "2.0.116-alpha.25",
54
+ "@types/react": "^17.0.36",
55
+ "@types/react-dom": "^16.9.8",
56
+ "@types/styled-components": "^5.1.3",
57
+ "babel-loader": "^8.2.3",
58
+ "i18next": "^21.6.13",
59
+ "react": "^17.0.2",
60
+ "react-docgen-typescript-loader": "^3.7.2",
61
+ "react-dom": "^17.0.2",
62
+ "react-i18next": "^11.15.5",
63
+ "react-is": "^17.0.2",
64
+ "styled-components": "5.3.5",
65
+ "ts-loader": "^8.0.5"
66
+ },
67
+ "gitHead": "a79dd81437a356bb120548a6e72241106bc83ac0"
68
+ }