From 2f8df21f1727994332d4ee6c7ef18dd0fe5018dd Mon Sep 17 00:00:00 2001 From: Gia Phu Date: Tue, 7 Feb 2023 17:15:52 +0700 Subject: [PATCH 01/11] Migrator page --- package.json | 1 + src/components/Form/index.jsx | 24 ++-- src/components/Menu/index.jsx | 24 +++- .../MigratorPage/MigratorForm/JoomlaForm.jsx | 110 ++++++++++++++++++ .../MigratorForm/MergeDataPage.jsx | 27 +++++ .../MigratorForm/WordPressForm.jsx | 82 +++++++++++++ .../MigratorStore/MigratorStore.js | 0 .../MigratorViewModels/JoomlaFormViewModel.js | 17 +++ .../MigratorViewModels/MigratorViewModel.js | 22 ++++ .../WordPressFormViewModel.js | 17 +++ src/containers/MigratorPage/index.jsx | 47 ++++++++ src/routes/routes.js | 6 + src/translations/dk/common.json | 3 +- src/translations/en/common.json | 3 +- src/translations/es/common.json | 4 +- src/translations/fr/common.json | 4 +- src/translations/hr/common.json | 4 +- src/translations/th/common.json | 4 +- src/translations/ua/common.json | 4 +- src/translations/vi/common.json | 4 +- yarn.lock | 5 + 21 files changed, 386 insertions(+), 26 deletions(-) create mode 100644 src/containers/MigratorPage/MigratorForm/JoomlaForm.jsx create mode 100644 src/containers/MigratorPage/MigratorForm/MergeDataPage.jsx create mode 100644 src/containers/MigratorPage/MigratorForm/WordPressForm.jsx create mode 100644 src/containers/MigratorPage/MigratorStore/MigratorStore.js create mode 100644 src/containers/MigratorPage/MigratorViewModels/JoomlaFormViewModel.js create mode 100644 src/containers/MigratorPage/MigratorViewModels/MigratorViewModel.js create mode 100644 src/containers/MigratorPage/MigratorViewModels/WordPressFormViewModel.js create mode 100644 src/containers/MigratorPage/index.jsx diff --git a/package.json b/package.json index 273f450..63b9175 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "react-select": "^5.4.0", "react-simple-maps": "^3.0.0", "react-spinners": "^0.13.6", + "react-step-wizard": "^5.3.11", "react-table": "^7.6.2", "react-timezone-select": "^1.0.7", "react-toastify": "^9.0.8", diff --git a/src/components/Form/index.jsx b/src/components/Form/index.jsx index e055b02..315744f 100644 --- a/src/components/Form/index.jsx +++ b/src/components/Form/index.jsx @@ -1,7 +1,7 @@ import React, { Component } from 'react'; import SimpleReactValidator from 'simple-react-validator'; -// import { Form } from 'react-bootstrap'; +import { Form } from 'react-bootstrap'; import { renderingGroupFieldHandler } from '../../utils/form'; @@ -43,17 +43,17 @@ class FormComponent extends Component { renderingFormHandler = (formSetting) => { return ( <> - {/*
*/} - {Object.keys(formSetting) - .map((groupIndex) => { - return [...Array(formSetting[groupIndex])].map((group) => { - return renderingGroupFieldHandler(group, this.validator); - }); - }) - .reduce((arr, el) => { - return arr.concat(el); - }, [])} - {/*
*/} +
+ {Object.keys(formSetting) + .map((groupIndex) => { + return [...Array(formSetting[groupIndex])].map((group) => { + return renderingGroupFieldHandler(group, this.validator); + }); + }) + .reduce((arr, el) => { + return arr.concat(el); + }, [])} +
); }; diff --git a/src/components/Menu/index.jsx b/src/components/Menu/index.jsx index 7143cc7..5cdc6b2 100644 --- a/src/components/Menu/index.jsx +++ b/src/components/Menu/index.jsx @@ -93,12 +93,24 @@ const Menu = observer((props) => { icons_color: '/assets/images/image.png', width: 24, height: 24, - // submenu: [ - // { - // text: "txt_menu_overview", - // link: `/data-${dataStreamActive}/audience/overview`, - // }, - // ], + }, + { + text: 'txt_migrator', + link: `/migrator`, + icons: '/assets/images/image.png', + icons_color: '/assets/images/image.png', + width: 24, + height: 24, + submenu: [ + { + text: 'Joomla', + link: '/migrator/joomla', + }, + { + text: 'Wordpress', + link: '/migrator/wordpress', + }, + ], }, ]; diff --git a/src/containers/MigratorPage/MigratorForm/JoomlaForm.jsx b/src/containers/MigratorPage/MigratorForm/JoomlaForm.jsx new file mode 100644 index 0000000..ea88287 --- /dev/null +++ b/src/containers/MigratorPage/MigratorForm/JoomlaForm.jsx @@ -0,0 +1,110 @@ +import Input from 'components/Form/Input'; +import { FORM_FIELD_TYPE } from 'constants/FormFieldType'; +import React, { Component } from 'react'; +import { Button, Form } from 'react-bootstrap'; +import SimpleReactValidator from 'simple-react-validator'; +import { observer } from 'mobx-react'; +import { notify } from 'components/Toast'; + +const JoomlaForm = observer( + class JoomlaForm extends Component { + formPropsData = { + joomla_bearer_token: '', + joomla_api_url: '', + }; + constructor(props) { + super(props); + this.validator = new SimpleReactValidator({ autoForceUpdate: this }); + this.state = { + loading: false, + }; + } + render() { + const { nextStep } = this.props; + const { loading } = this.state; + const hanldeClick = () => { + this.setState({ loading: true }); + if (this.validator.allValid()) { + nextStep(); + } else { + notify('Please input all required fields', 'warn'); + this.validator.showMessages(); + } + this.setState({ loading: false }); + }; + return ( +
+
+
+ + + Joomla Bearer Token + * + + { + this.formPropsData['joomla_bearer_token'] = e.target.value; + console.log(e.target.value); + }, + blurred: () => { + this.validator.showMessageFor('Joomla Bearer Token'); + }, + }} + /> + {this.validator.message( + 'Joomla Bearer Token', + this.formPropsData['joomla_bearer_token'], + 'required', + { + className: 'text-danger mt-1', + } + )} + + + + Joomla API URL + * + + { + this.formPropsData['joomla_api_url'] = e.target.value; + console.log(e.target.value); + }, + blurred: () => { + this.validator.showMessageFor('Joomla API URL'); + }, + }} + /> + {this.validator.message( + 'Joomla API URL', + this.formPropsData['joomla_api_url'], + 'required', + { + className: 'text-danger mt-1', + } + )} + +
+
+ +
+
+
+ ); + } + } +); +export default JoomlaForm; diff --git a/src/containers/MigratorPage/MigratorForm/MergeDataPage.jsx b/src/containers/MigratorPage/MigratorForm/MergeDataPage.jsx new file mode 100644 index 0000000..9b35421 --- /dev/null +++ b/src/containers/MigratorPage/MigratorForm/MergeDataPage.jsx @@ -0,0 +1,27 @@ +import React, { Component } from 'react'; +import { Button } from 'react-bootstrap'; + +export default class MergeDataPage extends Component { + render() { + const { previousStep, viewModel } = this.props; + const handleClick = () => { + console.log(viewModel); + }; + return ( + <> +
+ +
+ + + ); + } +} diff --git a/src/containers/MigratorPage/MigratorForm/WordPressForm.jsx b/src/containers/MigratorPage/MigratorForm/WordPressForm.jsx new file mode 100644 index 0000000..3993f96 --- /dev/null +++ b/src/containers/MigratorPage/MigratorForm/WordPressForm.jsx @@ -0,0 +1,82 @@ +import Input from 'components/Form/Input'; +import { FORM_FIELD_TYPE } from 'constants/FormFieldType'; +import React, { Component } from 'react'; +import { Button, Form } from 'react-bootstrap'; +import SimpleReactValidator from 'simple-react-validator'; +import { observer } from 'mobx-react'; +import { notify } from 'components/Toast'; + +const JoomlaForm = observer( + class JoomlaForm extends Component { + formPropsData = { + url: '', + }; + constructor(props) { + super(props); + this.validator = new SimpleReactValidator({ autoForceUpdate: this }); + this.state = { + loading: false, + }; + } + render() { + const { nextStep } = this.props; + const { loading } = this.state; + const hanldeClick = () => { + this.setState({ loading: true }); + if (this.validator.allValid()) { + nextStep(); + } else { + notify('Please input WordPress API URL fields', 'warn'); + this.validator.showMessages(); + } + this.setState({ loading: false }); + }; + return ( +
+
+
+ + + WordPress API URL + * + + { + this.formPropsData['url'] = e.target.value; + console.log(e.target.value); + }, + blurred: () => { + this.validator.showMessageFor('WordPress API URL'); + }, + }} + /> + {this.validator.message( + 'WordPress API URL', + this.formPropsData['url'], + 'required', + { + className: 'text-danger mt-1', + } + )} + +
+
+ +
+
+
+ ); + } + } +); +export default JoomlaForm; diff --git a/src/containers/MigratorPage/MigratorStore/MigratorStore.js b/src/containers/MigratorPage/MigratorStore/MigratorStore.js new file mode 100644 index 0000000..e69de29 diff --git a/src/containers/MigratorPage/MigratorViewModels/JoomlaFormViewModel.js b/src/containers/MigratorPage/MigratorViewModels/JoomlaFormViewModel.js new file mode 100644 index 0000000..a487113 --- /dev/null +++ b/src/containers/MigratorPage/MigratorViewModels/JoomlaFormViewModel.js @@ -0,0 +1,17 @@ +/* + * @copyright Copyright (C) 2022 AesirX. All rights reserved. + * @license GNU General Public License version 3, see LICENSE. + */ + +import { makeAutoObservable } from 'mobx'; + +class JoomlaFormViewModel { + migratorStore = null; + + constructor(migratorStore) { + makeAutoObservable(this); + this.migratorStore = migratorStore; + } +} + +export default JoomlaFormViewModel; diff --git a/src/containers/MigratorPage/MigratorViewModels/MigratorViewModel.js b/src/containers/MigratorPage/MigratorViewModels/MigratorViewModel.js new file mode 100644 index 0000000..079c239 --- /dev/null +++ b/src/containers/MigratorPage/MigratorViewModels/MigratorViewModel.js @@ -0,0 +1,22 @@ +/* + * @copyright Copyright (C) 2022 AesirX. All rights reserved. + * @license GNU General Public License version 3, see LICENSE. + */ +import JoomlaFormViewModel from './JoomlaFormViewModel'; +import WordPressFormViewModel from './WordPressFormViewModel'; + +class MigratorViewModel { + joomlaFormViewModel = null; + wordpressFormViewModel = null; + + constructor(migratorStore) { + if (migratorStore) { + this.joomlaFormViewModel = new JoomlaFormViewModel(migratorStore); + this.wordpressFormViewModel = new WordPressFormViewModel(migratorStore); + } + } + getJoomlaFormViewModel = () => this.joomlaFormViewModel; + getWordPressFormViewModel = () => this.wordpressFormViewModel; +} + +export default MigratorViewModel; diff --git a/src/containers/MigratorPage/MigratorViewModels/WordPressFormViewModel.js b/src/containers/MigratorPage/MigratorViewModels/WordPressFormViewModel.js new file mode 100644 index 0000000..833670b --- /dev/null +++ b/src/containers/MigratorPage/MigratorViewModels/WordPressFormViewModel.js @@ -0,0 +1,17 @@ +/* + * @copyright Copyright (C) 2022 AesirX. All rights reserved. + * @license GNU General Public License version 3, see LICENSE. + */ + +import { makeAutoObservable } from 'mobx'; + +class WordPressFormViewModel { + migratorStore = null; + + constructor(migratorStore) { + makeAutoObservable(this); + this.migratorStore = migratorStore; + } +} + +export default WordPressFormViewModel; diff --git a/src/containers/MigratorPage/index.jsx b/src/containers/MigratorPage/index.jsx new file mode 100644 index 0000000..f9d4dac --- /dev/null +++ b/src/containers/MigratorPage/index.jsx @@ -0,0 +1,47 @@ +import React, { Component } from 'react'; +import { Route } from 'react-router-dom'; +import StepWizard from 'react-step-wizard'; +import JoomlaForm from './MigratorForm/JoomlaForm'; +import WordPressForm from './MigratorForm/WordPressForm'; +import MergeDataPage from './MigratorForm/MergeDataPage'; + +export class MigratorPage extends Component { + render() { + return ( +
+ + + + + + + + + + + + +
+ ); + } +} + +export default MigratorPage; diff --git a/src/routes/routes.js b/src/routes/routes.js index 24ed887..ab61dc8 100644 --- a/src/routes/routes.js +++ b/src/routes/routes.js @@ -7,6 +7,7 @@ const ItemsPage = lazy(() => import('../containers/ItemsPage')); const ProfilePage = lazy(() => import('../containers/ProfilePage')); const CategoriesPage = lazy(() => import('../containers/Categories')); const DamPage = lazy(() => import('../containers/DamPage')); +const MigratorPage = lazy(() => import('../containers/MigratorPage')); const ContentPage = lazy(() => import('../containers/ContentPage')); const SettingPage = lazy(() => import('../containers/ItemsPage')); const HelpCenterPage = lazy(() => import('../containers/ItemsPage')); @@ -38,6 +39,11 @@ const mainRoutes = [ exact: true, main: ({ match }) => , }, + { + path: ['/migrator/joomla', '/migrator/wordpress'], + exact: true, + main: ({ match }) => , + }, { path: '/categories', exact: true, diff --git a/src/translations/dk/common.json b/src/translations/dk/common.json index 459fb63..16639d0 100644 --- a/src/translations/dk/common.json +++ b/src/translations/dk/common.json @@ -105,5 +105,6 @@ "txt_error": "Fejl", "txt_successfuly":"Succesfuldt", "txt_unsuccess": "Forgæves", - "txt_delete_success": "Slet med succes" + "txt_delete_success": "Slet med succes", + "txt_migrator": "Migrator" } \ No newline at end of file diff --git a/src/translations/en/common.json b/src/translations/en/common.json index 1b1f495..e2b0185 100644 --- a/src/translations/en/common.json +++ b/src/translations/en/common.json @@ -105,5 +105,6 @@ "txt_error": "Error", "txt_successfuly":"Successfully", "txt_unsuccess": "Unsuccessfully", - "txt_delete_success": "Delete Successfully" + "txt_delete_success": "Delete Successfully", + "txt_migrator": "Migrator" } \ No newline at end of file diff --git a/src/translations/es/common.json b/src/translations/es/common.json index 032a5d7..f3a5d98 100644 --- a/src/translations/es/common.json +++ b/src/translations/es/common.json @@ -105,5 +105,7 @@ "txt_error": "Error", "txt_successfuly":"ErrorCon éxito", "txt_unsuccess": "sin éxito", - "txt_delete_success": "Eliminar con éxito" + "txt_delete_success": "Eliminar con éxito", + "txt_migrator": "Migrator" + } \ No newline at end of file diff --git a/src/translations/fr/common.json b/src/translations/fr/common.json index 33e15ce..1a55a72 100644 --- a/src/translations/fr/common.json +++ b/src/translations/fr/common.json @@ -105,5 +105,7 @@ "txt_error": "Erreur", "txt_successfuly":"Avec succès", "txt_unsuccess": "Sans succès", - "txt_delete_success": "Supprimer avec succès" + "txt_delete_success": "Supprimer avec succès", + "txt_migrator": "Migrator" + } \ No newline at end of file diff --git a/src/translations/hr/common.json b/src/translations/hr/common.json index e694685..65c7122 100644 --- a/src/translations/hr/common.json +++ b/src/translations/hr/common.json @@ -105,5 +105,7 @@ "txt_error": "Greška", "txt_successfuly":"Uspješno", "txt_unsuccess": "Neuspješno", - "txt_delete_success": "Uspješno brisanje" + "txt_delete_success": "Uspješno brisanje", + "txt_migrator": "Migrator" + } \ No newline at end of file diff --git a/src/translations/th/common.json b/src/translations/th/common.json index 942c735..30057ed 100644 --- a/src/translations/th/common.json +++ b/src/translations/th/common.json @@ -105,5 +105,7 @@ "txt_error": "ข้อผิดพลาด", "txt_successfuly":"เรียบร้อยแล้ว", "txt_unsuccess": "ไม่สำเร็จ", - "txt_delete_success": "ลบสำเร็จ" + "txt_delete_success": "ลบสำเร็จ", + "txt_migrator": "Migrator" + } \ No newline at end of file diff --git a/src/translations/ua/common.json b/src/translations/ua/common.json index 7d357a6..2ed0005 100644 --- a/src/translations/ua/common.json +++ b/src/translations/ua/common.json @@ -105,5 +105,7 @@ "txt_error": "Помилка", "txt_successfuly":"Успішно", "txt_unsuccess": "Безуспішно", - "txt_delete_success": "Видалити успішно" + "txt_delete_success": "Видалити успішно", + "txt_migrator": "Migrator" + } \ No newline at end of file diff --git a/src/translations/vi/common.json b/src/translations/vi/common.json index 682a2f3..ad4b564 100644 --- a/src/translations/vi/common.json +++ b/src/translations/vi/common.json @@ -104,5 +104,7 @@ "txt_error": "Lỗi", "txt_successfuly":"Thành công", "txt_unsuccess": "Không thành công", - "txt_delete_success": "Xóa thành công" + "txt_delete_success": "Xóa thành công", + "txt_migrator": "Migrator" + } \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 3e8860c..30a2a2d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9432,6 +9432,11 @@ react-spinners@^0.13.6: resolved "https://registry.yarnpkg.com/react-spinners/-/react-spinners-0.13.8.tgz#5262571be0f745d86bbd49a1e6b49f9f9cb19acc" integrity sha512-3e+k56lUkPj0vb5NDXPVFAOkPC//XyhKPJjvcGjyMNPWsBKpplfeyialP74G7H7+It7KzhtET+MvGqbKgAqpZA== +react-step-wizard@^5.3.11: + version "5.3.11" + resolved "https://registry.yarnpkg.com/react-step-wizard/-/react-step-wizard-5.3.11.tgz#a52b46db772c0340dd6f45f93716d2afcf2196e2" + integrity sha512-TD3ocUdt4XWvisTNEiATh+cFuh1RK0LgvYqOResTIhLtFmdWnXzFVaNIZJ3qzW5Bm6yeotzZ4KAmRjmsqBXnWQ== + react-table@^7.6.2: version "7.8.0" resolved "https://registry.yarnpkg.com/react-table/-/react-table-7.8.0.tgz#07858c01c1718c09f7f1aed7034fcfd7bda907d2" From 0a88e64ba03150bd8b41506ab024d7e61b4f2d36 Mon Sep 17 00:00:00 2001 From: Gia Phu Date: Wed, 8 Feb 2023 17:52:19 +0700 Subject: [PATCH 02/11] viewmodel & store migrator page --- .../MigratorPage/MigratorForm/JoomlaForm.jsx | 172 +++++++++--------- .../MigratorForm/WordPressForm.jsx | 121 ++++++------ .../MigratorStore/MigratorStore.js | 8 + .../MigratorViewModels/JoomlaFormViewModel.js | 5 + .../MigratorViewModelContextProvider.js | 19 ++ .../WordPressFormViewModel.js | 8 +- src/containers/MigratorPage/index.jsx | 90 +++++---- 7 files changed, 247 insertions(+), 176 deletions(-) create mode 100644 src/containers/MigratorPage/MigratorViewModels/MigratorViewModelContextProvider.js diff --git a/src/containers/MigratorPage/MigratorForm/JoomlaForm.jsx b/src/containers/MigratorPage/MigratorForm/JoomlaForm.jsx index ea88287..9502225 100644 --- a/src/containers/MigratorPage/MigratorForm/JoomlaForm.jsx +++ b/src/containers/MigratorPage/MigratorForm/JoomlaForm.jsx @@ -5,106 +5,116 @@ import { Button, Form } from 'react-bootstrap'; import SimpleReactValidator from 'simple-react-validator'; import { observer } from 'mobx-react'; import { notify } from 'components/Toast'; - +import { withMigratorViewModel } from '../MigratorViewModels/MigratorViewModelContextProvider'; const JoomlaForm = observer( class JoomlaForm extends Component { + joomlaFormViewmodel = ''; formPropsData = { joomla_bearer_token: '', joomla_api_url: '', }; constructor(props) { super(props); + this.joomlaFormViewmodel = props.viewModel?.getJoomlaFormViewModel(); this.validator = new SimpleReactValidator({ autoForceUpdate: this }); this.state = { loading: false, }; } - render() { + hanldeClick = () => { const { nextStep } = this.props; + this.setState({ loading: true }); + if (this.validator.allValid()) { + nextStep(); + } else { + notify('Please input all required fields', 'warn'); + this.validator.showMessages(); + } + this.setState({ loading: false }); + }; + componentWillUnmount() { + console.log('test'); + } + render() { const { loading } = this.state; - const hanldeClick = () => { - this.setState({ loading: true }); - if (this.validator.allValid()) { - nextStep(); - } else { - notify('Please input all required fields', 'warn'); - this.validator.showMessages(); - } - this.setState({ loading: false }); - }; return ( -
-
-
- - - Joomla Bearer Token - * - - { - this.formPropsData['joomla_bearer_token'] = e.target.value; - console.log(e.target.value); - }, - blurred: () => { - this.validator.showMessageFor('Joomla Bearer Token'); - }, - }} - /> - {this.validator.message( - 'Joomla Bearer Token', - this.formPropsData['joomla_bearer_token'], - 'required', - { - className: 'text-danger mt-1', - } - )} - - - - Joomla API URL - * - - { - this.formPropsData['joomla_api_url'] = e.target.value; - console.log(e.target.value); - }, - blurred: () => { - this.validator.showMessageFor('Joomla API URL'); - }, - }} - /> - {this.validator.message( - 'Joomla API URL', - this.formPropsData['joomla_api_url'], - 'required', - { - className: 'text-danger mt-1', - } - )} - -
-
- + <> +

Migrator Joomla Data

+ +
+
+
+ + + Joomla Bearer Token + * + + { + this.joomlaFormViewmodel.formPropsData['joomla_bearer_token'] = + e.target.value; + console.log(e.target.value); + }, + blurred: () => { + this.validator.showMessageFor('Joomla Bearer Token'); + }, + }} + /> + {this.validator.message( + 'Joomla Bearer Token', + this.joomlaFormViewmodel?.formPropsData['joomla_bearer_token'], + 'required', + { + className: 'text-danger mt-1', + } + )} + + + + Joomla API URL + * + + { + this.joomlaFormViewmodel.formPropsData['joomla_api_url'] = e.target.value; + console.log(e.target.value); + }, + blurred: () => { + this.validator.showMessageFor('Joomla API URL'); + }, + }} + /> + {this.validator.message( + 'Joomla API URL', + this.joomlaFormViewmodel?.formPropsData['joomla_api_url'], + 'required', + { + className: 'text-danger mt-1', + } + )} + +
+
+ +
-
+ ); } } ); -export default JoomlaForm; +export default withMigratorViewModel(JoomlaForm); diff --git a/src/containers/MigratorPage/MigratorForm/WordPressForm.jsx b/src/containers/MigratorPage/MigratorForm/WordPressForm.jsx index 3993f96..fc1822b 100644 --- a/src/containers/MigratorPage/MigratorForm/WordPressForm.jsx +++ b/src/containers/MigratorPage/MigratorForm/WordPressForm.jsx @@ -5,78 +5,87 @@ import { Button, Form } from 'react-bootstrap'; import SimpleReactValidator from 'simple-react-validator'; import { observer } from 'mobx-react'; import { notify } from 'components/Toast'; +import { withMigratorViewModel } from '../MigratorViewModels/MigratorViewModelContextProvider'; -const JoomlaForm = observer( - class JoomlaForm extends Component { +const WordPressForm = observer( + class WordPressForm extends Component { + wordPressFormViewModel = ''; formPropsData = { - url: '', + wordpress_api_url: '', }; constructor(props) { super(props); + this.wordPressFormViewModel = props.viewModel.getWordPressFormViewModel(); this.validator = new SimpleReactValidator({ autoForceUpdate: this }); this.state = { loading: false, }; } - render() { + hanldeClick = () => { const { nextStep } = this.props; + this.setState({ loading: true }); + if (this.validator.allValid()) { + nextStep(); + } else { + notify('Please input WordPress API URL fields', 'warn'); + this.validator.showMessages(); + } + this.setState({ loading: false }); + }; + + render() { const { loading } = this.state; - const hanldeClick = () => { - this.setState({ loading: true }); - if (this.validator.allValid()) { - nextStep(); - } else { - notify('Please input WordPress API URL fields', 'warn'); - this.validator.showMessages(); - } - this.setState({ loading: false }); - }; + return ( -
-
-
- - - WordPress API URL - * - - { - this.formPropsData['url'] = e.target.value; - console.log(e.target.value); - }, - blurred: () => { - this.validator.showMessageFor('WordPress API URL'); - }, - }} - /> - {this.validator.message( - 'WordPress API URL', - this.formPropsData['url'], - 'required', - { - className: 'text-danger mt-1', - } - )} - -
-
- + <> +

Migrator WordPress Data

+
+
+
+ + + WordPress API URL + * + + { + this.wordPressFormViewModel.formPropsData['wordpress_api_url'] = + e.target.value; + console.log(e.target.value); + }, + blurred: () => { + this.validator.showMessageFor('WordPress API URL'); + }, + }} + /> + {this.validator.message( + 'WordPress API URL', + this.wordPressFormViewModel.formPropsData['wordpress_api_url'], + 'required', + { + className: 'text-danger mt-1', + } + )} + +
+
+ +
-
+ ); } } ); -export default JoomlaForm; +export default withMigratorViewModel(WordPressForm); diff --git a/src/containers/MigratorPage/MigratorStore/MigratorStore.js b/src/containers/MigratorPage/MigratorStore/MigratorStore.js index e69de29..10857ce 100644 --- a/src/containers/MigratorPage/MigratorStore/MigratorStore.js +++ b/src/containers/MigratorPage/MigratorStore/MigratorStore.js @@ -0,0 +1,8 @@ +// import { Joomla } from 'aesirx-cms-migrator/dist/joomla/script'; +// import { Wordpress } from 'aesirx-cms-migrator/dist/wordpress/script'; +// import { AesirX } from 'aesirx-cms-migrator/dist/aesirx/script'; +export default class MigratorStore { + migratorData() { + // console.log(Joomla, Wordpress, AesirX); + } +} diff --git a/src/containers/MigratorPage/MigratorViewModels/JoomlaFormViewModel.js b/src/containers/MigratorPage/MigratorViewModels/JoomlaFormViewModel.js index a487113..a0da2b2 100644 --- a/src/containers/MigratorPage/MigratorViewModels/JoomlaFormViewModel.js +++ b/src/containers/MigratorPage/MigratorViewModels/JoomlaFormViewModel.js @@ -7,11 +7,16 @@ import { makeAutoObservable } from 'mobx'; class JoomlaFormViewModel { migratorStore = null; + formPropsData = { + type: 'JOOMLA', + }; constructor(migratorStore) { makeAutoObservable(this); this.migratorStore = migratorStore; } + + migratorData = () => {}; } export default JoomlaFormViewModel; diff --git a/src/containers/MigratorPage/MigratorViewModels/MigratorViewModelContextProvider.js b/src/containers/MigratorPage/MigratorViewModels/MigratorViewModelContextProvider.js new file mode 100644 index 0000000..bfaf3aa --- /dev/null +++ b/src/containers/MigratorPage/MigratorViewModels/MigratorViewModelContextProvider.js @@ -0,0 +1,19 @@ +import React from 'react'; + +const MigratorViewModelContext = React.createContext(); + +export const MigratorViewModelContextProvider = ({ children, viewModel }) => { + return ( + + {children} + + ); +}; + +/* Hook to use store in any functional component */ +export const useMigratorViewModel = () => React.useContext(MigratorViewModelContext); + +/* HOC to inject store to any functional or class component */ +export const withMigratorViewModel = (Component) => (props) => { + return ; +}; diff --git a/src/containers/MigratorPage/MigratorViewModels/WordPressFormViewModel.js b/src/containers/MigratorPage/MigratorViewModels/WordPressFormViewModel.js index 833670b..87cda07 100644 --- a/src/containers/MigratorPage/MigratorViewModels/WordPressFormViewModel.js +++ b/src/containers/MigratorPage/MigratorViewModels/WordPressFormViewModel.js @@ -7,11 +7,17 @@ import { makeAutoObservable } from 'mobx'; class WordPressFormViewModel { migratorStore = null; - + formPropsData = { + type: 'WORDPRESS', + }; constructor(migratorStore) { makeAutoObservable(this); this.migratorStore = migratorStore; } + resetData = () => { + this.formPropsData = { type: 'WORDPRESS' }; + }; + migratorData = () => {}; } export default WordPressFormViewModel; diff --git a/src/containers/MigratorPage/index.jsx b/src/containers/MigratorPage/index.jsx index f9d4dac..bf8cceb 100644 --- a/src/containers/MigratorPage/index.jsx +++ b/src/containers/MigratorPage/index.jsx @@ -4,44 +4,58 @@ import StepWizard from 'react-step-wizard'; import JoomlaForm from './MigratorForm/JoomlaForm'; import WordPressForm from './MigratorForm/WordPressForm'; import MergeDataPage from './MigratorForm/MergeDataPage'; +import { observer } from 'mobx-react'; -export class MigratorPage extends Component { - render() { - return ( -
- - - - - - - - - - - - -
- ); - } -} +import MigratorStore from './MigratorStore/MigratorStore'; +import MigratorViewModel from './MigratorViewModels/MigratorViewModel'; +import { MigratorViewModelContextProvider } from './MigratorViewModels/MigratorViewModelContextProvider'; +const migratorStore = new MigratorStore(); +const migratorViewModel = new MigratorViewModel(migratorStore); +const MigratorPage = observer( + class MigratorPage extends Component { + constructor(props) { + super(props); + this.match = props.match; + } + render() { + return ( + +
+ + + + + + + + + + + + +
+
+ ); + } + } +); export default MigratorPage; From 6ac745cdc41f7405256a658986e665d3f33b5d37 Mon Sep 17 00:00:00 2001 From: Gia Phu Date: Thu, 9 Feb 2023 17:30:51 +0700 Subject: [PATCH 03/11] api migrate --- package.json | 2 +- src/components/SbarLeft/index.scss | 3 - .../MigratorForm/MergeDataPage.jsx | 77 +++++--- .../MigratorStore/MigratorStore.js | 7 +- .../MigratorPage/MigratorUtils/aesirx.js | 123 ++++++++++++ .../MigratorPage/MigratorUtils/index.js | 25 +++ .../MigratorPage/MigratorUtils/joomla.js | 177 ++++++++++++++++++ .../MigratorPage/MigratorUtils/wordpress.js | 162 ++++++++++++++++ .../MigratorViewModels/JoomlaFormViewModel.js | 10 +- .../WordPressFormViewModel.js | 11 +- src/containers/MigratorPage/index.jsx | 4 +- yarn.lock | 25 ++- 12 files changed, 584 insertions(+), 42 deletions(-) create mode 100644 src/containers/MigratorPage/MigratorUtils/aesirx.js create mode 100644 src/containers/MigratorPage/MigratorUtils/index.js create mode 100644 src/containers/MigratorPage/MigratorUtils/joomla.js create mode 100644 src/containers/MigratorPage/MigratorUtils/wordpress.js diff --git a/package.json b/package.json index 63b9175..b81ce0e 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "aesirx-dma-app": "^1.6.2", "aesirx-dma-lib": "^1.7.6", "aesirx-sso": "^1.0.3", - "axios": "^0.21.0", + "axios": "^1.3.2", "bootstrap": "^5.2.2", "d3-fetch": "^3.0.1", "date-fns": "^2.16.1", diff --git a/src/components/SbarLeft/index.scss b/src/components/SbarLeft/index.scss index 817df63..e69de29 100644 --- a/src/components/SbarLeft/index.scss +++ b/src/components/SbarLeft/index.scss @@ -1,3 +0,0 @@ -.progress { - height: 4px; -} diff --git a/src/containers/MigratorPage/MigratorForm/MergeDataPage.jsx b/src/containers/MigratorPage/MigratorForm/MergeDataPage.jsx index 9b35421..8bcf69a 100644 --- a/src/containers/MigratorPage/MigratorForm/MergeDataPage.jsx +++ b/src/containers/MigratorPage/MigratorForm/MergeDataPage.jsx @@ -1,27 +1,62 @@ import React, { Component } from 'react'; import { Button } from 'react-bootstrap'; +import ProgressBar from 'react-bootstrap/ProgressBar'; +import { observer } from 'mobx-react'; -export default class MergeDataPage extends Component { - render() { - const { previousStep, viewModel } = this.props; - const handleClick = () => { - console.log(viewModel); +const MergeDataPage = observer( + class MergeDataPage extends Component { + constructor(props) { + super(props); + this.viewModel = props.viewModel; + this.state = { + isMerging: false, + }; + } + handleClick = () => { + this.setState({ isMerging: true }); + this.viewModel.migratorData(); }; - return ( - <> -
- +
+ {this.viewModel?.processPercent ? ( +
+ +
+ ) : null} +
+
+ -
- - - ); + + ); + } } -} +); +export default MergeDataPage; diff --git a/src/containers/MigratorPage/MigratorStore/MigratorStore.js b/src/containers/MigratorPage/MigratorStore/MigratorStore.js index 10857ce..608e333 100644 --- a/src/containers/MigratorPage/MigratorStore/MigratorStore.js +++ b/src/containers/MigratorPage/MigratorStore/MigratorStore.js @@ -1,8 +1,7 @@ -// import { Joomla } from 'aesirx-cms-migrator/dist/joomla/script'; -// import { Wordpress } from 'aesirx-cms-migrator/dist/wordpress/script'; -// import { AesirX } from 'aesirx-cms-migrator/dist/aesirx/script'; +// import {mergeData} from "../MigratorUtils/index" + export default class MigratorStore { migratorData() { - // console.log(Joomla, Wordpress, AesirX); + console.log('testawdawdawdwad'); } } diff --git a/src/containers/MigratorPage/MigratorUtils/aesirx.js b/src/containers/MigratorPage/MigratorUtils/aesirx.js new file mode 100644 index 0000000..51b2451 --- /dev/null +++ b/src/containers/MigratorPage/MigratorUtils/aesirx.js @@ -0,0 +1,123 @@ +import axios from 'axios'; + +const Entity = { + Category: '&view=category_with_org_check_aesirx_categories_69', + Tag: '&view=category_with_org_check_aesirx_tags_70', + Item: '&view=item_with_org_check_aesirx_content_68', +}; + +class AesirX { + relatedAesirxUrl = + '/index.php?option=reditem&webserviceClient=site&webserviceVersion=1.0.0&api=hal'; + + constructor(aesirx_bearer_token, apiDomain, remotePrefix) { + this.ref = { + Category: {}, + Tag: {}, + Item: {}, + }; + this.aesirx_bearer_token = aesirx_bearer_token; + this.apiDomain = apiDomain; + this.remotePrefix = remotePrefix; + } + + setRemoteEntityId(localId, entityName, remoteKey) { + this.ref[entityName][localId] = remoteKey; + } + + async addTag(resource) { + const restTo = await axios.post( + this.apiDomain + this.relatedAesirxUrl + this.entityUrlPart[Entity.Item] + '&task=addTag', + resource, + { + acceptHeader: '*/*', + headers: { + Authorization: 'Bearer ' + this.aesirx_bearer_token, + }, + } + ); + + if (restTo.statusCode != 200 || !restTo.result) { + throw new Error('Entity was not created'); + } + } + + async create(entityName, resource) { + try { + resource.id = await this.getRemoteEntityId(resource.remote_key, entityName); + } catch (err) { + console.log(err); + } + + let use = { ...resource }; + use.remote_key = this.remotePrefix + '|' + use.remote_key; + + // Update + if (resource.id) { + const restTo = await axios.put( + this.apiDomain + this.relatedAesirxUrl + this.entityUrlPart[entityName], + use, + { + acceptHeader: '*/*', + } + ); + if (restTo.statusCode != 200 || !restTo.result) { + throw new Error('Entity was not created'); + } + + this.ref[entityName][resource.remote_key] = resource.id; + } + + // Create + else { + const restTo = await axios.post( + this.apiDomain + this.relatedAesirxUrl + this.entityUrlPart[entityName], + use, + { + acceptHeader: '*/*', + headers: { + Authorization: 'Bearer ' + this.aesirx_bearer_token, + }, + } + ); + if (restTo.statusCode != 201 || !restTo.result) { + throw new Error('Entity was not created'); + } + + this.ref[entityName][resource.remote_key] = restTo.result.id; + } + + return this.ref[entityName][resource.remote_key]; + } + async getRemoteEntityId(localId, entityName) { + if (!(localId in this.ref[entityName])) { + const restRes = await axios.get( + this.apiDomain + + this.relatedAesirxUrl + + this.entityUrlPart[entityName] + + '&filter[remote_key]=' + + this.remotePrefix + + '|' + + localId, + { + acceptHeader: '*/*', + additionalHeaders: { + 'Content-Type': 'application/json; charset=utf-8', + }, + headers: { + Authorization: 'Bearer ' + this.aesirx_bearer_token, + }, + } + ); + + if (restRes.statusCode != 200 || !restRes.result) { + throw new Error('Data not found'); + } + this.setRemoteEntityId(localId, entityName, restRes.result._embedded.item[0].id); + } + + return this.ref[entityName][localId]; + } +} + +export { AesirX, Entity }; diff --git a/src/containers/MigratorPage/MigratorUtils/index.js b/src/containers/MigratorPage/MigratorUtils/index.js new file mode 100644 index 0000000..64f1860 --- /dev/null +++ b/src/containers/MigratorPage/MigratorUtils/index.js @@ -0,0 +1,25 @@ +import { Joomla } from './joomla'; +import { AesirX } from './aesirx'; +import { Wordpress } from './wordpress'; + +const mergeData = (aesirx_migrate_type, aesirx_bearer_token, data) => { + try { + const aesirx = new AesirX( + aesirx_bearer_token, + process.env.REACT_APP_ENDPOINT_URL, + aesirx_migrate_type + ); + switch (aesirx_migrate_type) { + case 'WORDPRESS': + new Wordpress(aesirx, 'aesirx_migrator', data?.wordpress_api_url).runAll(); + break; + case 'JOOMLA': + default: + new Joomla(aesirx, data?.joomla_bearer_token, data?.joomla_api_url).runAll(); + break; + } + } catch (error) { + console.error('Failed: ' + error.message); + } +}; +export { mergeData }; diff --git a/src/containers/MigratorPage/MigratorUtils/joomla.js b/src/containers/MigratorPage/MigratorUtils/joomla.js new file mode 100644 index 0000000..1112fd0 --- /dev/null +++ b/src/containers/MigratorPage/MigratorUtils/joomla.js @@ -0,0 +1,177 @@ +import axios from 'axios'; +import { Entity } from './aesirx'; + +class Joomla { + joomla_api_url; + joomla_bearer_token; + limit = 20; + aesirx; + constructor(aesirx, joomla_api_url, joomla_bearer_token, limit = 20) { + this.limit = limit; + this.joomla_bearer_token = joomla_bearer_token; + this.joomla_api_url = joomla_api_url; + this.aesirx = aesirx; + } + async run(url, params, done) { + let offset = 0; + let loop = true; + + while (loop) { + const options = { + acceptHeader: '*/*', + headers: { + Authorization: 'Bearer ' + this.joomla_bearer_token, + }, + additionalHeaders: { + 'Content-Type': 'application/json; charset=utf-8', + }, + queryParameters: { + params: { + ...{ + page: { + limit: this.limit, + offset: offset, + }, + list: { + ordering: 'id', + direction: 'asc', + }, + }, + ...params, + }, + }, + }; + const restRes = await axios.get(this.joomla_api_url + url, options); + + if (restRes.statusCode != 200 || !restRes.result) { + throw new Error('Data not found'); + } + + // Probably less heavier for frontend executions + // https://gist.github.com/joeytwiddle/37d2085425c049629b80956d3c618971#process-each-player-in-serial-using-arrayprototypereduce + await restRes.result.data.reduce(async (prev, item) => { + // Wait for the previous item to finish processing + await prev; + // Process this item + await done(item); + }, Promise.resolve()); + + offset += this.limit; + + if (restRes.result.links.next === undefined) { + break; + } + } + } + async runCategories() { + await this.run( + '/api/index.php/v1/content/categories', + { + list: { + ordering: 'a.lft', + direction: 'asc', + }, + }, + async (item) => { + const resource = { + title: item.attributes.title, + remote_key: item.id, + }; + + if (item.attributes.parent_id != 1) { + resource.parent_id = await this.aesirx.getRemoteEntityId( + item.attributes.parent_id, + Entity.Category + ); + } + + const remoteId = await this.aesirx.create(Entity.Category, resource); + console.log(remoteId); + } + ); + } + + async runContents() { + const options = { + acceptHeader: '*/*', + }; + + await this.run( + '/api/index.php/v1/content/articles', + { + list: { + ordering: 'a.id', + direction: 'asc', + }, + }, + async (item) => { + const resource = { + title: item.attributes.title, + metaverse_content: item.attributes.text, + remote_key: item.id, + + // Empty tags and assign again later + aesirx_tags: [], + }; + + resource.categories = [ + await this.aesirx.getRemoteEntityId(item.relationships.category.data.id, Entity.Category), + ]; + + const restRes = await this.from.get( + '/api/index.php/v1/content/articles/' + item.id, + options + ); + + if (restRes.statusCode != 200 || !restRes.result) { + throw new Error('Data not found'); + } + + const remoteId = await this.aesirx.create(Entity.Item, resource); + + for (const idx in restRes.result.data.attributes.tags) { + await this.aesirx.addTag({ + content_id: remoteId, + tag_id: await this.aesirx.getRemoteEntityId(idx, Entity.Tag), + }); + } + } + ); + } + + async runTags() { + await this.run( + '/api/index.php/v1/tags', + { + list: { + ordering: 'a.lft', + direction: 'asc', + }, + }, + async (item) => { + const resource = { + title: item.attributes.title, + description: item.attributes.description, + remote_key: item.id, + }; + + if (item.attributes.parent_id != 1) { + resource.parent_id = await this.aesirx.getRemoteEntityId( + item.attributes.parent_id, + Entity.Tag + ); + } + + const remoteId = await this.aesirx.create(Entity.Tag, resource); + console.log(remoteId); + } + ); + } + + async runAll() { + await this.runCategories(); + await this.runTags(); + await this.runContents(); + } +} +export { Joomla }; diff --git a/src/containers/MigratorPage/MigratorUtils/wordpress.js b/src/containers/MigratorPage/MigratorUtils/wordpress.js new file mode 100644 index 0000000..4f3e189 --- /dev/null +++ b/src/containers/MigratorPage/MigratorUtils/wordpress.js @@ -0,0 +1,162 @@ +import axios from 'axios'; +import { Entity } from './aesirx'; + +export class Wordpress { + wordpress_api_url; + limit = 20; + aesirx; + + constructor(aesirx, wordpress_api_url, limit = 20) { + this.limit = limit; + this.wordpress_api_url = wordpress_api_url; + this.aesirx = aesirx; + } + + async run(url, params, done) { + let page = 1; + let loop = true; + while (loop) { + const options = { + acceptHeader: '*/*', + additionalHeaders: { + 'Content-Type': 'application/json; charset=utf-8', + }, + queryParameters: { + params: { + ...{ + per_page: this.limit, + page: page, + order: 'asc', + orderby: 'id', + }, + ...params, + }, + }, + }; + const restRes = await axios.get(this.wordpress_api_url + url, options); + + if (restRes.statusCode != 200 || restRes.result === null) { + throw new Error('Data not found'); + } + + if (restRes.result.length == 0) { + break; + } + + // Probably less heavier for frontend executions + // https://gist.github.com/joeytwiddle/37d2085425c049629b80956d3c618971#process-each-player-in-serial-using-arrayprototypereduce + await restRes.result.reduce(async (prev, item) => { + // Wait for the previous item to finish processing + await prev; + // Process this item + await done(item); + }, Promise.resolve()); + + if (restRes.result.length < this.limit) { + break; + } + + page += 1; + } + } + + async runCategories() { + let parents = [0]; + let loop = true; + while (loop) { + if (parents.length === 0) { + break; + } + + // @ts-ignore + let parent = parents.pop(); + + await this.run( + '/wp-json/wp/v2/categories', + { + parent: parent, + }, + async (item) => { + const resource = { + title: item.name, + remote_key: item.id, + description: item.description, + }; + + if (item.parent != 0) { + resource.parent_id = await this.aesirx.getRemoteEntityId(item.parent, Entity.Category); + } + + const remoteId = await this.aesirx.create(Entity.Category, resource); + console.log(remoteId); + parents.push(item.id); + } + ); + } + } + + async runPosts() { + await this.run('/wp-json/wp/v2/posts', {}, async (item) => { + const resource = { + title: item.title.rendered, + metaverse_content: item.content.rendered, + excerpt: item.excerpt.rendered, + remote_key: item.id, + + // Empty tags and assign again later + aesirx_tags: [], + }; + + if (item.categories.length) { + resource.categories = []; + + for (const id of item.categories) { + resource.categories.push(await this.aesirx.getRemoteEntityId(id, Entity.Category)); + } + } + + const remoteId = await this.aesirx.create(Entity.Item, resource); + + for (const idx of item.tags) { + await this.aesirx.addTag({ + content_id: remoteId, + tag_id: await this.aesirx.getRemoteEntityId(idx, Entity.Tag), + }); + } + }); + } + + async runPages() { + await this.run('/wp-json/wp/v2/pages', {}, async (item) => { + const resource = { + title: item.title.rendered, + metaverse_content: item.content.rendered, + excerpt: item.excerpt.rendered, + remote_key: item.id, + }; + + const remoteId = await this.aesirx.create(Entity.Item, resource); + console.log(remoteId); + }); + } + + async runTags() { + await this.run('/wp-json/wp/v2/tags', {}, async (item) => { + const resource = { + title: item.name, + description: item.description, + remote_key: item.id, + }; + + const remoteId = await this.aesirx.create(Entity.Tag, resource); + console.log(remoteId); + }); + } + + async runAll() { + await this.runCategories(); + await this.runTags(); + await this.runPosts(); + await this.runPages(); + } +} diff --git a/src/containers/MigratorPage/MigratorViewModels/JoomlaFormViewModel.js b/src/containers/MigratorPage/MigratorViewModels/JoomlaFormViewModel.js index a0da2b2..924f85c 100644 --- a/src/containers/MigratorPage/MigratorViewModels/JoomlaFormViewModel.js +++ b/src/containers/MigratorPage/MigratorViewModels/JoomlaFormViewModel.js @@ -7,16 +7,18 @@ import { makeAutoObservable } from 'mobx'; class JoomlaFormViewModel { migratorStore = null; - formPropsData = { - type: 'JOOMLA', - }; + processPercent = 0; + type = 'JOOMLA'; + formPropsData = {}; constructor(migratorStore) { makeAutoObservable(this); this.migratorStore = migratorStore; } - migratorData = () => {}; + migratorData = () => { + this.migratorStore.migratorData(); + }; } export default JoomlaFormViewModel; diff --git a/src/containers/MigratorPage/MigratorViewModels/WordPressFormViewModel.js b/src/containers/MigratorPage/MigratorViewModels/WordPressFormViewModel.js index 87cda07..d93bd72 100644 --- a/src/containers/MigratorPage/MigratorViewModels/WordPressFormViewModel.js +++ b/src/containers/MigratorPage/MigratorViewModels/WordPressFormViewModel.js @@ -7,17 +7,16 @@ import { makeAutoObservable } from 'mobx'; class WordPressFormViewModel { migratorStore = null; - formPropsData = { - type: 'WORDPRESS', - }; + processPercent = 0; + type = 'WORDPRESS'; + formPropsData = {}; constructor(migratorStore) { makeAutoObservable(this); this.migratorStore = migratorStore; } - resetData = () => { - this.formPropsData = { type: 'WORDPRESS' }; + migratorData = () => { + this.migratorStore.migratorData(); }; - migratorData = () => {}; } export default WordPressFormViewModel; diff --git a/src/containers/MigratorPage/index.jsx b/src/containers/MigratorPage/index.jsx index bf8cceb..350e7f3 100644 --- a/src/containers/MigratorPage/index.jsx +++ b/src/containers/MigratorPage/index.jsx @@ -34,7 +34,7 @@ const MigratorPage = observer( initialStep={1} > - + @@ -49,7 +49,7 @@ const MigratorPage = observer( initialStep={1} > - +
diff --git a/yarn.lock b/yarn.lock index 30a2a2d..f6c5214 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3317,6 +3317,15 @@ axios@^0.21.0: dependencies: follow-redirects "^1.14.0" +axios@^1.3.2: + version "1.3.2" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.3.2.tgz#7ac517f0fa3ec46e0e636223fd973713a09c72b3" + integrity sha512-1M3O703bYqYuPhbHeya5bnhpYVsDDRyQSabNja04mZtboLNSuZ4YrltestrLXfHgmzua4TpUqRiVKbiQuo2epw== + dependencies: + follow-redirects "^1.15.0" + form-data "^4.0.0" + proxy-from-env "^1.1.0" + axobject-query@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-3.1.1.tgz#3b6e5c6d4e43ca7ba51c5babf99d22a9c68485e1" @@ -5654,7 +5663,7 @@ flatted@^3.1.0: resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.7.tgz#609f39207cb614b89d0765b477cb2d437fbf9787" integrity sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ== -follow-redirects@^1.0.0, follow-redirects@^1.14.0: +follow-redirects@^1.0.0, follow-redirects@^1.14.0, follow-redirects@^1.15.0: version "1.15.2" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== @@ -5694,6 +5703,15 @@ form-data@^3.0.0: combined-stream "^1.0.8" mime-types "^2.1.12" +form-data@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452" + integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww== + dependencies: + asynckit "^0.4.0" + combined-stream "^1.0.8" + mime-types "^2.1.12" + forwarded@0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.2.0.tgz#2269936428aad4c15c7ebe9779a84bf0b2a81811" @@ -8900,6 +8918,11 @@ proxy-addr@~2.0.7: forwarded "0.2.0" ipaddr.js "1.9.1" +proxy-from-env@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2" + integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg== + psl@^1.1.33: version "1.9.0" resolved "https://registry.yarnpkg.com/psl/-/psl-1.9.0.tgz#d0df2a137f00794565fcaf3b2c00cd09f8d5a5a7" From 7ab22335c0165269bef26370cd9b578f6eca3c81 Mon Sep 17 00:00:00 2001 From: Gia Phu Date: Thu, 16 Feb 2023 15:16:52 +0700 Subject: [PATCH 04/11] update --- src/containers/MigratorPage/MigratorStore/MigratorStore.js | 7 +++++-- .../MigratorPage/MigratorViewModels/JoomlaFormViewModel.js | 2 +- .../MigratorViewModels/WordPressFormViewModel.js | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/containers/MigratorPage/MigratorStore/MigratorStore.js b/src/containers/MigratorPage/MigratorStore/MigratorStore.js index 608e333..b1a87c9 100644 --- a/src/containers/MigratorPage/MigratorStore/MigratorStore.js +++ b/src/containers/MigratorPage/MigratorStore/MigratorStore.js @@ -1,7 +1,10 @@ // import {mergeData} from "../MigratorUtils/index" +import { AUTHORIZATION_KEY, Storage } from 'aesirx-dma-lib'; export default class MigratorStore { - migratorData() { - console.log('testawdawdawdwad'); + migratorData(aesirx_migrate_type, data) { + const aesirx_bearer_token = Storage.getItem(AUTHORIZATION_KEY.ACCESS_TOKEN); + // mergeData(aesirx_migrate_type, aesirx_bearer_token, data) + console.log(aesirx_migrate_type, aesirx_bearer_token, data); } } diff --git a/src/containers/MigratorPage/MigratorViewModels/JoomlaFormViewModel.js b/src/containers/MigratorPage/MigratorViewModels/JoomlaFormViewModel.js index 924f85c..4ec93fd 100644 --- a/src/containers/MigratorPage/MigratorViewModels/JoomlaFormViewModel.js +++ b/src/containers/MigratorPage/MigratorViewModels/JoomlaFormViewModel.js @@ -17,7 +17,7 @@ class JoomlaFormViewModel { } migratorData = () => { - this.migratorStore.migratorData(); + this.migratorStore.migratorData(this.type, this.formPropsData); }; } diff --git a/src/containers/MigratorPage/MigratorViewModels/WordPressFormViewModel.js b/src/containers/MigratorPage/MigratorViewModels/WordPressFormViewModel.js index d93bd72..17e8282 100644 --- a/src/containers/MigratorPage/MigratorViewModels/WordPressFormViewModel.js +++ b/src/containers/MigratorPage/MigratorViewModels/WordPressFormViewModel.js @@ -15,7 +15,7 @@ class WordPressFormViewModel { this.migratorStore = migratorStore; } migratorData = () => { - this.migratorStore.migratorData(); + this.migratorStore.migratorData(this.type, this.formPropsData); }; } From 64852291cdcdd9afa371b63b356f71257e2df1ba Mon Sep 17 00:00:00 2001 From: Gia Phu Date: Mon, 20 Feb 2023 10:12:30 +0700 Subject: [PATCH 05/11] fix params when fetch data --- .../MigratorPage/MigratorForm/JoomlaForm.jsx | 6 +---- .../MigratorStore/MigratorStore.js | 5 ++--- .../MigratorPage/MigratorUtils/aesirx.js | 1 - .../MigratorPage/MigratorUtils/index.js | 4 ++-- .../MigratorPage/MigratorUtils/joomla.js | 22 +++++++++---------- .../MigratorPage/MigratorUtils/wordpress.js | 16 ++++++-------- 6 files changed, 22 insertions(+), 32 deletions(-) diff --git a/src/containers/MigratorPage/MigratorForm/JoomlaForm.jsx b/src/containers/MigratorPage/MigratorForm/JoomlaForm.jsx index 9502225..f4345ac 100644 --- a/src/containers/MigratorPage/MigratorForm/JoomlaForm.jsx +++ b/src/containers/MigratorPage/MigratorForm/JoomlaForm.jsx @@ -32,9 +32,7 @@ const JoomlaForm = observer( } this.setState({ loading: false }); }; - componentWillUnmount() { - console.log('test'); - } + render() { const { loading } = this.state; return ( @@ -56,7 +54,6 @@ const JoomlaForm = observer( changed: (e) => { this.joomlaFormViewmodel.formPropsData['joomla_bearer_token'] = e.target.value; - console.log(e.target.value); }, blurred: () => { this.validator.showMessageFor('Joomla Bearer Token'); @@ -83,7 +80,6 @@ const JoomlaForm = observer( value: this.joomlaFormViewmodel.formPropsData['joomla_api_url'], changed: (e) => { this.joomlaFormViewmodel.formPropsData['joomla_api_url'] = e.target.value; - console.log(e.target.value); }, blurred: () => { this.validator.showMessageFor('Joomla API URL'); diff --git a/src/containers/MigratorPage/MigratorStore/MigratorStore.js b/src/containers/MigratorPage/MigratorStore/MigratorStore.js index b1a87c9..3acc952 100644 --- a/src/containers/MigratorPage/MigratorStore/MigratorStore.js +++ b/src/containers/MigratorPage/MigratorStore/MigratorStore.js @@ -1,10 +1,9 @@ -// import {mergeData} from "../MigratorUtils/index" +import { mergeData } from '../MigratorUtils/index'; import { AUTHORIZATION_KEY, Storage } from 'aesirx-dma-lib'; export default class MigratorStore { migratorData(aesirx_migrate_type, data) { const aesirx_bearer_token = Storage.getItem(AUTHORIZATION_KEY.ACCESS_TOKEN); - // mergeData(aesirx_migrate_type, aesirx_bearer_token, data) - console.log(aesirx_migrate_type, aesirx_bearer_token, data); + mergeData(aesirx_migrate_type, aesirx_bearer_token, data); } } diff --git a/src/containers/MigratorPage/MigratorUtils/aesirx.js b/src/containers/MigratorPage/MigratorUtils/aesirx.js index 51b2451..9d2ed42 100644 --- a/src/containers/MigratorPage/MigratorUtils/aesirx.js +++ b/src/containers/MigratorPage/MigratorUtils/aesirx.js @@ -20,7 +20,6 @@ class AesirX { this.apiDomain = apiDomain; this.remotePrefix = remotePrefix; } - setRemoteEntityId(localId, entityName, remoteKey) { this.ref[entityName][localId] = remoteKey; } diff --git a/src/containers/MigratorPage/MigratorUtils/index.js b/src/containers/MigratorPage/MigratorUtils/index.js index 64f1860..1e85a00 100644 --- a/src/containers/MigratorPage/MigratorUtils/index.js +++ b/src/containers/MigratorPage/MigratorUtils/index.js @@ -11,11 +11,11 @@ const mergeData = (aesirx_migrate_type, aesirx_bearer_token, data) => { ); switch (aesirx_migrate_type) { case 'WORDPRESS': - new Wordpress(aesirx, 'aesirx_migrator', data?.wordpress_api_url).runAll(); + new Wordpress(aesirx, data?.wordpress_api_url).runAll(); break; case 'JOOMLA': default: - new Joomla(aesirx, data?.joomla_bearer_token, data?.joomla_api_url).runAll(); + new Joomla(aesirx, data?.joomla_api_url, data?.joomla_bearer_token).runAll(); break; } } catch (error) { diff --git a/src/containers/MigratorPage/MigratorUtils/joomla.js b/src/containers/MigratorPage/MigratorUtils/joomla.js index 1112fd0..c8014c1 100644 --- a/src/containers/MigratorPage/MigratorUtils/joomla.js +++ b/src/containers/MigratorPage/MigratorUtils/joomla.js @@ -25,20 +25,18 @@ class Joomla { additionalHeaders: { 'Content-Type': 'application/json; charset=utf-8', }, - queryParameters: { - params: { - ...{ - page: { - limit: this.limit, - offset: offset, - }, - list: { - ordering: 'id', - direction: 'asc', - }, + params: { + ...{ + page: { + limit: this.limit, + offset: offset, + }, + list: { + ordering: 'id', + direction: 'asc', }, - ...params, }, + ...params, }, }; const restRes = await axios.get(this.joomla_api_url + url, options); diff --git a/src/containers/MigratorPage/MigratorUtils/wordpress.js b/src/containers/MigratorPage/MigratorUtils/wordpress.js index 4f3e189..82ba470 100644 --- a/src/containers/MigratorPage/MigratorUtils/wordpress.js +++ b/src/containers/MigratorPage/MigratorUtils/wordpress.js @@ -21,16 +21,14 @@ export class Wordpress { additionalHeaders: { 'Content-Type': 'application/json; charset=utf-8', }, - queryParameters: { - params: { - ...{ - per_page: this.limit, - page: page, - order: 'asc', - orderby: 'id', - }, - ...params, + params: { + ...{ + per_page: this.limit, + page: page, + order: 'asc', + orderby: 'id', }, + ...params, }, }; const restRes = await axios.get(this.wordpress_api_url + url, options); From d88bf81b74ccd8375c85a943982e0a33c663320e Mon Sep 17 00:00:00 2001 From: Gia Phu Date: Tue, 21 Feb 2023 13:22:22 +0700 Subject: [PATCH 06/11] update --- .../MigratorPage/MigratorForm/JoomlaForm.jsx | 17 +++---- .../MigratorForm/MergeDataPage.jsx | 2 +- .../MigratorForm/WordPressForm.jsx | 4 +- .../MigratorPage/MigratorUtils/aesirx.js | 24 ++++++---- .../MigratorPage/MigratorUtils/joomla.js | 46 +++++++++---------- .../MigratorPage/MigratorUtils/wordpress.js | 7 ++- 6 files changed, 55 insertions(+), 45 deletions(-) diff --git a/src/containers/MigratorPage/MigratorForm/JoomlaForm.jsx b/src/containers/MigratorPage/MigratorForm/JoomlaForm.jsx index f4345ac..cca7a8f 100644 --- a/src/containers/MigratorPage/MigratorForm/JoomlaForm.jsx +++ b/src/containers/MigratorPage/MigratorForm/JoomlaForm.jsx @@ -6,12 +6,13 @@ import SimpleReactValidator from 'simple-react-validator'; import { observer } from 'mobx-react'; import { notify } from 'components/Toast'; import { withMigratorViewModel } from '../MigratorViewModels/MigratorViewModelContextProvider'; +import { JOOMLA_FIELDS } from '../MigratorUtils/joomla'; const JoomlaForm = observer( class JoomlaForm extends Component { joomlaFormViewmodel = ''; formPropsData = { - joomla_bearer_token: '', - joomla_api_url: '', + [JOOMLA_FIELDS.URL]: '', + [JOOMLA_FIELDS.TOKEN]: '', }; constructor(props) { super(props); @@ -50,9 +51,9 @@ const JoomlaForm = observer( { - this.joomlaFormViewmodel.formPropsData['joomla_bearer_token'] = + this.joomlaFormViewmodel.formPropsData[JOOMLA_FIELDS.TOKEN] = e.target.value; }, blurred: () => { @@ -62,7 +63,7 @@ const JoomlaForm = observer( /> {this.validator.message( 'Joomla Bearer Token', - this.joomlaFormViewmodel?.formPropsData['joomla_bearer_token'], + this.joomlaFormViewmodel?.formPropsData[JOOMLA_FIELDS.TOKEN], 'required', { className: 'text-danger mt-1', @@ -77,9 +78,9 @@ const JoomlaForm = observer( { - this.joomlaFormViewmodel.formPropsData['joomla_api_url'] = e.target.value; + this.joomlaFormViewmodel.formPropsData[JOOMLA_FIELDS.URL] = e.target.value; }, blurred: () => { this.validator.showMessageFor('Joomla API URL'); @@ -88,7 +89,7 @@ const JoomlaForm = observer( /> {this.validator.message( 'Joomla API URL', - this.joomlaFormViewmodel?.formPropsData['joomla_api_url'], + this.joomlaFormViewmodel?.formPropsData[JOOMLA_FIELDS.URL], 'required', { className: 'text-danger mt-1', diff --git a/src/containers/MigratorPage/MigratorForm/MergeDataPage.jsx b/src/containers/MigratorPage/MigratorForm/MergeDataPage.jsx index 8bcf69a..cb4b210 100644 --- a/src/containers/MigratorPage/MigratorForm/MergeDataPage.jsx +++ b/src/containers/MigratorPage/MigratorForm/MergeDataPage.jsx @@ -13,7 +13,7 @@ const MergeDataPage = observer( }; } handleClick = () => { - this.setState({ isMerging: true }); + // this.setState({ isMerging: true }); this.viewModel.migratorData(); }; render() { diff --git a/src/containers/MigratorPage/MigratorForm/WordPressForm.jsx b/src/containers/MigratorPage/MigratorForm/WordPressForm.jsx index fc1822b..91b1774 100644 --- a/src/containers/MigratorPage/MigratorForm/WordPressForm.jsx +++ b/src/containers/MigratorPage/MigratorForm/WordPressForm.jsx @@ -6,7 +6,7 @@ import SimpleReactValidator from 'simple-react-validator'; import { observer } from 'mobx-react'; import { notify } from 'components/Toast'; import { withMigratorViewModel } from '../MigratorViewModels/MigratorViewModelContextProvider'; - +import { WORDPRESS_FIELDS } from '../MigratorUtils/wordpress'; const WordPressForm = observer( class WordPressForm extends Component { wordPressFormViewModel = ''; @@ -35,7 +35,7 @@ const WordPressForm = observer( render() { const { loading } = this.state; - + console.log(WORDPRESS_FIELDS['URL']); return ( <>

Migrator WordPress Data

diff --git a/src/containers/MigratorPage/MigratorUtils/aesirx.js b/src/containers/MigratorPage/MigratorUtils/aesirx.js index 9d2ed42..ba14f6a 100644 --- a/src/containers/MigratorPage/MigratorUtils/aesirx.js +++ b/src/containers/MigratorPage/MigratorUtils/aesirx.js @@ -1,9 +1,9 @@ import axios from 'axios'; const Entity = { - Category: '&view=category_with_org_check_aesirx_categories_69', - Tag: '&view=category_with_org_check_aesirx_tags_70', - Item: '&view=item_with_org_check_aesirx_content_68', + Category: 'Category', + Tag: 'Tag', + Item: 'Item', }; class AesirX { @@ -16,6 +16,11 @@ class AesirX { Tag: {}, Item: {}, }; + this.entityUrlPart = { + [Entity.Category]: '&view=category_with_org_check_aesirx_categories_69', + [Entity.Tag]: '&view=category_with_org_check_aesirx_tags_70', + [Entity.Item]: '&view=item_with_org_check_aesirx_content_68', + }; this.aesirx_bearer_token = aesirx_bearer_token; this.apiDomain = apiDomain; this.remotePrefix = remotePrefix; @@ -50,7 +55,7 @@ class AesirX { let use = { ...resource }; use.remote_key = this.remotePrefix + '|' + use.remote_key; - + console.log('resource', resource.id); // Update if (resource.id) { const restTo = await axios.put( @@ -60,7 +65,8 @@ class AesirX { acceptHeader: '*/*', } ); - if (restTo.statusCode != 200 || !restTo.result) { + console.log('Update', restTo); + if (restTo.status != 200 || !restTo.result) { throw new Error('Entity was not created'); } @@ -79,7 +85,8 @@ class AesirX { }, } ); - if (restTo.statusCode != 201 || !restTo.result) { + console.log('Create', restTo); + if (restTo.status != 201 || !restTo.result) { throw new Error('Entity was not created'); } @@ -108,11 +115,12 @@ class AesirX { }, } ); + console.log('getRemoteEntityId', restRes); - if (restRes.statusCode != 200 || !restRes.result) { + if (restRes.status != 200 || !restRes.data) { throw new Error('Data not found'); } - this.setRemoteEntityId(localId, entityName, restRes.result._embedded.item[0].id); + this.setRemoteEntityId(localId, entityName, restRes.data._embedded.item[0].id); } return this.ref[entityName][localId]; diff --git a/src/containers/MigratorPage/MigratorUtils/joomla.js b/src/containers/MigratorPage/MigratorUtils/joomla.js index c8014c1..c1adeed 100644 --- a/src/containers/MigratorPage/MigratorUtils/joomla.js +++ b/src/containers/MigratorPage/MigratorUtils/joomla.js @@ -1,6 +1,11 @@ import axios from 'axios'; import { Entity } from './aesirx'; +const JOOMLA_FIELDS = { + URL: 'joomla_api_url', + TOKEN: 'joomla_bearer_token', +}; + class Joomla { joomla_api_url; joomla_bearer_token; @@ -27,27 +32,24 @@ class Joomla { }, params: { ...{ - page: { - limit: this.limit, - offset: offset, - }, - list: { - ordering: 'id', - direction: 'asc', - }, + 'page[limit]': this.limit, + 'page[offset]': offset, + 'list[ordering]': 'id', + 'list[direction]': 'asc', }, ...params, }, }; const restRes = await axios.get(this.joomla_api_url + url, options); - if (restRes.statusCode != 200 || !restRes.result) { - throw new Error('Data not found'); + if (restRes.status != 200 || !restRes?.data?.data) { + console.log("Don't have data"); + break; } // Probably less heavier for frontend executions // https://gist.github.com/joeytwiddle/37d2085425c049629b80956d3c618971#process-each-player-in-serial-using-arrayprototypereduce - await restRes.result.data.reduce(async (prev, item) => { + await restRes.data.data.reduce(async (prev, item) => { // Wait for the previous item to finish processing await prev; // Process this item @@ -56,7 +58,7 @@ class Joomla { offset += this.limit; - if (restRes.result.links.next === undefined) { + if (!restRes?.result?.links?.next) { break; } } @@ -65,10 +67,8 @@ class Joomla { await this.run( '/api/index.php/v1/content/categories', { - list: { - ordering: 'a.lft', - direction: 'asc', - }, + 'list[ordering]': 'a.lft', + 'list[direction]': 'asc', }, async (item) => { const resource = { @@ -97,10 +97,8 @@ class Joomla { await this.run( '/api/index.php/v1/content/articles', { - list: { - ordering: 'a.id', - direction: 'asc', - }, + 'list[ordering]': 'a.id', + 'list[direction]': 'asc', }, async (item) => { const resource = { @@ -141,10 +139,8 @@ class Joomla { await this.run( '/api/index.php/v1/tags', { - list: { - ordering: 'a.lft', - direction: 'asc', - }, + 'list[ordering]': 'a.lft', + 'list[direction]': 'asc', }, async (item) => { const resource = { @@ -172,4 +168,4 @@ class Joomla { await this.runContents(); } } -export { Joomla }; +export { Joomla, JOOMLA_FIELDS }; diff --git a/src/containers/MigratorPage/MigratorUtils/wordpress.js b/src/containers/MigratorPage/MigratorUtils/wordpress.js index 82ba470..7d9bbf4 100644 --- a/src/containers/MigratorPage/MigratorUtils/wordpress.js +++ b/src/containers/MigratorPage/MigratorUtils/wordpress.js @@ -1,7 +1,10 @@ import axios from 'axios'; import { Entity } from './aesirx'; -export class Wordpress { +const WORDPRESS_FIELDS = { + URL: 'wordpress_api_url', +}; +class Wordpress { wordpress_api_url; limit = 20; aesirx; @@ -158,3 +161,5 @@ export class Wordpress { await this.runPages(); } } + +export { Wordpress, WORDPRESS_FIELDS }; From 67503926d96ecd022b27349fe97893008883857e Mon Sep 17 00:00:00 2001 From: Gia Phu Date: Tue, 21 Feb 2023 17:01:53 +0700 Subject: [PATCH 07/11] fix migrator --- .../MigratorForm/MergeDataPage.jsx | 29 ++++++++-------- .../MigratorStore/MigratorStore.js | 33 ++++++++++++++++--- .../MigratorPage/MigratorUtils/aesirx.js | 28 ++++++++-------- .../MigratorPage/MigratorUtils/index.js | 25 -------------- .../MigratorPage/MigratorUtils/joomla.js | 8 ++--- .../MigratorPage/MigratorUtils/wordpress.js | 23 +++++-------- .../MigratorViewModels/JoomlaFormViewModel.js | 17 ++++++++-- .../WordPressFormViewModel.js | 14 +++++++- 8 files changed, 96 insertions(+), 81 deletions(-) delete mode 100644 src/containers/MigratorPage/MigratorUtils/index.js diff --git a/src/containers/MigratorPage/MigratorForm/MergeDataPage.jsx b/src/containers/MigratorPage/MigratorForm/MergeDataPage.jsx index cb4b210..39b1b6e 100644 --- a/src/containers/MigratorPage/MigratorForm/MergeDataPage.jsx +++ b/src/containers/MigratorPage/MigratorForm/MergeDataPage.jsx @@ -12,9 +12,10 @@ const MergeDataPage = observer( isMerging: false, }; } - handleClick = () => { - // this.setState({ isMerging: true }); - this.viewModel.migratorData(); + handleClick = async () => { + this.setState({ isMerging: true }); + await this.viewModel.migratorData(); + this.setState({ isMerging: false }); }; render() { const { previousStep } = this.props; @@ -33,18 +34,16 @@ const MergeDataPage = observer( {isMerging ? 'Merging...' : 'Merge Data'} - {this.viewModel?.processPercent ? ( -
- -
- ) : null} +
+ +
@@ -114,4 +116,4 @@ const JoomlaForm = observer( } } ); -export default withMigratorViewModel(JoomlaForm); +export default withTranslation('common')(withMigratorViewModel(JoomlaForm)); diff --git a/src/containers/MigratorPage/MigratorForm/MergeDataPage.jsx b/src/containers/MigratorPage/MigratorForm/MergeDataPage.jsx index 72af3fb..c223e0a 100644 --- a/src/containers/MigratorPage/MigratorForm/MergeDataPage.jsx +++ b/src/containers/MigratorPage/MigratorForm/MergeDataPage.jsx @@ -2,6 +2,7 @@ import React, { Component } from 'react'; import { Button } from 'react-bootstrap'; import ProgressBar from 'react-bootstrap/ProgressBar'; import { observer } from 'mobx-react'; +import { withTranslation } from 'react-i18next'; const MergeDataPage = observer( class MergeDataPage extends Component { @@ -29,7 +30,7 @@ const MergeDataPage = observer( this.setState({ isMerging: false }); }; render() { - const { previousStep } = this.props; + const { previousStep, t } = this.props; const { isMerging, percent } = this.state; return ( <> @@ -62,11 +63,11 @@ const MergeDataPage = observer( variant="outline-secondary" className=" fs-14 fw-semibold p-2 mt-4" > - Previous Step + {t('txt_previous_step')} ); } } ); -export default MergeDataPage; +export default withTranslation('common')(MergeDataPage); diff --git a/src/containers/MigratorPage/MigratorForm/WordPressForm.jsx b/src/containers/MigratorPage/MigratorForm/WordPressForm.jsx index 2a15f6a..46948ae 100644 --- a/src/containers/MigratorPage/MigratorForm/WordPressForm.jsx +++ b/src/containers/MigratorPage/MigratorForm/WordPressForm.jsx @@ -7,6 +7,7 @@ import { observer } from 'mobx-react'; import { notify } from 'components/Toast'; import { withMigratorViewModel } from '../MigratorViewModels/MigratorViewModelContextProvider'; import { WORDPRESS_FIELDS } from '../MigratorUtils/wordpress'; +import { withTranslation } from 'react-i18next'; const WordPressForm = observer( class WordPressForm extends Component { wordPressFormViewModel = ''; @@ -34,10 +35,11 @@ const WordPressForm = observer( }; render() { + const { t } = this.props; const { loading } = this.state; return ( <> -

Migrator WordPress Data

+

{t('txt_migrator_wordpress')}

@@ -76,7 +78,7 @@ const WordPressForm = observer( className="fw-semibold rounded-1 px-4" onClick={this.hanldeClick} > - Submit + {t('txt_next_step')}
@@ -86,4 +88,4 @@ const WordPressForm = observer( } } ); -export default withMigratorViewModel(WordPressForm); +export default withTranslation('common')(withMigratorViewModel(WordPressForm)); diff --git a/src/translations/dk/common.json b/src/translations/dk/common.json index 16639d0..833e768 100644 --- a/src/translations/dk/common.json +++ b/src/translations/dk/common.json @@ -106,5 +106,9 @@ "txt_successfuly":"Succesfuldt", "txt_unsuccess": "Forgæves", "txt_delete_success": "Slet med succes", - "txt_migrator": "Migrator" + "txt_migrator": "Migrator", + "txt_migrator_wordpress": "Migrator WordPress Data", + "txt_migrator_joomla": "Migrator Joomla Data", + "txt_next_step": "Næste skridt", + "txt_previous_step": "Forrige trin" } \ No newline at end of file diff --git a/src/translations/en/common.json b/src/translations/en/common.json index e2b0185..b839600 100644 --- a/src/translations/en/common.json +++ b/src/translations/en/common.json @@ -106,5 +106,9 @@ "txt_successfuly":"Successfully", "txt_unsuccess": "Unsuccessfully", "txt_delete_success": "Delete Successfully", - "txt_migrator": "Migrator" + "txt_migrator": "Migrator", + "txt_migrator_wordpress": "Migrator WordPress Data", + "txt_migrator_joomla": "Migrator Joomla Data", + "txt_next_step": "Next Step", + "txt_previous_step": "Previous Step" } \ No newline at end of file diff --git a/src/translations/es/common.json b/src/translations/es/common.json index f3a5d98..43b6594 100644 --- a/src/translations/es/common.json +++ b/src/translations/es/common.json @@ -106,6 +106,10 @@ "txt_successfuly":"ErrorCon éxito", "txt_unsuccess": "sin éxito", "txt_delete_success": "Eliminar con éxito", - "txt_migrator": "Migrator" + "txt_migrator": "Migrator", + "txt_migrator_wordpress": "Migrator de datos de WordPress", + "txt_migrator_joomla": "Migrator de datos de Joomla", + "txt_next_step": "Próximo paso", + "txt_previous_step": "Paso anterior" } \ No newline at end of file diff --git a/src/translations/fr/common.json b/src/translations/fr/common.json index 1a55a72..c46cc82 100644 --- a/src/translations/fr/common.json +++ b/src/translations/fr/common.json @@ -106,6 +106,10 @@ "txt_successfuly":"Avec succès", "txt_unsuccess": "Sans succès", "txt_delete_success": "Supprimer avec succès", - "txt_migrator": "Migrator" + "txt_migrator": "Migrateur", + "txt_migrator_wordpress": "Migrateur de données WordPress", + "txt_migrator_joomla": "Migration de données Joomla", + "txt_next_step": "L'étape suivante", + "txt_previous_step": "Étape précédente" } \ No newline at end of file diff --git a/src/translations/hr/common.json b/src/translations/hr/common.json index 65c7122..8d8c3d4 100644 --- a/src/translations/hr/common.json +++ b/src/translations/hr/common.json @@ -106,6 +106,9 @@ "txt_successfuly":"Uspješno", "txt_unsuccess": "Neuspješno", "txt_delete_success": "Uspješno brisanje", - "txt_migrator": "Migrator" - + "txt_migrator": "Migrator", + "txt_migrator_wordpress": "Migrator WordPress podataka", + "txt_migrator_joomla": "Migrator Joomla podataka", + "txt_next_step": "Sljedeći korak", + "txt_previous_step": "Prethodni korak" } \ No newline at end of file diff --git a/src/translations/th/common.json b/src/translations/th/common.json index 30057ed..0142a61 100644 --- a/src/translations/th/common.json +++ b/src/translations/th/common.json @@ -106,6 +106,9 @@ "txt_successfuly":"เรียบร้อยแล้ว", "txt_unsuccess": "ไม่สำเร็จ", "txt_delete_success": "ลบสำเร็จ", - "txt_migrator": "Migrator" - + "txt_migrator": "ผู้อพยพ", + "txt_migrator_wordpress": "การย้ายข้อมูล WordPress", + "txt_migrator_joomla": "การย้ายข้อมูล Joomla", + "txt_next_step": "ขั้นตอนต่อไป", + "txt_previous_step": "ขั้นตอนก่อนหน้า" } \ No newline at end of file diff --git a/src/translations/ua/common.json b/src/translations/ua/common.json index 2ed0005..70f47ab 100644 --- a/src/translations/ua/common.json +++ b/src/translations/ua/common.json @@ -106,6 +106,9 @@ "txt_successfuly":"Успішно", "txt_unsuccess": "Безуспішно", "txt_delete_success": "Видалити успішно", - "txt_migrator": "Migrator" - + "txt_migrator": "Переселенець", + "txt_migrator_wordpress": "Мігратор даних WordPress", + "txt_migrator_joomla": "Мігратор даних Joomla", + "txt_next_step": "Наступний крок", + "txt_previous_step": "Попередній крок" } \ No newline at end of file diff --git a/src/translations/vi/common.json b/src/translations/vi/common.json index ad4b564..4f54a30 100644 --- a/src/translations/vi/common.json +++ b/src/translations/vi/common.json @@ -105,6 +105,9 @@ "txt_successfuly":"Thành công", "txt_unsuccess": "Không thành công", "txt_delete_success": "Xóa thành công", - "txt_migrator": "Migrator" - + "txt_migrator": "Chuyển đổi", + "txt_migrator_wordpress": "Chuyển đổi dữ liệu WordPress", + "txt_migrator_joomla": "Chuyển đổi dữ liệu Joomla", + "txt_next_step": "Bước tiếp theo", + "txt_previous_step": "Bước trước đó" } \ No newline at end of file From 4b60d491017f0835508337695d4f4ba60a10ae57 Mon Sep 17 00:00:00 2001 From: Gia Phu Date: Wed, 22 Feb 2023 13:42:32 +0700 Subject: [PATCH 10/11] update yarn.lock --- yarn.lock | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/yarn.lock b/yarn.lock index 6d69317..77cea3f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7030,7 +7030,7 @@ flush-write-stream@^1.0.0: inherits "^2.0.3" readable-stream "^2.3.6" -follow-redirects@>=1.14.7, follow-redirects@^1.0.0, follow-redirects@^1.14.0: +follow-redirects@>=1.14.7, follow-redirects@^1.0.0, follow-redirects@^1.14.0, follow-redirects@^1.15.0: version "1.15.2" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== @@ -10881,6 +10881,11 @@ proxy-addr@~2.0.7: forwarded "0.2.0" ipaddr.js "1.9.1" +proxy-from-env@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2" + integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg== + prr@~1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/prr/-/prr-1.0.1.tgz#d3fc114ba06995a45ec6893f484ceb1d78f5f476" @@ -11492,7 +11497,7 @@ react-spinners@^0.13.6: resolved "https://registry.yarnpkg.com/react-spinners/-/react-spinners-0.13.8.tgz#5262571be0f745d86bbd49a1e6b49f9f9cb19acc" integrity sha512-3e+k56lUkPj0vb5NDXPVFAOkPC//XyhKPJjvcGjyMNPWsBKpplfeyialP74G7H7+It7KzhtET+MvGqbKgAqpZA== -react-step-wizard@^5.3.11: +react-step-wizard@^5.3.11, react-step-wizard@^5.3.5: version "5.3.11" resolved "https://registry.yarnpkg.com/react-step-wizard/-/react-step-wizard-5.3.11.tgz#a52b46db772c0340dd6f45f93716d2afcf2196e2" integrity sha512-TD3ocUdt4XWvisTNEiATh+cFuh1RK0LgvYqOResTIhLtFmdWnXzFVaNIZJ3qzW5Bm6yeotzZ4KAmRjmsqBXnWQ== From bdd5fb7c18d8c7421c0474946ea108b69e53584c Mon Sep 17 00:00:00 2001 From: Gia Phu Date: Wed, 22 Feb 2023 16:34:11 +0700 Subject: [PATCH 11/11] remove cms-migrator lib --- package.json | 1 - yarn.lock | 60 +++++----------------------------------------------- 2 files changed, 5 insertions(+), 56 deletions(-) diff --git a/package.json b/package.json index d8d7ac3..57a7802 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,6 @@ "@fortawesome/free-solid-svg-icons": "^5.15.1", "@fortawesome/react-fontawesome": "^0.1.12", "aesirx-ckeditor": "^1.0.0", - "aesirx-cms-migrator": "https://github.com/aesirxio/cms-migrator", "aesirx-dam-app": "^1.2.1", "aesirx-dma-app": "^1.6.2", "aesirx-dma-lib": "^1.7.11", diff --git a/yarn.lock b/yarn.lock index 77cea3f..15702fa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3614,15 +3614,6 @@ aesirx-ckeditor@^1.0.0: resolved "https://registry.yarnpkg.com/aesirx-ckeditor/-/aesirx-ckeditor-1.0.0.tgz#25bb08c5a20281e191df258596d34d1d1ba6b09a" integrity sha512-CTNTVe6OGdAikmZTgy60XIgIYI3nAhlAIwTPGFlwhcM0tHzaHneG249fQBldR2UvaZR/p/SCY9GOQd6OyFEywQ== -"aesirx-cms-migrator@https://github.com/aesirxio/cms-migrator": - version "1.0.0" - resolved "https://github.com/aesirxio/cms-migrator#75c73358e5df6de8925ba790340a1559ac98624a" - dependencies: - dotenv "^16.0.3" - node-rest-client "^3.1.1" - tslog "^4.7.1" - typed-rest-client "^1.8.9" - aesirx-dam-app@^1.2.1, aesirx-dam-app@^1.2.3: version "1.2.6" resolved "https://registry.yarnpkg.com/aesirx-dam-app/-/aesirx-dam-app-1.2.6.tgz#a19136e79c53d8cb1e230d8e2f87b47fef6be2ff" @@ -5687,7 +5678,7 @@ debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@^2.6.0: dependencies: ms "2.0.0" -debug@4, debug@^4.1.0, debug@^4.1.1, debug@^4.3.2, debug@^4.3.4, debug@~4.3.1, debug@~4.3.2, debug@~4.3.3: +debug@4, debug@^4.1.0, debug@^4.1.1, debug@^4.3.2, debug@^4.3.4, debug@~4.3.1, debug@~4.3.2: version "4.3.4" resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865" integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ== @@ -7030,7 +7021,7 @@ flush-write-stream@^1.0.0: inherits "^2.0.3" readable-stream "^2.3.6" -follow-redirects@>=1.14.7, follow-redirects@^1.0.0, follow-redirects@^1.14.0, follow-redirects@^1.15.0: +follow-redirects@^1.0.0, follow-redirects@^1.14.0, follow-redirects@^1.15.0: version "1.15.2" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== @@ -9639,15 +9630,6 @@ node-releases@^2.0.8: resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.10.tgz#c311ebae3b6a148c89b1813fd7c4d3c024ef537f" integrity sha512-5GFldHPXVG/YZmFzJvKK2zDSzPKhEp0+ZR5SVaoSag9fsL5YgHbUHDfnG5494ISANDcK4KwPXAx2xqVEydmd7w== -node-rest-client@^3.1.1: - version "3.1.1" - resolved "https://registry.yarnpkg.com/node-rest-client/-/node-rest-client-3.1.1.tgz#6e0dfeb9bb3275cbee1f306bc206cb21600368d7" - integrity sha512-O8RUGGhGLLbzlL7SFOBza1AgUWP3uITv4mas4f5Q7A87HAy6qtYpa8Sj5x4UG9cDf4374v7lWyvgWladI04zzQ== - dependencies: - debug "~4.3.3" - follow-redirects ">=1.14.7" - xml2js ">=0.4.23" - normalize-package-data@^2.3.2: version "2.5.0" resolved "https://registry.yarnpkg.com/normalize-package-data/-/normalize-package-data-2.5.0.tgz#e66db1838b200c1dfc233225d12cb36520e234a8" @@ -10953,7 +10935,7 @@ q@^1.1.2: resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7" integrity sha512-kV/CThkXo6xyFEZUugw/+pIOywXcDbFYgSct5cT3gqlbkBE1SJdwy6UQoZvodiWF/ckQLZyDE/Bu1M6gVu5lVw== -qs@6.11.0, qs@^6.10.1, qs@^6.9.1: +qs@6.11.0, qs@^6.10.1: version "6.11.0" resolved "https://registry.yarnpkg.com/qs/-/qs-6.11.0.tgz#fd0d963446f7a65e1367e01abd85429453f0c37a" integrity sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q== @@ -11996,7 +11978,7 @@ sass@^1.52: immutable "^4.0.0" source-map-js ">=0.6.2 <2.0.0" -sax@>=0.6.0, sax@~1.2.4: +sax@~1.2.4: version "1.2.4" resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw== @@ -13117,7 +13099,7 @@ tslib@^2.0.3, tslib@^2.4.0: resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.0.tgz#42bfed86f5787aeb41d031866c8f402429e0fddf" integrity sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg== -tslog@^4.7.1, tslog@^4.7.2: +tslog@^4.7.2: version "4.7.4" resolved "https://registry.yarnpkg.com/tslog/-/tslog-4.7.4.tgz#09540c7af00c2e76dfc7121fbabff24d2f224a41" integrity sha512-/hz7E1ahN9KXNywEGJZ8SL4s3YLu9fKYBHOXsKgXwk73qZ7Y5NCkqktP6Y+0MQNfnqOdH8eRE0Rw0spmyTWLPg== @@ -13134,11 +13116,6 @@ tty-browserify@0.0.0: resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6" integrity sha512-JVa5ijo+j/sOoHGjw0sxw734b1LhBkQ3bvUGNdxnVXDCX81Yx7TFgnZygxrIIWn23hbfTaMYLwRmAxFyDuFmIw== -tunnel@0.0.6: - version "0.0.6" - resolved "https://registry.yarnpkg.com/tunnel/-/tunnel-0.0.6.tgz#72f1314b34a5b192db012324df2cc587ca47f92c" - integrity sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg== - type-check@^0.4.0, type-check@~0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.4.0.tgz#07b8203bfa7056c0657050e3ccd2c37730bab8f1" @@ -13190,15 +13167,6 @@ typed-array-length@^1.0.4: for-each "^0.3.3" is-typed-array "^1.1.9" -typed-rest-client@^1.8.9: - version "1.8.9" - resolved "https://registry.yarnpkg.com/typed-rest-client/-/typed-rest-client-1.8.9.tgz#e560226bcadfe71b0fb5c416b587f8da3b8f92d8" - integrity sha512-uSmjE38B80wjL85UFX3sTYEUlvZ1JgCRhsWj/fJ4rZ0FqDUFoIuodtiVeE+cUqiVTOKPdKrp/sdftD15MDek6g== - dependencies: - qs "^6.9.1" - tunnel "0.0.6" - underscore "^1.12.1" - typed-styles@^0.0.7: version "0.0.7" resolved "https://registry.yarnpkg.com/typed-styles/-/typed-styles-0.0.7.tgz#93392a008794c4595119ff62dde6809dbc40a3d9" @@ -13236,11 +13204,6 @@ uncontrollable@^7.0.0, uncontrollable@^7.2.1: invariant "^2.2.4" react-lifecycles-compat "^3.0.4" -underscore@^1.12.1: - version "1.13.6" - resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.13.6.tgz#04786a1f589dc6c09f761fc5f45b89e935136441" - integrity sha512-+A5Sja4HP1M08MaXya7p5LvjuM7K6q/2EaC0+iovj/wOcMsTzMvDFbasi/oSapiwOlt252IqsKqPjCl7huKS0A== - unicode-canonical-property-names-ecmascript@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.0.tgz#301acdc525631670d39f6146e0e77ff6bbdebddc" @@ -14038,19 +14001,6 @@ xml-name-validator@^3.0.0: resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-3.0.0.tgz#6ae73e06de4d8c6e47f9fb181f78d648ad457c6a" integrity sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw== -xml2js@>=0.4.23: - version "0.4.23" - resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.4.23.tgz#a0c69516752421eb2ac758ee4d4ccf58843eac66" - integrity sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug== - dependencies: - sax ">=0.6.0" - xmlbuilder "~11.0.0" - -xmlbuilder@~11.0.0: - version "11.0.1" - resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-11.0.1.tgz#be9bae1c8a046e76b31127726347d0ad7002beb3" - integrity sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA== - xmlchars@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/xmlchars/-/xmlchars-2.2.0.tgz#060fe1bcb7f9c76fe2a17db86a9bc3ab894210cb"