Skip to content

Commit

Permalink
Remove instances of word 'family'
Browse files Browse the repository at this point in the history
  • Loading branch information
vasharma05 committed Nov 19, 2024
1 parent 6b3e441 commit 4261d34
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function Workspace({ workspaceInstance, additionalWorkspaceProps }: WorkspacePro
<div className={styles.overlayHeaderSpacer} />
<HeaderGlobalBar className={styles.headerButtons}>
<ExtensionSlot
name={`workspace-header-family-${workspaceInstance.currentWorkspaceGroup}-slot`}
name={`workspace-header-group-${workspaceInstance.currentWorkspaceGroup}-slot`}
state={workspaceProps}
/>
<ExtensionSlot name={`workspace-header-type-${workspaceInstance.type}-slot`} state={workspaceProps} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface WorkspaceRendererProps {

export function WorkspaceRenderer({ workspace, additionalPropsFromPage }: WorkspaceRendererProps) {
const [lifecycle, setLifecycle] = useState<ParcelConfig | undefined>();
const workspaceFamilyState = useWorkspaceGroupStore(workspace.currentWorkspaceGroup);
const workspaceGroupState = useWorkspaceGroupStore(workspace.currentWorkspaceGroup);

useEffect(() => {
let active = true;
Expand All @@ -36,10 +36,10 @@ export function WorkspaceRenderer({ workspace, additionalPropsFromPage }: Worksp
promptBeforeClosing: workspace.promptBeforeClosing,
setTitle: workspace.setTitle,
...additionalPropsFromPage,
...workspaceFamilyState,
...workspaceGroupState,
...workspace.additionalProps,
},
[workspace, additionalPropsFromPage, workspaceFamilyState],
[workspace, additionalPropsFromPage, workspaceGroupState],
);

return lifecycle ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ describe('WorkspaceRenderer', () => {
const mockedPromptBeforeClosing = jest.fn();
const mockedSetTitle = jest.fn();
const mockedLoadFn = jest.fn().mockImplementation(() => Promise.resolve({ default: 'file-content' }));
getWorkspaceGroupStore('test-sidebar-family')?.setState({
// Testing that the workspace family state should be overrided by additionalProps
getWorkspaceGroupStore('test-sidebar-store')?.setState({
// Testing that the workspace group state should be overrided by additionalProps
foo: false,
workspaceFamilyState: {},
workspaceGroupStore: {},
});
render(
<WorkspaceRenderer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { useEffect, useState } from 'react';
import { getWorkspaceGroupStore } from '../workspaces';

/**
* This hook is used to interact with the store of a workspace family.
* A workspace family is defined as a group of workspaces that share the same sidebarFamilyName.
* This hook is used to interact with the store of a workspace store.
* A workspace store is defined as a group of workspaces that open in the same workspace group.
*
* In case a workspace doesn't have a sidebarFamilyName, it will be considered as a standalone workspace, and hence this hook will return an empty object and updateFunction as an empty function.
* In case a workspace group is not active, it will be considered as a standalone workspace, and hence this hook will return an empty object and updateFunction as an empty function.
*
* @internal
*
* @param {string} sidebarFamilyName The sidebarFamilyName of the workspace used when registering the workspace in the module's routes.json file.
* @param {string} workspaceGroupName The workspaceGroupName of the workspace used when registering the workspace in the module's routes.json file.
*/
export function useWorkspaceGroupStore(workspaceGroupName?: string) {
const [storeState, setStoreState] = useState<object>({});
Expand Down
88 changes: 44 additions & 44 deletions packages/framework/esm-styleguide/src/workspaces/workspaces.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,36 +443,36 @@ describe('workspace system', () => {

describe('Testing `getWorkspaceGroupStore` function', () => {
it('should return undefined if no workspace sidebar name is passed', () => {
let workspaceFamilyStore = getWorkspaceGroupStore(undefined);
expect(workspaceFamilyStore).toBeUndefined();
workspaceFamilyStore = getWorkspaceGroupStore('default');
expect(workspaceFamilyStore).toBeUndefined();
let workspaceGroupStore = getWorkspaceGroupStore(undefined);
expect(workspaceGroupStore).toBeUndefined();
workspaceGroupStore = getWorkspaceGroupStore('default');
expect(workspaceGroupStore).toBeUndefined();
});

it('should return store if workspace sidebar name is passed', () => {
const workspaceFamilyStore = getWorkspaceGroupStore('ward-patient-store', {
const workspaceGroupStore = getWorkspaceGroupStore('ward-patient-store', {
foo: true,
});
expect(workspaceFamilyStore).toBeTruthy();
expect(workspaceFamilyStore?.getState()?.['foo']).toBe(true);
expect(workspaceGroupStore).toBeTruthy();
expect(workspaceGroupStore?.getState()?.['foo']).toBe(true);
});

it('should update the store state with new additionalProps if workspaces with same workspaceGroup name calls the function', () => {
let workspaceFamilyStore = getWorkspaceGroupStore('ward-patient-store', {
let workspaceGroupStore = getWorkspaceGroupStore('ward-patient-store', {
foo: true,
});
expect(workspaceFamilyStore).toBeTruthy();
expect(workspaceFamilyStore?.getState()?.['foo']).toBe(true);
workspaceFamilyStore = getWorkspaceGroupStore('ward-patient-store', {
expect(workspaceGroupStore).toBeTruthy();
expect(workspaceGroupStore?.getState()?.['foo']).toBe(true);
workspaceGroupStore = getWorkspaceGroupStore('ward-patient-store', {
bar: true,
});
expect(workspaceFamilyStore).toBeTruthy();
expect(workspaceFamilyStore?.getState()?.['foo']).toBe(true);
expect(workspaceFamilyStore?.getState()?.['bar']).toBe(true);
expect(workspaceGroupStore).toBeTruthy();
expect(workspaceGroupStore?.getState()?.['foo']).toBe(true);
expect(workspaceGroupStore?.getState()?.['bar']).toBe(true);
});
});

describe('Testing workspace family store', () => {
describe('Testing workspace group store', () => {
it('should create store for workspace groups', () => {
registerWorkspace({
name: 'allergies',
Expand All @@ -492,19 +492,19 @@ describe('workspace system', () => {
state: {},
workspaceToLaunch: { name: 'ward-patient-workspace' },
});
const workspaceFamilyStore = getWorkspaceGroupStore('ward-patient-store');
const workspaceGroupStore = getWorkspaceGroupStore('ward-patient-store');
const workspaceStore = getWorkspaceStore();
expect(workspaceStore.getState().openWorkspaces.length).toBe(1);
expect(workspaceStore.getState().openWorkspaces[0].name).toBe('ward-patient-workspace');
expect(workspaceFamilyStore).toBeTruthy();
expect(workspaceGroupStore).toBeTruthy();
workspaceStore.getState().openWorkspaces[0].closeWorkspace({ ignoreChanges: true });
launchWorkspace('allergies');
expect(workspaceStore.getState().openWorkspaces.length).toBe(1);
expect(workspaceStore.getState().openWorkspaces[0].name).toBe('allergies');
expect(workspaceFamilyStore?.getState()).toStrictEqual({});
expect(workspaceGroupStore?.getState()).toStrictEqual({});
});

it('should clear workspace family store by default if the workspace is closed, since `closeWorkspaceGroup` is true by default', async () => {
it('should clear workspace group store by default if the workspace is closed, since `closeWorkspaceGroup` is true by default', async () => {
registerWorkspace({
name: 'ward-patient-workspace',
title: 'Ward Patient Workspace',
Expand All @@ -519,12 +519,12 @@ describe('workspace system', () => {
},
workspaceToLaunch: { name: 'ward-patient-workspace' },
});
const workspaceFamilyStore = getWorkspaceGroupStore('ward-patient-store');
expect(workspaceFamilyStore).toBeTruthy();
expect(workspaceFamilyStore?.getState()?.['foo']).toBe(true);
const workspaceGroupStore = getWorkspaceGroupStore('ward-patient-store');
expect(workspaceGroupStore).toBeTruthy();
expect(workspaceGroupStore?.getState()?.['foo']).toBe(true);
closeWorkspace('ward-patient-workspace');
expect(workspaceFamilyStore?.getState()?.['foo']).toBeUndefined();
expect(workspaceFamilyStore?.getState()).toStrictEqual({});
expect(workspaceGroupStore?.getState()?.['foo']).toBeUndefined();
expect(workspaceGroupStore?.getState()).toStrictEqual({});
});

it('should not clear the workspace store if the new workspace opened can open in the same group', () => {
Expand Down Expand Up @@ -580,7 +580,7 @@ describe('workspace system', () => {
load: jest.fn(),
type: 'transfer-patient',
moduleName: '@openmrs/esm-ward-app',
groups: ['another-sidebar-family'],
groups: ['another-sidebar-group'],
});
const workspaceStore = getWorkspaceStore();
launchWorkspaceGroup('ward-patient-store', {
Expand All @@ -589,25 +589,25 @@ describe('workspace system', () => {
},
workspaceToLaunch: { name: 'ward-patient-workspace' },
});
const wardPatientFamilyStore = getWorkspaceGroupStore('ward-patient-store');
const wardPatientGroupStore = getWorkspaceGroupStore('ward-patient-store');
expect(workspaceStore.getState().openWorkspaces.length).toBe(1);
expect(wardPatientFamilyStore).toBeTruthy();
expect(wardPatientFamilyStore?.getState()?.['foo']).toBe(true);
launchWorkspaceGroup('another-sidebar-family', {
expect(wardPatientGroupStore).toBeTruthy();
expect(wardPatientGroupStore?.getState()?.['foo']).toBe(true);
launchWorkspaceGroup('another-sidebar-group', {
state: {
bar: false,
},
workspaceToLaunch: { name: 'transfer-patient-workspace' },
});
expect(workspaceStore.getState().workspaceGroup?.name).toBe('another-sidebar-family');
const anotherWorkspaceGroupStore = getWorkspaceGroupStore('another-sidebar-family');
expect(workspaceStore.getState().workspaceGroup?.name).toBe('another-sidebar-group');
const anotherWorkspaceGroupStore = getWorkspaceGroupStore('another-sidebar-group');
expect(workspaceStore.getState().openWorkspaces.length).toBe(1);
expect(anotherWorkspaceGroupStore?.getState()?.['bar']).toBe(false);
expect(wardPatientFamilyStore?.getState()?.['foo']).toBeUndefined();
expect(wardPatientFamilyStore?.getState()).toStrictEqual({});
expect(wardPatientGroupStore?.getState()?.['foo']).toBeUndefined();
expect(wardPatientGroupStore?.getState()).toStrictEqual({});
});

it('should not clear the workspace if a workspace of same sidebar family is opened', () => {
it('should not clear the workspace if a workspace of same sidebar group is opened', () => {
registerWorkspace({
name: 'ward-patient-workspace',
title: 'Ward Patient Workspace',
Expand All @@ -632,14 +632,14 @@ describe('workspace system', () => {
},
workspaceToLaunch: { name: 'ward-patient-workspace' },
});
const wardPatientFamilyStore = getWorkspaceGroupStore('ward-patient-store');
const wardPatientGroupStore = getWorkspaceGroupStore('ward-patient-store');
expect(workspaceStore.getState().openWorkspaces.length).toBe(1);
expect(wardPatientFamilyStore).toBeTruthy();
expect(wardPatientFamilyStore?.getState()?.['foo']).toBe(true);
expect(wardPatientGroupStore).toBeTruthy();
expect(wardPatientGroupStore?.getState()?.['foo']).toBe(true);
launchWorkspace('transfer-patient-workspace', { bar: false });
expect(workspaceStore.getState().openWorkspaces.length).toBe(2);
expect(wardPatientFamilyStore?.getState()?.['foo']).toBe(true);
expect(wardPatientFamilyStore?.getState()?.['bar']).toBe(false);
expect(wardPatientGroupStore?.getState()?.['foo']).toBe(true);
expect(wardPatientGroupStore?.getState()?.['bar']).toBe(false);
});

it('should retain default closeWorkspace options in case workspace options are passed', () => {
Expand All @@ -655,13 +655,13 @@ describe('workspace system', () => {
state: { foo: true },
workspaceToLaunch: { name: 'ward-patient-workspace' },
});
const workspaceFamilyStore = getWorkspaceGroupStore('ward-patient-store');
expect(workspaceFamilyStore).toBeTruthy();
expect(workspaceFamilyStore?.getState()?.['foo']).toBe(true);
const workspaceGroupStore = getWorkspaceGroupStore('ward-patient-store');
expect(workspaceGroupStore).toBeTruthy();
expect(workspaceGroupStore?.getState()?.['foo']).toBe(true);
// test that default options are interpolated when providing options to `closeWorkspace`
closeWorkspace('ward-patient-workspace', { ignoreChanges: true });
expect(workspaceFamilyStore?.getState()?.['foo']).toBeUndefined();
expect(workspaceFamilyStore?.getState()).toStrictEqual({});
expect(workspaceGroupStore?.getState()?.['foo']).toBeUndefined();
expect(workspaceGroupStore?.getState()).toStrictEqual({});
});
});
});
10 changes: 5 additions & 5 deletions packages/framework/esm-styleguide/src/workspaces/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ function closeWorkspaceGroup(groupName: string, onWorkspaceCloseup?: Function) {

closeAllWorkspaces(() => {
// Clearing the workspace group and respective store if the new workspace is not part of the current group, which is handled in the `launchWorkspace` function.
const workspaceFamilyStore = getWorkspaceGroupStore(groupName);
if (workspaceFamilyStore) {
workspaceFamilyStore.setState({}, true);
const unsubscribe = workspaceFamilyStore.subscribe(() => {});
const workspaceGroupStore = getWorkspaceGroupStore(groupName);
if (workspaceGroupStore) {
workspaceGroupStore.setState({}, true);
const unsubscribe = workspaceGroupStore.subscribe(() => {});
unsubscribe?.();
}
if (currentWorkspaceGroup && typeof currentWorkspaceGroup?.cleanup === 'function') {
Expand Down Expand Up @@ -243,7 +243,7 @@ function promptBeforeLaunchingWorkspace(
// Calling the launchWorkspace again, since one of the `if` case
// might resolve, but we need to check all the cases before launching the form.
onWorkspaceClose: () => launchWorkspace(name, additionalProps),
// If the new workspace is of the same sidebar family, then we don't need to clear the workspace family store.
// If the new workspace is of the same sidebar group, then we don't need to clear the workspace group store.
closeWorkspaceGroup: false,
});
};
Expand Down

0 comments on commit 4261d34

Please sign in to comment.