Skip to content

Commit

Permalink
fix: close sidesheet when context changes (#1012)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustav-Eikaas authored May 3, 2024
1 parent c4a2175 commit b40d3e8
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 1 deletion.
2 changes: 2 additions & 0 deletions libs/handoverapp/src/lib/config/workspaceConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
useCCApiAccessCheck,
useCloseSidesheetOnContextChange,
useContextId,
usePBIOptions,
useWorkspaceBookmarks,
Expand All @@ -18,6 +19,7 @@ import { useTableConfig } from './tableConfig';

export const WorkspaceWrapper = () => {
const contextId = useContextId();
useCloseSidesheetOnContextChange();
const client = useHttpClient('cc-app');
const { isLoading } = useCCApiAccessCheck(contextId, client, 'handover');

Expand Down
2 changes: 2 additions & 0 deletions libs/heattraceapp/src/lib/config/workspaceConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useTableConfig } from './tableConfig';
import { useStatusBarConfig } from './statusBarConfig';
import {
useCCApiAccessCheck,
useCloseSidesheetOnContextChange,
useContextId,
useHttpClient,
usePBIOptions,
Expand All @@ -18,6 +19,7 @@ import { sidesheetConfig } from './heattraceSidesheet';

export const WorkspaceWrapper = () => {
const contextId = useContextId();
useCloseSidesheetOnContextChange();
const client = useHttpClient();
const { isLoading } = useCCApiAccessCheck(contextId, client, 'heat-trace');

Expand Down
2 changes: 2 additions & 0 deletions libs/loopapp/src/lib/config/workspaceConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
useContextId,
useHttpClient,
useWorkspaceBookmarks,
useCloseSidesheetOnContextChange,
} from '@cc-components/shared';
import { useFilterConfig } from '@cc-components/shared/workspace-config';
import { Workspace } from '@equinor/workspace-fusion';
Expand All @@ -19,6 +20,7 @@ import { CCApiAccessLoading } from '@cc-components/sharedcomponents';

export const WorkspaceWrapper = () => {
const contextId = useContextId();
useCloseSidesheetOnContextChange();
const pbi = usePBIOptions('loop-analytics', {
column: 'ProjectMaster GUID',
table: 'Dim_ProjectMaster',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
useCCApiAccessCheck,
useCloseSidesheetOnContextChange,
useContextId,
useWorkspaceBookmarks,
} from '@cc-components/shared';
Expand All @@ -18,6 +19,7 @@ import { useTableConfig } from './tableConfig';

export const WorkspaceWrapper = () => {
const contextId = useContextId();
useCloseSidesheetOnContextChange();
const client = useHttpClient('cc-app');
const { isLoading } = useCCApiAccessCheck(contextId, client, 'mechanical-completion');

Expand Down
2 changes: 2 additions & 0 deletions libs/pipingapp/src/lib/config/workspaceConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import {
useCCApiAccessCheck,
useWorkspaceBookmarks,
usePBIOptions,
useCloseSidesheetOnContextChange,
} from '@cc-components/shared';
import { useGardenConfig } from './gardenConfig';
import { sidesheetConfig } from './pipingSidesheet';
import { CCApiAccessLoading } from '@cc-components/sharedcomponents';

export const WorkspaceWrapper = () => {
const contextId = useContextId();
useCloseSidesheetOnContextChange();
const client = useHttpClient();
const { isLoading } = useCCApiAccessCheck(contextId, client, 'pipetest');
const { bookmarkKey, currentBookmark, onBookmarkChange } = useWorkspaceBookmarks();
Expand Down
2 changes: 2 additions & 0 deletions libs/punchapp/src/lib/config/workspaceConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
useCCApiAccessCheck,
useCloseSidesheetOnContextChange,
useContextId,
useHttpClient,
usePBIOptions,
Expand All @@ -21,6 +22,7 @@ import { useGardenConfig } from './gardenConfig';

export const WorkspaceWrapper = () => {
const contextId = useContextId();
useCloseSidesheetOnContextChange();
const ccApi = useHttpClient();
const { bookmarkKey, currentBookmark, onBookmarkChange } = useWorkspaceBookmarks();

Expand Down
2 changes: 2 additions & 0 deletions libs/scopechangerequestapp/src/lib/config/workspaceConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { gridModule } from '@equinor/workspace-fusion/grid-module';
import { useTableConfig } from './tableConfig';
import { useFilterConfig } from '@cc-components/shared/workspace-config';
import {
useCloseSidesheetOnContextChange,
useContextId,
useHttpClient,
useWorkspaceBookmarks,
Expand All @@ -19,6 +20,7 @@ const options: WorkspaceConfig<ScopeChangeRequest> = {

export const WorkspaceWrapper = () => {
const contextId = useContextId();
useCloseSidesheetOnContextChange();
const client = useHttpClient();

const pbi = usePBIOptions('pp-scope-change-analytics', {
Expand Down
1 change: 1 addition & 0 deletions libs/shared/src/packages/hooks/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { usePackageResource } from './useResourceData';
export * from './useExternalContextId';
export * from './useContextId';
export * from './useServiceDiscovery';
export * from './useCloseSidesheetOnContextChanges';
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useEffect, useRef } from "react";
import { useContextId } from "./useContextId";

function usePrevious(value: string) {
const ref = useRef<string>();
useEffect(() => {
ref.current = value;
}, [value]);
return ref.current;
}

export function useCloseSidesheetOnContextChange() {
const contextId = useContextId();
const previous = usePrevious(contextId)

useEffect(() => {
if (previous && previous !== contextId) {

const url = new URL(window.location.href)
url.searchParams.delete("item")
window.history.pushState(null, "", url);
}
}, [contextId])

}
2 changes: 2 additions & 0 deletions libs/swcrapp/src/lib/config/workspaceConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
useCCApiAccessCheck,
useCloseSidesheetOnContextChange,
useContextId,
useHttpClient,
usePBIOptions,
Expand All @@ -21,6 +22,7 @@ import { useTableConfig } from './tableConfig';

export const WorkspaceWrapper = () => {
const contextId = useContextId();
useCloseSidesheetOnContextChange();
const ccApi = useHttpClient();

const pbi = usePBIOptions('swcr-analytics', {
Expand Down
5 changes: 4 additions & 1 deletion libs/workorderapp/src/lib/config/workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
useHttpClient,
usePBIOptions,
useWorkspaceBookmarks,
useCloseSidesheetOnContextChange
} from '@cc-components/shared';
import { useFilterConfig } from '@cc-components/shared/workspace-config';
import Workspace from '@equinor/workspace-fusion';
Expand All @@ -20,7 +21,7 @@ import { CCApiAccessLoading } from '@cc-components/sharedcomponents';

export const WorkspaceWrapper = () => {
const contextId = useContextId();

useCloseSidesheetOnContextChange();
const client = useHttpClient();
const { bookmarkKey, currentBookmark, onBookmarkChange } = useWorkspaceBookmarks();
const { isLoading } = useCCApiAccessCheck(contextId, client, 'work-orders');
Expand All @@ -36,10 +37,12 @@ export const WorkspaceWrapper = () => {
const statusBarConfig = useStatusBarConfig(contextId);
const gardenConfig = useGardenConfig(contextId);


if (isLoading) {
return <CCApiAccessLoading />;
}


return (
<>
<Workspace
Expand Down

0 comments on commit b40d3e8

Please sign in to comment.