Skip to content

Commit 3539880

Browse files
docs(ui): more documentation
1 parent 2c632f1 commit 3539880

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# UI/Layout
2+
3+
We use https://github.com/mathuo/dockview for layout. This library supports resizable and dockable panels. Users can drag and drop panels to rearrange them.
4+
5+
The intention when adopting this library was to allow users to create their own custom layouts and save them. However, this feature is not yet implemented and each tab only has a predefined layout.
6+
7+
This works well, but it _is_ fairly complex. You can see that we've needed to write a fairly involved API to manage the layouts: invokeai/frontend/web/src/features/ui/layouts/navigation-api.ts
8+
9+
And the layouts themselves are awkward to define, especially when compared to plain JSX: invokeai/frontend/web/src/features/ui/layouts/generate-tab-auto-layout.tsx
10+
11+
This complexity may or may not be worth it.
12+
13+
## Previous approach
14+
15+
Previously we used https://github.com/bvaughn/react-resizable-panels and simple JSX components.
16+
17+
This library is great except it doesn't support absolute size constraints, only relative/percentage constraints. We had a brittle abstraction layer on top of it to try to enforce minimum pixel sizes for panels but it was janky and had FP precision issues causing drifting sizes.
18+
19+
It also doesn't support dockable panels.
20+
21+
## Future possibilities
22+
23+
1. Continue with dockview and implement custom layout saving/loading. We experimented with this and it was _really_ nice. We defined a component for each panel type and use react context to manage state. But we thought that it would be confusing for most users, so we flagged it for a future iteration and instead shipped with predefined layouts.
24+
2. Switch to a simpler layout library or roll our own.
25+
26+
In hindsight, we should have skipped dockview and found something else that was simpler until we were ready to invest in custom layouts.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# API
2+
3+
The API client is a fairly standard Redux Toolkit Query (RTK-Query) setup.
4+
5+
It defines a simple base query with special handling for OpenAPI schema queries and endpoints: invokeai/frontend/web/src/services/api/index.ts
6+
7+
## Types
8+
9+
The API provides an OpenAPI schema and we generate TS types from it. They are stored in: invokeai/frontend/web/src/services/api/schema.ts
10+
11+
We use https://github.com/openapi-ts/openapi-typescript/ to generate the types.
12+
13+
- Python script to outut the OpenAPI schema: scripts/generate_openapi_schema.py
14+
- Node script to call openapi-typescript and generate the TS types: invokeai/frontend/web/scripts/typegen.js
15+
16+
Pipe the output of the python script to the node script to update the types. There is a `make` target that does this in one fell swoop (after activating venv): `make frontend-typegen`
17+
18+
Alternatively, start the ptyhon server and run `pnpm typegen`.
19+
20+
The schema.ts file is pushed to the repo, and a CI check ensures it is up to date.

invokeai/frontend/web/src/services/events/onInvocationComplete.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,18 @@ import type { JsonObject } from 'type-fest';
2626

2727
const log = logger('events');
2828

29+
// These nodes are passthrough nodes. They do not add images to the gallery, so we must skip that handling for them.
2930
const nodeTypeDenylist = ['load_image', 'image'];
3031

32+
/**
33+
* Builds the socket event handler for invocation complete events. Adds output images to the gallery and/or updates
34+
* node execution states for the workflow editor.
35+
*
36+
* @param getState The Redux getState function.
37+
* @param dispatch The Redux dispatch function.
38+
* @param finishedQueueItemIds A cache of finished queue item IDs to prevent duplicate handling and avoid race
39+
* conditions that can happen when a graph finishes very quickly.
40+
*/
3141
export const buildOnInvocationComplete = (
3242
getState: AppGetState,
3343
dispatch: AppDispatch,

invokeai/frontend/web/src/services/events/onModelInstallError.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ const getHFTokenStatus = async (dispatch: AppDispatch): Promise<S['HFTokenStatus
3939
}
4040
};
4141

42+
/**
43+
* Handles model install error events by logging the error, displaying appropriate toast notifications.
44+
*/
4245
export const buildOnModelInstallError = (getState: AppGetState, dispatch: AppDispatch) => {
4346
return async (data: S['ModelInstallErrorEvent']) => {
4447
log.error({ data }, 'Model install error');

invokeai/frontend/web/src/services/events/setEventListeners.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ type SetEventListenersArg = {
3333

3434
const selectModelInstalls = modelsApi.endpoints.listModelInstalls.select();
3535

36+
/**
37+
* Sets up event listeners for the socketio client. Some components will set up their own listeners. These are the ones
38+
* that have app-wide implications.
39+
*/
3640
export const setEventListeners = ({ socket, store, setIsConnected }: SetEventListenersArg) => {
3741
const { dispatch, getState } = store;
3842

0 commit comments

Comments
 (0)