@astral/features 3.107.0 → 3.109.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/node/productSwitcher/components/AstralProductSwitcher/AstralProductSwitcher.d.ts +7 -2
  2. package/node/productSwitcher/components/AstralProductSwitcher/AstralProductSwitcher.js +11 -3
  3. package/node/productSwitcher/components/AstralProductSwitcher/enums.d.ts +4 -0
  4. package/node/productSwitcher/components/AstralProductSwitcher/enums.js +8 -0
  5. package/node/productSwitcher/components/AstralProductSwitcher/index.d.ts +1 -0
  6. package/node/productSwitcher/components/AstralProductSwitcher/index.js +1 -0
  7. package/node/productSwitcher/components/AstralProductSwitcher/utils/getFilteredProducts/getFilteredProducts.d.ts +7 -0
  8. package/node/productSwitcher/components/AstralProductSwitcher/utils/getFilteredProducts/getFilteredProducts.js +23 -0
  9. package/node/productSwitcher/components/AstralProductSwitcher/utils/getFilteredProducts/index.d.ts +1 -0
  10. package/node/productSwitcher/components/AstralProductSwitcher/utils/getFilteredProducts/index.js +17 -0
  11. package/node/productSwitcher/components/AstralProductSwitcher/utils/index.d.ts +1 -0
  12. package/node/productSwitcher/components/AstralProductSwitcher/utils/index.js +17 -0
  13. package/node/productSwitcher/components/IdentityProductSwitcher/IdentityProductSwitcher.js +2 -2
  14. package/node/productSwitcher/components/IdentityProductSwitcher/hooks/useLogic/useLogic.d.ts +1 -0
  15. package/node/productSwitcher/components/IdentityProductSwitcher/hooks/useLogic/useLogic.js +2 -0
  16. package/node/productSwitcher/utils/getGroupsProducts/getGroupsProducts.d.ts +6 -0
  17. package/node/productSwitcher/utils/getGroupsProducts/getGroupsProducts.js +31 -0
  18. package/node/productSwitcher/utils/getGroupsProducts/index.d.ts +1 -0
  19. package/node/productSwitcher/utils/getGroupsProducts/index.js +17 -0
  20. package/node/productSwitcher/utils/getIdentityProducts/getIdentityProducts.d.ts +2 -2
  21. package/node/productSwitcher/utils/getIdentityProducts/getIdentityProducts.js +3 -3
  22. package/package.json +2 -2
  23. package/productSwitcher/components/AstralProductSwitcher/AstralProductSwitcher.d.ts +7 -2
  24. package/productSwitcher/components/AstralProductSwitcher/AstralProductSwitcher.js +11 -3
  25. package/productSwitcher/components/AstralProductSwitcher/enums.d.ts +4 -0
  26. package/productSwitcher/components/AstralProductSwitcher/enums.js +5 -0
  27. package/productSwitcher/components/AstralProductSwitcher/index.d.ts +1 -0
  28. package/productSwitcher/components/AstralProductSwitcher/index.js +1 -0
  29. package/productSwitcher/components/AstralProductSwitcher/utils/getFilteredProducts/getFilteredProducts.d.ts +7 -0
  30. package/productSwitcher/components/AstralProductSwitcher/utils/getFilteredProducts/getFilteredProducts.js +19 -0
  31. package/productSwitcher/components/AstralProductSwitcher/utils/getFilteredProducts/index.d.ts +1 -0
  32. package/productSwitcher/components/AstralProductSwitcher/utils/getFilteredProducts/index.js +1 -0
  33. package/productSwitcher/components/AstralProductSwitcher/utils/index.d.ts +1 -0
  34. package/productSwitcher/components/AstralProductSwitcher/utils/index.js +1 -0
  35. package/productSwitcher/components/IdentityProductSwitcher/IdentityProductSwitcher.js +2 -2
  36. package/productSwitcher/components/IdentityProductSwitcher/hooks/useLogic/useLogic.d.ts +1 -0
  37. package/productSwitcher/components/IdentityProductSwitcher/hooks/useLogic/useLogic.js +2 -0
  38. package/productSwitcher/utils/getGroupsProducts/getGroupsProducts.d.ts +6 -0
  39. package/productSwitcher/utils/getGroupsProducts/getGroupsProducts.js +27 -0
  40. package/productSwitcher/utils/getGroupsProducts/index.d.ts +1 -0
  41. package/productSwitcher/utils/getGroupsProducts/index.js +1 -0
  42. package/productSwitcher/utils/getIdentityProducts/getIdentityProducts.d.ts +2 -2
  43. package/productSwitcher/utils/getIdentityProducts/getIdentityProducts.js +3 -3
@@ -1,12 +1,17 @@
1
+ import { ProductFilterType } from './enums';
1
2
  export type AstralProductSwitcherType = {
2
3
  /**
3
4
  * Адрес identity
4
5
  * */
5
6
  identityUrl: string;
7
+ /** Тип фильтрации продуктов */
8
+ filterBy?: ProductFilterType;
9
+ /** Код для фильтрации */
10
+ code?: string;
6
11
  /**
7
12
  * Идентификатор экосистемы
8
- * @default astral
13
+ * @deprecated
9
14
  * */
10
15
  tenantId?: string;
11
16
  };
12
- export declare const AstralProductSwitcher: ({ identityUrl, tenantId, }: AstralProductSwitcherType) => import("react/jsx-runtime").JSX.Element;
17
+ export declare const AstralProductSwitcher: ({ identityUrl, filterBy, code, tenantId, }: AstralProductSwitcherType) => import("react/jsx-runtime").JSX.Element;
@@ -14,15 +14,23 @@ const jsx_runtime_1 = require("react/jsx-runtime");
14
14
  const ui_1 = require("@astral/ui");
15
15
  const react_1 = require("react");
16
16
  const utils_1 = require("../../utils");
17
- const AstralProductSwitcher = ({ identityUrl, tenantId = 'astral', }) => {
17
+ const enums_1 = require("./enums");
18
+ const utils_2 = require("./utils");
19
+ const AstralProductSwitcher = ({ identityUrl, filterBy = enums_1.ProductFilterType.Tenant, code = 'astral', tenantId, }) => {
18
20
  const [products, setProducts] = (0, react_1.useState)([]);
19
21
  const handleGetProducts = () => __awaiter(void 0, void 0, void 0, function* () {
20
- if (!products.length) {
22
+ if (products.length) {
23
+ return products;
24
+ }
25
+ // Это заглушка для обратной совместимости, убрать после релиза мажорной версии
26
+ if (tenantId) {
21
27
  const productsList = yield (0, utils_1.getIdentityProducts)(identityUrl, tenantId);
22
28
  setProducts(productsList);
23
29
  return productsList;
24
30
  }
25
- return products;
31
+ const filteredProductsList = yield (0, utils_2.getFilteredProducts)(identityUrl, filterBy, code);
32
+ setProducts(filteredProductsList);
33
+ return filteredProductsList;
26
34
  });
27
35
  return (0, jsx_runtime_1.jsx)(ui_1.ProductSwitcher, { getProducts: handleGetProducts });
28
36
  };
@@ -0,0 +1,4 @@
1
+ export declare enum ProductFilterType {
2
+ Tenant = "tenant",
3
+ Group = "group"
4
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProductFilterType = void 0;
4
+ var ProductFilterType;
5
+ (function (ProductFilterType) {
6
+ ProductFilterType["Tenant"] = "tenant";
7
+ ProductFilterType["Group"] = "group";
8
+ })(ProductFilterType || (exports.ProductFilterType = ProductFilterType = {}));
@@ -1 +1,2 @@
1
1
  export * from './AstralProductSwitcher';
2
+ export * from './enums';
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./AstralProductSwitcher"), exports);
18
+ __exportStar(require("./enums"), exports);
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Получение всех продуктов из разных экосистем и группировка в единую мапу
3
+ * @param identityUrl - адрес экосистемы
4
+ * @param filterBy - тип фильтрации продуктов
5
+ * @param code - код-значение для фильтрации
6
+ */
7
+ export declare const getFilteredProducts: (identityUrl: string, filterBy: string, code: string) => Promise<import("@astral/components").WidgetProduct[]>;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFilteredProducts = void 0;
4
+ const utils_1 = require("../../../../utils");
5
+ const enums_1 = require("../../enums");
6
+ const getGroupsProducts_1 = require("../../../../utils/getGroupsProducts");
7
+ /**
8
+ * Получение всех продуктов из разных экосистем и группировка в единую мапу
9
+ * @param identityUrl - адрес экосистемы
10
+ * @param filterBy - тип фильтрации продуктов
11
+ * @param code - код-значение для фильтрации
12
+ */
13
+ const getFilteredProducts = (identityUrl, filterBy, code) => {
14
+ switch (filterBy) {
15
+ case enums_1.ProductFilterType.Group: {
16
+ return (0, getGroupsProducts_1.getGroupsProducts)(identityUrl, code);
17
+ }
18
+ default: {
19
+ return (0, utils_1.getIdentityProducts)(identityUrl, code);
20
+ }
21
+ }
22
+ };
23
+ exports.getFilteredProducts = getFilteredProducts;
@@ -0,0 +1 @@
1
+ export * from './getFilteredProducts';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./getFilteredProducts"), exports);
@@ -0,0 +1 @@
1
+ export * from './getFilteredProducts';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./getFilteredProducts"), exports);
@@ -8,12 +8,12 @@ const hooks_1 = require("./hooks");
8
8
  exports.ASTRAL_IDENTITY_DEFAULT_TENANT = 'astral';
9
9
  const IdentityProductSwitcher = ({ identityUrl, }) => {
10
10
  const { open, anchorRef, handleOpenMenu, handleCloseMenu } = (0, ui_1.useMenu)();
11
- const { isLoading, isError, tenantId, tenants, productList, handleChangeTenant, handleShowProducts, } = (0, hooks_1.useLogic)(identityUrl, handleOpenMenu);
11
+ const { isLoading, isError, tenantId, tenants, productList, handleChangeTenant, handleShowProducts, isShowToggleButton, } = (0, hooks_1.useLogic)(identityUrl, handleOpenMenu);
12
12
  return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(ui_1.IconButton, { ref: anchorRef, selected: open, variant: "text", onClick: handleShowProducts, children: (0, jsx_runtime_1.jsx)(ui_1.ProductsFillMd, {}) }), (0, jsx_runtime_1.jsx)(styles_1.StyledMenu, { open: open, anchorEl: anchorRef.current, onClose: handleCloseMenu, children: (0, jsx_runtime_1.jsx)(ui_1.MenuGroup, { label: "\u041F\u0440\u043E\u0434\u0443\u043A\u0442\u044B \u044D\u043A\u043E\u0441\u0438\u0441\u0442\u0435\u043C\u044B", children: (0, jsx_runtime_1.jsxs)(ui_1.ContentState, { isLoading: isLoading, isCustom: isError, customState: {
13
13
  imgAlt: 'Что-то пошло не так',
14
14
  title: ((0, jsx_runtime_1.jsxs)(styles_1.ErrorContainer, { container: true, autoFlow: "column", alignItems: "center", justifyContent: "center", component: "span", children: [(0, jsx_runtime_1.jsx)(ui_1.ErrorFillSm, { color: "inherit" }), (0, jsx_runtime_1.jsx)(ui_1.Typography, { variant: "h6", color: "grey", colorIntensity: "900", children: "\u0427\u0442\u043E-\u0442\u043E \u043F\u043E\u0448\u043B\u043E \u043D\u0435 \u0442\u0430\u043A" })] })),
15
15
  description: 'Произошла ошибка. Повторите попытку позже.',
16
- }, children: [Boolean(tenants === null || tenants === void 0 ? void 0 : tenants.length) && ((0, jsx_runtime_1.jsx)(styles_1.TenantsToggleButtonGroup, { exclusive: true, onChange: handleChangeTenant, value: tenantId, children: tenants === null || tenants === void 0 ? void 0 : tenants.map(({ id, name }) => ((0, jsx_runtime_1.jsx)(styles_1.TenantToggleButton, { value: id, children: name }, id))) })), productList === null || productList === void 0 ? void 0 : productList.map((product) => {
16
+ }, children: [isShowToggleButton && ((0, jsx_runtime_1.jsx)(styles_1.TenantsToggleButtonGroup, { exclusive: true, onChange: handleChangeTenant, value: tenantId, children: tenants === null || tenants === void 0 ? void 0 : tenants.map(({ id, name }) => ((0, jsx_runtime_1.jsx)(styles_1.TenantToggleButton, { value: id, children: name }, id))) })), productList === null || productList === void 0 ? void 0 : productList.map((product) => {
17
17
  return ((0, jsx_runtime_1.jsx)("li", { children: (0, jsx_runtime_1.jsxs)(styles_1.StyledMenuItem, { component: "a", href: product.url, children: [(0, jsx_runtime_1.jsx)(styles_1.Logo, { src: product.logoUrl, color: product.color }), (0, jsx_runtime_1.jsx)(ui_1.Typography, { variant: "ui", color: "grey", colorIntensity: "900", children: product.name })] }) }, product.id));
18
18
  })] }) }) })] }));
19
19
  };
@@ -9,4 +9,5 @@ export declare const useLogic: (identityUrl: string, openMenu: () => void) => {
9
9
  handleChangeTenant: (_event: MouseEvent<HTMLElement>, selectedValue: string) => void;
10
10
  tenantId: string;
11
11
  productList: WidgetProduct[] | undefined;
12
+ isShowToggleButton: boolean;
12
13
  };
@@ -54,6 +54,7 @@ const useLogic = (identityUrl, openMenu) => {
54
54
  setTenantId(selectedValue);
55
55
  }
56
56
  };
57
+ const isShowToggleButton = Boolean(tenants === null || tenants === void 0 ? void 0 : tenants.length) && Number(tenants === null || tenants === void 0 ? void 0 : tenants.length) > 1;
57
58
  return {
58
59
  handleShowProducts,
59
60
  isLoading,
@@ -62,6 +63,7 @@ const useLogic = (identityUrl, openMenu) => {
62
63
  handleChangeTenant,
63
64
  tenantId,
64
65
  productList,
66
+ isShowToggleButton,
65
67
  };
66
68
  };
67
69
  exports.useLogic = useLogic;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Получение данных из identity
3
+ * @param identityUrl - адрес identity
4
+ * @param group - код группы
5
+ */
6
+ export declare const getGroupsProducts: (identityUrl: string, group: string) => Promise<import("@astral/components").WidgetProduct[]>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getGroupsProducts = void 0;
13
+ const formatIdentityProducts_1 = require("../formatIdentityProducts");
14
+ /**
15
+ * Получение данных из identity
16
+ * @param identityUrl - адрес identity
17
+ * @param group - код группы
18
+ */
19
+ const getGroupsProducts = (identityUrl, group) => __awaiter(void 0, void 0, void 0, function* () {
20
+ return fetch(`${identityUrl}/api/products/group?groupId=${group}`)
21
+ .then((response) => {
22
+ if (!response.ok) {
23
+ throw new Error(response.statusText);
24
+ }
25
+ return response.json();
26
+ })
27
+ .then(({ data }) => {
28
+ return (0, formatIdentityProducts_1.formatIdentityProducts)(identityUrl, data);
29
+ });
30
+ });
31
+ exports.getGroupsProducts = getGroupsProducts;
@@ -0,0 +1 @@
1
+ export * from './getGroupsProducts';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./getGroupsProducts"), exports);
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Получение данных из identity
3
3
  * @param identityUrl - адрес identity
4
- * @param tenantId - идентификатор экосистемы
4
+ * @param tenant - код экосистемы
5
5
  */
6
- export declare const getIdentityProducts: (identityUrl: string, tenantId?: string) => Promise<import("@astral/components").WidgetProduct[]>;
6
+ export declare const getIdentityProducts: (identityUrl: string, tenant?: string) => Promise<import("@astral/components").WidgetProduct[]>;
@@ -14,10 +14,10 @@ const formatIdentityProducts_1 = require("../formatIdentityProducts");
14
14
  /**
15
15
  * Получение данных из identity
16
16
  * @param identityUrl - адрес identity
17
- * @param tenantId - идентификатор экосистемы
17
+ * @param tenant - код экосистемы
18
18
  */
19
- const getIdentityProducts = (identityUrl, tenantId = 'astral') => __awaiter(void 0, void 0, void 0, function* () {
20
- return fetch(`${identityUrl}/api/products/widget?tenantId=${tenantId}`)
19
+ const getIdentityProducts = (identityUrl, tenant = 'astral') => __awaiter(void 0, void 0, void 0, function* () {
20
+ return fetch(`${identityUrl}/api/products/widget?tenantId=${tenant}`)
21
21
  .then((response) => {
22
22
  if (!response.ok) {
23
23
  throw new Error(response.statusText);
package/package.json CHANGED
@@ -2,9 +2,9 @@
2
2
  "name": "@astral/features",
3
3
  "browser": "./index.js",
4
4
  "main": "./node/index.js",
5
- "version": "3.107.0",
5
+ "version": "3.109.0",
6
6
  "dependencies": {
7
- "@astral/ui": "^3.107.0",
7
+ "@astral/ui": "^3.109.0",
8
8
  "mobx": "^6.8.0",
9
9
  "mobx-react-lite": "^3.4.0",
10
10
  "@astral/cryptopro-cades": "^1.5.1"
@@ -1,12 +1,17 @@
1
+ import { ProductFilterType } from './enums';
1
2
  export type AstralProductSwitcherType = {
2
3
  /**
3
4
  * Адрес identity
4
5
  * */
5
6
  identityUrl: string;
7
+ /** Тип фильтрации продуктов */
8
+ filterBy?: ProductFilterType;
9
+ /** Код для фильтрации */
10
+ code?: string;
6
11
  /**
7
12
  * Идентификатор экосистемы
8
- * @default astral
13
+ * @deprecated
9
14
  * */
10
15
  tenantId?: string;
11
16
  };
12
- export declare const AstralProductSwitcher: ({ identityUrl, tenantId, }: AstralProductSwitcherType) => import("react/jsx-runtime").JSX.Element;
17
+ export declare const AstralProductSwitcher: ({ identityUrl, filterBy, code, tenantId, }: AstralProductSwitcherType) => import("react/jsx-runtime").JSX.Element;
@@ -11,15 +11,23 @@ import { jsx as _jsx } from "react/jsx-runtime";
11
11
  import { ProductSwitcher } from '@astral/ui';
12
12
  import { useState } from 'react';
13
13
  import { getIdentityProducts } from '../../utils';
14
- export const AstralProductSwitcher = ({ identityUrl, tenantId = 'astral', }) => {
14
+ import { ProductFilterType } from './enums';
15
+ import { getFilteredProducts } from './utils';
16
+ export const AstralProductSwitcher = ({ identityUrl, filterBy = ProductFilterType.Tenant, code = 'astral', tenantId, }) => {
15
17
  const [products, setProducts] = useState([]);
16
18
  const handleGetProducts = () => __awaiter(void 0, void 0, void 0, function* () {
17
- if (!products.length) {
19
+ if (products.length) {
20
+ return products;
21
+ }
22
+ // Это заглушка для обратной совместимости, убрать после релиза мажорной версии
23
+ if (tenantId) {
18
24
  const productsList = yield getIdentityProducts(identityUrl, tenantId);
19
25
  setProducts(productsList);
20
26
  return productsList;
21
27
  }
22
- return products;
28
+ const filteredProductsList = yield getFilteredProducts(identityUrl, filterBy, code);
29
+ setProducts(filteredProductsList);
30
+ return filteredProductsList;
23
31
  });
24
32
  return _jsx(ProductSwitcher, { getProducts: handleGetProducts });
25
33
  };
@@ -0,0 +1,4 @@
1
+ export declare enum ProductFilterType {
2
+ Tenant = "tenant",
3
+ Group = "group"
4
+ }
@@ -0,0 +1,5 @@
1
+ export var ProductFilterType;
2
+ (function (ProductFilterType) {
3
+ ProductFilterType["Tenant"] = "tenant";
4
+ ProductFilterType["Group"] = "group";
5
+ })(ProductFilterType || (ProductFilterType = {}));
@@ -1 +1,2 @@
1
1
  export * from './AstralProductSwitcher';
2
+ export * from './enums';
@@ -1 +1,2 @@
1
1
  export * from './AstralProductSwitcher';
2
+ export * from './enums';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Получение всех продуктов из разных экосистем и группировка в единую мапу
3
+ * @param identityUrl - адрес экосистемы
4
+ * @param filterBy - тип фильтрации продуктов
5
+ * @param code - код-значение для фильтрации
6
+ */
7
+ export declare const getFilteredProducts: (identityUrl: string, filterBy: string, code: string) => Promise<import("@astral/components").WidgetProduct[]>;
@@ -0,0 +1,19 @@
1
+ import { getIdentityProducts } from '../../../../utils';
2
+ import { ProductFilterType } from '../../enums';
3
+ import { getGroupsProducts } from '../../../../utils/getGroupsProducts';
4
+ /**
5
+ * Получение всех продуктов из разных экосистем и группировка в единую мапу
6
+ * @param identityUrl - адрес экосистемы
7
+ * @param filterBy - тип фильтрации продуктов
8
+ * @param code - код-значение для фильтрации
9
+ */
10
+ export const getFilteredProducts = (identityUrl, filterBy, code) => {
11
+ switch (filterBy) {
12
+ case ProductFilterType.Group: {
13
+ return getGroupsProducts(identityUrl, code);
14
+ }
15
+ default: {
16
+ return getIdentityProducts(identityUrl, code);
17
+ }
18
+ }
19
+ };
@@ -0,0 +1 @@
1
+ export * from './getFilteredProducts';
@@ -0,0 +1 @@
1
+ export * from './getFilteredProducts';
@@ -0,0 +1 @@
1
+ export * from './getFilteredProducts';
@@ -0,0 +1 @@
1
+ export * from './getFilteredProducts';
@@ -5,12 +5,12 @@ import { useLogic } from './hooks';
5
5
  export const ASTRAL_IDENTITY_DEFAULT_TENANT = 'astral';
6
6
  export const IdentityProductSwitcher = ({ identityUrl, }) => {
7
7
  const { open, anchorRef, handleOpenMenu, handleCloseMenu } = useMenu();
8
- const { isLoading, isError, tenantId, tenants, productList, handleChangeTenant, handleShowProducts, } = useLogic(identityUrl, handleOpenMenu);
8
+ const { isLoading, isError, tenantId, tenants, productList, handleChangeTenant, handleShowProducts, isShowToggleButton, } = useLogic(identityUrl, handleOpenMenu);
9
9
  return (_jsxs(_Fragment, { children: [_jsx(IconButton, { ref: anchorRef, selected: open, variant: "text", onClick: handleShowProducts, children: _jsx(ProductsFillMd, {}) }), _jsx(StyledMenu, { open: open, anchorEl: anchorRef.current, onClose: handleCloseMenu, children: _jsx(MenuGroup, { label: "\u041F\u0440\u043E\u0434\u0443\u043A\u0442\u044B \u044D\u043A\u043E\u0441\u0438\u0441\u0442\u0435\u043C\u044B", children: _jsxs(ContentState, { isLoading: isLoading, isCustom: isError, customState: {
10
10
  imgAlt: 'Что-то пошло не так',
11
11
  title: (_jsxs(ErrorContainer, { container: true, autoFlow: "column", alignItems: "center", justifyContent: "center", component: "span", children: [_jsx(ErrorFillSm, { color: "inherit" }), _jsx(Typography, { variant: "h6", color: "grey", colorIntensity: "900", children: "\u0427\u0442\u043E-\u0442\u043E \u043F\u043E\u0448\u043B\u043E \u043D\u0435 \u0442\u0430\u043A" })] })),
12
12
  description: 'Произошла ошибка. Повторите попытку позже.',
13
- }, children: [Boolean(tenants === null || tenants === void 0 ? void 0 : tenants.length) && (_jsx(TenantsToggleButtonGroup, { exclusive: true, onChange: handleChangeTenant, value: tenantId, children: tenants === null || tenants === void 0 ? void 0 : tenants.map(({ id, name }) => (_jsx(TenantToggleButton, { value: id, children: name }, id))) })), productList === null || productList === void 0 ? void 0 : productList.map((product) => {
13
+ }, children: [isShowToggleButton && (_jsx(TenantsToggleButtonGroup, { exclusive: true, onChange: handleChangeTenant, value: tenantId, children: tenants === null || tenants === void 0 ? void 0 : tenants.map(({ id, name }) => (_jsx(TenantToggleButton, { value: id, children: name }, id))) })), productList === null || productList === void 0 ? void 0 : productList.map((product) => {
14
14
  return (_jsx("li", { children: _jsxs(StyledMenuItem, { component: "a", href: product.url, children: [_jsx(Logo, { src: product.logoUrl, color: product.color }), _jsx(Typography, { variant: "ui", color: "grey", colorIntensity: "900", children: product.name })] }) }, product.id));
15
15
  })] }) }) })] }));
16
16
  };
@@ -9,4 +9,5 @@ export declare const useLogic: (identityUrl: string, openMenu: () => void) => {
9
9
  handleChangeTenant: (_event: MouseEvent<HTMLElement>, selectedValue: string) => void;
10
10
  tenantId: string;
11
11
  productList: WidgetProduct[] | undefined;
12
+ isShowToggleButton: boolean;
12
13
  };
@@ -51,6 +51,7 @@ export const useLogic = (identityUrl, openMenu) => {
51
51
  setTenantId(selectedValue);
52
52
  }
53
53
  };
54
+ const isShowToggleButton = Boolean(tenants === null || tenants === void 0 ? void 0 : tenants.length) && Number(tenants === null || tenants === void 0 ? void 0 : tenants.length) > 1;
54
55
  return {
55
56
  handleShowProducts,
56
57
  isLoading,
@@ -59,5 +60,6 @@ export const useLogic = (identityUrl, openMenu) => {
59
60
  handleChangeTenant,
60
61
  tenantId,
61
62
  productList,
63
+ isShowToggleButton,
62
64
  };
63
65
  };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Получение данных из identity
3
+ * @param identityUrl - адрес identity
4
+ * @param group - код группы
5
+ */
6
+ export declare const getGroupsProducts: (identityUrl: string, group: string) => Promise<import("@astral/components").WidgetProduct[]>;
@@ -0,0 +1,27 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { formatIdentityProducts } from '../formatIdentityProducts';
11
+ /**
12
+ * Получение данных из identity
13
+ * @param identityUrl - адрес identity
14
+ * @param group - код группы
15
+ */
16
+ export const getGroupsProducts = (identityUrl, group) => __awaiter(void 0, void 0, void 0, function* () {
17
+ return fetch(`${identityUrl}/api/products/group?groupId=${group}`)
18
+ .then((response) => {
19
+ if (!response.ok) {
20
+ throw new Error(response.statusText);
21
+ }
22
+ return response.json();
23
+ })
24
+ .then(({ data }) => {
25
+ return formatIdentityProducts(identityUrl, data);
26
+ });
27
+ });
@@ -0,0 +1 @@
1
+ export * from './getGroupsProducts';
@@ -0,0 +1 @@
1
+ export * from './getGroupsProducts';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Получение данных из identity
3
3
  * @param identityUrl - адрес identity
4
- * @param tenantId - идентификатор экосистемы
4
+ * @param tenant - код экосистемы
5
5
  */
6
- export declare const getIdentityProducts: (identityUrl: string, tenantId?: string) => Promise<import("@astral/components").WidgetProduct[]>;
6
+ export declare const getIdentityProducts: (identityUrl: string, tenant?: string) => Promise<import("@astral/components").WidgetProduct[]>;
@@ -11,10 +11,10 @@ import { formatIdentityProducts } from '../formatIdentityProducts';
11
11
  /**
12
12
  * Получение данных из identity
13
13
  * @param identityUrl - адрес identity
14
- * @param tenantId - идентификатор экосистемы
14
+ * @param tenant - код экосистемы
15
15
  */
16
- export const getIdentityProducts = (identityUrl, tenantId = 'astral') => __awaiter(void 0, void 0, void 0, function* () {
17
- return fetch(`${identityUrl}/api/products/widget?tenantId=${tenantId}`)
16
+ export const getIdentityProducts = (identityUrl, tenant = 'astral') => __awaiter(void 0, void 0, void 0, function* () {
17
+ return fetch(`${identityUrl}/api/products/widget?tenantId=${tenant}`)
18
18
  .then((response) => {
19
19
  if (!response.ok) {
20
20
  throw new Error(response.statusText);