Skip to content

Commit

Permalink
(fix) O3-3691: The workspace family store shouldn't reset if workspac…
Browse files Browse the repository at this point in the history
…e of same family is launched (#1103)

* Adding a new check to know that the workspace to be opened is of the same sidebar family as of the workspace to be closed

* Added tests for workspace renderer and added workspaceFamilyState in the dependency array for the props

* Updated documentation

* Add check for not clearing store if workspace is opened in the background

* Updated documentation

* Review updates

* Updated documentation

* Separate workspace family store handling from closeWorkspace API

Co-authored-by: Brandon Istenes <[email protected]>

* Update documentation

* Update packages/framework/esm-styleguide/src/workspaces/workspaces.ts

Co-authored-by: Ian <[email protected]>

* Update the comment for testing the default options

Co-authored-by: Brandon Istenes <[email protected]>

* Review changes

* Update documentation

---------

Co-authored-by: Brandon Istenes <[email protected]>
Co-authored-by: Ian <[email protected]>
  • Loading branch information
3 people authored Aug 1, 2024
1 parent 6c99789 commit a099d31
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 56 deletions.
8 changes: 4 additions & 4 deletions packages/framework/esm-framework/docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -6994,7 +6994,7 @@ Function to close an opened workspace

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:288](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L288)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:305](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L305)

___

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

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:166](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L166)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:178](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L178)

___

Expand All @@ -7071,7 +7071,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:251](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L251)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:263](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L263)

___

Expand All @@ -7085,4 +7085,4 @@ ___

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:402](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L402)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:419](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L419)
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:38](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L38)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:47](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L47)

___

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

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:48](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L48)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:57](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L57)

___

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:43](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L43)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:52](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L52)

___

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

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:63](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L63)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:72](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L72)
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ ___

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:98](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L98)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:107](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L107)

## Methods

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

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:38](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L38)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:47](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L47)

___

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

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:48](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L48)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:57](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L57)

___

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

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:43](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L43)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:52](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L52)

___

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

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:63](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L63)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:72](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L72)
10 changes: 5 additions & 5 deletions packages/framework/esm-framework/docs/interfaces/Prompt.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:82](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L82)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:91](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L91)

___

Expand All @@ -35,7 +35,7 @@ Defaults to "Cancel"

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:87](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L87)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:96](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L96)

___

Expand All @@ -47,7 +47,7 @@ Defaults to "Confirm"

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:84](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L84)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:93](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L93)

___

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

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:81](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L81)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:90](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L90)

## Methods

Expand All @@ -71,4 +71,4 @@ ___

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:85](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L85)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:94](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L94)
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:396](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L396)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:413](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L413)

___

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

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:397](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L397)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:414](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L414)

___

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

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:398](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L398)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:415](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L415)

___

Expand All @@ -49,4 +49,4 @@ ___

#### Defined in

[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:399](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L399)
[packages/framework/esm-styleguide/src/workspaces/workspaces.ts:416](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-styleguide/src/workspaces/workspaces.ts#L416)
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function WorkspaceRenderer({ workspace, additionalPropsFromPage }: Worksp
...workspaceFamilyState,
...workspace.additionalProps,
},
[workspace, additionalPropsFromPage],
[workspace, additionalPropsFromPage, workspaceFamilyState],
);

return lifecycle ? (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { WorkspaceRenderer } from './workspace-renderer.component';
import { getWorkspaceFamilyStore, OpenWorkspace } from '../workspaces';
import Parcel from 'single-spa-react/parcel';

const mockFn = jest.fn();

jest.mock('single-spa-react/parcel', () =>
jest.fn((props) => {
mockFn(props);
return <div data-testid="mocked-parcel" />;
}),
);

describe('WorkspaceRenderer', () => {
it('should render workspace', async () => {
const mockedCloseWorkspace = jest.fn();
const mockedCloseWorkspaceWithSavedChanges = jest.fn();
const mockedPromptBeforeClosing = jest.fn();
const mockedSetTitle = jest.fn();
const mockedLoadFn = jest.fn().mockImplementation(() => Promise.resolve({ default: 'file-content' }));
getWorkspaceFamilyStore('test-sidebar-family')?.setState({
// Testing that the workspace family state should be overrided by additionalProps
foo: false,
workspaceFamilyState: {},
});
render(
<WorkspaceRenderer
// @ts-ignore The workspace is of type OpenWorkspace and not all properties are required
workspace={{
closeWorkspace: mockedCloseWorkspace,
name: 'workspace-name',
load: mockedLoadFn,
title: 'Workspace title',
closeWorkspaceWithSavedChanges: mockedCloseWorkspaceWithSavedChanges,
promptBeforeClosing: mockedPromptBeforeClosing,
setTitle: mockedSetTitle,
additionalProps: {
foo: 'true',
},
sidebarFamily: 'test-sidebar-family',
}}
additionalPropsFromPage={{ bar: 'true' }}
/>,
);

expect(screen.getByText('Loading ...')).toBeInTheDocument();
expect(mockedLoadFn).toHaveBeenCalled();
await screen.findByTestId('mocked-parcel');

expect(mockFn).toHaveBeenCalledWith({
config: 'file-content',
mountParcel: undefined,
closeWorkspace: mockedCloseWorkspace,
closeWorkspaceWithSavedChanges: mockedCloseWorkspaceWithSavedChanges,
promptBeforeClosing: mockedPromptBeforeClosing,
setTitle: mockedSetTitle,
foo: 'true',
bar: 'true',
workspaceFamilyState: {},
});
});
});
Loading

0 comments on commit a099d31

Please sign in to comment.