Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix) O3-4080: Option of adding a key in workspace #1177

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/framework/esm-extensions/src/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { translateFrom } from '@openmrs/esm-translations';
export interface WorkspaceRegistration {
name: string;
title: string;
key?: string;
titleNode?: ReactNode;
type: string;
canHide: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ interface WorkspaceRendererProps {
workspace: OpenWorkspace;
additionalPropsFromPage?: object;
}

export function WorkspaceRenderer({ workspace, additionalPropsFromPage }: WorkspaceRendererProps) {
const [lifecycle, setLifecycle] = useState<ParcelConfig | undefined>();
const workspaceFamilyState = useWorkspaceFamilyStore(workspace.sidebarFamily);
Expand Down Expand Up @@ -41,9 +40,8 @@ export function WorkspaceRenderer({ workspace, additionalPropsFromPage }: Worksp
},
[workspace, additionalPropsFromPage, workspaceFamilyState],
);

return lifecycle ? (
<Parcel key={workspace.name} config={lifecycle} mountParcel={mountRootParcel} {...props} />
<Parcel key={workspace.key || workspace.name} config={lifecycle} mountParcel={mountRootParcel} {...props} />
) : (
<InlineLoading className={styles.loader} description={`${getCoreTranslation('loading', 'Loading')} ...`} />
);
Expand Down
10 changes: 7 additions & 3 deletions packages/framework/esm-styleguide/src/workspaces/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,12 @@ function promptBeforeLaunchingWorkspace(
*/
export function launchWorkspace<
T extends DefaultWorkspaceProps | object = DefaultWorkspaceProps & { [key: string]: any },
>(name: string, additionalProps?: Omit<T, keyof DefaultWorkspaceProps> & { workspaceTitle?: string }) {
>(name: string, additionalProps?: Omit<T, keyof DefaultWorkspaceProps> & { workspaceTitle?: string; key?: string }) {
const store = getWorkspaceStore();
const workspace = getWorkspaceRegistration(name);
const newWorkspace: OpenWorkspace = {
...workspace,
key: getWorkspaceKey(workspace,additionalProps),
title: getWorkspaceTitle(workspace, additionalProps),
closeWorkspace: (options: CloseWorkspaceOptions = {}) => closeWorkspace(name, options),
closeWorkspaceWithSavedChanges: (options: CloseWorkspaceOptions) =>
Expand Down Expand Up @@ -209,7 +210,6 @@ export function launchWorkspace<
store.setState((state) => {
const openWorkspaces = [workspaceToBeAdded, ...(restOfTheWorkspaces ?? state.openWorkspaces)];
let workspaceWindowState = getUpdatedWorkspaceWindowState(workspaceToBeAdded);

return {
...state,
openWorkspaces,
Expand All @@ -236,11 +236,12 @@ export function launchWorkspace<
if (openWorkspace.title === getWorkspaceTitle(openWorkspace, openWorkspace.additionalProps)) {
openWorkspace.title = getWorkspaceTitle(newWorkspace, newWorkspace.additionalProps);
}
openWorkspace.additionalProps = newWorkspace.additionalProps;
openWorkspace.additionalProps = Object.assign({}, openWorkspace.additionalProps, newWorkspace.additionalProps);
const restOfTheWorkspaces = openWorkspaces.filter((w) => w.name != name);
updateStoreWithNewWorkspace(openWorkspaces[workspaceIndexInOpenWorkspaces], restOfTheWorkspaces);
} else if (openedWorkspaceWithSameType) {
const restOfTheWorkspaces = store.getState().openWorkspaces.filter((w) => w.type != newWorkspace.type);

updateStoreWithNewWorkspace(openedWorkspaceWithSameType, restOfTheWorkspaces);
promptBeforeLaunchingWorkspace(openedWorkspaceWithSameType, {
name,
Expand Down Expand Up @@ -522,6 +523,9 @@ function getWorkspaceTitle(workspace: WorkspaceRegistration, additionalProps?: o
return additionalProps?.['workspaceTitle'] ?? workspace.title;
}

function getWorkspaceKey(workspace:WorkspaceRegistration,additionalProps?:object){
return additionalProps?.['key'] ?? workspace.key ?? workspace.name;
}
export function resetWorkspaceStore() {
getWorkspaceStore().setState(initialState);
}
Expand Down
Loading