@vegan-friendly/strapi-plugin-elasticsearch 0.1.0-alpha.3 → 0.2.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 (109) hide show
  1. package/dist/admin/index.js +4 -4
  2. package/dist/admin/pluginId.js +1 -1
  3. package/dist/admin/src/components/Initializer/index.js +2 -1
  4. package/dist/admin/src/components/SubNavigation/index.js +10 -8
  5. package/dist/admin/src/pages/ConfigureCollectionList/index.js +40 -28
  6. package/dist/admin/src/pages/Homepage/index.js +20 -21
  7. package/dist/admin/src/pluginId.d.ts +1 -1
  8. package/dist/admin/src/utils/apiUrls.js +1 -0
  9. package/dist/admin/src/utils/axiosInstance.js +3 -4
  10. package/dist/package.json +64 -0
  11. package/dist/server/bootstrap.d.ts +4 -0
  12. package/dist/server/bootstrap.js +31 -5
  13. package/dist/server/config/index.d.ts +5 -0
  14. package/dist/server/config/index.js +2 -1
  15. package/dist/server/content-types/index.d.ts +83 -2
  16. package/dist/server/content-types/index.js +9 -5
  17. package/dist/server/content-types/indexing-logs.d.ts +32 -0
  18. package/dist/server/content-types/indexing-logs.js +22 -24
  19. package/dist/server/content-types/tasks.d.ts +46 -0
  20. package/dist/server/content-types/tasks.js +33 -38
  21. package/dist/server/controllers/configure-indexing.d.ts +11 -0
  22. package/dist/server/controllers/configure-indexing.js +3 -2
  23. package/dist/server/controllers/index.d.ts +33 -5
  24. package/dist/server/controllers/index.js +15 -11
  25. package/dist/server/controllers/log-indexing.d.ts +6 -0
  26. package/dist/server/controllers/log-indexing.js +3 -2
  27. package/dist/server/controllers/perform-indexing.d.ts +8 -0
  28. package/dist/server/controllers/perform-indexing.js +3 -2
  29. package/dist/server/controllers/perform-search.d.ts +4 -1
  30. package/dist/server/controllers/perform-search.js +11 -8
  31. package/dist/server/controllers/setup-info.d.ts +6 -0
  32. package/dist/server/controllers/setup-info.js +2 -1
  33. package/dist/server/destroy.d.ts +4 -0
  34. package/dist/server/destroy.js +2 -1
  35. package/dist/server/index.d.ts +296 -10
  36. package/dist/server/index.js +40 -21
  37. package/dist/server/middlewares/index.d.ts +2 -0
  38. package/dist/server/middlewares/index.js +2 -1
  39. package/dist/server/policies/index.d.ts +2 -0
  40. package/dist/server/policies/index.js +2 -1
  41. package/dist/server/register.d.ts +4 -0
  42. package/dist/server/register.js +2 -1
  43. package/dist/server/routes/configure-indexing.d.ts +12 -0
  44. package/dist/server/routes/configure-indexing.js +2 -1
  45. package/dist/server/routes/index.d.ts +58 -5
  46. package/dist/server/routes/index.js +15 -11
  47. package/dist/server/routes/perform-indexing.d.ts +12 -0
  48. package/dist/server/routes/perform-indexing.js +2 -1
  49. package/dist/server/routes/perform-search.d.ts +12 -0
  50. package/dist/server/routes/perform-search.js +4 -3
  51. package/dist/server/routes/run-log.d.ts +12 -0
  52. package/dist/server/routes/run-log.js +3 -2
  53. package/dist/server/routes/setup-info.d.ts +12 -0
  54. package/dist/server/routes/setup-info.js +3 -2
  55. package/dist/server/services/configure-indexing.d.ts +23 -23
  56. package/dist/server/services/configure-indexing.js +32 -20
  57. package/dist/server/services/es-interface.d.ts +5 -4
  58. package/dist/server/services/es-interface.js +19 -20
  59. package/dist/server/services/helper.d.ts +34 -33
  60. package/dist/server/services/helper.js +65 -61
  61. package/dist/server/services/index.d.ts +107 -7
  62. package/dist/server/services/index.js +23 -15
  63. package/dist/server/services/log-indexing.d.ts +8 -0
  64. package/dist/server/services/log-indexing.js +8 -7
  65. package/dist/server/services/perform-indexing.d.ts +8 -0
  66. package/dist/server/services/perform-indexing.js +35 -17
  67. package/dist/server/services/schedule-indexing.d.ts +19 -0
  68. package/dist/server/services/schedule-indexing.js +13 -12
  69. package/dist/server/services/transform-content.d.ts +7 -2
  70. package/dist/server/services/transform-content.js +4 -3
  71. package/dist/server/services/virtual-collections-indexer.d.ts +8 -0
  72. package/dist/server/services/virtual-collections-indexer.js +142 -0
  73. package/dist/server/services/virtual-collections-registry.d.ts +8 -0
  74. package/dist/server/services/virtual-collections-registry.js +32 -0
  75. package/dist/server/types/esInterface.type.d.ts +70 -0
  76. package/dist/server/types/esInterface.type.js +2 -0
  77. package/dist/server/types/index.d.ts +2 -0
  78. package/dist/server/types/index.js +18 -0
  79. package/dist/server/types/virtual-collections.d.ts +30 -0
  80. package/dist/server/types/virtual-collections.js +2 -0
  81. package/dist/server/types/virtual-collections.type.d.ts +57 -0
  82. package/dist/server/types/virtual-collections.type.js +2 -0
  83. package/package.json +6 -3
  84. package/dist/admin/components/Initializer/index.d.ts +0 -15
  85. package/dist/admin/components/Initializer/index.js +0 -25
  86. package/dist/admin/components/PluginIcon/index.d.ts +0 -8
  87. package/dist/admin/components/PluginIcon/index.js +0 -14
  88. package/dist/admin/components/SubNavigation/index.d.ts +0 -4
  89. package/dist/admin/components/SubNavigation/index.js +0 -40
  90. package/dist/admin/pages/App/index.d.ts +0 -9
  91. package/dist/admin/pages/App/index.js +0 -29
  92. package/dist/admin/pages/ConfigureCollection/index.d.ts +0 -3
  93. package/dist/admin/pages/ConfigureCollection/index.js +0 -193
  94. package/dist/admin/pages/ConfigureCollectionList/index.d.ts +0 -3
  95. package/dist/admin/pages/ConfigureCollectionList/index.js +0 -228
  96. package/dist/admin/pages/Homepage/index.d.ts +0 -3
  97. package/dist/admin/pages/Homepage/index.js +0 -155
  98. package/dist/admin/pages/ViewIndexingRunLog/index.d.ts +0 -3
  99. package/dist/admin/pages/ViewIndexingRunLog/index.js +0 -125
  100. package/dist/admin/utils/apiUrls.d.ts +0 -10
  101. package/dist/admin/utils/apiUrls.js +0 -20
  102. package/dist/admin/utils/axiosInstance.d.ts +0 -5
  103. package/dist/admin/utils/axiosInstance.js +0 -33
  104. package/dist/admin/utils/getTrad.d.ts +0 -2
  105. package/dist/admin/utils/getTrad.js +0 -8
  106. package/dist/strapi-admin.d.ts +0 -0
  107. package/dist/strapi-admin.js +0 -2
  108. package/dist/strapi-server.d.ts +0 -0
  109. package/dist/strapi-server.js +0 -2
@@ -0,0 +1,70 @@
1
+ export interface EsInterfaceService {
2
+ /**
3
+ * Initializes the search engine connection.
4
+ * @param params - Connection parameters that include host, uname, password, and cert.
5
+ * @returns A promise that resolves when the initialization is complete.
6
+ */
7
+ initializeSearchEngine(params: {
8
+ host: string;
9
+ uname: string;
10
+ password: string;
11
+ cert: string;
12
+ }): Promise<void>;
13
+ /**
14
+ * Creates an index in the search engine.
15
+ * @param indexName - The name of the index to create.
16
+ * @returns A promise that resolves when the index is created.
17
+ */
18
+ createIndex(indexName: string): Promise<void>;
19
+ /**
20
+ * Deletes an index from the search engine.
21
+ * @param indexName - The name of the index to delete.
22
+ * @returns A promise that resolves when the index is deleted.
23
+ */
24
+ deleteIndex(indexName: string): Promise<void>;
25
+ /**
26
+ * Attaches an alias to a specific index.
27
+ * @param indexName - The index to which the alias should be attached.
28
+ * @returns A promise that resolves when the alias is set.
29
+ */
30
+ attachAliasToIndex(indexName: string): Promise<void>;
31
+ /**
32
+ * Checks the connection status of the search engine.
33
+ * @returns A promise that resolves with the connection status.
34
+ */
35
+ checkESConnection(): Promise<any>;
36
+ /**
37
+ * Indexes data to a specific index.
38
+ * @param data - An object containing the itemId and itemData to index.
39
+ * @param data.itemId - The full ID of the item to index, in format `collectionName + '::' + itemId`.
40
+ * @param indexName - The target index name.
41
+ * @returns A promise that resolves when the data is indexed.
42
+ */
43
+ indexDataToSpecificIndex(data: {
44
+ itemId: string;
45
+ itemData: any;
46
+ }, indexName: string): Promise<any>;
47
+ /**
48
+ * Indexes data.
49
+ * @param data - An object containing the itemId and itemData to index.
50
+ * @returns A promise that resolves when the data is indexed.
51
+ */
52
+ indexData(data: {
53
+ itemId: string;
54
+ itemData: any;
55
+ }): Promise<any>;
56
+ /**
57
+ * Removes an item from the index.
58
+ * @param data - An object containing the itemId.
59
+ * @returns A promise that resolves when the item is removed.
60
+ */
61
+ removeItemFromIndex(data: {
62
+ itemId: string;
63
+ }): Promise<any>;
64
+ /**
65
+ * Searches data in the search engine.
66
+ * @param searchQuery - The search query.
67
+ * @returns A promise that resolves with the search results.
68
+ */
69
+ searchData(searchQuery: any): Promise<any>;
70
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export * from './virtual-collections.type';
2
+ export * from './esInterface.type';
@@ -0,0 +1,18 @@
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("./virtual-collections.type"), exports);
18
+ __exportStar(require("./esInterface.type"), exports);
@@ -0,0 +1,30 @@
1
+ export type VirtualCollectionConfig<T extends {}> = {
2
+ indexName: string;
3
+ collectionName: string;
4
+ extractData: (page: number, pageSize?: number) => Promise<T[]>;
5
+ extractById: (ids: number[]) => Promise<T[]>;
6
+ triggers: Array<{
7
+ collection: string;
8
+ getIdsToReindex: (result: any) => Promise<number[]>;
9
+ }>;
10
+ mapToIndex: (item: T) => Promise<object>;
11
+ };
12
+ export interface VirtualCollectionsRegistryService {
13
+ /**
14
+ * Initialize indexes for all registered virtual collections
15
+ */
16
+ initializeIndexes(): Promise<void>;
17
+ /**
18
+ * Register a virtual collection
19
+ * @param config - The configuration for the virtual collection
20
+ * @returns The current instance of the registry
21
+ */
22
+ register<T extends {}>(config: VirtualCollectionConfig<T>): this;
23
+ /**
24
+ * get all registered virtual collections
25
+ * @returns An array of all registered virtual collections
26
+ */
27
+ getAll(): Array<VirtualCollectionConfig<any>>;
28
+ get(collectionName: string): VirtualCollectionConfig<any> | null;
29
+ findTriggersByCollection(collectionUID: string): Array<VirtualCollectionConfig<any>>;
30
+ }
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,57 @@
1
+ export type VirtualCollectionConfig<T extends {}> = {
2
+ indexName: string;
3
+ collectionName: string;
4
+ extractData: (page: number, pageSize?: number) => Promise<T[]>;
5
+ extractById: (ids: number[]) => Promise<T[]>;
6
+ triggers: Array<{
7
+ collection: string;
8
+ getIdsToReindex: (result: any) => Promise<number[]>;
9
+ }>;
10
+ mapToIndex?: (item: T) => Promise<object>;
11
+ };
12
+ export interface VirtualCollectionsRegistryService {
13
+ /**
14
+ * Register a virtual collection
15
+ * @param config - The configuration for the virtual collection
16
+ * @returns The current instance of the registry
17
+ */
18
+ register<T extends {}>(config: VirtualCollectionConfig<T>): this;
19
+ /**
20
+ * get all registered virtual collections
21
+ * @returns An array of all registered virtual collections
22
+ */
23
+ getAll(): Array<VirtualCollectionConfig<any>>;
24
+ get(collectionName: string): VirtualCollectionConfig<any> | null;
25
+ findTriggersByCollection(collectionUID: string): Array<VirtualCollectionConfig<any>>;
26
+ }
27
+ export interface VirtualCollectionsIndexerService {
28
+ /**
29
+ * Index a single item from a virtual collection.
30
+ * @param collectionName - The name of the virtual collection.
31
+ * @param itemId - The id of the item to be indexed.
32
+ */
33
+ indexItem(collectionName: string, itemId: number): Promise<any>;
34
+ /**
35
+ * Reindex all items in a virtual collection index.
36
+ * @param indexName - The target index name.
37
+ */
38
+ reindexAll(indexName: string): Promise<any>;
39
+ /**
40
+ * Reindex all items in a virtual collection.
41
+ * @param collectionName - The name of the virtual collection.
42
+ * @param indexName - The target index name.
43
+ */
44
+ reindex(collectionName: string, indexName: string): Promise<any>;
45
+ /**
46
+ * Handle a trigger event from a collection.
47
+ * @param event - The trigger event.
48
+ */
49
+ handleTriggerEvent(event: any): Promise<any>;
50
+ /**
51
+ * Delete an item from a virtual collection index.
52
+ * @param collectionName - The name of the virtual collection.
53
+ * @param itemId - The id of the item to be deleted.
54
+ * @returns A promise that resolves to a boolean indicating success.
55
+ */
56
+ deleteItem(collectionName: string, itemId: string): Promise<boolean>;
57
+ }
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vegan-friendly/strapi-plugin-elasticsearch",
3
- "version": "0.1.0-alpha.3",
3
+ "version": "0.2.0",
4
4
  "description": "A Strapi plugin to enable using Elasticsearch with Strapi CMS.",
5
5
  "homepage": "https://github.com/vegan-friendly/strapi-plugin-elasticsearch",
6
6
  "strapi": {
@@ -36,7 +36,9 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@elastic/elasticsearch": "^8.9.0",
39
- "markdown-to-txt": "^2.0.1"
39
+ "@strapi/design-system": "^1.19.0",
40
+ "markdown-to-txt": "^2.0.1",
41
+ "pretty-ms": "^9.2.0"
40
42
  },
41
43
  "peerDependencies": {
42
44
  "@strapi/strapi": "^4.0.0"
@@ -54,8 +56,9 @@
54
56
  },
55
57
  "license": "MIT",
56
58
  "devDependencies": {
59
+ "@strapi/typescript-utils": "^5.12.5",
57
60
  "@types/node": "^22.14.1",
58
61
  "ts-node": "^10.9.2",
59
62
  "typescript": "^5.8.3"
60
63
  }
61
- }
64
+ }
@@ -1,15 +0,0 @@
1
- /**
2
- *
3
- * Initializer
4
- *
5
- */
6
- import PropTypes from 'prop-types';
7
- declare const Initializer: {
8
- ({ setPlugin }: {
9
- setPlugin: any;
10
- }): null;
11
- propTypes: {
12
- setPlugin: PropTypes.Validator<(...args: any[]) => any>;
13
- };
14
- };
15
- export default Initializer;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- /**
3
- *
4
- * Initializer
5
- *
6
- */
7
- var __importDefault = (this && this.__importDefault) || function (mod) {
8
- return (mod && mod.__esModule) ? mod : { "default": mod };
9
- };
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- const react_1 = require("react");
12
- const prop_types_1 = __importDefault(require("prop-types"));
13
- const pluginId_1 = __importDefault(require("../../pluginId"));
14
- const Initializer = ({ setPlugin }) => {
15
- const ref = (0, react_1.useRef)();
16
- ref.current = setPlugin;
17
- (0, react_1.useEffect)(() => {
18
- ref.current(pluginId_1.default);
19
- }, []);
20
- return null;
21
- };
22
- Initializer.propTypes = {
23
- setPlugin: prop_types_1.default.func.isRequired,
24
- };
25
- exports.default = Initializer;
@@ -1,8 +0,0 @@
1
- /**
2
- *
3
- * PluginIcon
4
- *
5
- */
6
- import React from 'react';
7
- declare const PluginIcon: () => React.JSX.Element;
8
- export default PluginIcon;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- /**
3
- *
4
- * PluginIcon
5
- *
6
- */
7
- var __importDefault = (this && this.__importDefault) || function (mod) {
8
- return (mod && mod.__esModule) ? mod : { "default": mod };
9
- };
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- const react_1 = __importDefault(require("react"));
12
- const icons_1 = require("@strapi/icons");
13
- const PluginIcon = () => react_1.default.createElement(icons_1.Search, null);
14
- exports.default = PluginIcon;
@@ -1,4 +0,0 @@
1
- import React from 'react';
2
- export declare const SubNavigation: ({ activeUrl }: {
3
- activeUrl: any;
4
- }) => React.JSX.Element;
@@ -1,40 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SubNavigation = void 0;
7
- const react_1 = __importDefault(require("react"));
8
- const icons_1 = require("@strapi/icons");
9
- const design_system_1 = require("@strapi/design-system");
10
- const v2_1 = require("@strapi/design-system/v2");
11
- const react_router_dom_1 = require("react-router-dom");
12
- const pluginId_1 = __importDefault(require("../../pluginId"));
13
- const SubNavigation = ({ activeUrl }) => {
14
- const links = [{
15
- id: 1,
16
- label: 'Setup Information',
17
- icon: icons_1.Connector,
18
- to: `/plugins/${pluginId_1.default}/home`,
19
- },
20
- {
21
- id: 2,
22
- label: 'Configure Collections',
23
- icon: icons_1.Connector,
24
- to: `/plugins/${pluginId_1.default}/configure-collections`,
25
- },
26
- {
27
- id: 3,
28
- label: 'Indexing Run Logs',
29
- icon: icons_1.Connector,
30
- to: `/plugins/${pluginId_1.default}/view-indexing-logs`,
31
- }];
32
- return (react_1.default.createElement(design_system_1.Box, { style: {
33
- height: '100vh'
34
- }, background: "neutral200" },
35
- react_1.default.createElement(v2_1.SubNav, { ariaLabel: "Settings sub nav" },
36
- react_1.default.createElement(v2_1.SubNavHeader, { label: "Strapi Elasticsearch" }),
37
- react_1.default.createElement(v2_1.SubNavSections, null,
38
- react_1.default.createElement(v2_1.SubNavSection, null, links.map(link => link.icon && react_1.default.createElement(v2_1.SubNavLink, { as: react_router_dom_1.NavLink, to: link.to, icon: link.icon, key: link.id }, link.label)))))));
39
- };
40
- exports.SubNavigation = SubNavigation;
@@ -1,9 +0,0 @@
1
- /**
2
- *
3
- * This component is the skeleton around the actual pages, and should only
4
- * contain code that should be seen on all pages. (e.g. navigation bar)
5
- *
6
- */
7
- import React from 'react';
8
- declare const App: () => React.JSX.Element;
9
- export default App;
@@ -1,29 +0,0 @@
1
- "use strict";
2
- /**
3
- *
4
- * This component is the skeleton around the actual pages, and should only
5
- * contain code that should be seen on all pages. (e.g. navigation bar)
6
- *
7
- */
8
- var __importDefault = (this && this.__importDefault) || function (mod) {
9
- return (mod && mod.__esModule) ? mod : { "default": mod };
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const react_1 = __importDefault(require("react"));
13
- const react_router_dom_1 = require("react-router-dom");
14
- const helper_plugin_1 = require("@strapi/helper-plugin");
15
- const pluginId_1 = __importDefault(require("../../pluginId"));
16
- const ConfigureCollectionList_1 = __importDefault(require("../ConfigureCollectionList"));
17
- const ConfigureCollection_1 = __importDefault(require("../ConfigureCollection"));
18
- const ViewIndexingRunLog_1 = __importDefault(require("../ViewIndexingRunLog"));
19
- const Homepage_1 = __importDefault(require("../Homepage"));
20
- const App = () => {
21
- return (react_1.default.createElement(react_router_dom_1.Switch, null,
22
- react_1.default.createElement(react_router_dom_1.Route, { path: `/plugins/${pluginId_1.default}`, render: () => (react_1.default.createElement(react_router_dom_1.Redirect, { to: `/plugins/${pluginId_1.default}/home` })), exact: true }),
23
- react_1.default.createElement(react_router_dom_1.Route, { path: `/plugins/${pluginId_1.default}/home`, component: Homepage_1.default, exact: true }),
24
- react_1.default.createElement(react_router_dom_1.Route, { path: `/plugins/${pluginId_1.default}/configure-collections`, component: ConfigureCollectionList_1.default, exact: true }),
25
- react_1.default.createElement(react_router_dom_1.Route, { path: `/plugins/${pluginId_1.default}/configure-collections/:collectionName`, component: ConfigureCollection_1.default, exact: true }),
26
- react_1.default.createElement(react_router_dom_1.Route, { path: `/plugins/${pluginId_1.default}/view-indexing-logs`, component: ViewIndexingRunLog_1.default }),
27
- react_1.default.createElement(react_router_dom_1.Route, { component: helper_plugin_1.AnErrorOccurred })));
28
- };
29
- exports.default = App;
@@ -1,3 +0,0 @@
1
- import React from 'react';
2
- declare const ConfigureCollection: () => React.JSX.Element;
3
- export default ConfigureCollection;
@@ -1,193 +0,0 @@
1
- "use strict";
2
- /*
3
- *
4
- * HomePage
5
- *
6
- */
7
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
- if (k2 === undefined) k2 = k;
9
- var desc = Object.getOwnPropertyDescriptor(m, k);
10
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
- desc = { enumerable: true, get: function() { return m[k]; } };
12
- }
13
- Object.defineProperty(o, k2, desc);
14
- }) : (function(o, m, k, k2) {
15
- if (k2 === undefined) k2 = k;
16
- o[k2] = m[k];
17
- }));
18
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
- Object.defineProperty(o, "default", { enumerable: true, value: v });
20
- }) : function(o, v) {
21
- o["default"] = v;
22
- });
23
- var __importStar = (this && this.__importStar) || (function () {
24
- var ownKeys = function(o) {
25
- ownKeys = Object.getOwnPropertyNames || function (o) {
26
- var ar = [];
27
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
- return ar;
29
- };
30
- return ownKeys(o);
31
- };
32
- return function (mod) {
33
- if (mod && mod.__esModule) return mod;
34
- var result = {};
35
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
- __setModuleDefault(result, mod);
37
- return result;
38
- };
39
- })();
40
- var __importDefault = (this && this.__importDefault) || function (mod) {
41
- return (mod && mod.__esModule) ? mod : { "default": mod };
42
- };
43
- Object.defineProperty(exports, "__esModule", { value: true });
44
- const react_1 = __importStar(require("react"));
45
- const react_router_dom_1 = require("react-router-dom");
46
- const axiosInstance_1 = __importDefault(require("../../utils/axiosInstance"));
47
- const SubNavigation_1 = require("../../components/SubNavigation");
48
- ;
49
- const design_system_1 = require("@strapi/design-system");
50
- const design_system_2 = require("@strapi/design-system");
51
- const helper_plugin_1 = require("@strapi/helper-plugin");
52
- const pluginId_1 = __importDefault(require("../../pluginId"));
53
- const apiUrls_1 = require("../../utils/apiUrls");
54
- const design_system_3 = require("@strapi/design-system");
55
- const icons_1 = require("@strapi/icons");
56
- const design_system_4 = require("@strapi/design-system");
57
- const design_system_5 = require("@strapi/design-system");
58
- const helper_plugin_2 = require("@strapi/helper-plugin");
59
- const loadConfigForCollection = (collectionName) => {
60
- return axiosInstance_1.default.get((0, apiUrls_1.apiGetCollectionConfig)(collectionName))
61
- .then((resp) => resp.data);
62
- };
63
- const saveConfigForCollection = (collectionName, data) => {
64
- return axiosInstance_1.default.post((0, apiUrls_1.apiSaveCollectionConfig)(collectionName), {
65
- data
66
- });
67
- };
68
- const ConfigureField = ({ config, index, setFieldConfig }) => {
69
- const validateSubfieldsConfig = (conf) => {
70
- if (conf && conf.length > 0) {
71
- try {
72
- JSON.parse(conf);
73
- return true;
74
- }
75
- catch (e) {
76
- return false;
77
- }
78
- }
79
- else
80
- return true;
81
- };
82
- const updateIndex = (checked) => {
83
- setFieldConfig({ index, config: { ...config, index: checked } });
84
- };
85
- const updateSubfieldConfig = (subfields) => {
86
- const subfieldsConfigValid = validateSubfieldsConfig(subfields);
87
- setFieldConfig({ index, config: { ...config, subfields, subfieldsConfigValid } });
88
- };
89
- const updateMappedFieldName = (mappedName) => {
90
- setFieldConfig({ index, config: { ...config, searchFieldName: mappedName } });
91
- };
92
- return (react_1.default.createElement(design_system_1.Box, { background: "neutral100", borderColor: "neutral200", hasRadius: true, index: index, padding: 4 },
93
- react_1.default.createElement(design_system_1.Box, { paddingTop: 2, paddingBottom: 2 },
94
- react_1.default.createElement(design_system_4.Typography, { fontWeight: "bold", textColor: "neutral600" }, config.name)),
95
- react_1.default.createElement(design_system_1.Box, { paddingTop: 2, paddingBottom: 2 },
96
- react_1.default.createElement(design_system_2.ToggleInput, { label: "Index", onLabel: "Yes", offLabel: "No", checked: config.index, onChange: (e) => updateIndex(e.target.checked) })),
97
- react_1.default.createElement(design_system_1.Box, { width: "50%", paddingTop: 2, paddingBottom: 2 },
98
- react_1.default.createElement(design_system_5.TextInput, { label: "Maps to search field", placeholder: "Enter field name", name: "Search field", onChange: e => updateMappedFieldName(e.target.value), value: config.searchFieldName || "" })),
99
- config.index && config.type && config.type === "dynamiczone" ? (react_1.default.createElement(design_system_1.Box, { paddingTop: 2, paddingBottom: 2 },
100
- react_1.default.createElement(design_system_5.Textarea, { label: "Dynamic zone fields to index", error: config.subfieldsConfigValid === false ? 'Invalid indexing configuration' : undefined, onChange: e => updateSubfieldConfig(e.target.value) }, config.subfields || ""))) : null,
101
- config.index && config.type && config.type === "component" ? (react_1.default.createElement(design_system_1.Box, { paddingTop: 2, paddingBottom: 2 },
102
- react_1.default.createElement(design_system_5.Textarea, { label: "Component fields to index", error: config.subfieldsConfigValid === false ? 'Invalid indexing configuration' : undefined, onChange: e => updateSubfieldConfig(e.target.value) }, config.subfields || ""))) : null));
103
- };
104
- const ConfigureCollection = () => {
105
- const [isInProgress, setIsInProgress] = (0, react_1.useState)(false);
106
- const [selectedCollection, setSelectedCollection] = (0, react_1.useState)(null);
107
- const [collectionConfig, setCollectionConfig] = (0, react_1.useState)(null);
108
- const params = (0, react_router_dom_1.useParams)();
109
- const toggleNotification = (0, helper_plugin_2.useNotification)();
110
- const updateCollectionsConfig = ({ index, config }) => {
111
- setCollectionConfig({
112
- collectionName: collectionConfig.collectionName,
113
- attributes: collectionConfig.attributes.map((e, idx) => index === idx ? config : e)
114
- });
115
- };
116
- const saveCollectionConfig = () => {
117
- if (collectionConfig && collectionConfig.collectionName) {
118
- const data = {};
119
- data[collectionConfig.collectionName] = {};
120
- for (let k = 0; k < collectionConfig.attributes.length; k++) {
121
- const { name, ...attribs } = collectionConfig.attributes[k];
122
- data[collectionConfig.collectionName][name] = attribs;
123
- }
124
- setIsInProgress(true);
125
- saveConfigForCollection(collectionConfig.collectionName, data)
126
- .then((resp) => {
127
- toggleNotification({
128
- type: "success", message: "The collection configuration is saved.", timeout: 5000
129
- });
130
- })
131
- .catch((err) => {
132
- toggleNotification({
133
- type: "warning", message: err.message || "An error was encountered.", timeout: 5000
134
- });
135
- console.log(err);
136
- })
137
- .finally(() => setIsInProgress(false));
138
- }
139
- };
140
- (0, react_1.useEffect)(() => {
141
- if (params && params.collectionName)
142
- setSelectedCollection(params.collectionName);
143
- }, [params]);
144
- (0, react_1.useEffect)(() => {
145
- if (selectedCollection) {
146
- loadConfigForCollection(selectedCollection)
147
- .then((resp) => {
148
- if (Object.keys(resp).length === 0) {
149
- toggleNotification({
150
- type: "warning", message: 'No collection with the selected name exists.', timeout: 5000
151
- });
152
- }
153
- else {
154
- const collectionName = Object.keys(resp)[0];
155
- const attributeNames = Object.keys(resp[collectionName]);
156
- const attributes = [];
157
- for (let s = 0; s < attributeNames.length; s++)
158
- attributes.push({ name: attributeNames[s], ...resp[collectionName][attributeNames[s]] });
159
- const item = { collectionName, attributes };
160
- setCollectionConfig(item);
161
- }
162
- })
163
- .catch((err) => {
164
- toggleNotification({
165
- type: "warning", message: err.message || "An error was encountered.", timeout: 5000
166
- });
167
- console.log(err);
168
- });
169
- }
170
- }, [selectedCollection]);
171
- if (collectionConfig === null)
172
- return react_1.default.createElement(helper_plugin_2.LoadingIndicatorPage, null);
173
- else
174
- return (react_1.default.createElement(design_system_1.Flex, { alignItems: "stretch", gap: 4 },
175
- react_1.default.createElement(SubNavigation_1.SubNavigation, null),
176
- react_1.default.createElement(design_system_1.Box, { padding: 8, background: "neutral100", width: "100%" },
177
- react_1.default.createElement(design_system_1.Box, { paddingBottom: 4 },
178
- react_1.default.createElement(helper_plugin_1.Link, { startIcon: react_1.default.createElement(icons_1.ArrowLeft, null), to: `/plugins/${pluginId_1.default}/configure-collections/` }, "Back")),
179
- selectedCollection && (react_1.default.createElement(design_system_1.Box, { paddingBottom: 4 },
180
- react_1.default.createElement(design_system_4.Typography, { variant: "alpha" }, selectedCollection))),
181
- collectionConfig && (react_1.default.createElement(react_1.default.Fragment, null,
182
- react_1.default.createElement(design_system_1.Flex, { alignItems: "stretch", gap: 4, width: "100%" },
183
- react_1.default.createElement(design_system_1.Box, { padding: 8, background: "neutral0", width: "100%" },
184
- react_1.default.createElement(design_system_1.Box, { paddingBottom: 2 },
185
- react_1.default.createElement(design_system_4.Typography, { variant: "beta" }, "Attributes"),
186
- collectionConfig.attributes.map((a, idx) => {
187
- return react_1.default.createElement(design_system_1.Box, { paddingTop: 4, paddingBottom: 4 },
188
- react_1.default.createElement(ConfigureField, { index: idx, config: a, setFieldConfig: updateCollectionsConfig }));
189
- })))),
190
- react_1.default.createElement(design_system_1.Box, { paddingTop: 4 },
191
- react_1.default.createElement(design_system_3.Button, { loading: isInProgress, variant: "default", onClick: saveCollectionConfig }, "Save Configuration Changes")))))));
192
- };
193
- exports.default = ConfigureCollection;
@@ -1,3 +0,0 @@
1
- import React from 'react';
2
- declare const Configure: () => React.JSX.Element;
3
- export default Configure;