@localazy/strapi-plugin 0.1.8 → 0.1.9
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/.github/workflows/.build.yml +2 -13
- package/admin/src/modules/plugin-settings/components/ContentTransferSetup/index.js +33 -22
- package/admin/src/modules/plugin-settings/components/ContentTransferSetupEmpty/index.js +86 -0
- package/admin/src/modules/plugin-settings/components/Tree/index.js +10 -1
- package/admin/src/modules/plugin-settings/locale/en.js +7 -0
- package/admin/src/modules/plugin-settings/services/plugin-settings-service.js +23 -0
- package/admin/src/pages/App/index.js +3 -1
- package/admin/src/pages/Download/index.js +4 -0
- package/admin/src/pages/Settings/index.js +4 -0
- package/admin/src/pages/Upload/index.js +3 -0
- package/package.json +1 -1
- package/server/controllers/plugin-settings-controller.js +14 -0
- package/server/db/model/plugin-settings.js +13 -0
- package/server/routes/plugin-settings.js +16 -0
- package/server/services/plugin-settings-service.js +28 -7
|
@@ -10,20 +10,9 @@ jobs:
|
|
|
10
10
|
run: pwd && sudo chown -R $USER:$USER ./
|
|
11
11
|
- uses: actions/checkout@v2
|
|
12
12
|
- name: Setup Node.js environment
|
|
13
|
-
uses: actions/setup-node@
|
|
13
|
+
uses: actions/setup-node@v3
|
|
14
14
|
with:
|
|
15
|
-
node-version: 14.x
|
|
16
|
-
- name: Cache node modules
|
|
17
|
-
uses: actions/cache@v1
|
|
18
|
-
env:
|
|
19
|
-
cache-name: cache-node-modules
|
|
20
|
-
with:
|
|
21
|
-
path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS
|
|
22
|
-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
|
|
23
|
-
restore-keys: |
|
|
24
|
-
${{ runner.os }}-build-${{ env.cache-name }}-
|
|
25
|
-
${{ runner.os }}-build-
|
|
26
|
-
${{ runner.os }}-
|
|
15
|
+
node-version: 14.x
|
|
27
16
|
- name: Install dependencies
|
|
28
17
|
run: npm ci
|
|
29
18
|
- name: Run unit tests
|
|
@@ -21,6 +21,7 @@ import hasModelChanged from "../../functions/has-model-changed";
|
|
|
21
21
|
import buildContentTransferSetupSchema from "../../functions/build-content-transfer-setup-schema";
|
|
22
22
|
import { getLocalazyIdentity } from "../../../../state/localazy-identity";
|
|
23
23
|
import Tree from "../Tree";
|
|
24
|
+
import ContentTransferSetupEmpty from "../ContentTransferSetupEmpty";
|
|
24
25
|
|
|
25
26
|
import "../../../../i18n";
|
|
26
27
|
|
|
@@ -28,7 +29,6 @@ function ContentTransferSetup() {
|
|
|
28
29
|
/**
|
|
29
30
|
* Translation function
|
|
30
31
|
*/
|
|
31
|
-
// eslint-disable-next-line no-unused-vars
|
|
32
32
|
const { t } = useTranslation();
|
|
33
33
|
|
|
34
34
|
/**
|
|
@@ -250,6 +250,10 @@ function ContentTransferSetup() {
|
|
|
250
250
|
shadow="tableShadow"
|
|
251
251
|
hasRadius
|
|
252
252
|
>
|
|
253
|
+
{!formModel.length && (
|
|
254
|
+
// empty state
|
|
255
|
+
<ContentTransferSetupEmpty />
|
|
256
|
+
)}
|
|
253
257
|
{formModel.map((tree, index) => {
|
|
254
258
|
return (
|
|
255
259
|
<Box
|
|
@@ -257,30 +261,37 @@ function ContentTransferSetup() {
|
|
|
257
261
|
key={`box_tree_${index}`}
|
|
258
262
|
marginBottom={3}
|
|
259
263
|
>
|
|
260
|
-
<Tree
|
|
264
|
+
<Tree
|
|
265
|
+
onTreeItemClick={onTreeItemClick}
|
|
266
|
+
objects={tree}
|
|
267
|
+
initiallyExpanded={index === 0} />
|
|
261
268
|
</Box>
|
|
262
269
|
);
|
|
263
270
|
})}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
271
|
+
{!!formModel.length && (
|
|
272
|
+
<Box>
|
|
273
|
+
<Box
|
|
274
|
+
paddingTop={6}
|
|
275
|
+
paddingBottom={6}
|
|
276
|
+
>
|
|
277
|
+
<Divider />
|
|
278
|
+
</Box>
|
|
279
|
+
<Typography variant="omega">{t("plugin_settings.you_can_upload_download")}</Typography>
|
|
280
|
+
<Typography variant="omega" fontWeight="semiBold">{t("plugin_settings.only_text_based_content")}</Typography>
|
|
281
|
+
<br />
|
|
282
|
+
<br />
|
|
283
|
+
<Typography variant="omega">{t("plugin_settings.learn_more_in_docs_message_a")}</Typography>
|
|
284
|
+
<Typography
|
|
285
|
+
onClick={onReadDocumentationClick}
|
|
286
|
+
variant="omega"
|
|
287
|
+
fontWeight="semiBold"
|
|
288
|
+
textColor="primary600"
|
|
289
|
+
style={{ cursor: "pointer" }}
|
|
290
|
+
>
|
|
291
|
+
{t("plugin_settings.learn_more_in_docs_message_b")}
|
|
292
|
+
</Typography>
|
|
293
|
+
</Box>
|
|
294
|
+
)}
|
|
284
295
|
</Box>
|
|
285
296
|
)
|
|
286
297
|
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { useTranslation, Trans } from "react-i18next";
|
|
3
|
+
import styled from 'styled-components';
|
|
4
|
+
import { Typography, Flex } from "@strapi/design-system";
|
|
5
|
+
import Dot from '@strapi/icons/Dot';
|
|
6
|
+
|
|
7
|
+
const CustomBullet = styled(Dot)`
|
|
8
|
+
width: ${12 / 16}rem;
|
|
9
|
+
height: ${4 / 16}rem;
|
|
10
|
+
margin-right: ${4 / 16}rem;
|
|
11
|
+
* {
|
|
12
|
+
fill: ${({ theme, $active }) => ($active ? theme.colors.primary600 : theme.colors.neutral600)};
|
|
13
|
+
}
|
|
14
|
+
`;
|
|
15
|
+
|
|
16
|
+
function ContentTransferSetupEmpty() {
|
|
17
|
+
const { t } = useTranslation();
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<div>
|
|
21
|
+
<Typography
|
|
22
|
+
textColor="neutral600"
|
|
23
|
+
variant="beta"
|
|
24
|
+
>
|
|
25
|
+
{t("plugin_settings.there_is_nothing_to_transfer")}
|
|
26
|
+
</Typography>
|
|
27
|
+
<br />
|
|
28
|
+
<br />
|
|
29
|
+
<Typography
|
|
30
|
+
textColor="neutral600"
|
|
31
|
+
variant="omega"
|
|
32
|
+
>
|
|
33
|
+
{t("plugin_settings.please_check_that_you_have_entered_a_valid_collection")}
|
|
34
|
+
</Typography>
|
|
35
|
+
<br />
|
|
36
|
+
<Flex marginTop={1} alignItems="center">
|
|
37
|
+
<CustomBullet />
|
|
38
|
+
<Typography
|
|
39
|
+
textColor="neutral600"
|
|
40
|
+
variant="omega"
|
|
41
|
+
>
|
|
42
|
+
<Trans i18nKey="plugin_settings.step_1" components={{ 1: <Typography variant="omega" fontWeight="semiBold" /> }} />
|
|
43
|
+
</Typography>
|
|
44
|
+
</Flex>
|
|
45
|
+
<Flex marginTop={1} alignItems="center">
|
|
46
|
+
<CustomBullet />
|
|
47
|
+
|
|
48
|
+
<Typography
|
|
49
|
+
textColor="neutral600"
|
|
50
|
+
variant="omega"
|
|
51
|
+
>
|
|
52
|
+
<Trans i18nKey="plugin_settings.step_2" components={{ 1: <Typography variant="omega" fontWeight="semiBold" /> }} />
|
|
53
|
+
</Typography>
|
|
54
|
+
</Flex>
|
|
55
|
+
<Flex marginTop={1} alignItems="center">
|
|
56
|
+
<CustomBullet />
|
|
57
|
+
<Typography
|
|
58
|
+
textColor="neutral600"
|
|
59
|
+
variant="omega"
|
|
60
|
+
>
|
|
61
|
+
<Trans i18nKey="plugin_settings.step_3" components={{ 1: <Typography variant="omega" fontWeight="semiBold" /> }} />
|
|
62
|
+
</Typography>
|
|
63
|
+
</Flex>
|
|
64
|
+
<Flex marginTop={1} alignItems="center">
|
|
65
|
+
<CustomBullet />
|
|
66
|
+
<Typography
|
|
67
|
+
textColor="neutral600"
|
|
68
|
+
variant="omega"
|
|
69
|
+
>
|
|
70
|
+
<Trans i18nKey="plugin_settings.step_4" components={{ 1: <Typography variant="omega" fontWeight="semiBold" /> }} />
|
|
71
|
+
</Typography>
|
|
72
|
+
</Flex>
|
|
73
|
+
<Flex marginTop={1} alignItems="center">
|
|
74
|
+
<CustomBullet />
|
|
75
|
+
<Typography
|
|
76
|
+
textColor="neutral600"
|
|
77
|
+
variant="omega"
|
|
78
|
+
>
|
|
79
|
+
<Trans i18nKey="plugin_settings.step_5" components={{ 1: <Typography variant="omega" fontWeight="semiBold" /> }} />
|
|
80
|
+
</Typography>
|
|
81
|
+
</Flex>
|
|
82
|
+
</div >
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export default ContentTransferSetupEmpty;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState } from "react";
|
|
1
|
+
import React, { useState, useEffect } from "react";
|
|
2
2
|
import PropTypes from "prop-types";
|
|
3
3
|
import { Box } from "@strapi/design-system/Box";
|
|
4
4
|
import { Switch } from '@strapi/design-system/Switch';
|
|
@@ -13,6 +13,10 @@ function Tree(props) {
|
|
|
13
13
|
props.onTreeItemClick(key, currentValue);
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
setIsExpanded(props.initiallyExpanded);
|
|
18
|
+
}, [props.initiallyExpanded]);
|
|
19
|
+
|
|
16
20
|
const createTree = (name, branch, path = "") => {
|
|
17
21
|
const isBranchObject = typeof branch === "object" && branch !== null;
|
|
18
22
|
|
|
@@ -115,6 +119,11 @@ function Tree(props) {
|
|
|
115
119
|
Tree.propTypes = {
|
|
116
120
|
objects: PropTypes.object.isRequired,
|
|
117
121
|
onTreeItemClick: PropTypes.func.isRequired,
|
|
122
|
+
initiallyExpanded: PropTypes.bool,
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
Tree.defaultProps = {
|
|
126
|
+
initiallyExpanded: false,
|
|
118
127
|
};
|
|
119
128
|
|
|
120
129
|
export default Tree;
|
|
@@ -16,4 +16,11 @@ export default {
|
|
|
16
16
|
only_text_based_content: "only text based content.",
|
|
17
17
|
learn_more_in_docs_message_a: "If you want to learn more about how to setup your Content Transfer settings read the ",
|
|
18
18
|
learn_more_in_docs_message_b: "Localazy documentation.",
|
|
19
|
+
there_is_nothing_to_transfer: "There is nothing to transfer.",
|
|
20
|
+
please_check_that_you_have_entered_a_valid_collection: "To finish the content transfer setup, you must enable localization for at least one Content-Type.",
|
|
21
|
+
step_1: "Go to the <1>Content-Type Builder</1>",
|
|
22
|
+
step_2: "Click on <1>Edit</1> and select the <1>Advanced Settings</1> tab",
|
|
23
|
+
step_3: "Check <1>Enable localization for this Content-Type</1>",
|
|
24
|
+
step_4: "Repeat for all Content-Types you want to translate",
|
|
25
|
+
step_5: "Return to this screen and finish the transfer setup",
|
|
19
26
|
};
|
|
@@ -29,4 +29,27 @@ export default class PluginSettingsService {
|
|
|
29
29
|
throw e;
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
+
|
|
33
|
+
static async getPluginSettings() {
|
|
34
|
+
try {
|
|
35
|
+
const result = await axiosInstance.get(`${BASE_PATH}/plugin-settings`);
|
|
36
|
+
|
|
37
|
+
return result.data;
|
|
38
|
+
} catch (e) {
|
|
39
|
+
throw e;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static async updatePluginSettings(data) {
|
|
44
|
+
try {
|
|
45
|
+
const result = await axiosInstance.put(
|
|
46
|
+
`${BASE_PATH}/plugin-settings`,
|
|
47
|
+
data
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
return result.data;
|
|
51
|
+
} catch (e) {
|
|
52
|
+
throw e;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
32
55
|
}
|
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
getLocalazyIdentity,
|
|
33
33
|
} from "../../state/localazy-identity";
|
|
34
34
|
import history from "../../modules/@common/utils/history";
|
|
35
|
+
import PluginSettingsService from "../../modules/plugin-settings/services/plugin-settings-service";
|
|
35
36
|
|
|
36
37
|
import "../../i18n";
|
|
37
38
|
|
|
@@ -89,7 +90,8 @@ function App() {
|
|
|
89
90
|
if (!hasLocalazyIdentity()) {
|
|
90
91
|
redirectToPluginRoute(PLUGIN_ROUTES.LOGIN);
|
|
91
92
|
} else {
|
|
92
|
-
|
|
93
|
+
const lastRoute = (await PluginSettingsService.getPluginSettings()).defaultRoute || PLUGIN_ROUTES.UPLOAD;
|
|
94
|
+
redirectToPluginRoute(lastRoute);
|
|
93
95
|
}
|
|
94
96
|
}
|
|
95
97
|
}
|
|
@@ -18,6 +18,8 @@ import ReadDocsButton from "../../modules/localazy-upload/components/ReadDocsBut
|
|
|
18
18
|
import "../../i18n";
|
|
19
19
|
import { getLocalazyIdentity } from "../../state/localazy-identity";
|
|
20
20
|
import ProductAnalyticsService from "../../modules/@common/services/product-analytics-service";
|
|
21
|
+
import PluginSettingsService from "../../modules/plugin-settings/services/plugin-settings-service";
|
|
22
|
+
import { PLUGIN_ROUTES } from "../../modules/@common/utils/redirect-to-plugin-route";
|
|
21
23
|
|
|
22
24
|
function Download(props) {
|
|
23
25
|
const { t } = useTranslation();
|
|
@@ -69,6 +71,8 @@ function Download(props) {
|
|
|
69
71
|
setModelChanged(await hasModelChanged());
|
|
70
72
|
setLocalesIncompatible(!(await areLocalesCompatible()));
|
|
71
73
|
|
|
74
|
+
PluginSettingsService.updatePluginSettings({ defaultRoute: PLUGIN_ROUTES.DOWNLOAD });
|
|
75
|
+
|
|
72
76
|
setIsLoading(false);
|
|
73
77
|
}
|
|
74
78
|
initComponent();
|
|
@@ -18,6 +18,7 @@ import PrerequisitiesInfo from "../../modules/settings/components/Prerequisities
|
|
|
18
18
|
import ProjectService from "../../modules/@common/services/project-service";
|
|
19
19
|
import ProductAnalyticsService from "../../modules/@common/services/product-analytics-service";
|
|
20
20
|
import formatNumber from "../../modules/@common/utils/format-number";
|
|
21
|
+
import PluginSettingsService from "../../modules/plugin-settings/services/plugin-settings-service";
|
|
21
22
|
|
|
22
23
|
import "../../i18n";
|
|
23
24
|
|
|
@@ -37,6 +38,9 @@ function Settings(props) {
|
|
|
37
38
|
setIsLoading(true);
|
|
38
39
|
const project = await ProjectService.getConnectedProject();
|
|
39
40
|
setConnectedProject(project);
|
|
41
|
+
|
|
42
|
+
PluginSettingsService.updatePluginSettings({ defaultRoute: PLUGIN_ROUTES.SETTINGS });
|
|
43
|
+
|
|
40
44
|
setIsLoading(false);
|
|
41
45
|
}
|
|
42
46
|
|
|
@@ -23,6 +23,7 @@ import redirectToPluginRoute, {
|
|
|
23
23
|
} from "../../modules/@common/utils/redirect-to-plugin-route";
|
|
24
24
|
import { getLocalazyIdentity } from "../../state/localazy-identity";
|
|
25
25
|
import ProductAnalyticsService from "../../modules/@common/services/product-analytics-service";
|
|
26
|
+
import PluginSettingsService from "../../modules/plugin-settings/services/plugin-settings-service";
|
|
26
27
|
|
|
27
28
|
import "../../i18n";
|
|
28
29
|
|
|
@@ -79,6 +80,8 @@ function Upload(props) {
|
|
|
79
80
|
setModelChanged(await hasModelChanged());
|
|
80
81
|
setLocalesIncompatible(!(await areLocalesCompatible(strapiDefaultLocale, localazySourceLanguage)));
|
|
81
82
|
|
|
83
|
+
PluginSettingsService.updatePluginSettings({ defaultRoute: PLUGIN_ROUTES.UPLOAD });
|
|
84
|
+
|
|
82
85
|
setIsLoading(false);
|
|
83
86
|
}
|
|
84
87
|
initComponent();
|
package/package.json
CHANGED
|
@@ -14,4 +14,18 @@ module.exports = {
|
|
|
14
14
|
.service("pluginSettingsService")
|
|
15
15
|
.updateContentTransferSetup(ctx.request.body);
|
|
16
16
|
},
|
|
17
|
+
|
|
18
|
+
async getPluginSettings(ctx) {
|
|
19
|
+
ctx.body = await strapi
|
|
20
|
+
.plugin("localazy")
|
|
21
|
+
.service("pluginSettingsService")
|
|
22
|
+
.getPluginSettings();
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
async updatePluginSettings(ctx) {
|
|
26
|
+
ctx.body = await strapi
|
|
27
|
+
.plugin("localazy")
|
|
28
|
+
.service("pluginSettingsService")
|
|
29
|
+
.updatePluginSettings(ctx.request.body);
|
|
30
|
+
}
|
|
17
31
|
};
|
|
@@ -19,4 +19,20 @@ module.exports = [
|
|
|
19
19
|
policies: [],
|
|
20
20
|
},
|
|
21
21
|
},
|
|
22
|
+
{
|
|
23
|
+
method: "GET",
|
|
24
|
+
path: `${ROUTE_PREFIX}/plugin-settings`,
|
|
25
|
+
handler: "pluginSettingsController.getPluginSettings",
|
|
26
|
+
config: {
|
|
27
|
+
policies: [],
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
method: "PUT",
|
|
32
|
+
path: `${ROUTE_PREFIX}/plugin-settings`,
|
|
33
|
+
handler: "pluginSettingsController.updatePluginSettings",
|
|
34
|
+
config: {
|
|
35
|
+
policies: [],
|
|
36
|
+
},
|
|
37
|
+
}
|
|
22
38
|
];
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
const contentTransferSetupModel = require("../db/model/content-transfer-setup");
|
|
4
|
+
|
|
5
|
+
const pluginSettingsModel = require("../db/model/plugin-settings");
|
|
6
|
+
// {
|
|
7
|
+
// KEY,
|
|
8
|
+
// emptyPluginSettings,
|
|
9
|
+
// } = require("../db/model/plugin-settings");
|
|
7
10
|
const getStrapiStore = require("../db/model/utils/get-strapi-store");
|
|
8
11
|
|
|
9
12
|
module.exports = ({ strapi }) => ({
|
|
10
13
|
async getContentTransferSetup() {
|
|
11
14
|
const pluginStore = getStrapiStore(strapi);
|
|
12
|
-
const setup = await pluginStore.get({ key: KEY });
|
|
15
|
+
const setup = await pluginStore.get({ key: contentTransferSetupModel.KEY });
|
|
13
16
|
|
|
14
|
-
return setup || emptyContentTransferSetup;
|
|
17
|
+
return setup || contentTransferSetupModel.emptyContentTransferSetup;
|
|
15
18
|
},
|
|
16
19
|
|
|
17
20
|
async updateContentTransferSetup(setup) {
|
|
@@ -21,10 +24,28 @@ module.exports = ({ strapi }) => ({
|
|
|
21
24
|
};
|
|
22
25
|
const pluginStore = getStrapiStore(strapi);
|
|
23
26
|
await pluginStore.set({
|
|
24
|
-
key: KEY,
|
|
27
|
+
key: contentTransferSetupModel.KEY,
|
|
25
28
|
value: newSetup,
|
|
26
29
|
});
|
|
27
30
|
|
|
28
31
|
return newSetup;
|
|
29
32
|
},
|
|
33
|
+
|
|
34
|
+
async getPluginSettings() {
|
|
35
|
+
const pluginStore = getStrapiStore(strapi);
|
|
36
|
+
const settings = await pluginStore.get({ key: pluginSettingsModel.KEY });
|
|
37
|
+
|
|
38
|
+
return settings || pluginSettingsModel.emptyPluginSettings;
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
async updatePluginSettings(settings) {
|
|
42
|
+
const newSettings = settings;
|
|
43
|
+
const pluginStore = getStrapiStore(strapi);
|
|
44
|
+
await pluginStore.set({
|
|
45
|
+
key: pluginSettingsModel.KEY,
|
|
46
|
+
value: newSettings,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return newSettings;
|
|
50
|
+
},
|
|
30
51
|
});
|