@vegan-friendly/strapi-plugin-elasticsearch 0.1.0-alpha.1 → 0.1.0-alpha.2
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/dist/admin/src/components/Initializer/index.d.ts +15 -0
- package/dist/admin/src/components/Initializer/index.js +25 -0
- package/dist/admin/src/components/PluginIcon/index.d.ts +8 -0
- package/dist/admin/src/components/PluginIcon/index.js +14 -0
- package/dist/admin/src/components/SubNavigation/index.d.ts +4 -0
- package/dist/admin/src/components/SubNavigation/index.js +40 -0
- package/dist/admin/src/index.d.ts +8 -0
- package/dist/admin/src/index.js +92 -0
- package/dist/admin/src/pages/App/index.d.ts +9 -0
- package/dist/admin/src/pages/App/index.js +29 -0
- package/dist/admin/src/pages/ConfigureCollection/index.d.ts +3 -0
- package/dist/admin/src/pages/ConfigureCollection/index.js +193 -0
- package/dist/admin/src/pages/ConfigureCollectionList/index.d.ts +3 -0
- package/dist/admin/src/pages/ConfigureCollectionList/index.js +228 -0
- package/dist/admin/src/pages/Homepage/index.d.ts +3 -0
- package/dist/admin/src/pages/Homepage/index.js +155 -0
- package/dist/admin/src/pages/ViewIndexingRunLog/index.d.ts +3 -0
- package/dist/admin/src/pages/ViewIndexingRunLog/index.js +125 -0
- package/dist/admin/src/pluginId.d.ts +2 -0
- package/dist/admin/src/pluginId.js +8 -0
- package/dist/admin/src/utils/apiUrls.d.ts +10 -0
- package/dist/admin/src/utils/apiUrls.js +20 -0
- package/dist/admin/src/utils/axiosInstance.d.ts +5 -0
- package/dist/admin/src/utils/axiosInstance.js +33 -0
- package/dist/admin/src/utils/getTrad.d.ts +2 -0
- package/dist/admin/src/utils/getTrad.js +8 -0
- package/dist/server/bootstrap.js +125 -0
- package/dist/server/config/index.d.ts +0 -0
- package/dist/server/config/index.js +5 -0
- package/dist/server/content-types/index.d.ts +2 -0
- package/{server → dist/server}/content-types/index.js +7 -9
- package/dist/server/content-types/indexing-logs.d.ts +0 -0
- package/dist/server/content-types/indexing-logs.js +35 -0
- package/dist/server/content-types/name-prefix.d.ts +0 -0
- package/dist/server/content-types/name-prefix.js +1 -0
- package/dist/server/content-types/tasks.d.ts +0 -0
- package/dist/server/content-types/tasks.js +52 -0
- package/dist/server/controllers/configure-indexing.d.ts +0 -0
- package/dist/server/controllers/configure-indexing.js +58 -0
- package/dist/server/controllers/index.d.ts +5 -0
- package/{server → dist/server}/controllers/index.js +13 -15
- package/dist/server/controllers/log-indexing.d.ts +0 -0
- package/{server → dist/server}/controllers/log-indexing.js +10 -11
- package/dist/server/controllers/perform-indexing.d.ts +0 -0
- package/{server → dist/server}/controllers/perform-indexing.js +22 -28
- package/dist/server/controllers/perform-search.d.ts +1 -0
- package/dist/server/controllers/perform-search.js +29 -0
- package/dist/server/controllers/setup-info.d.ts +0 -0
- package/{server → dist/server}/controllers/setup-info.js +10 -14
- package/dist/server/destroy.d.ts +0 -0
- package/{server → dist/server}/destroy.js +4 -5
- package/dist/server/index.d.ts +10 -0
- package/{server → dist/server}/index.js +23 -25
- package/dist/server/middlewares/index.d.ts +0 -0
- package/{server → dist/server}/middlewares/index.js +2 -3
- package/dist/server/policies/index.d.ts +0 -0
- package/{server → dist/server}/policies/index.js +2 -3
- package/dist/server/register.d.ts +0 -0
- package/{server → dist/server}/register.js +4 -5
- package/dist/server/routes/configure-indexing.d.ts +0 -0
- package/dist/server/routes/configure-indexing.js +43 -0
- package/dist/server/routes/index.d.ts +5 -0
- package/{server → dist/server}/routes/index.js +13 -13
- package/dist/server/routes/perform-indexing.d.ts +0 -0
- package/dist/server/routes/perform-indexing.js +25 -0
- package/dist/server/routes/perform-search.d.ts +0 -0
- package/dist/server/routes/perform-search.js +15 -0
- package/dist/server/routes/run-log.d.ts +0 -0
- package/dist/server/routes/run-log.js +13 -0
- package/dist/server/routes/setup-info.d.ts +0 -0
- package/dist/server/routes/setup-info.js +13 -0
- package/dist/server/services/configure-indexing.d.ts +24 -0
- package/dist/server/services/configure-indexing.js +161 -0
- package/dist/server/services/es-interface.d.ts +4 -0
- package/dist/server/services/es-interface.js +161 -0
- package/dist/server/services/helper.d.ts +34 -0
- package/{server → dist/server}/services/helper.js +269 -305
- package/dist/server/services/index.d.ts +7 -0
- package/{server → dist/server}/services/index.js +17 -21
- package/dist/server/services/log-indexing.d.ts +0 -0
- package/{server → dist/server}/services/log-indexing.js +27 -26
- package/dist/server/services/perform-indexing.d.ts +0 -0
- package/{server → dist/server}/services/perform-indexing.js +147 -173
- package/dist/server/services/schedule-indexing.d.ts +0 -0
- package/{server → dist/server}/services/schedule-indexing.js +61 -65
- package/dist/server/services/transform-content.d.ts +2 -0
- package/{server → dist/server}/services/transform-content.js +21 -22
- package/dist/strapi-admin.d.ts +0 -0
- package/{strapi-admin.js → dist/strapi-admin.js} +2 -3
- package/dist/strapi-server.d.ts +0 -0
- package/{strapi-server.js → dist/strapi-server.js} +2 -3
- package/package.json +24 -3
- package/.prettierrc +0 -7
- package/.vscode/settings.json +0 -24
- package/admin/src/components/Initializer/index.js +0 -26
- package/admin/src/components/PluginIcon/index.js +0 -12
- package/admin/src/components/SubNavigation/index.js +0 -48
- package/admin/src/index.js +0 -63
- package/admin/src/pages/App/index.js +0 -29
- package/admin/src/pages/ConfigureCollection/index.js +0 -225
- package/admin/src/pages/ConfigureCollectionList/index.js +0 -266
- package/admin/src/pages/Homepage/index.js +0 -168
- package/admin/src/pages/ViewIndexingRunLog/index.js +0 -124
- package/admin/src/pluginId.js +0 -5
- package/admin/src/translations/en.json +0 -1
- package/admin/src/translations/fr.json +0 -1
- package/admin/src/utils/apiUrls.js +0 -14
- package/admin/src/utils/axiosInstance.js +0 -40
- package/admin/src/utils/getTrad.js +0 -5
- package/server/bootstrap.js +0 -142
- package/server/config/index.js +0 -6
- package/server/content-types/indexing-logs.js +0 -35
- package/server/content-types/tasks.js +0 -52
- package/server/controllers/configure-indexing.js +0 -66
- package/server/controllers/perform-search.js +0 -31
- package/server/routes/configure-indexing.js +0 -42
- package/server/routes/perform-indexing.js +0 -24
- package/server/routes/perform-search.js +0 -14
- package/server/routes/run-log.js +0 -12
- package/server/routes/setup-info.js +0 -12
- package/server/services/configure-indexing.js +0 -184
- package/server/services/es-interface.js +0 -187
- package/server/services/virtual-collections-registry.js +0 -346
- /package/{server/content-types/name-prefix.js → dist/server/bootstrap.d.ts} +0 -0
@@ -0,0 +1,15 @@
|
|
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;
|
@@ -0,0 +1,25 @@
|
|
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;
|
@@ -0,0 +1,14 @@
|
|
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;
|
@@ -0,0 +1,40 @@
|
|
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;
|
@@ -0,0 +1,92 @@
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
19
|
+
var ownKeys = function(o) {
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
21
|
+
var ar = [];
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
23
|
+
return ar;
|
24
|
+
};
|
25
|
+
return ownKeys(o);
|
26
|
+
};
|
27
|
+
return function (mod) {
|
28
|
+
if (mod && mod.__esModule) return mod;
|
29
|
+
var result = {};
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
+
__setModuleDefault(result, mod);
|
32
|
+
return result;
|
33
|
+
};
|
34
|
+
})();
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
37
|
+
};
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
39
|
+
const helper_plugin_1 = require("@strapi/helper-plugin");
|
40
|
+
const package_json_1 = __importDefault(require("../../package.json"));
|
41
|
+
const pluginId_1 = __importDefault(require("./pluginId"));
|
42
|
+
const Initializer_1 = __importDefault(require("./components/Initializer"));
|
43
|
+
const PluginIcon_1 = __importDefault(require("./components/PluginIcon"));
|
44
|
+
const name = package_json_1.default.strapi.name;
|
45
|
+
exports.default = {
|
46
|
+
register(app) {
|
47
|
+
app.addMenuLink({
|
48
|
+
to: `/plugins/${pluginId_1.default}`,
|
49
|
+
icon: PluginIcon_1.default,
|
50
|
+
intlLabel: {
|
51
|
+
id: `${pluginId_1.default}.plugin.name`,
|
52
|
+
defaultMessage: 'Elasticsearch',
|
53
|
+
},
|
54
|
+
Component: async () => {
|
55
|
+
const component = await Promise.resolve().then(() => __importStar(require(/* webpackChunkName: "[request]" */ './pages/App')));
|
56
|
+
return component;
|
57
|
+
},
|
58
|
+
permissions: [
|
59
|
+
// Uncomment to set the permissions of the plugin here
|
60
|
+
// {
|
61
|
+
// action: '', // the action name should be plugin::plugin-name.actionType
|
62
|
+
// subject: null,
|
63
|
+
// },
|
64
|
+
],
|
65
|
+
});
|
66
|
+
app.registerPlugin({
|
67
|
+
id: pluginId_1.default,
|
68
|
+
initializer: Initializer_1.default,
|
69
|
+
isReady: false,
|
70
|
+
name,
|
71
|
+
});
|
72
|
+
},
|
73
|
+
bootstrap(app) { },
|
74
|
+
async registerTrads({ locales }) {
|
75
|
+
const importedTrads = await Promise.all(locales.map((locale) => {
|
76
|
+
return Promise.resolve(`${
|
77
|
+
/* webpackChunkName: "translation-[request]" */ `./translations/${locale}.json`}`).then(s => __importStar(require(s))).then(({ default: data }) => {
|
78
|
+
return {
|
79
|
+
data: (0, helper_plugin_1.prefixPluginTranslations)(data, pluginId_1.default),
|
80
|
+
locale,
|
81
|
+
};
|
82
|
+
})
|
83
|
+
.catch(() => {
|
84
|
+
return {
|
85
|
+
data: {},
|
86
|
+
locale,
|
87
|
+
};
|
88
|
+
});
|
89
|
+
}));
|
90
|
+
return Promise.resolve(importedTrads);
|
91
|
+
},
|
92
|
+
};
|
@@ -0,0 +1,29 @@
|
|
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;
|
@@ -0,0 +1,193 @@
|
|
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;
|