Skip to content

Commit

Permalink
chore: adding the webui to the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
lholmquist committed Jan 22, 2025
1 parent d8196e5 commit 637db0c
Show file tree
Hide file tree
Showing 68 changed files with 35,125 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,6 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# MacOS related
.DS_Store
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"main": "server.mjs",
"scripts": {
"prebuildui": "npm run cleanui",
"buildui": "cd ../parasol-insurance/app/src/main/webui && npm install && npm run build",
"cleanui": "rm -rf ../parasol-insurance/app/src/main/webui/node_modules ../parasol-insurance/app/src/main/webui/dist",
"buildui": "cd ./webui && npm install && npm run build",
"cleanui": "rm -rf ./webui/node_modules ./webui/dist",
"start": "node server.mjs",
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down
2 changes: 1 addition & 1 deletion server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ await fastify.register(fastifyEnv, {
});

// WebUI related setup and serving
const webuiLocation = '../parasol-insurance/app/src/main/webui/dist';
const webuiLocation = './webui/dist';

fastify.register(fastifyStatic, {
wildcard: false,
Expand Down
17 changes: 17 additions & 0 deletions webui/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Editor configuration, see http://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.snap]
max_line_length = off
trim_trailing_whitespace = false

[*.md]
max_line_length = off
trim_trailing_whitespace = false
76 changes: 76 additions & 0 deletions webui/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
export default {
// tells eslint to use the TypeScript parser
"parser": "@typescript-eslint/parser",
// tell the TypeScript parser that we want to use JSX syntax
"parserOptions": {
"tsx": true,
"jsx": true,
"js": true,
"useJSXTextNode": true,
"project": "./tsconfig.json",
"tsconfigRootDir": __dirname
},
// we want to use the recommended rules provided from the typescript plugin
"extends": [
"@redhat-cloud-services/eslint-config-redhat-cloud-services",
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended"
],
"globals": {
"window": "readonly",
"describe": "readonly",
"test": "readonly",
"expect": "readonly",
"it": "readonly",
"process": "readonly",
"document": "readonly",
"insights": "readonly",
"shallow": "readonly",
"render": "readonly",
"mount": "readonly"
},
"overrides": [
{
"files": ["src/**/*.ts", "src/**/*.tsx"],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": ["plugin:@typescript-eslint/recommended"],
"rules": {
"react/prop-types": "off",
"@typescript-eslint/no-unused-vars": "error"
},
},
],
"settings": {
"react": {
"version": "^16.11.0"
}
},
// includes the typescript specific rules found here: https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#supported-rules
"plugins": [
"@typescript-eslint",
"react-hooks",
"eslint-plugin-react-hooks"
],
"rules": {
"sort-imports": [
"error",
{
"ignoreDeclarationSort": true
}
],
"@typescript-eslint/explicit-function-return-type": "off",
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"@typescript-eslint/interface-name-prefix": "off",
"prettier/prettier": "off",
"import/no-unresolved": "off",
"import/extensions": "off",
"react/prop-types": "off"
},
"env": {
"browser": true,
"node": true
}
}
10 changes: 10 additions & 0 deletions webui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
**/node_modules
dist
yarn-error.log
yarn.lock
stats.json
coverage
storybook-static
.DS_Store
.idea
.env
1 change: 1 addition & 0 deletions webui/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package.json
4 changes: 4 additions & 0 deletions webui/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"printWidth": 120
}
111 changes: 111 additions & 0 deletions webui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Patternfly Seed

Patternfly Seed is an open source build scaffolding utility for web apps. The primary purpose of this project is to give developers a jump start when creating new projects that will use patternfly. A secondary purpose of this project is to serve as a reference for how to configure various aspects of an application that uses patternfly, webpack, react, typescript, etc.

Out of the box you'll get an app layout with chrome (header/sidebar), routing, build pipeline, test suite, and some code quality tools. Basically, all the essentials.

<img width="1058" alt="Out of box dashboard view of patternfly seed" src="https://user-images.githubusercontent.com/5942899/103803761-03a0a500-501f-11eb-870a-345d7d035e6b.png">

## Quick-start

```bash
git clone https://github.com/patternfly/patternfly-react-seed
cd patternfly-react-seed
npm install && npm run start:dev
```

## Development scripts

```sh
# Install development/build dependencies
npm install

# Start the development server
npm run start:dev

# Run a production build (outputs to "dist" dir)
npm run build

# Run the test suite
npm run test

# Run the test suite with coverage
npm run test:coverage

# Run the linter
npm run lint

# Run the code formatter
npm run format

# Launch a tool to inspect the bundle size
npm run bundle-profile:analyze

# Start the express server (run a production build first)
npm run start

# Start storybook component explorer
npm run storybook

# Build storybook component explorer as standalone app (outputs to "storybook-static" dir)
npm run build:storybook
```

## Configurations
* [TypeScript Config](./tsconfig.json)
* [Webpack Config](./webpack.common.js)
* [Jest Config](./jest.config.js)
* [Editor Config](./.editorconfig)

## Raster image support

To use an image asset that's shipped with PatternFly core, you'll prefix the paths with "@assets". `@assets` is an alias for the PatternFly assets directory in node_modules.

For example:
```js
import imgSrc from '@assets/images/g_sizing.png';
<img src={imgSrc} alt="Some image" />
```

You can use a similar technique to import assets from your local app, just prefix the paths with "@app". `@app` is an alias for the main src/app directory.

```js
import loader from '@app/assets/images/loader.gif';
<img src={loader} alt="Content loading />
```
## Vector image support
Inlining SVG in the app's markup is also possible.
```js
import logo from '@app/assets/images/logo.svg';
<span dangerouslySetInnerHTML={{__html: logo}} />
```
You can also use SVG when applying background images with CSS. To do this, your SVG's must live under a `bgimages` directory (this directory name is configurable in [webpack.common.js](./webpack.common.js#L5)). This is necessary because you may need to use SVG's in several other context (inline images, fonts, icons, etc.) and so we need to be able to differentiate between these usages so the appropriate loader is invoked.
```css
body {
background: url(./assets/bgimages/img_avatar.svg);
}
```
## Adding custom CSS
When importing CSS from a third-party package for the first time, you may encounter the error `Module parse failed: Unexpected token... You may need an appropriate loader to handle this file typ...`. You need to register the path to the stylesheet directory in [stylePaths.js](./stylePaths.js). We specify these explicitly for performance reasons to avoid webpack needing to crawl through the entire node_modules directory when parsing CSS modules.
## Code quality tools
* For accessibility compliance, we use [react-axe](https://github.com/dequelabs/react-axe)
* To keep our bundle size in check, we use [webpack-bundle-analyzer](https://github.com/webpack-contrib/webpack-bundle-analyzer)
* To keep our code formatting in check, we use [prettier](https://github.com/prettier/prettier)
* To keep our code logic and test coverage in check, we use [jest](https://github.com/facebook/jest)
* To ensure code styles remain consistent, we use [eslint](https://eslint.org/)
* To provide a place to showcase custom components, we integrate with [storybook](https://storybook.js.org/)
## Multi environment configuration
This project uses [dotenv-webpack](https://www.npmjs.com/package/dotenv-webpack) for exposing environment variables to your code. Either export them at the system level like `export MY_ENV_VAR=http://dev.myendpoint.com && npm run start:dev` or simply drop a `.env` file in the root that contains your key-value pairs like below:
```sh
ENV_1=http://1.myendpoint.com
ENV_2=http://2.myendpoint.com
```
With that in place, you can use the values in your code like `console.log(process.env.ENV_1);`
36 changes: 36 additions & 0 deletions webui/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
chrome: 100,
},
},
],
'@babel/preset-react',
'@babel/preset-typescript',
],
plugins: [
// Devs tend to write `import { someIcon } from '@patternfly/react-icons';`
// This transforms the import to be specific which prevents having to parse 2k+ icons
// Also prevents potential bundle size blowups with CJS
[
'transform-imports',
{
'@patternfly/react-icons': {
transform: (importName) =>
`@patternfly/react-icons/dist/js/icons/${
importName === 'PathMissingIcon'
? 'pathMissing-icon'
: importName
.split(/(?=[A-Z])/)
.join('-')
.toLowerCase()
}`,
preventFullImport: true,
},
},
],
],
};
7 changes: 7 additions & 0 deletions webui/dr-surge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const fs = require('fs');
const path = require('path');
const indexPath = path.resolve(__dirname, 'dist/index.html');
const targetFilePath = path.resolve(__dirname, 'dist/200.html');
// ensure we have bookmarkable url's when publishing to surge
// https://surge.sh/help/adding-a-200-page-for-client-side-routing
fs.createReadStream(indexPath).pipe(fs.createWriteStream(targetFilePath));
32 changes: 32 additions & 0 deletions webui/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// For a detailed explanation regarding each configuration property, visit:
// https://jestjs.io/docs/en/configuration.html

module.exports = {
// Automatically clear mock calls and instances between every test
clearMocks: true,

// Indicates whether the coverage information should be collected while executing the test
collectCoverage: false,

// The directory where Jest should output its coverage files
coverageDirectory: 'coverage',

// An array of directory names to be searched recursively up from the requiring module's location
moduleDirectories: [
"node_modules",
"<rootDir>/src"
],

// A map from regular expressions to module names that allow to stub out resources with a single module
moduleNameMapper: {
'\\.(css|less)$': '<rootDir>/__mocks__/styleMock.js',
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
"@app/(.*)": '<rootDir>/src/app/$1'
},

// A preset that is used as a base for Jest's configuration
preset: "ts-jest/presets/js-with-ts",

// The test environment that will be used for testing.
testEnvironment: "jsdom",
};
Loading

0 comments on commit 637db0c

Please sign in to comment.