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

refactor: upgrade from CRA to Vite #512

Merged
merged 23 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
92a7212
chore: use vite instead of CRA
Mohammer5 Jul 15, 2024
199b821
fix(dhis2 ui types): correct wrongly used types
Mohammer5 Jul 16, 2024
147f6bf
fix(dhis2 ui): update to fix type issues
Mohammer5 Jul 16, 2024
0a44c71
fix(public files): add favicon, images and update index.html
Mohammer5 Jul 16, 2024
991a5af
chore: add github workflows
Mohammer5 Jul 16, 2024
c88490e
chore: restore helm, .hooks and e2e folders
Mohammer5 Jul 16, 2024
2d1e87d
chore: add missing deps & .prettierrc.js
Mohammer5 Jul 16, 2024
16b7b23
chore: fix linter issues
Mohammer5 Jul 16, 2024
315835f
chore: add missing files
Mohammer5 Jul 16, 2024
37e5edd
chore: merge branch 'master' into DEVOPS-428
Mohammer5 Jul 16, 2024
5f75f32
chore: align playwright dep versions to get tests to work again
Mohammer5 Jul 18, 2024
0727ba6
chore: add missing empty-db file
Mohammer5 Jul 18, 2024
3af514a
chore(dockerfile): use node 20
Mohammer5 Jul 18, 2024
6f2461e
chore: get jest to work again
Mohammer5 Jul 18, 2024
d21a879
chore(make test): run yarn directly
Mohammer5 Jul 18, 2024
c3c2bcd
chore: make esline work again
Mohammer5 Jul 18, 2024
195d52e
chore: add dhis2 code style rules
Mohammer5 Jul 22, 2024
cad06e8
chore: merge branch 'master' into DEVOPS-428
Mohammer5 Jul 25, 2024
6d9627c
chore: re-generate type files
Mohammer5 Jul 25, 2024
59a3b8e
chore: apply PR feedback
Mohammer5 Jul 25, 2024
c74d66c
chore(dockerfile): use node 20 for alpine
Mohammer5 Jul 25, 2024
57f4c33
chore(makefile): use docker for running tests
Mohammer5 Jul 25, 2024
1c5abed
chore: apply linter/prettier rules
Mohammer5 Jul 25, 2024
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
18 changes: 18 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
Mohammer5 marked this conversation as resolved.
Show resolved Hide resolved
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
Mohammer5 marked this conversation as resolved.
Show resolved Hide resolved
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
32 changes: 25 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,27 +1,45 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage
!/e2e/fixtures/empty-db.sql.gz

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

.idea
.env
/test-results/
Expand Down
3 changes: 2 additions & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const { config } = require('@dhis2/cli-style')
const defaultConfig = require(config.prettier)

module.exports = {
...require(config.prettier),
...defaultConfig,
printWidth: 180,
overrides: [
{
Expand Down
42 changes: 22 additions & 20 deletions README.md
tonsV2 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
# Instance Manager Web Client
# React + TypeScript + Vite

## Run the app locally
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

1. `yarn`
2. `yarn start`
Currently, two official plugins are available:

## Run using docker compose
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

```sh
make dev
```

## Run using skaffold
## Expanding the ESLint configuration

```sh
skaffold dev
```
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

## Notes about fixed dependency versions
- Configure the top-level `parserOptions` property like this:

- `openapi-typescript@5.4.1` is used because later versions do not work with OpenAPI V2, which our backend is stuck on

## TODO
```js
export default {
// other rules...
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
}
```

- Validate create group form
- Can submit without hostname... No effect, no error
- Loading shows within form
- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
6 changes: 1 addition & 5 deletions e2e/utils/delete-database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,5 @@ export const deleteTestDatabase = async (page, dbName = defaultDbName) => {
await expect(page.getByTestId('dhis2-uicore-modalcontent')).toContainText(dbFileName)
await page.getByRole('button', { name: 'Confirm' }).click()

await expect(
page
.getByTestId('dhis2-uicore-alertbar')
.getByText(new RegExp(`Successfully deleted [^/]+/${dbFileName}`))
).toBeVisible()
await expect(page.getByTestId('dhis2-uicore-alertbar').getByText(new RegExp(`Successfully deleted [^/]+/${dbFileName}`))).toBeVisible()
}
14 changes: 14 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#000000" />
<title>DHIS2 Instances Manager</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
84 changes: 36 additions & 48 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,70 +1,58 @@
{
"name": "instance-manager",
"version": "0.1.0",
"name": "my-vue-app",
"private": true,
"dependencies": {
"@dhis2/app-runtime": "^3.10.1",
"@dhis2/app-service-alerts": "^3.9.4",
"@dhis2/d2-i18n": "^1.1.3",
"@dhis2/ui": "^8.16.0",
"@fontsource/roboto": "^5.0.12",
"axios": "^1.7.2",
"axios-hooks": "^5.0.2",
"final-form": "^4.20.10",
"moment": "^2.30.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-final-form": "^6.5.9",
"react-moment": "^1.1.3",
"react-router": "^6.24.1",
"react-router-dom": "^6.22.3",
"react-scripts": "5.0.1",
"styled-jsx": "^5.1.2",
"typescript": "^5.4.4",
"web-vitals": "^3.5.2"
},
"version": "0.0.0",
"__type": "module ;; doesn't work with our tooling setup, should be updated as it's deprecated! See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated",
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"start": "vite --port 3000",
"build": "tsc -b && vite build",
"preview": "vite preview",
"format": "yarn d2-style apply",
"_lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"lint": "yarn d2-style check",
"e2e": "yarn playwright test --ui",
"generate-types": "rm -rf ./src/types/generated && yarn openapi --input https://dev.api.im.dhis2.org/swagger.yaml --output ./src/types/generated --client axios --useOptions --useUnionTypes --exportCore false --exportServices false --exportModels true --exportSchemas false && yarn prettier src/types/generated --write --loglevel silent"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
"dependencies": {
"@dhis2/app-service-alerts": "^3.10.5",
"@dhis2/ui": "^9.10.2",
"@fontsource/roboto": "^5.0.13",
"axios": "^1.7.2",
"axios-hooks": "^5.0.2",
"final-form": "^4.20.10",
"moment": "^2.30.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-moment": "^1.1.3",
"react-router-dom": "^6.24.1"
},
"devDependencies": {
"@dhis2/app-runtime": "^3",
"@dhis2/cli-style": "^10.5.1",
"@ls-lint/ls-lint": "^2.2.2",
"@playwright/test": "^1.44.1",
"@playwright/test": "1.44.1",
"@testing-library/jest-dom": "^6.4.6",
"@testing-library/react": "^14.2.1",
"@testing-library/user-event": "^14.5.2",
"@types/jest": "^29.5.12",
"@types/node": "^20.12.2",
"@types/react": "^18.2.65",
"@types/react-dom": "^18.2.23",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/react-router-dom": "^5.3.3",
"@typescript-eslint/eslint-plugin": "^7.13.1",
"@typescript-eslint/parser": "^7.13.1",
"@vitejs/plugin-react": "^4.3.1",
"dotenv": "^16.4.5",
"dotenv-expand": "^11.0.6",
"openapi-typescript-codegen": "^0.29.0"
"eslint": "^8.57.0",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-refresh": "^0.4.7",
"openapi-typescript-codegen": "^0.29.0",
"playwright-core": "1.44.1",
"playwright": "1.44.1",
"styled-jsx": "^5.1.6",
"ts-jest": "^29.2.2",
"typescript": "^5.2.2",
"vite": "^5.3.1"
}
}
39 changes: 0 additions & 39 deletions public/index.html

This file was deleted.

25 changes: 0 additions & 25 deletions public/manifest.json

This file was deleted.

1 change: 1 addition & 0 deletions public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 8 additions & 23 deletions src/index.tsx → src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import '@fontsource/roboto/700.css'
import React from 'react'
import ReactDOM from 'react-dom/client'
import { createBrowserRouter, createRoutesFromElements, Route, RouterProvider } from 'react-router-dom'
import { Alerts, AuthProvider, ErrorView, Layout } from './components'
import './index.module.css'
import { DatabasesList, DeploymentDetails, InstancesList, NewDhis2Instance, RequestPasswordReset, ResetPassword, SignUp, StackDetails, StacksList } from './views'
import { UsersList } from './views/users'
import { GroupsList } from './views/groups'
import { Validate } from './views/validate'
import { UserDetails } from './views/users/user-details'
import { Alerts, AuthProvider, ErrorView, Layout } from '../components'
import { DatabasesList, DeploymentDetails, InstancesList, NewDhis2Instance, RequestPasswordReset, ResetPassword, SignUp, StackDetails, StacksList } from '../views'
import { UsersList } from '../views/users'
import { GroupsList } from '../views/groups'
import { Validate } from '../views/validate'
import { UserDetails } from '../views/users/user-details'

const router = createBrowserRouter(
createRoutesFromElements(
Expand All @@ -40,22 +39,8 @@ const router = createBrowserRouter(
)
)

const render = (tree) => {
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement)

if (process.env.REACT_APP_SUPRESS_STRICT_MODE) {
return root.render(tree)
}

return root.render(
<React.StrictMode>
{tree}
</React.StrictMode>
)
}

render(
<AlertsProvider>
export const App = () => (
<AlertsProvider plugin={false} parentAlertsAdd={undefined as Function} showAlertsInPlugin={false}>
<CssReset />
<CssVariables colors theme layers spacers elevations />
<RouterProvider router={router} />
Expand Down
1 change: 1 addition & 0 deletions src/app/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { App } from './app'
Loading
Loading