Skip to content

Commit 1c7ac1b

Browse files
authored
Fix/cli/dev portal/context selector/clear external (#2360)
* fix(cli): adds contextClearEvent when clearing context outside ctx-selector * docs: changeset
1 parent decb9e9 commit 1c7ac1b

File tree

4 files changed

+324
-296
lines changed

4 files changed

+324
-296
lines changed

.changeset/small-fishes-destroy.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@equinor/fusion-framework-cli": patch
3+
---
4+
5+
Enhanced ContextSelector component in the CLI package:
6+
- Implemented responsive context clearing mechanism
7+
- Improved handling of context selection and clearing events
8+
- Optimized component rendering with useMemo and useCallback hooks

packages/cli/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"@equinor/fusion-framework-react-components-bookmark": "workspace:^",
7777
"@equinor/fusion-framework-react-module-bookmark": "workspace:^",
7878
"@equinor/fusion-query": "workspace:^",
79-
"@equinor/fusion-react-context-selector": "^0.6.3",
79+
"@equinor/fusion-react-context-selector": "^0.6.6",
8080
"@equinor/fusion-react-progress-indicator": "^0.3.0",
8181
"@equinor/fusion-react-side-sheet": "1.3.3",
8282
"@equinor/fusion-react-styles": "^0.6.0",

packages/cli/src/bin/dev-portal/ContextSelector/ContextSelector.tsx

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { useCallback } from 'react';
1+
import { useCallback, useEffect, useMemo } from 'react';
22
import {
33
ContextProvider,
44
ContextSearch,
55
ContextSearchProps,
66
ContextSelectEvent,
7+
ContextClearEvent,
78
} from '@equinor/fusion-react-context-selector';
89
import { useContextResolver } from './useContextResolver';
910

@@ -38,6 +39,16 @@ export const ContextSelector = (props: ContextSearchProps): JSX.Element | null =
3839
[provider],
3940
);
4041

42+
/**
43+
* Clears context when ctx has been cleared outside the selector.
44+
*/
45+
const clearEvent = useMemo(() => new ContextClearEvent({ date: Date.now() }), []);
46+
useEffect(() => {
47+
if (!selectedContextItem) {
48+
document.dispatchEvent(clearEvent);
49+
}
50+
}, [clearEvent, selectedContextItem]);
51+
4152
if (!resolver) return null;
4253

4354
return (

0 commit comments

Comments
 (0)