Skip to content

Commit

Permalink
(refactor) O3-4077: Improve the workspace group workflow (#1185)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasharma05 authored Dec 11, 2024
1 parent c3e54c4 commit a5b386a
Show file tree
Hide file tree
Showing 21 changed files with 500 additions and 329 deletions.
12 changes: 4 additions & 8 deletions packages/framework/esm-extensions/src/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ export interface WorkspaceRegistration {
canHide: boolean;
canMaximize: boolean;
width: 'narrow' | 'wider' | 'extra-wide';
hasOwnSidebar: boolean;
sidebarFamily: string;
preferredWindowSize: WorkspaceWindowState;
load: () => Promise<{ default?: LifeCycles } & LifeCycles>;
moduleName: string;
groups?: Array<string>;
}

interface WorkspaceRegistrationStore {
Expand All @@ -37,11 +36,10 @@ export interface RegisterWorkspaceOptions {
canHide?: boolean;
canMaximize?: boolean;
width?: 'narrow' | 'wider' | 'extra-wide';
hasOwnSidebar?: boolean;
sidebarFamily?: string;
preferredWindowSize?: WorkspaceWindowState;
load: () => Promise<{ default?: LifeCycles } & LifeCycles>;
moduleName: string;
groups?: Array<string>;
}

/**
Expand All @@ -60,8 +58,7 @@ export function registerWorkspace(workspace: RegisterWorkspaceOptions) {
canHide: workspace.canHide ?? false,
canMaximize: workspace.canMaximize ?? false,
width: workspace.width ?? 'narrow',
hasOwnSidebar: workspace.hasOwnSidebar ?? false,
sidebarFamily: workspace.sidebarFamily ?? 'default',
groups: workspace.groups ?? [],
},
},
}));
Expand Down Expand Up @@ -97,8 +94,7 @@ export function getWorkspaceRegistration(name: string): WorkspaceRegistration {
canHide: workspaceExtension.meta?.canHide ?? false,
canMaximize: workspaceExtension.meta?.canMaximize ?? false,
width: workspaceExtension.meta?.width ?? 'narrow',
sidebarFamily: 'default',
hasOwnSidebar: false,
groups: workspaceExtension?.meta?.groups ?? [],
};
} else {
throw new Error(`No workspace named '${name}' has been registered.`);
Expand Down
46 changes: 39 additions & 7 deletions packages/framework/esm-framework/docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@

- [closeWorkspace](API.md#closeworkspace)
- [launchWorkspace](API.md#launchworkspace)
- [launchWorkspaceGroup](API.md#launchworkspacegroup)
- [navigateAndLaunchWorkspace](API.md#navigateandlaunchworkspace)
- [useWorkspaces](API.md#useworkspaces)

Expand Down Expand Up @@ -609,7 +610,7 @@ ___

#### Defined in

[packages/framework/esm-globals/src/types.ts:396](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-globals/src/types.ts#L396)
[packages/framework/esm-globals/src/types.ts:409](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-globals/src/types.ts#L409)

___

Expand All @@ -622,7 +623,7 @@ Basically, this is the same as the app routes, with each routes definition keyed

#### Defined in

[packages/framework/esm-globals/src/types.ts:387](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-globals/src/types.ts#L387)
[packages/framework/esm-globals/src/types.ts:400](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-globals/src/types.ts#L400)

___

Expand Down Expand Up @@ -792,7 +793,7 @@ ___

### WorkspaceDefinition

Ƭ **WorkspaceDefinition**: { `canHide?`: `boolean` ; `canMaximize?`: `boolean` ; `hasOwnSidebar?`: `boolean` ; `name`: `string` ; `preferredWindowSize?`: [`WorkspaceWindowState`](API.md#workspacewindowstate) ; `sidebarFamily?`: `string` ; `title`: `string` ; `type`: `string` ; `width?`: ``"narrow"`` \| ``"wider"`` \| ``"extra-wide"`` } & { `component`: `string` } \| { `component?`: `never` }
Ƭ **WorkspaceDefinition**: { `canHide?`: `boolean` ; `canMaximize?`: `boolean` ; `groups`: `string`[] ; `name`: `string` ; `preferredWindowSize?`: [`WorkspaceWindowState`](API.md#workspacewindowstate) ; `title`: `string` ; `type`: `string` ; `width?`: ``"narrow"`` \| ``"wider"`` \| ``"extra-wide"`` } & { `component`: `string` } \| { `component?`: `never` }

A definition of a workspace as extracted from an app's routes.json

Expand Down Expand Up @@ -8230,7 +8231,7 @@ Function to close an opened workspace

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:304](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L304)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:425](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L425)

___

Expand Down Expand Up @@ -8281,7 +8282,38 @@ prop named `workspaceTitle` will override the title of the workspace.

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:177](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L177)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:289](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L289)

___

### launchWorkspaceGroup

▸ **launchWorkspaceGroup**(`groupName`, `args`): `void`

Launches a workspace group with the specified name and configuration.
If there are any open workspaces, it will first close them before launching the new workspace group.

**`example`**
launchWorkspaceGroup("myGroup", {
state: initialState,
onWorkspaceGroupLaunch: () => console.log("Workspace group launched"),
workspaceGroupCleanup: () => console.log("Cleaning up workspace group")
});

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `groupName` | `string` | The name of the workspace group to launch |
| `args` | `LaunchWorkspaceGroupArg` | Configuration object for launching the workspace group |

#### Returns

`void`

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:205](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L205)

___

Expand All @@ -8307,7 +8339,7 @@ Use this function to navigate to a new page and launch a workspace on that page.

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:262](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L262)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:382](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L382)

___

Expand All @@ -8321,4 +8353,4 @@ ___

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:418](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L418)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:536](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L536)
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

### Workspace Properties

- [closeWorkspaceGroup](CloseWorkspaceOptions.md#closeworkspacegroup)
- [ignoreChanges](CloseWorkspaceOptions.md#ignorechanges)

### Workspace Methods
Expand All @@ -14,6 +15,22 @@

## Workspace Properties

### closeWorkspaceGroup

`Optional` **closeWorkspaceGroup**: `boolean`

Controls whether the workspace group should be closed and store to be
cleared when this workspace is closed.
Defaults to true except when opening a new workspace of the same group.

**`default`** true

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:33](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L33)

___

### ignoreChanges

`Optional` **ignoreChanges**: `boolean`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ closed, given the user forcefully closes the workspace.

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:46](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L46)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:45](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L45)

___

Expand All @@ -66,7 +66,7 @@ will directly close the workspace without any prompt

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:56](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L56)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:55](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L55)

___

Expand All @@ -89,7 +89,7 @@ this workspace is closed; e.g. if there is unsaved data.

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:51](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L51)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:50](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L50)

___

Expand Down Expand Up @@ -117,4 +117,4 @@ title needs to be set dynamically.

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:71](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L71)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:70](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L70)
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ An explanation of what the flag does, which will be displayed in the Implementer

#### Defined in

[packages/framework/esm-globals/src/types.ts:350](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-globals/src/types.ts#L350)
[packages/framework/esm-globals/src/types.ts:363](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-globals/src/types.ts#L363)

___

Expand All @@ -34,7 +34,7 @@ A code-friendly name for the flag, which will be used to reference it in code

#### Defined in

[packages/framework/esm-globals/src/types.ts:346](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-globals/src/types.ts#L346)
[packages/framework/esm-globals/src/types.ts:359](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-globals/src/types.ts#L359)

___

Expand All @@ -46,4 +46,4 @@ A human-friendly name which will be displayed in the Implementer Tools

#### Defined in

[packages/framework/esm-globals/src/types.ts:348](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-globals/src/types.ts#L348)
[packages/framework/esm-globals/src/types.ts:361](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-globals/src/types.ts#L361)
52 changes: 24 additions & 28 deletions packages/framework/esm-framework/docs/interfaces/OpenWorkspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@

- [canHide](OpenWorkspace.md#canhide)
- [canMaximize](OpenWorkspace.md#canmaximize)
- [hasOwnSidebar](OpenWorkspace.md#hasownsidebar)
- [groups](OpenWorkspace.md#groups)
- [moduleName](OpenWorkspace.md#modulename)
- [name](OpenWorkspace.md#name)
- [preferredWindowSize](OpenWorkspace.md#preferredwindowsize)
- [sidebarFamily](OpenWorkspace.md#sidebarfamily)
- [title](OpenWorkspace.md#title)
- [titleNode](OpenWorkspace.md#titlenode)
- [type](OpenWorkspace.md#type)
Expand All @@ -29,6 +28,7 @@
### Workspace Properties

- [additionalProps](OpenWorkspace.md#additionalprops)
- [currentWorkspaceGroup](OpenWorkspace.md#currentworkspacegroup)

### Methods

Expand Down Expand Up @@ -68,17 +68,17 @@ ___

___

### hasOwnSidebar
### groups

**hasOwnSidebar**: `boolean`
`Optional` **groups**: `string`[]

#### Inherited from

[WorkspaceRegistration](WorkspaceRegistration.md).[hasOwnSidebar](WorkspaceRegistration.md#hasownsidebar)
[WorkspaceRegistration](WorkspaceRegistration.md).[groups](WorkspaceRegistration.md#groups)

#### Defined in

[packages/framework/esm-extensions/src/workspaces.ts:17](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-extensions/src/workspaces.ts#L17)
[packages/framework/esm-extensions/src/workspaces.ts:20](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-extensions/src/workspaces.ts#L20)

___

Expand All @@ -92,7 +92,7 @@ ___

#### Defined in

[packages/framework/esm-extensions/src/workspaces.ts:21](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-extensions/src/workspaces.ts#L21)
[packages/framework/esm-extensions/src/workspaces.ts:19](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-extensions/src/workspaces.ts#L19)

___

Expand Down Expand Up @@ -120,21 +120,7 @@ ___

#### Defined in

[packages/framework/esm-extensions/src/workspaces.ts:19](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-extensions/src/workspaces.ts#L19)

___

### sidebarFamily

**sidebarFamily**: `string`

#### Inherited from

[WorkspaceRegistration](WorkspaceRegistration.md).[sidebarFamily](WorkspaceRegistration.md#sidebarfamily)

#### Defined in

[packages/framework/esm-extensions/src/workspaces.ts:18](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-extensions/src/workspaces.ts#L18)
[packages/framework/esm-extensions/src/workspaces.ts:17](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-extensions/src/workspaces.ts#L17)

___

Expand Down Expand Up @@ -202,7 +188,17 @@ ___

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:106](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L106)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:109](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L109)

___

### currentWorkspaceGroup

`Optional` **currentWorkspaceGroup**: `string`

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:110](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L110)

## Methods

Expand Down Expand Up @@ -232,7 +228,7 @@ closed, given the user forcefully closes the workspace.

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:46](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L46)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:45](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L45)

___

Expand All @@ -259,7 +255,7 @@ will directly close the workspace without any prompt

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:56](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L56)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:55](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L55)

___

Expand All @@ -277,7 +273,7 @@ ___

#### Defined in

[packages/framework/esm-extensions/src/workspaces.ts:20](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-extensions/src/workspaces.ts#L20)
[packages/framework/esm-extensions/src/workspaces.ts:18](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-extensions/src/workspaces.ts#L18)

___

Expand All @@ -304,7 +300,7 @@ this workspace is closed; e.g. if there is unsaved data.

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:51](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L51)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:50](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L50)

___

Expand Down Expand Up @@ -336,4 +332,4 @@ title needs to be set dynamically.

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:71](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L71)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:70](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L70)
Loading

0 comments on commit a5b386a

Please sign in to comment.