|
5 | 5 | This project manages the User Interface (UI) for KBase tools, not including the |
6 | 6 | narrative interface or documentation site [kbase.us](https://kbase.us). |
7 | 7 |
|
8 | | -This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app) |
9 | | -using the command `npx create-react-app ui-refresh-test --template typescript`. |
10 | | - |
11 | | -It also includes the following: |
12 | | - |
13 | | -- Redux (`@reduxjs/toolkit`) for state management |
14 | | -- `react-router-dom` for routing |
15 | | -- `prettier` for code formatting |
16 | | -- extended eslint configuration and eslint/prettier integration |
17 | | -- npm linting scripts (`lint`, `lint:fix`, `lint:strict`) |
18 | | -- `husky` to enable a `lint:strict` precommit hook |
19 | | -- `.nvmrc` specifying the node version |
20 | | -- `.editorconfig` for cross-editor config defaults. See |
21 | | - [editorconfig.org](https://editorconfig.org) for compatability |
22 | | -- Storybook (`npm run storybook`) for dev docs, style examples, and component |
23 | | - examples. |
| 8 | +## Tech Stack |
| 9 | + |
| 10 | +- **Build Tool**: [Vite](https://vitejs.dev/) - Fast, modern build tool with native ES modules |
| 11 | +- **Framework**: [React 18](https://react.dev/) with TypeScript |
| 12 | +- **State Management**: [Redux Toolkit](https://redux-toolkit.js.org/) with RTK Query |
| 13 | +- **Routing**: [React Router v6](https://reactrouter.com/) |
| 14 | +- **Styling**: [Sass](https://sass-lang.com/) modules with [Material-UI](https://mui.com/) |
| 15 | +- **Testing**: [Vitest](https://vitest.dev/) with React Testing Library |
| 16 | +- **Component Docs**: [Storybook 8](https://storybook.js.org/) |
| 17 | +- **Code Quality**: ESLint, Prettier, Husky pre-commit hooks |
24 | 18 |
|
25 | 19 | ## Architectural Decision Records |
26 | 20 |
|
@@ -53,65 +47,103 @@ Start the app: |
53 | 47 | npm start |
54 | 48 | ``` |
55 | 49 |
|
56 | | -### Troubleshooting |
| 50 | +Open [http://localhost:3000](http://localhost:3000) to view it in the browser. |
57 | 51 |
|
58 | | -- If you receive the following error message after running `npm start`: |
59 | | -`Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.` |
60 | | -then you may need to set the following environment variable: |
61 | | -`DANGEROUSLY_DISABLE_HOST_CHECK=true` |
62 | | -- If you are using a Mac with an M1 or M2 chip, you may run into an |
63 | | -error caused by `canvas` and `node-gyp` after running `npm install`. |
| 52 | +## Available Scripts |
64 | 53 |
|
65 | | - - First, make sure your global python version (`python --version`) |
66 | | - is under 3.12. |
67 | | - - If the install step still isn't working, try to install node-canvas |
68 | | - from source by following the Installation: Mac OS X, HomeBrew steps below |
69 | | - or on [this page](https://github.com/Automattic/node-canvas/wiki/Installation:-Mac-OS-X). |
| 54 | +### `npm start` |
70 | 55 |
|
71 | | - - `brew install pkg-config cairo pango libpng jpeg giflib librsvg` |
72 | | - - This python aspect of this issue may become obsolete once |
73 | | - the `node-gyp` peer dependency is able to upgrade to v10+. |
| 56 | +Runs the app in development mode with hot module replacement (HMR). |
| 57 | +The page will reload instantly when you make edits. |
74 | 58 |
|
75 | | -## Available Scripts |
| 59 | +### `npm test` |
76 | 60 |
|
77 | | -In the project directory, you can run: |
| 61 | +Launches Vitest in watch mode. Press `a` to run all tests, `f` to run only |
| 62 | +failed tests, or `q` to quit. |
78 | 63 |
|
79 | | -### `npm start` |
| 64 | +```sh |
| 65 | +npm test # Watch mode |
| 66 | +npm run test:ui # Vitest UI (browser-based test runner) |
| 67 | +npm run test:coverage # Run with coverage report |
| 68 | +``` |
80 | 69 |
|
81 | | -Runs the app in the development mode.\ |
82 | | -Open [http://localhost:3000](http://localhost:3000) to view it in the browser. |
| 70 | +### `npm run build` |
83 | 71 |
|
84 | | -The page will reload if you make edits.\ |
85 | | -You will also see any lint errors in the console. |
| 72 | +Builds the app for production to the `build` folder. The build is minified |
| 73 | +and optimized for best performance. |
86 | 74 |
|
87 | | -### `npm test` |
| 75 | +### `npm run lint` |
88 | 76 |
|
89 | | -Launches the test runner in the interactive watch mode.\ |
90 | | -See the section about [running tests][running-tests] for more information. |
| 77 | +Runs ESLint, Prettier, Stylelint, and TypeScript checks. |
91 | 78 |
|
92 | | -[running-tests]: https://facebook.github.io/create-react-app/docs/running-tests |
| 79 | +```sh |
| 80 | +npm run lint # Show errors/warnings |
| 81 | +npm run lint:fix # Auto-fix where possible |
| 82 | +npm run lint:strict # Fail on any errors/warnings (used in pre-commit hook) |
| 83 | +``` |
93 | 84 |
|
94 | | -### `npm run build` |
| 85 | +### `npm run storybook` |
95 | 86 |
|
96 | | -Builds the app for production to the `build` folder.\ |
97 | | -It correctly bundles React in production mode and optimizes the build for the |
98 | | -best performance. |
| 87 | +Opens Storybook locally for component development and documentation. |
| 88 | +Watches `*.stories.tsx` files and launches a local server at |
| 89 | +[http://localhost:6006](http://localhost:6006). |
99 | 90 |
|
100 | | -The build is minified and the filenames include the hashes.\ |
101 | | -Your app is ready to be deployed! |
| 91 | +```sh |
| 92 | +npm run storybook # Start dev server |
| 93 | +npm run build-storybook # Build static storybook |
| 94 | +``` |
102 | 95 |
|
103 | | -See the section about |
104 | | -[deployment](https://facebook.github.io/create-react-app/docs/deployment) for |
105 | | -more information. |
| 96 | +## Development |
106 | 97 |
|
107 | | -### `npm run lint`, `npm run lint:fix`, `npm run lint:strict` |
| 98 | +### Environment Variables |
108 | 99 |
|
109 | | -Runs eslint/prettier and shows errors/warnings. `npm run lint:fix` will fix |
110 | | -files in-place where possible. `npm run lint:strict` will fail with any |
111 | | -errors/warnings and is used as a pre-commit hook. |
| 100 | +Environment variables are prefixed with `VITE_` and accessed via `import.meta.env`: |
112 | 101 |
|
113 | | -### `npm run storybook` |
| 102 | +```typescript |
| 103 | +const domain = import.meta.env.VITE_KBASE_DOMAIN; |
| 104 | +const isDev = import.meta.env.MODE === 'development'; |
| 105 | +``` |
| 106 | + |
| 107 | +See `.env` files for available variables. |
| 108 | + |
| 109 | +### API Proxy |
| 110 | + |
| 111 | +In development, requests to `/services/*` are proxied to the KBase API |
| 112 | +(configured in `vite.config.ts`). This avoids CORS issues during local development. |
| 113 | + |
| 114 | +### Network Access |
| 115 | + |
| 116 | +To access the dev server from other devices on your network (e.g., mobile testing): |
| 117 | + |
| 118 | +```sh |
| 119 | +npm start -- --host |
| 120 | +``` |
| 121 | + |
| 122 | +Then access via your machine's IP address or hostname. |
| 123 | + |
| 124 | +## Project Structure |
| 125 | + |
| 126 | +``` |
| 127 | +src/ |
| 128 | +├── app/ # App setup, routes, store |
| 129 | +├── common/ # Shared components, hooks, utilities |
| 130 | +│ ├── api/ # RTK Query API definitions |
| 131 | +│ └── components/ # Reusable UI components |
| 132 | +├── features/ # Feature-based modules |
| 133 | +│ ├── auth/ # Authentication |
| 134 | +│ ├── collections/ # Data collections |
| 135 | +│ ├── navigator/ # Narrative browser |
| 136 | +│ └── ... |
| 137 | +├── stories/ # Storybook stories |
| 138 | +└── test/ # Test utilities and mocks |
| 139 | +``` |
| 140 | + |
| 141 | +## Contributing |
| 142 | + |
| 143 | +1. Create a feature branch from `main` |
| 144 | +2. Make your changes |
| 145 | +3. Ensure tests pass: `npm test` |
| 146 | +4. Ensure linting passes: `npm run lint:strict` |
| 147 | +5. Submit a pull request |
114 | 148 |
|
115 | | -Opens storybook locally. Builds and watches `*.stories.[tsx|mdx]` files and |
116 | | -launches a local storybook server. The storybook contains component examples |
117 | | -and other dev documentation. |
| 149 | +The pre-commit hook will run `lint:strict` automatically. |
0 commit comments