Updates the strategy change component used in change requests to have a "tab"-like functionality, where you can switch between "Change" (the rendered strategy) and "View diff" (the JSON diff). This is a tab switcher, so you navigate it with arrow keys if on a keyboard, and I've set selection to follow focus for now. This is my preference as it saves you extra space/enter taps, but we can remove it later if we want. Most of the changes in this PR is wrapping the existing strategy change components/sections in tab panels and tab context providers. Later changes in this project will remove the existing "view diff" hover link in favor of this view. There is some work to do on the design front (in terms of spacing, borders, etc), but this covers the core functionality. The pre-existing strategy change component has been moved into the "LegacyStrategyChange" file with no changes beyond a deprecation comment. The existing tests now test the new component instead with no breakage. (I anticipate breaking when we remove the view diff link, though) Change with strategy variants: <img width="991" alt="image" src="https://github.com/user-attachments/assets/ac28912f-5b08-4a9c-96da-81bfd0b2e68e" /> <img width="1005" alt="image" src="https://github.com/user-attachments/assets/4addaacc-101c-46cb-888f-95dc3b1cac25" /> ## Edge case: deleted strat with no reference strategy There is a case in the code where "reference strategy" can be undefined for a deleted strategy. It is defined as follows: ```ts const referenceStrategy = changeRequestState === 'Applied' ? change.payload.snapshot : currentStrategy; ``` I've decided to still show the "(no changes)" json diff in that setting, so that the tabs actually affect something. I don't know how often this happens, though: probably not anymore unless your CR is _ancient_, as we introduced the snapshot quite a while ago, and `currentStrategy` shouldn't really be undefined here, I should think. Deleted strategy with no reference strategy: Change: <img width="1013" alt="image" src="https://github.com/user-attachments/assets/352eaec9-c0ef-4d5a-b765-11304daf4474" /> Diff: <img width="1029" alt="image" src="https://github.com/user-attachments/assets/e69c81a6-1ef7-47ff-853a-9fb900b26303" /> |
||
---|---|---|
.. | ||
.yarn/releases | ||
cypress | ||
public | ||
scripts | ||
src | ||
.editorconfig | ||
.gitignore | ||
.npmignore | ||
.nvmrc | ||
.yarnrc.yml | ||
check-imports.rc | ||
cypress.config.ts | ||
cypress.d.ts | ||
index.html | ||
index.js | ||
mise.toml | ||
orval.config.ts | ||
package.json | ||
README.md | ||
tsconfig.json | ||
tsconfig.node.json | ||
vercel.json | ||
vite.config.mts | ||
yarn.lock |
frontend
This directory contains the Unleash Admin UI frontend app.
Run with a local instance of the unleash-api
Refer to the Contributing to Unleash guide for instructions. The frontend dev server runs (in port 3000) simultaneously with the backend dev server (in port 4242):
yarn install
yarn dev
Run with a sandbox instance of the Unleash API
Alternatively, instead of running unleash-api on localhost, you can use a remote instance:
cd ./frontend
yarn install
yarn run start:sandbox
Running end-to-end tests
We have a set of Cypress tests that run on the build before a PR can be merged so it's important that you check these yourself before submitting a PR. On the server the tests will run against the deployed Heroku app so this is what you probably want to test against:
yarn run start:sandbox
In a different shell, you can run the tests themselves:
yarn run e2e:heroku
If you need to test against patches against a local server instance, you'll need to run that, and then run the end to end tests using:
yarn run e2e
You may also need to test that a feature works against the enterprise version of unleash. Assuming the Heroku instance is still running, this can be done by:
yarn run start:enterprise
yarn run e2e
Generating the OpenAPI client
The frontend uses an OpenAPI client generated from the backend's OpenAPI spec. Whenever there are changes to the backend API, the client should be regenerated:
For now we only use generated types (src/openapi/models). We will use methods (src/openapi/apis) for new features soon.
yarn gen:api
rm -rf src/openapi/apis
clean up src/openapi/index.ts
imports, only keep first line export * from './models';
This script assumes that you have a running instance of the enterprise backend at http://localhost:4242
.
The new OpenAPI client will be generated from the runtime schema of this instance.
The target URL can be changed by setting the UNLEASH_OPENAPI_URL
env var.
Analyzing bundle size
npx vite-bundle-visualizer
in the root of the frontend directory