Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LOC-1015 Strapi plugin does not work on certain versions #48

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ npm install @localazy/strapi-plugin@latest && npx @localazy/strapi-plugin

Note: Localazy plugin requires an updated Webpack configuration of your Strapi project. Follow the instructions in the console output during the installation process. Steps are also available in the [Install plugin via NPM](https://localazy.com/docs/strapi/strapi-plugin-introduction-installation#install-plugin-via-npm) section of the Localazy Docs.

Due to the changes in Strapi core code it's also necessary to add an environment variable to your Strapi project. Add the following line to your `.env` file (value is empty):

```
STRAPI_ADMIN_LOCALAZY_ENV=
```

## Configuration

Additional configuration object may be provided in the `plugins.js` file. The following options are available:
Expand Down
14 changes: 14 additions & 0 deletions admin/src/config/development/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default {
LOCALAZY_OAUTH_URL: "https://testing.localazy.com/oauth/authorize",
LOCALAZY_OAUTH_APP_CLIENT_ID: "18503917571895066466",
LOCALAZY_PLUGIN_CONNECTOR_API_URL: "https://testing.localazy.com/plugin-connector",
LOCALAZY_PUBLIC_API_URL: "https://testing.localazy.com/pubapi",
LOCALAZY_PLUGIN_ID: "1",
LOCALAZY_DEFAULT_FILE_NAME: "strapi.json",
LOCALAZY_DEFAULT_FILE_PATH: "",
LOCALAZY_DEFAULT_FILE_EXTENSION: "json",
LOCALAZY_DEFAULT_LOCALE: "en",
LOCALAZY_API_USER_JWT_COOKIE_NAME: "LOCALAZY-API-USER-JWT",
LOCALAZY_API_USER_COOKIE_EXPIRATION: 7,
LOCALAZY_PUBLIC_API_LIFTED_LIMITS: true,
};
14 changes: 14 additions & 0 deletions admin/src/config/example/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default {
LOCALAZY_OAUTH_URL: "",
LOCALAZY_OAUTH_APP_CLIENT_ID: "",
LOCALAZY_PLUGIN_CONNECTOR_API_URL: "",
LOCALAZY_PUBLIC_API_URL: "",
LOCALAZY_PLUGIN_ID: "",
LOCALAZY_DEFAULT_FILE_NAME: "",
LOCALAZY_DEFAULT_FILE_PATH: "",
LOCALAZY_DEFAULT_FILE_EXTENSION: "",
LOCALAZY_DEFAULT_LOCALE: "",
LOCALAZY_API_USER_JWT_COOKIE_NAME: "",
LOCALAZY_API_USER_COOKIE_EXPIRATION: -1,
LOCALAZY_PUBLIC_API_LIFTED_LIMITS: false,
};
21 changes: 21 additions & 0 deletions admin/src/config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import production from "./production/index";
import local from "./local/index";
import development from "./development/index";


// depending on the STRAPI_ADMIN_LOCALAZY_ENV, use the correct config
let config = production;

if (process.env.STRAPI_ADMIN_LOCALAZY_ENV === "local") {
config = local;
}

if (process.env.STRAPI_ADMIN_LOCALAZY_ENV === "development") {
config = development;
}

console.log(config);

export default {
...config,
};
14 changes: 14 additions & 0 deletions admin/src/config/local/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default {
LOCALAZY_OAUTH_URL: "https://testing.localazy.com/oauth/authorize",
LOCALAZY_OAUTH_APP_CLIENT_ID: "18503917571895066465",
LOCALAZY_PLUGIN_CONNECTOR_API_URL: "http://localhost:3000",
LOCALAZY_PUBLIC_API_URL: "https://testing.localazy.com/pubapi",
LOCALAZY_PLUGIN_ID: "1",
LOCALAZY_DEFAULT_FILE_NAME: "strapi.json",
LOCALAZY_DEFAULT_FILE_PATH: "",
LOCALAZY_DEFAULT_FILE_EXTENSION: "json",
LOCALAZY_DEFAULT_LOCALE: "en",
LOCALAZY_API_USER_JWT_COOKIE_NAME: "LOCALAZY-API-USER-JWT",
LOCALAZY_API_USER_COOKIE_EXPIRATION: 7,
LOCALAZY_PUBLIC_API_LIFTED_LIMITS: false,
};
15 changes: 15 additions & 0 deletions admin/src/config/production/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default {
LOCALAZY_OAUTH_URL: "https://localazy.com/oauth/authorize",
LOCALAZY_OAUTH_APP_CLIENT_ID: "18395772851999073783",
LOCALAZY_PLUGIN_CONNECTOR_API_URL:
"https://plugins.localazy.com/generic-connector",
LOCALAZY_PUBLIC_API_URL: "https://api.localazy.com",
LOCALAZY_PLUGIN_ID: "1",
LOCALAZY_DEFAULT_FILE_NAME: "strapi.json",
LOCALAZY_DEFAULT_FILE_PATH: "",
LOCALAZY_DEFAULT_FILE_EXTENSION: "json",
LOCALAZY_DEFAULT_LOCALE: "en",
LOCALAZY_API_USER_JWT_COOKIE_NAME: "LOCALAZY-API-USER-JWT",
LOCALAZY_API_USER_COOKIE_EXPIRATION: 7,
LOCALAZY_PUBLIC_API_LIFTED_LIMITS: true,
};
22 changes: 13 additions & 9 deletions admin/src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@ import en_download from "./modules/localazy-download/locale/en";
import en_upload from "./modules/localazy-upload/locale/en";
import en_plugin_settings from "./modules/plugin-settings/locale/en";

i18n
// detect user language
// pass the i18n instance to react-i18next.
.use(initReactI18next)
// init i18next
// for all options read: https://www.i18next.com/overview/configuration-options
.init({
debug: process.env.STRAPI_ADMIN_LOCALAZY_ENV === "development",
const initI18nParams = () => {
return {
debug: false, // set `true` to see more logs
fallbackLng: "en",
interpolation: {
escapeValue: false, // not needed for react as it escapes by default
Expand All @@ -32,6 +27,15 @@ i18n
},
},
},
});
};
}

i18n
// detect user language
// pass the i18n instance to react-i18next.
.use(initReactI18next)
// init i18next
// for all options read: https://www.i18next.com/overview/configuration-options
.init(initI18nParams());

export default i18n;
10 changes: 8 additions & 2 deletions admin/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,15 @@ export default {
defaultMessage: upperCaseName,
},
Component: async () => {
const component = await import("./pages/Index");
try {
const component = await import("./pages/Index");

return component;
return component;
} catch (e) {
console.log(e);
}

return null;
},
permissions: [
// Uncomment to set the permissions of the plugin here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { useTranslation } from "react-i18next";
import cloneDeep from "lodash-es/cloneDeep";
import { Select, Option } from '@strapi/design-system/Select';

import "../../../../i18n";

function LanguagesSelector(props) {
/**
* Translation function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { Flex } from '@strapi/design-system/Flex';
import { Loader } from "@strapi/design-system/Loader";
import { useTranslation } from "react-i18next";

import "../../../../i18n";

function PluginPageLoader() {
const { t } = useTranslation();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import PropTypes from "prop-types";
import { Alert } from "@strapi/design-system/Alert";
import { useTranslation } from "react-i18next";
import { Box } from "@strapi/design-system/Box";
import "../../../../i18n";

function TransferReport(props) {
const { t } = useTranslation();
Expand Down
2 changes: 1 addition & 1 deletion admin/src/modules/@common/utils/get-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Upload from "@strapi/icons/Upload";
import pluginId from "../../../pluginId";
import i18n from "../../../i18n";

const BASE_PATH = `${process.env.ADMIN_PATH}plugins/${pluginId}`;
const BASE_PATH = `${process.env.ADMIN_PATH}/plugins/${pluginId}`;
const t = i18n.t;
const gevNav = () => {
return [
Expand Down
4 changes: 2 additions & 2 deletions admin/src/modules/@common/utils/redirect-to-plugin-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export const PLUGIN_ROUTES = {

export default (route) => {
if (route === PLUGIN_ROUTES.CONTENT_TRANSFER_SETUP) {
history.push(`${process.env.ADMIN_PATH}settings/${pluginId}/${route}`);
history.push(`${process.env.ADMIN_PATH}/settings/${pluginId}/${route}`);

return;
}

history.push(`${process.env.ADMIN_PATH}plugins/${pluginId}/${route}`);
history.push(`${process.env.ADMIN_PATH}/plugins/${pluginId}/${route}`);
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react";
import { Button } from "@strapi/design-system/Button";
import { useTranslation } from "react-i18next";
import "../../../i18n";

function ReadDocsButton() {
const { t } = useTranslation();
Expand Down
7 changes: 3 additions & 4 deletions admin/src/modules/login/components/LoginButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import { useTranslation } from "react-i18next";
import LocalazyLoginService from "../../services/localazy-login-service";
import { getStrapiDefaultLocale } from "../../../@common/utils/get-default-locale";
import { isoStrapiToLocalazy } from "../../../@common/utils/iso-locales-utils";
import { config } from "../../../../../../server";
import "../../../../i18n";
import config from "../../../../config";

function LoginButton(props) {
const { t } = useTranslation();
Expand All @@ -25,12 +24,12 @@ function LoginButton(props) {
const localazyFormatLocaleCode = isoStrapiToLocalazy(strapiDefaultLocale.code);
const keys = await LocalazyLoginService.generateKeys();
const params = new URLSearchParams({
client_id: config.default.LOCALAZY_OAUTH_APP_CLIENT_ID,
client_id: config.LOCALAZY_OAUTH_APP_CLIENT_ID,
custom_id: keys.writeKey,
allow_create: "true",
create_locale: localazyFormatLocaleCode,
});
const url = `${config.default.LOCALAZY_OAUTH_URL}?${params.toString()}`;
const url = `${config.LOCALAZY_OAUTH_URL}?${params.toString()}`;
window.open(url);

const pollResult = await LocalazyLoginService.continuousPoll(keys.readKey);
Expand Down
1 change: 0 additions & 1 deletion admin/src/modules/login/components/LogoutButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { useTranslation } from "react-i18next";
import Exit from "@strapi/icons/Exit";
import LocalazyUserService from "../../../user/services/localazy-user-service";
import { setLocalazyIdentity } from "../../../../state/localazy-identity";
import "../../../../i18n";

function LogoutButton(props) {
const { t } = useTranslation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function ContentTransferSetup() {

return (
<>
{!isLoading && !isLoggedIn && <Redirect to={`${process.env.ADMIN_PATH}plugins/${pluginId}/login`} />}
{!isLoading && !isLoggedIn && <Redirect to={`/plugins/${pluginId}/login`} />}

<HeaderLayout
title={t("plugin_settings.content_transfer_setup")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function GlobalSettings() {

return (
<>
{!isLoading && !isLoggedIn && <Redirect to={`${process.env.ADMIN_PATH}plugins/${pluginId}/login`} />}
{!isLoading && !isLoggedIn && <Redirect to={`/plugins/${pluginId}/login`} />}

<HeaderLayout
title={t("plugin_settings.global_settings")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { Box } from "@strapi/design-system/Box";
import { useTranslation } from "react-i18next";
import { Typography } from "@strapi/design-system/Typography";

import "../../../../i18n";

function PrerequisitiesInfo() {
const { t } = useTranslation();

Expand Down
8 changes: 4 additions & 4 deletions admin/src/pages/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function App() {
<>
{!isLoggedIn && (
<Switch>
<Route path={`${process.env.ADMIN_PATH}plugins/${pluginId}/login`} exact>
<Route path={`${process.env.ADMIN_PATH}/plugins/${pluginId}/login`} exact>
<Login
title={headerTitle}
subtitle={headerSubtitle}
Expand All @@ -121,19 +121,19 @@ function App() {

{isLoggedIn && (
<Switch>
<Route path={`${process.env.ADMIN_PATH}plugins/${pluginId}/download`} exact>
<Route path={`${process.env.ADMIN_PATH}/plugins/${pluginId}/download`} exact>
<Download
title={headerTitle}
subtitle={headerSubtitle}
/>
</Route>
<Route path={`${process.env.ADMIN_PATH}plugins/${pluginId}/upload`} exact>
<Route path={`${process.env.ADMIN_PATH}/plugins/${pluginId}/upload`} exact>
<Upload
title={headerTitle}
subtitle={headerSubtitle}
/>
</Route>
<Route path={`${process.env.ADMIN_PATH}plugins/${pluginId}/settings`} exact>
<Route path={`${process.env.ADMIN_PATH}/plugins/${pluginId}/settings`} exact>
<Settings
title={headerTitle}
subtitle={headerSubtitle}
Expand Down
1 change: 0 additions & 1 deletion admin/src/pages/Download/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import areLocalesCompatible from "../../modules/@common/utils/are-locales-compat
import hasModelChanged from "../../modules/plugin-settings/functions/has-model-changed";
import TransferReport from "../../modules/@common/components/TransferReport";
import ReadDocsButton from "../../modules/localazy-upload/components/ReadDocsButton";
import "../../i18n";
import { getLocalazyIdentity } from "../../state/localazy-identity";
import ProductAnalyticsService from "../../modules/@common/services/product-analytics-service";
import PluginSettingsService from "../../modules/plugin-settings/services/plugin-settings-service";
Expand Down
2 changes: 0 additions & 2 deletions admin/src/pages/Login/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import redirectToPluginRoute, {
} from "../../modules/@common/utils/redirect-to-plugin-route";
import ProductAnalyticsService from "../../modules/@common/services/product-analytics-service";

import "../../i18n";

function Login(props) {
const history = useHistory();
const { t } = useTranslation();
Expand Down
2 changes: 0 additions & 2 deletions admin/src/pages/PluginSettings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import LocalazyUserService from "../../modules/user/services/localazy-user-servi
import { setLocalazyIdentity } from "../../state/localazy-identity";
import Loader from "../../modules/@common/components/PluginPageLoader";

import "../../i18n";

function PluginSettings() {
/**
* Translation function
Expand Down
2 changes: 0 additions & 2 deletions admin/src/pages/Settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import ProductAnalyticsService from "../../modules/@common/services/product-anal
import formatNumber from "../../modules/@common/utils/format-number";
import PluginSettingsService from "../../modules/plugin-settings/services/plugin-settings-service";

import "../../i18n";

function Settings(props) {
const history = useHistory();
const { t } = useTranslation();
Expand Down
2 changes: 0 additions & 2 deletions admin/src/pages/Upload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import ProductAnalyticsService from "../../modules/@common/services/product-anal
import PluginSettingsService from "../../modules/plugin-settings/services/plugin-settings-service";
import UploadAlertsService from "../../modules/localazy-upload/services/upload-alerts-service";

import "../../i18n";

const uploadAlertsService = new UploadAlertsService();
uploadAlertsService.subscribe();

Expand Down
4 changes: 2 additions & 2 deletions admin/src/utils/createPluginConnectorAxiosInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
*/

import axios from "axios";
import { config } from "../../../server";
import config from "../config";

const BASE_PLUGIN_PATH = config.default.LOCALAZY_PLUGIN_CONNECTOR_API_URL;
const BASE_PLUGIN_PATH = config.LOCALAZY_PLUGIN_CONNECTOR_API_URL;

const createPluginConnectorAxiosInstance = (baseUrl = null) => {
if (baseUrl === null) {
Expand Down
17 changes: 15 additions & 2 deletions install/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const install = () => new Promise((resolve, reject) => {
}
});

const updateConfig = () => new Promise((resolve, reject) => {
const createWebpackConfigSample = () => new Promise((resolve, reject) => {
try {
shell.exec(`echo "${template}" > src/admin/${exampleFileName}`, { silent: true }, () => {
resolve();
Expand All @@ -49,14 +49,27 @@ const updateConfig = () => new Promise((resolve, reject) => {
}
});

const updateEnvConfig = () => new Promise((resolve, reject) => {
try {
shell.exec(`echo "STRAPI_ADMIN_LOCALAZY_ENV=" >> .env`, { silent: true }, () => {
resolve();
});
} catch (err) {
reject(err);
}
});

console.log(banner);

installSpinner.start(`Installing ${name}${version}`);
await install();
installSpinner.succeed();

installSpinner.start(`Creating example ${file} file in ${chalk.bold.green("src/admin")} folder`);
await updateConfig();
await createWebpackConfigSample();
installSpinner.succeed();
installSpinner.start(`Updating ${chalk.bold.green(".env")} file with ${chalk.bold.green("STRAPI_ADMIN_LOCALAZY_ENV")} variable`);
await updateEnvConfig();
installSpinner.succeed();
installSpinner.succeed(`To run the plugin, you need to update your webpack config in ${chalk.bold.green("src/admin/webpack.config.js")} file`);
installSpinner.succeed(`Don't forget to build the admin panel with ${chalk.bold.green("npm run build")} command`);
Loading