@evergis/common 0.0.111 → 0.0.113

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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.111",
2
+ "version": "0.0.113",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -47,7 +47,7 @@
47
47
  "@babel/core": "^7.17.5",
48
48
  "@babel/plugin-transform-classes": "^7.16.7",
49
49
  "@babel/preset-env": "^7.16.11",
50
- "@evergis/api": "^3.0.213",
50
+ "@evergis/api": "^3.0.215",
51
51
  "@evergis/react-fetching": "0.1.8",
52
52
  "@evergis/sgis": "0.5.0-alpha.68",
53
53
  "@evergis/ui": "2.0.116-alpha.25",
@@ -64,5 +64,5 @@
64
64
  "styled-components": "5.3.5",
65
65
  "ts-loader": "^8.0.5"
66
66
  },
67
- "gitHead": "feda5145f5766ac15e3363f28ffd08b99c9aded1"
67
+ "gitHead": "f71807a4cab41dbd7b5f6d5a6047a69029ec540e"
68
68
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
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 DELETED
@@ -1,29 +0,0 @@
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
@@ -1,7 +0,0 @@
1
- import { FC } from 'react';
2
- import { Api } from '@evergis/api';
3
- export declare type ApiContextProps = {
4
- api?: Api;
5
- };
6
- export declare const ApiProvider: FC<ApiContextProps>;
7
- export declare const useApi: () => ApiContextProps;
@@ -1,310 +0,0 @@
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 React = require('react');
8
- var React__default = _interopDefault(React);
9
- var api = require('@evergis/api');
10
- var react = require('@evergis/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 = _ref => {
46
- let {
47
- username,
48
- onError,
49
- initialLimits
50
- } = _ref;
51
- const {
52
- t
53
- } = reactI18next.useTranslation('politics');
54
- const {
55
- api: api$1
56
- } = useApi();
57
- const {
58
- data: limits,
59
- refetch,
60
- error
61
- } = checkLimits(api$1).use({
62
- input: {
63
- userName: username
64
- },
65
- waitInput: true
66
- });
67
- React.useEffect(() => {
68
- if (error && onError) {
69
- onError(error);
70
- }
71
- }, [error, onError]);
72
- const politics = React.useMemo(() => {
73
- const currentLimits = limits || initialLimits;
74
- return currentLimits ? [{
75
- name: t('maps'),
76
- used: currentLimits.currentProjectCount,
77
- max: currentLimits.maxProjectsCount,
78
- type: api.PolicyType.CreateProject,
79
- icon: 'map'
80
- }, {
81
- name: t('layers'),
82
- used: currentLimits.currentServiceCount,
83
- max: currentLimits.maxServicesCount,
84
- type: api.PolicyType.CreateLayer,
85
- icon: 'layers'
86
- }, {
87
- name: t('tables'),
88
- used: currentLimits.currentTableCount,
89
- max: currentLimits.maxTablesCount,
90
- type: api.PolicyType.CreateTable,
91
- icon: 'table'
92
- }, {
93
- name: t('maxFeaturesInLayerLimit'),
94
- max: currentLimits.maxFeaturesInOneTable,
95
- type: api.PolicyType.MaxFeaturesInOneTable,
96
- icon: 'points'
97
- }, {
98
- name: t('maxFileSize'),
99
- max: currentLimits.maxUploadContentSize,
100
- type: api.PolicyType.MaxUploadContentSize,
101
- icon: 'textfile'
102
- }, {
103
- name: t('maxObjectsToExport'),
104
- max: currentLimits.maxObjectsToExport,
105
- type: api.PolicyType.MaxObjectsToExport,
106
- icon: 'points'
107
- }] : [];
108
- }, [t, limits, initialLimits]);
109
- const updatePolicy = React.useCallback(async (value, type) => {
110
- await api$1.security.setPolicy({
111
- value,
112
- type,
113
- role: "__" + username
114
- });
115
- await refetch();
116
- }, [api$1]);
117
- return [politics, updatePolicy];
118
- };
119
-
120
- const numberWithSpaces = function numberWithSpaces(input, maximumFractionDigits) {
121
- if (maximumFractionDigits === void 0) {
122
- maximumFractionDigits = 10;
123
- }
124
-
125
- if (input === null || input === undefined) {
126
- return '';
127
- }
128
-
129
- return parseFloat((typeof input === 'string' ? parseFloat(input) : input).toString()).toLocaleString('ru-RU', {
130
- maximumFractionDigits
131
- });
132
- };
133
-
134
- function _taggedTemplateLiteralLoose(strings, raw) {
135
- if (!raw) {
136
- raw = strings.slice(0);
137
- }
138
-
139
- strings.raw = raw;
140
- return strings;
141
- }
142
-
143
- var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11;
144
- const PoliticsContainer = /*#__PURE__*/styled(ui.Flex)(_templateObject || (_templateObject = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-top: 3rem;\n flex-direction: column;\n"])));
145
- const PoliticsTitle = /*#__PURE__*/styled(ui.H2)(_templateObject2 || (_templateObject2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin: 0;\n"])));
146
- 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"])));
147
- const PoliticsItemContainer = /*#__PURE__*/styled(ui.Flex)(_templateObject4 || (_templateObject4 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-top: 1rem;\n margin-right: 1rem;\n width: 14.5rem;\n height: 10.5rem;\n border-radius: 2px;\n background-color: #f6f6f6;\n flex-direction: column;\n"])));
148
- 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"])));
149
- const PoliticsItemIcon = /*#__PURE__*/styled(ui.Icon)(_templateObject6 || (_templateObject6 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n opacity: 0.28;\n"])));
150
- const PoliticsItemLimit = /*#__PURE__*/styled.span(_templateObject7 || (_templateObject7 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n font-size: 18px;\n font-weight: bold;\n margin-top: 0.75rem;\n"])));
151
- const PoliticsItemType = /*#__PURE__*/styled.span(_templateObject8 || (_templateObject8 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n font-size: 12px;\n color: ", ";\n text-align: center;\n"])), _ref => {
152
- let {
153
- theme: {
154
- palette
155
- }
156
- } = _ref;
157
- return palette.textSecondary;
158
- });
159
- const PoliticsRatioContainer = /*#__PURE__*/styled.div(_templateObject9 || (_templateObject9 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin: auto 0 0;\n height: 0.5rem;\n width: 100%;\n"])));
160
- const PoliticsRatio = /*#__PURE__*/styled(ui.RatioLine)(_templateObject10 || (_templateObject10 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n width: 100%;\n margin: 0;\n"])));
161
- 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"])));
162
-
163
- const WARN_ENTITY_COUNT_THRESHOLD = 75;
164
- const ERROR_ENTITY_COUNT_THRESHOLD = 90;
165
-
166
- function getRatioLineVariant(used, max) {
167
- const ratioUsed = used / max * 100;
168
-
169
- if (ratioUsed >= ERROR_ENTITY_COUNT_THRESHOLD) {
170
- return {
171
- error: true
172
- };
173
- }
174
-
175
- if (ratioUsed >= WARN_ENTITY_COUNT_THRESHOLD) {
176
- return {
177
- secondary: true
178
- };
179
- }
180
-
181
- return {
182
- primary: true
183
- };
184
- }
185
-
186
- const PolicyItem = _ref => {
187
- let {
188
- item,
189
- updatePolicyItem,
190
- canUpdate
191
- } = _ref;
192
- const {
193
- t
194
- } = reactI18next.useTranslation('politics');
195
- const {
196
- name,
197
- used,
198
- max,
199
- type,
200
- disabled,
201
- icon
202
- } = item;
203
- const onMaxLimitChange = React.useCallback(value => {
204
- updatePolicyItem(value || 0, type);
205
- }, [updatePolicyItem]);
206
- const maxValue = // @ts-ignore
207
- type === api.PolicyType.MaxUploadContentSize ? (max / (1024 * 1024)).toFixed(6) : max;
208
- const formattedMaxValue = numberWithSpaces(maxValue, 6);
209
- return React__default.createElement(PoliticsItemContainer, {
210
- key: name
211
- }, React__default.createElement(PoliticsItemContent, null, React__default.createElement(PoliticsItemIcon, {
212
- kind: icon
213
- }), React__default.createElement(PoliticsItemLimit, null, used !== undefined ? used + " " + t('from') + " " + (max === -1 ? '∞' : formattedMaxValue) : (max === -1 ? '∞' : formattedMaxValue) + " " + ( // @ts-ignore
214
- type === api.PolicyType.MaxUploadContentSize ? 'mb' : '')), React__default.createElement(PoliticsItemType, null, name), canUpdate && React__default.createElement(PoliticsLimit, null, React__default.createElement(ui.NumberInput, {
215
- required: true,
216
- disabled: disabled,
217
- counter: false,
218
- width: '100%',
219
- value: +maxValue,
220
- onChange: onMaxLimitChange
221
- }))), React__default.createElement(PoliticsRatioContainer, null, used !== undefined && React__default.createElement(PoliticsRatio, Object.assign({
222
- ratio: used / max * 100
223
- }, getRatioLineVariant(used, max)))));
224
- };
225
-
226
- const Politics = _ref => {
227
- let {
228
- username,
229
- canUpdate,
230
- title,
231
- className,
232
- initialLimits,
233
- onError
234
- } = _ref;
235
- const [politics, updatePolicy] = usePolitics({
236
- username,
237
- onError,
238
- initialLimits
239
- });
240
- const debounce = react.useDebouncedCallback(500);
241
- const updatePolicyItem = React.useCallback((value, type) => {
242
- debounce(async () => {
243
- const fixedValue = // max file size in mb
244
- // @ts-ignore
245
- type === api.PolicyType.MaxUploadContentSize ? value * 1024 * 1024 : value;
246
- await updatePolicy(fixedValue, type);
247
- });
248
- }, [username]);
249
- return React__default.createElement(PoliticsContainer, {
250
- className: className
251
- }, title && React__default.createElement(PoliticsTitle, null, title), React__default.createElement(PoliticsItems, null, politics.map(item => React__default.createElement(PolicyItem, {
252
- key: item.name,
253
- canUpdate: canUpdate,
254
- item: item,
255
- updatePolicyItem: updatePolicyItem
256
- }))));
257
- };
258
-
259
- var maps = "Maps";
260
- var layers = "Layers";
261
- var maxFeaturesInLayerLimit = "Max objects count in layer";
262
- var maxFileSize = "Max file size";
263
- var maxObjectsToExport = "Max objects to export";
264
- var tables = "Tables";
265
- var from = "from";
266
- var politics_en = {
267
- maps: maps,
268
- layers: layers,
269
- maxFeaturesInLayerLimit: maxFeaturesInLayerLimit,
270
- maxFileSize: maxFileSize,
271
- maxObjectsToExport: maxObjectsToExport,
272
- tables: tables,
273
- "in": "in",
274
- from: from
275
- };
276
-
277
- var maps$1 = "Карты";
278
- var layers$1 = "Слои";
279
- var maxFeaturesInLayerLimit$1 = "Макс. количество объектов в слое";
280
- var maxFileSize$1 = "Макс. размер файла";
281
- var maxObjectsToExport$1 = "Макс. количество объектов для экспорта";
282
- var tables$1 = "Таблицы";
283
- var from$1 = "из";
284
- var politics_ru = {
285
- maps: maps$1,
286
- layers: layers$1,
287
- maxFeaturesInLayerLimit: maxFeaturesInLayerLimit$1,
288
- maxFileSize: maxFileSize$1,
289
- maxObjectsToExport: maxObjectsToExport$1,
290
- tables: tables$1,
291
- "in": "в",
292
- from: from$1
293
- };
294
-
295
- const resources = {
296
- en: {
297
- politics: politics_en
298
- },
299
- ru: {
300
- politics: politics_ru
301
- }
302
- };
303
-
304
- exports.ApiProvider = ApiProvider;
305
- exports.Politics = Politics;
306
- exports.checkLimits = checkLimits;
307
- exports.numberWithSpaces = numberWithSpaces;
308
- exports.resources = resources;
309
- exports.useApi = useApi;
310
- //# sourceMappingURL=common.cjs.development.js.map
@@ -1 +0,0 @@
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 React, { createContext, FC, useContext } from 'react';\r\nimport { Api } from '@evergis/api';\r\n\r\nexport type ApiContextProps = {\r\n api?: Api;\r\n};\r\n\r\nconst ApiContext = createContext<ApiContextProps>({});\r\n\r\nexport const ApiProvider: FC<ApiContextProps> = ({ api, children }) => {\r\n return <ApiContext.Provider value={{ api }}>{children}</ApiContext.Provider>;\r\n};\r\n\r\nexport const useApi = (): ApiContextProps => {\r\n return useContext(ApiContext);\r\n};\r\n","import { Api, CheckLimitsParams } from '@evergis/api';\r\nimport { createResource } from '@evergis/react-fetching';\r\n\r\nlet resource: any;\r\n\r\nexport const checkLimits = (evergisApi: Api) => {\r\n if (!resource) {\r\n resource = createResource(\r\n (params: CheckLimitsParams) => async api => ({\r\n data: await api.resourceCatalog.checkLimits(params),\r\n }),\r\n { injected: evergisApi }\r\n );\r\n }\r\n\r\n return resource;\r\n};\r\n","import { Api, PolicyType, WorkspaceLimitsDc } from '@evergis/api';\r\nimport { useCallback, useEffect, useMemo } from 'react';\r\nimport { useTranslation } from 'react-i18next';\r\nimport { useApi } from '../../../ApiProvider';\r\nimport { checkLimits } from '../../../resources/limits';\r\nimport { PoliticsItem, UpdatePolicy } from '../types';\r\n\r\nexport type UsePoliticsConfig = {\r\n initialLimits?: WorkspaceLimitsDc;\r\n username?: string;\r\n onError?: (error: any) => void;\r\n};\r\n\r\nexport const usePolitics = ({\r\n username,\r\n onError,\r\n initialLimits,\r\n}: UsePoliticsConfig): [PoliticsItem[], UpdatePolicy] => {\r\n const { t } = useTranslation('politics');\r\n const { api } = useApi();\r\n\r\n const { data: limits, refetch, error } = checkLimits(api as Api).use({\r\n input: { userName: username },\r\n waitInput: true,\r\n });\r\n\r\n useEffect(() => {\r\n if (error && onError) {\r\n onError(error);\r\n }\r\n }, [error, onError]);\r\n\r\n const politics = useMemo<PoliticsItem[]>(() => {\r\n const currentLimits = limits || initialLimits;\r\n\r\n return currentLimits\r\n ? [\r\n {\r\n name: t('maps'),\r\n used: currentLimits.currentProjectCount as number,\r\n max: currentLimits.maxProjectsCount as number,\r\n type: PolicyType.CreateProject,\r\n icon: 'map',\r\n },\r\n {\r\n name: t('layers'),\r\n used: currentLimits.currentServiceCount as number,\r\n max: currentLimits.maxServicesCount as number,\r\n type: PolicyType.CreateLayer,\r\n icon: 'layers',\r\n },\r\n {\r\n name: t('tables'),\r\n used: currentLimits.currentTableCount as number,\r\n max: currentLimits.maxTablesCount as number,\r\n type: PolicyType.CreateTable,\r\n icon: 'table',\r\n },\r\n {\r\n name: t('maxFeaturesInLayerLimit'),\r\n max: currentLimits.maxFeaturesInOneTable as number,\r\n type: PolicyType.MaxFeaturesInOneTable,\r\n icon: 'points',\r\n },\r\n {\r\n name: t('maxFileSize'),\r\n max: currentLimits.maxUploadContentSize as number,\r\n type: PolicyType.MaxUploadContentSize,\r\n icon: 'textfile',\r\n },\r\n {\r\n name: t('maxObjectsToExport'),\r\n max: currentLimits.maxObjectsToExport as number,\r\n type: PolicyType.MaxObjectsToExport,\r\n icon: 'points',\r\n },\r\n ]\r\n : [];\r\n }, [t, limits, initialLimits]);\r\n\r\n const updatePolicy: UpdatePolicy = useCallback(\r\n async (value, type) => {\r\n await (api as Api).security.setPolicy({\r\n value,\r\n type,\r\n role: `__${username}`,\r\n });\r\n\r\n await refetch();\r\n },\r\n [api]\r\n );\r\n\r\n return [politics, updatePolicy];\r\n};\r\n","export const numberWithSpaces = (\r\n input: number | string | null,\r\n maximumFractionDigits = 10\r\n): string => {\r\n if (input === null || input === undefined) {\r\n return '';\r\n }\r\n\r\n return parseFloat(\r\n (typeof input === 'string' ? parseFloat(input) : input).toString()\r\n ).toLocaleString('ru-RU', {\r\n maximumFractionDigits,\r\n });\r\n};\r\n","import { Flex, H2, Icon, RatioLine } from '@evergis/ui';\r\nimport styled from 'styled-components';\r\n\r\nexport const PoliticsContainer = styled(Flex)`\r\n margin-top: 3rem;\r\n flex-direction: column;\r\n`;\r\n\r\nexport const PoliticsTitle = styled(H2)`\r\n margin: 0;\r\n`;\r\n\r\nexport const PoliticsItems = styled(Flex)`\r\n flex-wrap: wrap;\r\n margin-top: 0.5rem;\r\n margin-bottom: 0.75rem;\r\n`;\r\n\r\nexport const PoliticsItemContainer = styled(Flex)`\r\n margin-top: 1rem;\r\n margin-right: 1rem;\r\n width: 14.5rem;\r\n height: 10.5rem;\r\n border-radius: 2px;\r\n background-color: #f6f6f6;\r\n flex-direction: column;\r\n`;\r\n\r\nexport const PoliticsItemContent = styled(Flex)`\r\n flex-direction: column;\r\n align-items: center;\r\n padding: 1rem 1rem 0;\r\n width: 100%;\r\n box-sizing: border-box;\r\n`;\r\n\r\nexport const PoliticsItemIcon = styled(Icon)`\r\n opacity: 0.28;\r\n`;\r\n\r\nexport const PoliticsItemLimit = styled.span`\r\n font-size: 18px;\r\n font-weight: bold;\r\n margin-top: 0.75rem;\r\n`;\r\n\r\nexport const PoliticsItemType = styled.span`\r\n font-size: 12px;\r\n color: ${({ theme: { palette } }) => palette.textSecondary};\r\n text-align: center;\r\n`;\r\n\r\nexport const PoliticsRatioContainer = styled.div`\r\n margin: auto 0 0;\r\n height: 0.5rem;\r\n width: 100%;\r\n`;\r\n\r\nexport const PoliticsRatio = styled(RatioLine)`\r\n width: 100%;\r\n margin: 0;\r\n`;\r\n\r\nexport const PoliticsLimit = styled(Flex)`\r\n flex-direction: column;\r\n width: 100%;\r\n margin-top: 0.75rem;\r\n background: white;\r\n`;\r\n","import { PolicyType } from '@evergis/api';\r\nimport { NumberInput } from '@evergis/ui';\r\nimport React, { FC, useCallback } from 'react';\r\nimport { useTranslation } from 'react-i18next';\r\nimport { numberWithSpaces } from '../../utils';\r\nimport {\r\n PoliticsItemContainer,\r\n PoliticsItemContent,\r\n PoliticsItemIcon,\r\n PoliticsItemLimit,\r\n PoliticsItemType,\r\n PoliticsLimit,\r\n PoliticsRatio,\r\n PoliticsRatioContainer,\r\n} from './styled';\r\nimport { PolicyItemProps } from './types';\r\n\r\ntype RatioLineVariant = Partial<\r\n Record<'primary' | 'secondary' | 'error', boolean>\r\n>;\r\n\r\nconst WARN_ENTITY_COUNT_THRESHOLD = 75;\r\nconst ERROR_ENTITY_COUNT_THRESHOLD = 90;\r\n\r\nfunction getRatioLineVariant(used: number, max: number): RatioLineVariant {\r\n const ratioUsed = (used / max) * 100;\r\n\r\n if (ratioUsed >= ERROR_ENTITY_COUNT_THRESHOLD) {\r\n return { error: true };\r\n }\r\n\r\n if (ratioUsed >= WARN_ENTITY_COUNT_THRESHOLD) {\r\n return { secondary: true };\r\n }\r\n\r\n return { primary: true };\r\n}\r\n\r\nexport const PolicyItem: FC<PolicyItemProps> = ({\r\n item,\r\n updatePolicyItem,\r\n canUpdate,\r\n}) => {\r\n const { t } = useTranslation('politics');\r\n const { name, used, max, type, disabled, icon } = item;\r\n const onMaxLimitChange = useCallback(\r\n (value: number | null) => {\r\n updatePolicyItem(value || 0, type);\r\n },\r\n [updatePolicyItem]\r\n );\r\n\r\n const maxValue =\r\n // @ts-ignore\r\n type === PolicyType.MaxUploadContentSize\r\n ? (max / (1024 * 1024)).toFixed(6)\r\n : max;\r\n const formattedMaxValue = numberWithSpaces(maxValue, 6);\r\n\r\n return (\r\n <PoliticsItemContainer key={name}>\r\n <PoliticsItemContent>\r\n <PoliticsItemIcon kind={icon} />\r\n <PoliticsItemLimit>\r\n {used !== undefined\r\n ? `${used} ${t('from')} ${max === -1 ? '∞' : formattedMaxValue}`\r\n : `${max === -1 ? '∞' : formattedMaxValue} ${\r\n // @ts-ignore\r\n type === PolicyType.MaxUploadContentSize ? 'mb' : ''\r\n }`}\r\n </PoliticsItemLimit>\r\n <PoliticsItemType>{name}</PoliticsItemType>\r\n {canUpdate && (\r\n <PoliticsLimit>\r\n <NumberInput\r\n required\r\n disabled={disabled}\r\n counter={false}\r\n width={'100%'}\r\n value={+maxValue}\r\n onChange={onMaxLimitChange}\r\n />\r\n </PoliticsLimit>\r\n )}\r\n </PoliticsItemContent>\r\n <PoliticsRatioContainer>\r\n {used !== undefined && (\r\n <PoliticsRatio\r\n ratio={(used / max) * 100}\r\n {...getRatioLineVariant(used, max)}\r\n />\r\n )}\r\n </PoliticsRatioContainer>\r\n </PoliticsItemContainer>\r\n );\r\n};\r\n","import React, { FC, useCallback } from 'react';\r\nimport { PolicyType } from '@evergis/api';\r\nimport { useDebouncedCallback } from '@evergis/react';\r\n\r\nimport { usePolitics } from './hooks/usePolitics';\r\nimport { PolicyItem } from './PolicyItem';\r\nimport { PoliticsContainer, PoliticsItems, PoliticsTitle } from './styled';\r\nimport { PoliticsProps } from './types';\r\n\r\nexport const Politics: FC<PoliticsProps> = ({\r\n username,\r\n canUpdate,\r\n title,\r\n className,\r\n initialLimits,\r\n onError,\r\n}) => {\r\n const [politics, updatePolicy] = usePolitics({\r\n username,\r\n onError,\r\n initialLimits,\r\n });\r\n const debounce = useDebouncedCallback(500);\r\n const updatePolicyItem = useCallback(\r\n (value: number, type: PolicyType) => {\r\n debounce(async () => {\r\n const fixedValue =\r\n // max file size in mb\r\n // @ts-ignore\r\n type === PolicyType.MaxUploadContentSize\r\n ? value * 1024 * 1024\r\n : value;\r\n\r\n await updatePolicy(fixedValue, type);\r\n });\r\n },\r\n [username]\r\n );\r\n\r\n return (\r\n <PoliticsContainer className={className}>\r\n {title && <PoliticsTitle>{title}</PoliticsTitle>}\r\n <PoliticsItems>\r\n {politics.map(item => (\r\n <PolicyItem\r\n key={item.name}\r\n canUpdate={canUpdate}\r\n item={item}\r\n updatePolicyItem={updatePolicyItem}\r\n />\r\n ))}\r\n </PoliticsItems>\r\n </PoliticsContainer>\r\n );\r\n};\r\n","import politics_en from './en/politics.json';\r\nimport politics_ru from './ru/politics.json';\r\n\r\nexport const resources = {\r\n en: {\r\n politics: politics_en,\r\n },\r\n ru: {\r\n politics: politics_ru,\r\n },\r\n} as const;\r\n"],"names":["ApiContext","createContext","ApiProvider","api","children","React","Provider","value","useApi","useContext","resource","checkLimits","evergisApi","createResource","params","data","resourceCatalog","injected","usePolitics","username","onError","initialLimits","t","useTranslation","limits","refetch","error","use","input","userName","waitInput","useEffect","politics","useMemo","currentLimits","name","used","currentProjectCount","max","maxProjectsCount","type","PolicyType","CreateProject","icon","currentServiceCount","maxServicesCount","CreateLayer","currentTableCount","maxTablesCount","CreateTable","maxFeaturesInOneTable","MaxFeaturesInOneTable","maxUploadContentSize","MaxUploadContentSize","maxObjectsToExport","MaxObjectsToExport","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,KAA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D,MAAA,EACGxC,QAAQ,CAACqF,GAAT,CAAatB,IAAI,IAChB1F,4BAAA,CAACyF,UAAD;AACES,IAAAA,GAAG,EAAER,IAAI,CAAC5D;AACV8D,IAAAA,SAAS,EAAEA;AACXF,IAAAA,IAAI,EAAEA;AACNC,IAAAA,gBAAgB,EAAEA;GAJpB,CADD,CADH,CAFF,CADF;AAeD,CA7CM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MCNMsB,SAAS,GAAG;AACvBC,EAAAA,EAAE,EAAE;AACFvF,IAAAA,QAAQ,EAAEwF;AADR,GADmB;AAIvBC,EAAAA,EAAE,EAAE;AACFzF,IAAAA,QAAQ,EAAE0F;AADR;AAJmB,CAAlB;;;;;;;;;"}
@@ -1,2 +0,0 @@
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("react"),n=e(t),r=require("@evergis/api"),a=require("@evergis/react"),i=require("react-i18next"),o=require("@evergis/react-fetching"),l=require("@evergis/ui"),c=e(require("styled-components"));const s=t.createContext({}),m=()=>t.useContext(s);let u;const p=e=>(u||(u=o.createResource(e=>async t=>({data:await t.resourceCatalog.checkLimits(e)}),{injected:e})),u),x=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 d(e,t){return t||(t=e.slice(0)),e.raw=t,e}var y,b,g,f,E,C,T,h,P,v,F;const w=c(l.Flex)(y||(y=d(["\n margin-top: 3rem;\n flex-direction: column;\n"]))),L=c(l.H2)(b||(b=d(["\n margin: 0;\n"]))),j=c(l.Flex)(g||(g=d(["\n flex-wrap: wrap;\n margin-top: 0.5rem;\n margin-bottom: 0.75rem;\n"]))),S=c(l.Flex)(f||(f=d(["\n margin-top: 1rem;\n margin-right: 1rem;\n width: 14.5rem;\n height: 10.5rem;\n border-radius: 2px;\n background-color: #f6f6f6;\n flex-direction: column;\n"]))),z=c(l.Flex)(E||(E=d(["\n flex-direction: column;\n align-items: center;\n padding: 1rem 1rem 0;\n width: 100%;\n box-sizing: border-box;\n"]))),M=c(l.Icon)(C||(C=d(["\n opacity: 0.28;\n"]))),k=c.span(T||(T=d(["\n font-size: 18px;\n font-weight: bold;\n margin-top: 0.75rem;\n"]))),I=c.span(h||(h=d(["\n font-size: 12px;\n color: ",";\n text-align: center;\n"])),e=>{let{theme:{palette:t}}=e;return t.textSecondary}),O=c.div(P||(P=d(["\n margin: auto 0 0;\n height: 0.5rem;\n width: 100%;\n"]))),U=c(l.RatioLine)(v||(v=d(["\n width: 100%;\n margin: 0;\n"]))),q=c(l.Flex)(F||(F=d(["\n flex-direction: column;\n width: 100%;\n margin-top: 0.75rem;\n background: white;\n"]))),N=e=>{let{item:a,updatePolicyItem:o,canUpdate:c}=e;const{t:s}=i.useTranslation("politics"),{name:m,used:u,max:p,type:d,disabled:y,icon:b}=a,g=t.useCallback(e=>{o(e||0,d)},[o]),f=d===r.PolicyType.MaxUploadContentSize?(p/1048576).toFixed(6):p,E=x(f,6);return n.createElement(S,{key:m},n.createElement(z,null,n.createElement(M,{kind:b}),n.createElement(k,null,void 0!==u?u+" "+s("from")+" "+(-1===p?"∞":E):(-1===p?"∞":E)+" "+(d===r.PolicyType.MaxUploadContentSize?"mb":"")),n.createElement(I,null,m),c&&n.createElement(q,null,n.createElement(l.NumberInput,{required:!0,disabled:y,counter:!1,width:"100%",value:+f,onChange:g}))),n.createElement(O,null,void 0!==u&&n.createElement(U,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:r}=e;return n.createElement(s.Provider,{value:{api:t}},r)},exports.Politics=e=>{let{username:o,canUpdate:l,title:c,className:s,initialLimits:u,onError:x}=e;const[d,y]=(e=>{let{username:n,onError:a,initialLimits:o}=e;const{t:l}=i.useTranslation("politics"),{api:c}=m(),{data:s,refetch:u,error:x}=p(c).use({input:{userName:n},waitInput:!0});return t.useEffect(()=>{x&&a&&a(x)},[x,a]),[t.useMemo(()=>{const e=s||o;return e?[{name:l("maps"),used:e.currentProjectCount,max:e.maxProjectsCount,type:r.PolicyType.CreateProject,icon:"map"},{name:l("layers"),used:e.currentServiceCount,max:e.maxServicesCount,type:r.PolicyType.CreateLayer,icon:"layers"},{name:l("tables"),used:e.currentTableCount,max:e.maxTablesCount,type:r.PolicyType.CreateTable,icon:"table"},{name:l("maxFeaturesInLayerLimit"),max:e.maxFeaturesInOneTable,type:r.PolicyType.MaxFeaturesInOneTable,icon:"points"},{name:l("maxFileSize"),max:e.maxUploadContentSize,type:r.PolicyType.MaxUploadContentSize,icon:"textfile"},{name:l("maxObjectsToExport"),max:e.maxObjectsToExport,type:r.PolicyType.MaxObjectsToExport,icon:"points"}]:[]},[l,s,o]),t.useCallback(async(e,t)=>{await c.security.setPolicy({value:e,type:t,role:"__"+n}),await u()},[c])]})({username:o,onError:x,initialLimits:u}),b=a.useDebouncedCallback(500),g=t.useCallback((e,t)=>{b(async()=>{const n=t===r.PolicyType.MaxUploadContentSize?1024*e*1024:e;await y(n,t)})},[o]);return n.createElement(w,{className:s},c&&n.createElement(L,null,c),n.createElement(j,null,d.map(e=>n.createElement(N,{key:e.name,canUpdate:l,item:e,updatePolicyItem:g}))))},exports.checkLimits=p,exports.numberWithSpaces=x,exports.resources={en:{politics:{maps:"Maps",layers:"Layers",maxFeaturesInLayerLimit:"Max objects count in layer",maxFileSize:"Max file size",maxObjectsToExport:"Max objects to export",tables:"Tables",in:"in",from:"from"}},ru:{politics:{maps:"Карты",layers:"Слои",maxFeaturesInLayerLimit:"Макс. количество объектов в слое",maxFileSize:"Макс. размер файла",maxObjectsToExport:"Макс. количество объектов для экспорта",tables:"Таблицы",in:"в",from:"из"}}},exports.useApi=m;
2
- //# sourceMappingURL=common.cjs.production.min.js.map
@@ -1 +0,0 @@
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 React, { createContext, FC, useContext } from 'react';\r\nimport { Api } from '@evergis/api';\r\n\r\nexport type ApiContextProps = {\r\n api?: Api;\r\n};\r\n\r\nconst ApiContext = createContext<ApiContextProps>({});\r\n\r\nexport const ApiProvider: FC<ApiContextProps> = ({ api, children }) => {\r\n return <ApiContext.Provider value={{ api }}>{children}</ApiContext.Provider>;\r\n};\r\n\r\nexport const useApi = (): ApiContextProps => {\r\n return useContext(ApiContext);\r\n};\r\n","import { Api, CheckLimitsParams } from '@evergis/api';\r\nimport { createResource } from '@evergis/react-fetching';\r\n\r\nlet resource: any;\r\n\r\nexport const checkLimits = (evergisApi: Api) => {\r\n if (!resource) {\r\n resource = createResource(\r\n (params: CheckLimitsParams) => async api => ({\r\n data: await api.resourceCatalog.checkLimits(params),\r\n }),\r\n { injected: evergisApi }\r\n );\r\n }\r\n\r\n return resource;\r\n};\r\n","export const numberWithSpaces = (\r\n input: number | string | null,\r\n maximumFractionDigits = 10\r\n): string => {\r\n if (input === null || input === undefined) {\r\n return '';\r\n }\r\n\r\n return parseFloat(\r\n (typeof input === 'string' ? parseFloat(input) : input).toString()\r\n ).toLocaleString('ru-RU', {\r\n maximumFractionDigits,\r\n });\r\n};\r\n","import { Flex, H2, Icon, RatioLine } from '@evergis/ui';\r\nimport styled from 'styled-components';\r\n\r\nexport const PoliticsContainer = styled(Flex)`\r\n margin-top: 3rem;\r\n flex-direction: column;\r\n`;\r\n\r\nexport const PoliticsTitle = styled(H2)`\r\n margin: 0;\r\n`;\r\n\r\nexport const PoliticsItems = styled(Flex)`\r\n flex-wrap: wrap;\r\n margin-top: 0.5rem;\r\n margin-bottom: 0.75rem;\r\n`;\r\n\r\nexport const PoliticsItemContainer = styled(Flex)`\r\n margin-top: 1rem;\r\n margin-right: 1rem;\r\n width: 14.5rem;\r\n height: 10.5rem;\r\n border-radius: 2px;\r\n background-color: #f6f6f6;\r\n flex-direction: column;\r\n`;\r\n\r\nexport const PoliticsItemContent = styled(Flex)`\r\n flex-direction: column;\r\n align-items: center;\r\n padding: 1rem 1rem 0;\r\n width: 100%;\r\n box-sizing: border-box;\r\n`;\r\n\r\nexport const PoliticsItemIcon = styled(Icon)`\r\n opacity: 0.28;\r\n`;\r\n\r\nexport const PoliticsItemLimit = styled.span`\r\n font-size: 18px;\r\n font-weight: bold;\r\n margin-top: 0.75rem;\r\n`;\r\n\r\nexport const PoliticsItemType = styled.span`\r\n font-size: 12px;\r\n color: ${({ theme: { palette } }) => palette.textSecondary};\r\n text-align: center;\r\n`;\r\n\r\nexport const PoliticsRatioContainer = styled.div`\r\n margin: auto 0 0;\r\n height: 0.5rem;\r\n width: 100%;\r\n`;\r\n\r\nexport const PoliticsRatio = styled(RatioLine)`\r\n width: 100%;\r\n margin: 0;\r\n`;\r\n\r\nexport const PoliticsLimit = styled(Flex)`\r\n flex-direction: column;\r\n width: 100%;\r\n margin-top: 0.75rem;\r\n background: white;\r\n`;\r\n","import { PolicyType } from '@evergis/api';\r\nimport { NumberInput } from '@evergis/ui';\r\nimport React, { FC, useCallback } from 'react';\r\nimport { useTranslation } from 'react-i18next';\r\nimport { numberWithSpaces } from '../../utils';\r\nimport {\r\n PoliticsItemContainer,\r\n PoliticsItemContent,\r\n PoliticsItemIcon,\r\n PoliticsItemLimit,\r\n PoliticsItemType,\r\n PoliticsLimit,\r\n PoliticsRatio,\r\n PoliticsRatioContainer,\r\n} from './styled';\r\nimport { PolicyItemProps } from './types';\r\n\r\ntype RatioLineVariant = Partial<\r\n Record<'primary' | 'secondary' | 'error', boolean>\r\n>;\r\n\r\nconst WARN_ENTITY_COUNT_THRESHOLD = 75;\r\nconst ERROR_ENTITY_COUNT_THRESHOLD = 90;\r\n\r\nfunction getRatioLineVariant(used: number, max: number): RatioLineVariant {\r\n const ratioUsed = (used / max) * 100;\r\n\r\n if (ratioUsed >= ERROR_ENTITY_COUNT_THRESHOLD) {\r\n return { error: true };\r\n }\r\n\r\n if (ratioUsed >= WARN_ENTITY_COUNT_THRESHOLD) {\r\n return { secondary: true };\r\n }\r\n\r\n return { primary: true };\r\n}\r\n\r\nexport const PolicyItem: FC<PolicyItemProps> = ({\r\n item,\r\n updatePolicyItem,\r\n canUpdate,\r\n}) => {\r\n const { t } = useTranslation('politics');\r\n const { name, used, max, type, disabled, icon } = item;\r\n const onMaxLimitChange = useCallback(\r\n (value: number | null) => {\r\n updatePolicyItem(value || 0, type);\r\n },\r\n [updatePolicyItem]\r\n );\r\n\r\n const maxValue =\r\n // @ts-ignore\r\n type === PolicyType.MaxUploadContentSize\r\n ? (max / (1024 * 1024)).toFixed(6)\r\n : max;\r\n const formattedMaxValue = numberWithSpaces(maxValue, 6);\r\n\r\n return (\r\n <PoliticsItemContainer key={name}>\r\n <PoliticsItemContent>\r\n <PoliticsItemIcon kind={icon} />\r\n <PoliticsItemLimit>\r\n {used !== undefined\r\n ? `${used} ${t('from')} ${max === -1 ? '∞' : formattedMaxValue}`\r\n : `${max === -1 ? '∞' : formattedMaxValue} ${\r\n // @ts-ignore\r\n type === PolicyType.MaxUploadContentSize ? 'mb' : ''\r\n }`}\r\n </PoliticsItemLimit>\r\n <PoliticsItemType>{name}</PoliticsItemType>\r\n {canUpdate && (\r\n <PoliticsLimit>\r\n <NumberInput\r\n required\r\n disabled={disabled}\r\n counter={false}\r\n width={'100%'}\r\n value={+maxValue}\r\n onChange={onMaxLimitChange}\r\n />\r\n </PoliticsLimit>\r\n )}\r\n </PoliticsItemContent>\r\n <PoliticsRatioContainer>\r\n {used !== undefined && (\r\n <PoliticsRatio\r\n ratio={(used / max) * 100}\r\n {...getRatioLineVariant(used, max)}\r\n />\r\n )}\r\n </PoliticsRatioContainer>\r\n </PoliticsItemContainer>\r\n );\r\n};\r\n","import React, { FC, useCallback } from 'react';\r\nimport { PolicyType } from '@evergis/api';\r\nimport { useDebouncedCallback } from '@evergis/react';\r\n\r\nimport { usePolitics } from './hooks/usePolitics';\r\nimport { PolicyItem } from './PolicyItem';\r\nimport { PoliticsContainer, PoliticsItems, PoliticsTitle } from './styled';\r\nimport { PoliticsProps } from './types';\r\n\r\nexport const Politics: FC<PoliticsProps> = ({\r\n username,\r\n canUpdate,\r\n title,\r\n className,\r\n initialLimits,\r\n onError,\r\n}) => {\r\n const [politics, updatePolicy] = usePolitics({\r\n username,\r\n onError,\r\n initialLimits,\r\n });\r\n const debounce = useDebouncedCallback(500);\r\n const updatePolicyItem = useCallback(\r\n (value: number, type: PolicyType) => {\r\n debounce(async () => {\r\n const fixedValue =\r\n // max file size in mb\r\n // @ts-ignore\r\n type === PolicyType.MaxUploadContentSize\r\n ? value * 1024 * 1024\r\n : value;\r\n\r\n await updatePolicy(fixedValue, type);\r\n });\r\n },\r\n [username]\r\n );\r\n\r\n return (\r\n <PoliticsContainer className={className}>\r\n {title && <PoliticsTitle>{title}</PoliticsTitle>}\r\n <PoliticsItems>\r\n {politics.map(item => (\r\n <PolicyItem\r\n key={item.name}\r\n canUpdate={canUpdate}\r\n item={item}\r\n updatePolicyItem={updatePolicyItem}\r\n />\r\n ))}\r\n </PoliticsItems>\r\n </PoliticsContainer>\r\n );\r\n};\r\n","import { Api, PolicyType, WorkspaceLimitsDc } from '@evergis/api';\r\nimport { useCallback, useEffect, useMemo } from 'react';\r\nimport { useTranslation } from 'react-i18next';\r\nimport { useApi } from '../../../ApiProvider';\r\nimport { checkLimits } from '../../../resources/limits';\r\nimport { PoliticsItem, UpdatePolicy } from '../types';\r\n\r\nexport type UsePoliticsConfig = {\r\n initialLimits?: WorkspaceLimitsDc;\r\n username?: string;\r\n onError?: (error: any) => void;\r\n};\r\n\r\nexport const usePolitics = ({\r\n username,\r\n onError,\r\n initialLimits,\r\n}: UsePoliticsConfig): [PoliticsItem[], UpdatePolicy] => {\r\n const { t } = useTranslation('politics');\r\n const { api } = useApi();\r\n\r\n const { data: limits, refetch, error } = checkLimits(api as Api).use({\r\n input: { userName: username },\r\n waitInput: true,\r\n });\r\n\r\n useEffect(() => {\r\n if (error && onError) {\r\n onError(error);\r\n }\r\n }, [error, onError]);\r\n\r\n const politics = useMemo<PoliticsItem[]>(() => {\r\n const currentLimits = limits || initialLimits;\r\n\r\n return currentLimits\r\n ? [\r\n {\r\n name: t('maps'),\r\n used: currentLimits.currentProjectCount as number,\r\n max: currentLimits.maxProjectsCount as number,\r\n type: PolicyType.CreateProject,\r\n icon: 'map',\r\n },\r\n {\r\n name: t('layers'),\r\n used: currentLimits.currentServiceCount as number,\r\n max: currentLimits.maxServicesCount as number,\r\n type: PolicyType.CreateLayer,\r\n icon: 'layers',\r\n },\r\n {\r\n name: t('tables'),\r\n used: currentLimits.currentTableCount as number,\r\n max: currentLimits.maxTablesCount as number,\r\n type: PolicyType.CreateTable,\r\n icon: 'table',\r\n },\r\n {\r\n name: t('maxFeaturesInLayerLimit'),\r\n max: currentLimits.maxFeaturesInOneTable as number,\r\n type: PolicyType.MaxFeaturesInOneTable,\r\n icon: 'points',\r\n },\r\n {\r\n name: t('maxFileSize'),\r\n max: currentLimits.maxUploadContentSize as number,\r\n type: PolicyType.MaxUploadContentSize,\r\n icon: 'textfile',\r\n },\r\n {\r\n name: t('maxObjectsToExport'),\r\n max: currentLimits.maxObjectsToExport as number,\r\n type: PolicyType.MaxObjectsToExport,\r\n icon: 'points',\r\n },\r\n ]\r\n : [];\r\n }, [t, limits, initialLimits]);\r\n\r\n const updatePolicy: UpdatePolicy = useCallback(\r\n async (value, type) => {\r\n await (api as Api).security.setPolicy({\r\n value,\r\n type,\r\n role: `__${username}`,\r\n });\r\n\r\n await refetch();\r\n },\r\n [api]\r\n );\r\n\r\n return [politics, updatePolicy];\r\n};\r\n","import politics_en from './en/politics.json';\r\nimport politics_ru from './ru/politics.json';\r\n\r\nexport const resources = {\r\n en: {\r\n politics: politics_en,\r\n },\r\n ru: {\r\n politics: politics_ru,\r\n },\r\n} as const;\r\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","_ref","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","initialLimits","onError","politics","updatePolicy","limits","refetch","use","userName","waitInput","useEffect","useMemo","currentLimits","currentProjectCount","maxProjectsCount","CreateProject","currentServiceCount","maxServicesCount","CreateLayer","currentTableCount","maxTablesCount","CreateTable","maxFeaturesInOneTable","MaxFeaturesInOneTable","maxUploadContentSize","maxObjectsToExport","MaxObjectsToExport","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,mEAKpBE,EAAgBF,EAA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ACjBtD,KAAM,WAGR,IACH,CAACP,EAAGwC,EAAQJ,IAEoB3B,cACjC9C,MAAO+C,EAAOL,WACLxC,EAAYiG,SAASC,UAAU,CACpCrD,MAAAA,EACAL,KAAAA,EACA2D,UAAW/B,UAGPQ,KAER,CAAC5E,MDzE8BoG,CAAY,CAC3ChC,SAAAA,EACAI,QAAAA,EACAD,cAAAA,IAEI8B,EAAWC,uBAAqB,KAChCrE,EAAmBW,cACvB,CAACC,EAAeL,KACd6D,EAASvG,gBACDyG,EAGJ/D,IAASO,aAAWC,qBACR,KAARH,EAAe,KACfA,QAEA6B,EAAa6B,EAAY/D,MAGnC,CAAC4B,WAIDjB,gBAAC1C,GAAkB6D,UAAWA,GAC3BD,GAASlB,gBAACvC,OAAeyD,GAC1BlB,gBAACrC,OACE2D,EAAS+B,IAAIxE,GACZmB,gBAACpB,GACCqB,IAAKpB,EAAKK,KACVH,UAAWA,EACXF,KAAMA,EACNC,iBAAkBA,2EE7CL,CACvBwE,GAAI,CACFhC,wMAEFiC,GAAI,CACFjC"}
@@ -1,298 +0,0 @@
1
- import React, { useContext, createContext, useEffect, useMemo, useCallback } from 'react';
2
- import { PolicyType } from '@evergis/api';
3
- import { useDebouncedCallback } from '@evergis/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 = _ref => {
39
- let {
40
- username,
41
- onError,
42
- initialLimits
43
- } = _ref;
44
- const {
45
- t
46
- } = useTranslation('politics');
47
- const {
48
- api
49
- } = useApi();
50
- const {
51
- data: limits,
52
- refetch,
53
- error
54
- } = checkLimits(api).use({
55
- input: {
56
- userName: username
57
- },
58
- waitInput: true
59
- });
60
- useEffect(() => {
61
- if (error && onError) {
62
- onError(error);
63
- }
64
- }, [error, onError]);
65
- const politics = useMemo(() => {
66
- const currentLimits = limits || initialLimits;
67
- return currentLimits ? [{
68
- name: t('maps'),
69
- used: currentLimits.currentProjectCount,
70
- max: currentLimits.maxProjectsCount,
71
- type: PolicyType.CreateProject,
72
- icon: 'map'
73
- }, {
74
- name: t('layers'),
75
- used: currentLimits.currentServiceCount,
76
- max: currentLimits.maxServicesCount,
77
- type: PolicyType.CreateLayer,
78
- icon: 'layers'
79
- }, {
80
- name: t('tables'),
81
- used: currentLimits.currentTableCount,
82
- max: currentLimits.maxTablesCount,
83
- type: PolicyType.CreateTable,
84
- icon: 'table'
85
- }, {
86
- name: t('maxFeaturesInLayerLimit'),
87
- max: currentLimits.maxFeaturesInOneTable,
88
- type: PolicyType.MaxFeaturesInOneTable,
89
- icon: 'points'
90
- }, {
91
- name: t('maxFileSize'),
92
- max: currentLimits.maxUploadContentSize,
93
- type: PolicyType.MaxUploadContentSize,
94
- icon: 'textfile'
95
- }, {
96
- name: t('maxObjectsToExport'),
97
- max: currentLimits.maxObjectsToExport,
98
- type: PolicyType.MaxObjectsToExport,
99
- icon: 'points'
100
- }] : [];
101
- }, [t, limits, initialLimits]);
102
- const updatePolicy = useCallback(async (value, type) => {
103
- await api.security.setPolicy({
104
- value,
105
- type,
106
- role: "__" + username
107
- });
108
- await refetch();
109
- }, [api]);
110
- return [politics, updatePolicy];
111
- };
112
-
113
- const numberWithSpaces = function numberWithSpaces(input, maximumFractionDigits) {
114
- if (maximumFractionDigits === void 0) {
115
- maximumFractionDigits = 10;
116
- }
117
-
118
- if (input === null || input === undefined) {
119
- return '';
120
- }
121
-
122
- return parseFloat((typeof input === 'string' ? parseFloat(input) : input).toString()).toLocaleString('ru-RU', {
123
- maximumFractionDigits
124
- });
125
- };
126
-
127
- function _taggedTemplateLiteralLoose(strings, raw) {
128
- if (!raw) {
129
- raw = strings.slice(0);
130
- }
131
-
132
- strings.raw = raw;
133
- return strings;
134
- }
135
-
136
- var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11;
137
- const PoliticsContainer = /*#__PURE__*/styled(Flex)(_templateObject || (_templateObject = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-top: 3rem;\n flex-direction: column;\n"])));
138
- const PoliticsTitle = /*#__PURE__*/styled(H2)(_templateObject2 || (_templateObject2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin: 0;\n"])));
139
- const PoliticsItems = /*#__PURE__*/styled(Flex)(_templateObject3 || (_templateObject3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n flex-wrap: wrap;\n margin-top: 0.5rem;\n margin-bottom: 0.75rem;\n"])));
140
- const PoliticsItemContainer = /*#__PURE__*/styled(Flex)(_templateObject4 || (_templateObject4 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-top: 1rem;\n margin-right: 1rem;\n width: 14.5rem;\n height: 10.5rem;\n border-radius: 2px;\n background-color: #f6f6f6;\n flex-direction: column;\n"])));
141
- 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"])));
142
- const PoliticsItemIcon = /*#__PURE__*/styled(Icon)(_templateObject6 || (_templateObject6 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n opacity: 0.28;\n"])));
143
- const PoliticsItemLimit = /*#__PURE__*/styled.span(_templateObject7 || (_templateObject7 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n font-size: 18px;\n font-weight: bold;\n margin-top: 0.75rem;\n"])));
144
- const PoliticsItemType = /*#__PURE__*/styled.span(_templateObject8 || (_templateObject8 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n font-size: 12px;\n color: ", ";\n text-align: center;\n"])), _ref => {
145
- let {
146
- theme: {
147
- palette
148
- }
149
- } = _ref;
150
- return palette.textSecondary;
151
- });
152
- const PoliticsRatioContainer = /*#__PURE__*/styled.div(_templateObject9 || (_templateObject9 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin: auto 0 0;\n height: 0.5rem;\n width: 100%;\n"])));
153
- const PoliticsRatio = /*#__PURE__*/styled(RatioLine)(_templateObject10 || (_templateObject10 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n width: 100%;\n margin: 0;\n"])));
154
- 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"])));
155
-
156
- const WARN_ENTITY_COUNT_THRESHOLD = 75;
157
- const ERROR_ENTITY_COUNT_THRESHOLD = 90;
158
-
159
- function getRatioLineVariant(used, max) {
160
- const ratioUsed = used / max * 100;
161
-
162
- if (ratioUsed >= ERROR_ENTITY_COUNT_THRESHOLD) {
163
- return {
164
- error: true
165
- };
166
- }
167
-
168
- if (ratioUsed >= WARN_ENTITY_COUNT_THRESHOLD) {
169
- return {
170
- secondary: true
171
- };
172
- }
173
-
174
- return {
175
- primary: true
176
- };
177
- }
178
-
179
- const PolicyItem = _ref => {
180
- let {
181
- item,
182
- updatePolicyItem,
183
- canUpdate
184
- } = _ref;
185
- const {
186
- t
187
- } = useTranslation('politics');
188
- const {
189
- name,
190
- used,
191
- max,
192
- type,
193
- disabled,
194
- icon
195
- } = item;
196
- const onMaxLimitChange = useCallback(value => {
197
- updatePolicyItem(value || 0, type);
198
- }, [updatePolicyItem]);
199
- const maxValue = // @ts-ignore
200
- type === PolicyType.MaxUploadContentSize ? (max / (1024 * 1024)).toFixed(6) : max;
201
- const formattedMaxValue = numberWithSpaces(maxValue, 6);
202
- return React.createElement(PoliticsItemContainer, {
203
- key: name
204
- }, React.createElement(PoliticsItemContent, null, React.createElement(PoliticsItemIcon, {
205
- kind: icon
206
- }), React.createElement(PoliticsItemLimit, null, used !== undefined ? used + " " + t('from') + " " + (max === -1 ? '∞' : formattedMaxValue) : (max === -1 ? '∞' : formattedMaxValue) + " " + ( // @ts-ignore
207
- type === PolicyType.MaxUploadContentSize ? 'mb' : '')), React.createElement(PoliticsItemType, null, name), canUpdate && React.createElement(PoliticsLimit, null, React.createElement(NumberInput, {
208
- required: true,
209
- disabled: disabled,
210
- counter: false,
211
- width: '100%',
212
- value: +maxValue,
213
- onChange: onMaxLimitChange
214
- }))), React.createElement(PoliticsRatioContainer, null, used !== undefined && React.createElement(PoliticsRatio, Object.assign({
215
- ratio: used / max * 100
216
- }, getRatioLineVariant(used, max)))));
217
- };
218
-
219
- const Politics = _ref => {
220
- let {
221
- username,
222
- canUpdate,
223
- title,
224
- className,
225
- initialLimits,
226
- onError
227
- } = _ref;
228
- const [politics, updatePolicy] = usePolitics({
229
- username,
230
- onError,
231
- initialLimits
232
- });
233
- const debounce = useDebouncedCallback(500);
234
- const updatePolicyItem = useCallback((value, type) => {
235
- debounce(async () => {
236
- const fixedValue = // max file size in mb
237
- // @ts-ignore
238
- type === PolicyType.MaxUploadContentSize ? value * 1024 * 1024 : value;
239
- await updatePolicy(fixedValue, type);
240
- });
241
- }, [username]);
242
- return React.createElement(PoliticsContainer, {
243
- className: className
244
- }, title && React.createElement(PoliticsTitle, null, title), React.createElement(PoliticsItems, null, politics.map(item => React.createElement(PolicyItem, {
245
- key: item.name,
246
- canUpdate: canUpdate,
247
- item: item,
248
- updatePolicyItem: updatePolicyItem
249
- }))));
250
- };
251
-
252
- var maps = "Maps";
253
- var layers = "Layers";
254
- var maxFeaturesInLayerLimit = "Max objects count in layer";
255
- var maxFileSize = "Max file size";
256
- var maxObjectsToExport = "Max objects to export";
257
- var tables = "Tables";
258
- var from = "from";
259
- var politics_en = {
260
- maps: maps,
261
- layers: layers,
262
- maxFeaturesInLayerLimit: maxFeaturesInLayerLimit,
263
- maxFileSize: maxFileSize,
264
- maxObjectsToExport: maxObjectsToExport,
265
- tables: tables,
266
- "in": "in",
267
- from: from
268
- };
269
-
270
- var maps$1 = "Карты";
271
- var layers$1 = "Слои";
272
- var maxFeaturesInLayerLimit$1 = "Макс. количество объектов в слое";
273
- var maxFileSize$1 = "Макс. размер файла";
274
- var maxObjectsToExport$1 = "Макс. количество объектов для экспорта";
275
- var tables$1 = "Таблицы";
276
- var from$1 = "из";
277
- var politics_ru = {
278
- maps: maps$1,
279
- layers: layers$1,
280
- maxFeaturesInLayerLimit: maxFeaturesInLayerLimit$1,
281
- maxFileSize: maxFileSize$1,
282
- maxObjectsToExport: maxObjectsToExport$1,
283
- tables: tables$1,
284
- "in": "в",
285
- from: from$1
286
- };
287
-
288
- const resources = {
289
- en: {
290
- politics: politics_en
291
- },
292
- ru: {
293
- politics: politics_ru
294
- }
295
- };
296
-
297
- export { ApiProvider, Politics, checkLimits, numberWithSpaces, resources, useApi };
298
- //# sourceMappingURL=common.esm.js.map
@@ -1 +0,0 @@
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 React, { createContext, FC, useContext } from 'react';\r\nimport { Api } from '@evergis/api';\r\n\r\nexport type ApiContextProps = {\r\n api?: Api;\r\n};\r\n\r\nconst ApiContext = createContext<ApiContextProps>({});\r\n\r\nexport const ApiProvider: FC<ApiContextProps> = ({ api, children }) => {\r\n return <ApiContext.Provider value={{ api }}>{children}</ApiContext.Provider>;\r\n};\r\n\r\nexport const useApi = (): ApiContextProps => {\r\n return useContext(ApiContext);\r\n};\r\n","import { Api, CheckLimitsParams } from '@evergis/api';\r\nimport { createResource } from '@evergis/react-fetching';\r\n\r\nlet resource: any;\r\n\r\nexport const checkLimits = (evergisApi: Api) => {\r\n if (!resource) {\r\n resource = createResource(\r\n (params: CheckLimitsParams) => async api => ({\r\n data: await api.resourceCatalog.checkLimits(params),\r\n }),\r\n { injected: evergisApi }\r\n );\r\n }\r\n\r\n return resource;\r\n};\r\n","import { Api, PolicyType, WorkspaceLimitsDc } from '@evergis/api';\r\nimport { useCallback, useEffect, useMemo } from 'react';\r\nimport { useTranslation } from 'react-i18next';\r\nimport { useApi } from '../../../ApiProvider';\r\nimport { checkLimits } from '../../../resources/limits';\r\nimport { PoliticsItem, UpdatePolicy } from '../types';\r\n\r\nexport type UsePoliticsConfig = {\r\n initialLimits?: WorkspaceLimitsDc;\r\n username?: string;\r\n onError?: (error: any) => void;\r\n};\r\n\r\nexport const usePolitics = ({\r\n username,\r\n onError,\r\n initialLimits,\r\n}: UsePoliticsConfig): [PoliticsItem[], UpdatePolicy] => {\r\n const { t } = useTranslation('politics');\r\n const { api } = useApi();\r\n\r\n const { data: limits, refetch, error } = checkLimits(api as Api).use({\r\n input: { userName: username },\r\n waitInput: true,\r\n });\r\n\r\n useEffect(() => {\r\n if (error && onError) {\r\n onError(error);\r\n }\r\n }, [error, onError]);\r\n\r\n const politics = useMemo<PoliticsItem[]>(() => {\r\n const currentLimits = limits || initialLimits;\r\n\r\n return currentLimits\r\n ? [\r\n {\r\n name: t('maps'),\r\n used: currentLimits.currentProjectCount as number,\r\n max: currentLimits.maxProjectsCount as number,\r\n type: PolicyType.CreateProject,\r\n icon: 'map',\r\n },\r\n {\r\n name: t('layers'),\r\n used: currentLimits.currentServiceCount as number,\r\n max: currentLimits.maxServicesCount as number,\r\n type: PolicyType.CreateLayer,\r\n icon: 'layers',\r\n },\r\n {\r\n name: t('tables'),\r\n used: currentLimits.currentTableCount as number,\r\n max: currentLimits.maxTablesCount as number,\r\n type: PolicyType.CreateTable,\r\n icon: 'table',\r\n },\r\n {\r\n name: t('maxFeaturesInLayerLimit'),\r\n max: currentLimits.maxFeaturesInOneTable as number,\r\n type: PolicyType.MaxFeaturesInOneTable,\r\n icon: 'points',\r\n },\r\n {\r\n name: t('maxFileSize'),\r\n max: currentLimits.maxUploadContentSize as number,\r\n type: PolicyType.MaxUploadContentSize,\r\n icon: 'textfile',\r\n },\r\n {\r\n name: t('maxObjectsToExport'),\r\n max: currentLimits.maxObjectsToExport as number,\r\n type: PolicyType.MaxObjectsToExport,\r\n icon: 'points',\r\n },\r\n ]\r\n : [];\r\n }, [t, limits, initialLimits]);\r\n\r\n const updatePolicy: UpdatePolicy = useCallback(\r\n async (value, type) => {\r\n await (api as Api).security.setPolicy({\r\n value,\r\n type,\r\n role: `__${username}`,\r\n });\r\n\r\n await refetch();\r\n },\r\n [api]\r\n );\r\n\r\n return [politics, updatePolicy];\r\n};\r\n","export const numberWithSpaces = (\r\n input: number | string | null,\r\n maximumFractionDigits = 10\r\n): string => {\r\n if (input === null || input === undefined) {\r\n return '';\r\n }\r\n\r\n return parseFloat(\r\n (typeof input === 'string' ? parseFloat(input) : input).toString()\r\n ).toLocaleString('ru-RU', {\r\n maximumFractionDigits,\r\n });\r\n};\r\n","import { Flex, H2, Icon, RatioLine } from '@evergis/ui';\r\nimport styled from 'styled-components';\r\n\r\nexport const PoliticsContainer = styled(Flex)`\r\n margin-top: 3rem;\r\n flex-direction: column;\r\n`;\r\n\r\nexport const PoliticsTitle = styled(H2)`\r\n margin: 0;\r\n`;\r\n\r\nexport const PoliticsItems = styled(Flex)`\r\n flex-wrap: wrap;\r\n margin-top: 0.5rem;\r\n margin-bottom: 0.75rem;\r\n`;\r\n\r\nexport const PoliticsItemContainer = styled(Flex)`\r\n margin-top: 1rem;\r\n margin-right: 1rem;\r\n width: 14.5rem;\r\n height: 10.5rem;\r\n border-radius: 2px;\r\n background-color: #f6f6f6;\r\n flex-direction: column;\r\n`;\r\n\r\nexport const PoliticsItemContent = styled(Flex)`\r\n flex-direction: column;\r\n align-items: center;\r\n padding: 1rem 1rem 0;\r\n width: 100%;\r\n box-sizing: border-box;\r\n`;\r\n\r\nexport const PoliticsItemIcon = styled(Icon)`\r\n opacity: 0.28;\r\n`;\r\n\r\nexport const PoliticsItemLimit = styled.span`\r\n font-size: 18px;\r\n font-weight: bold;\r\n margin-top: 0.75rem;\r\n`;\r\n\r\nexport const PoliticsItemType = styled.span`\r\n font-size: 12px;\r\n color: ${({ theme: { palette } }) => palette.textSecondary};\r\n text-align: center;\r\n`;\r\n\r\nexport const PoliticsRatioContainer = styled.div`\r\n margin: auto 0 0;\r\n height: 0.5rem;\r\n width: 100%;\r\n`;\r\n\r\nexport const PoliticsRatio = styled(RatioLine)`\r\n width: 100%;\r\n margin: 0;\r\n`;\r\n\r\nexport const PoliticsLimit = styled(Flex)`\r\n flex-direction: column;\r\n width: 100%;\r\n margin-top: 0.75rem;\r\n background: white;\r\n`;\r\n","import { PolicyType } from '@evergis/api';\r\nimport { NumberInput } from '@evergis/ui';\r\nimport React, { FC, useCallback } from 'react';\r\nimport { useTranslation } from 'react-i18next';\r\nimport { numberWithSpaces } from '../../utils';\r\nimport {\r\n PoliticsItemContainer,\r\n PoliticsItemContent,\r\n PoliticsItemIcon,\r\n PoliticsItemLimit,\r\n PoliticsItemType,\r\n PoliticsLimit,\r\n PoliticsRatio,\r\n PoliticsRatioContainer,\r\n} from './styled';\r\nimport { PolicyItemProps } from './types';\r\n\r\ntype RatioLineVariant = Partial<\r\n Record<'primary' | 'secondary' | 'error', boolean>\r\n>;\r\n\r\nconst WARN_ENTITY_COUNT_THRESHOLD = 75;\r\nconst ERROR_ENTITY_COUNT_THRESHOLD = 90;\r\n\r\nfunction getRatioLineVariant(used: number, max: number): RatioLineVariant {\r\n const ratioUsed = (used / max) * 100;\r\n\r\n if (ratioUsed >= ERROR_ENTITY_COUNT_THRESHOLD) {\r\n return { error: true };\r\n }\r\n\r\n if (ratioUsed >= WARN_ENTITY_COUNT_THRESHOLD) {\r\n return { secondary: true };\r\n }\r\n\r\n return { primary: true };\r\n}\r\n\r\nexport const PolicyItem: FC<PolicyItemProps> = ({\r\n item,\r\n updatePolicyItem,\r\n canUpdate,\r\n}) => {\r\n const { t } = useTranslation('politics');\r\n const { name, used, max, type, disabled, icon } = item;\r\n const onMaxLimitChange = useCallback(\r\n (value: number | null) => {\r\n updatePolicyItem(value || 0, type);\r\n },\r\n [updatePolicyItem]\r\n );\r\n\r\n const maxValue =\r\n // @ts-ignore\r\n type === PolicyType.MaxUploadContentSize\r\n ? (max / (1024 * 1024)).toFixed(6)\r\n : max;\r\n const formattedMaxValue = numberWithSpaces(maxValue, 6);\r\n\r\n return (\r\n <PoliticsItemContainer key={name}>\r\n <PoliticsItemContent>\r\n <PoliticsItemIcon kind={icon} />\r\n <PoliticsItemLimit>\r\n {used !== undefined\r\n ? `${used} ${t('from')} ${max === -1 ? '∞' : formattedMaxValue}`\r\n : `${max === -1 ? '∞' : formattedMaxValue} ${\r\n // @ts-ignore\r\n type === PolicyType.MaxUploadContentSize ? 'mb' : ''\r\n }`}\r\n </PoliticsItemLimit>\r\n <PoliticsItemType>{name}</PoliticsItemType>\r\n {canUpdate && (\r\n <PoliticsLimit>\r\n <NumberInput\r\n required\r\n disabled={disabled}\r\n counter={false}\r\n width={'100%'}\r\n value={+maxValue}\r\n onChange={onMaxLimitChange}\r\n />\r\n </PoliticsLimit>\r\n )}\r\n </PoliticsItemContent>\r\n <PoliticsRatioContainer>\r\n {used !== undefined && (\r\n <PoliticsRatio\r\n ratio={(used / max) * 100}\r\n {...getRatioLineVariant(used, max)}\r\n />\r\n )}\r\n </PoliticsRatioContainer>\r\n </PoliticsItemContainer>\r\n );\r\n};\r\n","import React, { FC, useCallback } from 'react';\r\nimport { PolicyType } from '@evergis/api';\r\nimport { useDebouncedCallback } from '@evergis/react';\r\n\r\nimport { usePolitics } from './hooks/usePolitics';\r\nimport { PolicyItem } from './PolicyItem';\r\nimport { PoliticsContainer, PoliticsItems, PoliticsTitle } from './styled';\r\nimport { PoliticsProps } from './types';\r\n\r\nexport const Politics: FC<PoliticsProps> = ({\r\n username,\r\n canUpdate,\r\n title,\r\n className,\r\n initialLimits,\r\n onError,\r\n}) => {\r\n const [politics, updatePolicy] = usePolitics({\r\n username,\r\n onError,\r\n initialLimits,\r\n });\r\n const debounce = useDebouncedCallback(500);\r\n const updatePolicyItem = useCallback(\r\n (value: number, type: PolicyType) => {\r\n debounce(async () => {\r\n const fixedValue =\r\n // max file size in mb\r\n // @ts-ignore\r\n type === PolicyType.MaxUploadContentSize\r\n ? value * 1024 * 1024\r\n : value;\r\n\r\n await updatePolicy(fixedValue, type);\r\n });\r\n },\r\n [username]\r\n );\r\n\r\n return (\r\n <PoliticsContainer className={className}>\r\n {title && <PoliticsTitle>{title}</PoliticsTitle>}\r\n <PoliticsItems>\r\n {politics.map(item => (\r\n <PolicyItem\r\n key={item.name}\r\n canUpdate={canUpdate}\r\n item={item}\r\n updatePolicyItem={updatePolicyItem}\r\n />\r\n ))}\r\n </PoliticsItems>\r\n </PoliticsContainer>\r\n );\r\n};\r\n","import politics_en from './en/politics.json';\r\nimport politics_ru from './ru/politics.json';\r\n\r\nexport const resources = {\r\n en: {\r\n politics: politics_en,\r\n },\r\n ru: {\r\n politics: politics_ru,\r\n },\r\n} as const;\r\n"],"names":["ApiContext","createContext","ApiProvider","api","children","React","Provider","value","useApi","useContext","resource","checkLimits","evergisApi","createResource","params","data","resourceCatalog","injected","usePolitics","username","onError","initialLimits","t","useTranslation","limits","refetch","error","use","input","userName","waitInput","useEffect","politics","useMemo","currentLimits","name","used","currentProjectCount","max","maxProjectsCount","type","PolicyType","CreateProject","icon","currentServiceCount","maxServicesCount","CreateLayer","currentTableCount","maxTablesCount","CreateTable","maxFeaturesInOneTable","MaxFeaturesInOneTable","maxUploadContentSize","MaxUploadContentSize","maxObjectsToExport","MaxObjectsToExport","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;;ACQA,MAA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olicyItemProps } from './types';
3
- export declare const PolicyItem: FC<PolicyItemProps>;
@@ -1,8 +0,0 @@
1
- import { WorkspaceLimitsDc } from '@evergis/api';
2
- import { PoliticsItem, UpdatePolicy } from '../types';
3
- export declare type UsePoliticsConfig = {
4
- initialLimits?: WorkspaceLimitsDc;
5
- username?: string;
6
- onError?: (error: any) => void;
7
- };
8
- export declare const usePolitics: ({ username, onError, initialLimits, }: UsePoliticsConfig) => [PoliticsItem[], UpdatePolicy];
@@ -1,3 +0,0 @@
1
- import { FC } from 'react';
2
- import { PoliticsProps } from './types';
3
- export declare const Politics: FC<PoliticsProps>;
@@ -1,11 +0,0 @@
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>;
@@ -1,24 +0,0 @@
1
- import { PolicyType, WorkspaceLimitsDc } 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
- initialLimits?: WorkspaceLimitsDc;
17
- onError?: (error: any) => void;
18
- };
19
- export declare type UpdatePolicy = (value: number, type: PolicyType) => void;
20
- export declare type PolicyItemProps = {
21
- item: PoliticsItem;
22
- updatePolicyItem: UpdatePolicy;
23
- canUpdate: boolean;
24
- };
@@ -1 +0,0 @@
1
- export * from './Politics';
@@ -1,24 +0,0 @@
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
- };
package/dist/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from './components';
2
- export * from './resources';
3
- export * from './utils';
4
- export * from './i18n';
5
- export * from './ApiProvider';
@@ -1 +0,0 @@
1
- export * from './limits';
@@ -1,2 +0,0 @@
1
- import { Api } from '@evergis/api';
2
- export declare const checkLimits: (evergisApi: Api) => any;
@@ -1 +0,0 @@
1
- export declare const numberWithSpaces: (input: number | string | null, maximumFractionDigits?: number) => string;
@@ -1 +0,0 @@
1
- export * from './formatNumber';