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

WebApp update - Code quality #37

Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
329b9bf
DUGK-57 Updated readme instructions. (#36)
Omarley7 Mar 31, 2023
a14d738
DUGK-61 Refactored /e2e/Menu.test.ts (#37)
SyntaxXeror Apr 3, 2023
c959fb6
Development (#40)
Omarley7 Apr 10, 2023
de137b1
revert changes to git hooks
Omarley7 Apr 10, 2023
e82522e
DUGK-64 changed es version to 2022 (#41)
SyntaxXeror Apr 16, 2023
6d860f4
DUGK-65 Removed husky for git-hooks (#42)
Omarley7 Apr 17, 2023
a13b6a5
move TabData type to TabRender (#44)
DaloonOfDoom Apr 17, 2023
b6f3063
DUGK-68 Removed 'Components.tsx' and renamed '...Data.ts' (#47)
SyntaxXeror Apr 17, 2023
d7b3ebf
Small refactor of Workbench (#46)
SyntaxXeror Apr 17, 2023
78d21fa
DUGK-67 Removed 'Workflows.tsx' and renamed '...Data.ts' (#45)
SyntaxXeror Apr 17, 2023
ef3406e
DUGK-66 Updated CodeClimate config to V2 (#43)
SyntaxXeror Apr 17, 2023
777d555
Removed husky from enb
Omarley7 Apr 18, 2023
868a03a
Fixed test script continuing on error.
Omarley7 Apr 18, 2023
2382819
Tempoary fix on CI pipeline with unittest.
Omarley7 Apr 18, 2023
4a1d996
Added continue on error for tests cases.
Omarley7 Apr 19, 2023
846563e
DUGK-59 refactor tests (#48)
Omarley7 Apr 19, 2023
072008f
Removed contine on error from test step
Omarley7 Apr 20, 2023
3467ab0
Postponing to next PR
Omarley7 Apr 20, 2023
f64336c
Re-refactored E2E menu test (#49)
Omarley7 Apr 21, 2023
a8c1f54
config.bash format
SyntaxXeror Apr 21, 2023
f8ff069
fixed minor issues
Omarley7 Apr 21, 2023
4197c91
Removed continue on error
SyntaxXeror Apr 21, 2023
ab035d6
Merge branch 'feature/distributed-demo' of https://github.com/Omarley…
SyntaxXeror Apr 21, 2023
76c87f2
Added yarn develop to readme
Omarley7 Apr 21, 2023
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
37 changes: 13 additions & 24 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,31 @@
---
engines:
version: "2"
plugins:
shellcheck:
enabled: true
checkstyle:
enabled: true
channel: "beta"
csslint:
enabled: true
duplication:
enabled: true
config:
enabled: true
threshold: 7
languages:
- typescript
- javascript
- python
- php
- typescript:
- javascript:
- python:
- php:
eslint:
enabled: true
channel: "eslint-8"
config:
config: .eslintrc
config: client/.eslintrc
fixme:
enabled: true
ratings:
paths:
- "**.css"
- "**.inc"
- "**.ts"
- "**.js"
- "**.jsx"
- "**.tsx"
- "**.module"
- "**.sh"
- "**.bash"
exclude_paths:
exclude_patterns:
- "**.md"
- "**.txt"
- "**.json"
- docs/
- .husky/
- "**/node_modules/"
- "**/build/"
- "**/public/"
- "**/coverage"
5 changes: 2 additions & 3 deletions .husky/pre-commit → .git-hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

if git diff --cached --name-only | grep "^client/" >/dev/null; then
cd client
cd client || exit
yarn install
yarn format && yarn syntax
else
echo "No changes in the client directory. Skipping pre-commit hook."
printf "No changes in the client directory. Skipping pre-commit hook."
fi
11 changes: 11 additions & 0 deletions .git-hooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env sh

BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)

if git diff --name-only origin/"$BRANCH_NAME"...HEAD | grep "^client/" >/dev/null; then
cd client || exit
yarn install
yarn jest . --coverage=false
else
echo "No changes in the client directory. Skipping pre-push hook."
fi
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
2 changes: 0 additions & 2 deletions .github/workflows/client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ jobs:
uses: actions/checkout@v3

- name: Setup node
env:
HUSKY_SKIP_INSTALL: 1
uses: actions/setup-node@v3
with:
node-version: 18
Expand Down
10 changes: 0 additions & 10 deletions .husky/pre-push

This file was deleted.

10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,23 @@ The best way to use the DTaaS software is via a vagrant virtual machine. The ins
The rest of the information on this page is aimed at current and potential contributors to DTaaS software development.

To install the development environment, run

```bash
bash script/install.bash
```

Before you make commits, please install the git hooks provided in the repository.

```shell
script/configure-git-hooks.sh
```

This will ensure that your commits are formatted correctly and that the unittests pass before you push your changes. Be aware that the tests take a long time to run. If you want to skip the tests or formatting, you can use the `--no-verify` flag on `git commit` or `git push`.

### Infrastructure Components

The application uses [Træfik](https://github.com/traefik/traefik) and [ML Workspace](https://github.com/ml-tooling/ml-workspace) open-source components. It is possible to run [jupyterlab notebooks](script/jupyter.sh), [Grafana servers](script/grafana.sh) and [InfluxDB](script/influx.sh) as part of the DTaaS software. But terminal-based Jupyterlab, Grafana and InfluxDB are not installed in the default setup.


## License

This software is owned by [The INTO-CPS Association](https://into-cps.org/) and is available under [the INTO-CPS License](./LICENSE.txt).
6 changes: 2 additions & 4 deletions client/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"env": {
"browser": true,
"es6": true,
"es2022": true,
"jest": true,
"jest/globals": true
},
Expand Down Expand Up @@ -30,11 +30,9 @@
"parserOptions": {
"requireConfigFile": false,
"ecmaFeatures": {
"emacVersion": 6,
"sourceType": "module",
"jsx": true
},
"ecmaVersion": 2018,
"ecmaVersion": 11,
"sourceType": "module" // Allows for the use of imports
},
"plugins": ["jsx-a11y", "react", "jest", "@typescript-eslint"],
Expand Down
21 changes: 16 additions & 5 deletions client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The following steps are required to setup the environment and build the applicat

### Prerequisites

If you are using yarn 2, please change the package.json to use `postinstall` instead `prepare` scripts. This application is using **Husky** for pre-commit hooks, read more about husky and yarn 2 [here](https://typicode.github.io/husky/#/?id=yarn-2).
If you are using yarn 2, please change the package.json to use `postinstall` instead `prepare` scripts.

```bash
cd client
Expand All @@ -27,12 +27,23 @@ yarn clean #clean the directory of temporary files

---

## Configuration
## Custom configuration

To customize the configuration of endpoints to your preference, it is recommended that you configure the environment file of your choice located in the `'./config'` directory.
It is required to have a `env.js` in the root directory of `build` during runtime. This file is used to configure the endpoints of the application. See the [build instructions](../docs/CLIENT.md) for an example.

Once the configuration file has been updated, please rerun the configuration bash to apply the changes.
### Multiple configurations

If you want to switch between multiple environments, you can use the `yarn configapp` command to copy a configuration file from `client/config/` to the `build` directory.

1. Save the file as `client/config/<config-name>.js`.
2. Run the config command to copy the file to the `public` directory and the `build` directory, if a build is present.

```bash
yarn configapp #prod | dev
yarn configapp <config-name>
```

> Which ever env.js file is present in the `public` directory during `yarn build`, will be used in the build.

It is therefore reccommend to keep the configurations in the `client/config/` directory and use the `yarn configapp` command to switch between them.

---
5 changes: 1 addition & 4 deletions client/jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,5 @@
"verbose": true,
"testRegex": "/test/.*\\.test.tsx?$",
"modulePaths": ["<rootDir>/src/"],
"setupFilesAfterEnv": [
"<rootDir>/test/unitTests/config/test.env.js",
"<rootDir>/test/unitTests/config/importJestDom.ts"
]
"setupFilesAfterEnv": ["<rootDir>/test/unitTests/jest.setup.ts"]
}
14 changes: 10 additions & 4 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"start": "script/start.bash",
"clean": "script/clean.bash",
"format": "prettier --ignore-path ../.gitignore --write \"**/*.{ts,tsx,css,scss}\"",
"prepare": "cd .. && husky install"
"prepare": "../script/configure-git-hooks.sh"
},
"eslintConfig": {
"extends": [
Expand All @@ -40,22 +40,28 @@
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-is": "^18.2.0",
"react-router-dom": "^6.3.0",
"react-tabs": "^6.0.0",
"recharts": "^2.1.13",
"resize-observer-polyfill": "^1.5.1",
"serve": "^14.0.1",
"styled-components": "^5.3.9",
"typescript": "^4.9.5"
},
"devDependencies": {
"@babel/core": "^7.21.3",
"@babel/plugin-syntax-flow": "^7.18.6",
"@babel/plugin-transform-react-jsx": "^7.21.0",
"@playwright/test": "^1.25.0",
"@playwright/test": "^1.32.1",
"@testing-library/dom": "^9.2.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
"@types/jest": "^29.5.0",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@types/styled-components": "^5.1.26",
"@typescript-eslint/eslint-plugin": "^5.34.0",
"@typescript-eslint/parser": "^5.34.0",
"eslint": "^8.22.0",
Expand All @@ -65,11 +71,11 @@
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-jsx-a11y": "^6.6.1",
"eslint-plugin-react": "^7.30.1",
"husky": "^8.0.0",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"playwright": "^1.25.0",
"playwright": "^1.32.1",
"prettier": "2.7.1",
"react-iframe": "^1.8.5",
"react-scripts": "^5.0.1",
"ts-jest": "^29.0.5"
},
Expand Down
5 changes: 3 additions & 2 deletions client/script/build.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
export PATH="$(yarn bin):$PATH"
PATH="$(yarn bin):$PATH"
export PATH
#babel ./src --out-dir build --copy-files
react-scripts build
react-scripts build
29 changes: 15 additions & 14 deletions client/script/config.bash
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
# copy the correct environment variables file to react SPA
# https://stackoverflow.com/questions/51653931/react-configuration-file-for-post-deployment-settings
# https://dev.to/akdevcraft/react-runtime-variables-49dc
#!/bin/bash
mode=$1
if [ -z "$mode" ]; then
printf "Use yarn configapp with either dev, prod or test:"
Expand All @@ -17,20 +17,21 @@ set_env() {
fi
}

case "$mode" in
case "$mode" in

dev)
set_env dev
;;
prod)
set_env prod
;;
test)
set_env test
;;
*) echo "Invalid mode $mode - use 'dev', 'prod' or 'test'"
exit 1
;;
dev)
set_env dev
;;
prod)
set_env prod
;;
test)
set_env test
;;
*)
echo "Invalid mode $mode - use 'dev', 'prod' or 'test'"
exit 1
;;
esac

exit 0
3 changes: 2 additions & 1 deletion client/script/syntax.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
export PATH="$(yarn bin):$PATH"
PATH="$(yarn bin):$PATH"
export PATH
printf "Running eslint"
eslint .
20 changes: 17 additions & 3 deletions client/script/test.bash
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
#!/bin/bash
printf "\n\n################ Testing in progress ################"
printf "\n\n################ Testing in progress ################\n"
printf "\n################ Running Jest ################\n"
export PATH="$(yarn bin):$PATH"
PATH="$(yarn bin):$PATH" # Add yarn bin to path
export PATH
jest .

JEST_EXIT_CODE=$?
if [ $JEST_EXIT_CODE -ne 0 ]; then
printf "\n\n################ Jest tests failed ################"
exit 1
fi

# { { yarn start 2>&3 || [ $? -eq 137 ]; } 3>&2 2>/dev/null & } <-- Does not work. Trying to only suppress error 137.
yarn start >/dev/null & # Start server in background. Suppress stderr.
printf "\n\n################ Running Playwright ################"
printf "\n\n################ Running Playwright ################\n"
playwright test
PLAYWRGHT_EXIT_CODE=$?

printf "Closing server on port 4000..."
npx kill-port 4000

if [ $PLAYWRGHT_EXIT_CODE -ne 0 ]; then
printf "\n\n################ Playwright tests failed ################\n"
exit $PLAYWRGHT_EXIT_CODE
fi
11 changes: 5 additions & 6 deletions client/src/components/Iframe.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import * as React from 'react';
import IframeReact from 'react-iframe';

interface IFrameProps {
url: string;
fullsize?: boolean;
title: string;
}

function Iframe({ url, fullsize, title }: IFrameProps) {
function Iframe({ url, title }: IFrameProps) {
// Be aware sandbox is not supported by current JupyterLight implementation.
return (
<iframe
<IframeReact
title={title}
src={url}
url={url}
width="100%"
referrerPolicy="no-referrer"
style={fullsize ? { flexGrow: 1 } : { height: '100%' }}
styles={{ flexGrow: '1' }}
/>
);
}
Expand Down
Loading