Skip to content

Commit

Permalink
fix(seg): should be able to navigate outside toolbox and come back la…
Browse files Browse the repository at this point in the history
…ter (#4196)
  • Loading branch information
sedghi authored May 30, 2024
1 parent 5945887 commit 93e7609
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
8 changes: 4 additions & 4 deletions platform/ui/src/components/Toolbox/Toolbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function Toolbox({
buttonSection: buttonSectionId,
});

const prevButtonIdsRef = useRef();
const prevToolboxStateRef = useRef();
const prevButtonIdsRef = useRef('');
const prevToolboxStateRef = useRef('');

useEffect(() => {
const currentButtonIdsStr = JSON.stringify(
Expand Down Expand Up @@ -130,7 +130,7 @@ function Toolbox({
);

api.initializeToolOptions(initializeOptionsWithEnhancements);
}, [toolbarButtons, api, toolboxState]);
}, [toolbarButtons, api, toolboxState, commandsManager, servicesManager]);

const handleToolOptionChange = (toolName, optionName, newValue) => {
api.handleToolOptionChange(toolName, optionName, newValue);
Expand All @@ -147,7 +147,7 @@ function Toolbox({
{...props}
title={title}
toolbarButtons={toolbarButtons}
activeToolOptions={toolboxState.toolOptions?.[toolboxState.activeTool]}
toolboxState={toolboxState}
handleToolSelect={id => api.handleToolSelect(id)}
handleToolOptionChange={handleToolOptionChange}
onInteraction={onInteraction}
Expand Down
9 changes: 6 additions & 3 deletions platform/ui/src/components/Toolbox/ToolboxUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ function ToolboxUI(props: withAppTypes) {
const {
toolbarButtons,
handleToolSelect,
activeToolOptions,
toolboxState,
numRows,
servicesManager,
title,
useCollapsedPanel = true,
} = props;

const { activeTool, toolOptions, selectedEvent } = toolboxState;
const activeToolOptions = toolOptions?.[activeTool];

const prevToolOptions = usePrevious(activeToolOptions);

useEffect(() => {
Expand All @@ -35,7 +38,7 @@ function ToolboxUI(props: withAppTypes) {

activeToolOptions.forEach((option, index) => {
const prevOption = prevToolOptions ? prevToolOptions[index] : undefined;
if (!prevOption || option.value !== prevOption.value) {
if (!prevOption || option.value !== prevOption.value || selectedEvent) {
const isOptionValid = option.condition
? option.condition({ options: activeToolOptions })
: true;
Expand All @@ -45,7 +48,7 @@ function ToolboxUI(props: withAppTypes) {
}
}
});
}, [activeToolOptions]);
}, [activeToolOptions, selectedEvent]);

const render = () => {
return (
Expand Down
5 changes: 4 additions & 1 deletion platform/ui/src/contextProviders/Toolbox/ToolboxContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const toolboxReducer = (state, action) => {
const { toolbarSectionId } = action.payload;

if (!state[toolbarSectionId]) {
state[toolbarSectionId] = { activeTool: null, toolOptions: {} };
state[toolbarSectionId] = { activeTool: null, toolOptions: {}, selectedEvent: false };
}

switch (action.type) {
Expand All @@ -16,6 +16,7 @@ export const toolboxReducer = (state, action) => {
[toolbarSectionId]: {
...state[toolbarSectionId],
activeTool: action.payload.activeTool,
selectedEvent: true,
},
};
case 'UPDATE_TOOL_OPTION':
Expand All @@ -24,6 +25,7 @@ export const toolboxReducer = (state, action) => {
...state,
[toolbarSectionId]: {
...state[toolbarSectionId],
selectedEvent: false,
toolOptions: {
...state[toolbarSectionId].toolOptions,
[toolName]: state[toolbarSectionId].toolOptions[toolName].map(option =>
Expand All @@ -36,6 +38,7 @@ export const toolboxReducer = (state, action) => {
// Initialize tool options for each toolbarSectionId
return {
...state,
selectedEvent: false,
[action.toolbarSectionId]: {
...state[action.toolbarSectionId],
toolOptions: action.payload,
Expand Down

0 comments on commit 93e7609

Please sign in to comment.