Frontend Migration Guide From Data Viz 2.0 to 3.0
warning
- Before starting the migration ensure that you have migrated to the most recent version of Data Viz 2.0.
- The guide can be found here: Data Viz 2.0 Migration Guide
Key Changes​
React Router v7​
- We have updated the project to use React Router v7 (RR7) (framework-mode).
- RR7 introduces the concept of Server Side Rendering (SSR) and React Server Components (RSC).
- RR7 is a major version upgrade and it is highly recommended to upgrade to the latest version of RR7.
- RR7 comes as a vite plugin and it is used with vite.
- Vite is a faster build tool than webpack. It also has in-build support for SASS therefore we have removed the SASS loader from the project.
- More can be found here here
warning
- You should replace occurences of
react-router-domwithreact-routerin your project.
Removed submodules in favour of NPM packages​
- We have removed the
wp-react-libsubmodule in favour of the library version which can be found here
Project Based​
Migration Steps​
tip
- We recommend using
pnpmas the package manager. - We also recommend adopting type safety by using TypeScript. This can be done incrementally by adding type annotations to your code.
- If you have not installed
pnpmyet, you can install it by following the instructions here
1. Remove the front submodule folder​
git rm front
2.Create a new react router project​
- Create a new react router project using our template
- GitPick
- Degit
npx gitpick devgateway/data-viz-ui/tree/main/example front
npx tiged git@github.com:devgateway/data-viz-ui/front front --mode=git
3. Install the dependencies​
pnpm install
- If you are using
yarn,npmorbunas the package manager, you can use the following command to install the dependencies:
- npm
- pnpm
- Yarn
- Bun
npm install
pnpm install
yarn install
bun install
- Install
@devgateway/wp-react-liband@devgateway/dvz-ui-react
- npm
- pnpm
- Yarn
- Bun
npm install @devgateway/wp-react-lib@latest @devgateway/dvz-ui-react@latest
pnpm add @devgateway/wp-react-lib@latest @devgateway/dvz-ui-react@latest
yarn add @devgateway/wp-react-lib@latest @devgateway/dvz-ui-react@latest
bun add @devgateway/wp-react-lib@latest @devgateway/dvz-ui-react@latest
4. Configure the project​
- Remove the
embeddablefolder from the new project
rm -r front/app/embeddable
- Copy the
embeddedfolder from theui-customizerfoler to the new project
cp -r custom/ui-customizer/src/embedded front/app/embeddable
- Copy the
index.jsfile from theui-customizerfolder to the new project
cp -r custom/ui-customizer/src/index.js front/app/embeddable/index.js
- Copy the
reducersfolder from theui-customizerfolder to the new project
cp -r custom/ui-customzer/src/reducers front/app/reducers
- Create a
reducers/index.tsfile in to import all the reducers from the
import example from './example-reducer';
const reducers = {
example,
};
customizer.registerCustomReducers(Reducers);
- Update or create a
embeddable/index.tsfile to register your custom components
- embeddable/index.ts(New)
- embeddable/index.js(Old)
import { customizer } from '@devgateway/dvz-ui-react';
const ExampleButtonLazy = lazy(() => import('./button'));
const ExampleComponentLazy = lazy(() => import('./MyExampleComponent'));
const embeddables = {
exampleButton: ExampleButtonLazy,
exampleComponent: ExampleComponentLazy
};
customizer.registerCustomEmbeddables(embeddables);
const ExampleButtonLazy = lazy(() => import('./button'));
const ExampleComponentLazy = lazy(() => import('./MyExampleComponent'));
const components = {
exampleButton: ExampleButtonLazy,
};
const getComponentByNameIgnoreCase = (name) => {
const k = Object.keys(components).filter(
value => value.toLowerCase() === name.toLowerCase()
);
return components[k];
};
export { getComponentByNameIgnoreCase, Reducers };
- Copy Images from the
ui-customizerfolder to the new project
cp -r custom/ui-customzer/src/images front/public/images
- Adjust the image paths in your code to use the base path
/images
<img src="/images/logo.png" alt="logo" />
- Copy the CSS or SCSS files from the
ui-customizerfolder to the new project
cp -r custom/ui-customzer/src/scss front/src/styles
- Update the
front/app/root.tsxfile to import the CSS/SCSS files, embeddables and reducers
import './styles/main.scss'; // or './styles/main.css'
import './embeddable';
import './reducers';
- Install the
@devgateway/dvz-ui-reactand@devgateway/wp-react-libpackages
- npm
- pnpm
- Yarn
- Bun
npm install @devgateway/dvz-ui-react@latest @devgateway/wp-react-lib@latest
pnpm add @devgateway/dvz-ui-react@latest @devgateway/wp-react-lib@latest
yarn add @devgateway/dvz-ui-react@latest @devgateway/wp-react-lib@latest
bun add @devgateway/dvz-ui-react@latest @devgateway/wp-react-lib@latest
5. Cofigure the environment variables​
- Copy the
.env.examplefile in thefrontfolder and copy the following content:
cp .env.example .env
- Update the environment variables in the
.envfile with the correct values.
6. Run the project​
- npm
- pnpm
- Yarn
- Bun
npm run dev
pnpm run dev
yarn dev
bun run dev
File Extensions​
All Files with react components should have the .jsx or .tsx extension. Update the file extensions accordingly:
# Before
src/components/MyComponent.js
# After
src/components/MyComponent.jsx