diff --git a/packages/client/src/hooks/useParamsContext.tsx b/packages/client/src/hooks/useParamsContext.tsx index 97eeb4d5e..b90592cd8 100644 --- a/packages/client/src/hooks/useParamsContext.tsx +++ b/packages/client/src/hooks/useParamsContext.tsx @@ -23,6 +23,7 @@ const INITIAL_CONTEXT = { selectedDetailId: "", setSelectedDetailId: UNINITIALISED, appendDetailId: UNINITIALISED, + appendMultipleDetailIds: UNINITIALISED, removeDetailId: UNINITIALISED, clearAllDetailIds: UNINITIALISED, cleanAllParams: UNINITIALISED, @@ -36,6 +37,7 @@ interface SearchParamsContext { selectedDetailId: string; setSelectedDetailId: (id: string) => void; appendDetailId: (id: string) => void; + appendMultipleDetailIds: (ids: string[]) => void; removeDetailId: (id: string) => void; clearAllDetailIds: () => void; cleanAllParams: () => void; @@ -114,6 +116,34 @@ export const SearchParamsProvider = ({ setTimeout(() => setSelectedDetailId(id), 100); }; + const appendMultipleDetailIds = (ids: string[]) => { + const detailIdArray = getDetailIdArray(); + let newDetailIdArray: string[] = []; + + if (ids.length === 10) { + // use as it is + newDetailIdArray = ids; + } else if (ids.length > 10) { + // cut and use the first 10 + newDetailIdArray = ids.slice(0, maxTabCount); + } else { + // merge with existing + // remove already added ids and add them at the end + const filteredArray: string[] = detailIdArray.filter( + (id) => !ids.includes(id) + ); + newDetailIdArray = filteredArray.concat(ids); + if (newDetailIdArray.length > maxTabCount) { + newDetailIdArray = newDetailIdArray.slice( + newDetailIdArray.length - maxTabCount + ); + } + } + + setDetailId(newDetailIdArray.join(arrJoinChar)); + setTimeout(() => setSelectedDetailId(ids[0]), 100); + }; + const removeDetailId = (id: string) => { const detailIdArray = getDetailIdArray(); const index = detailIdArray.indexOf(id); @@ -228,6 +258,7 @@ export const SearchParamsProvider = ({ selectedDetailId, setSelectedDetailId, appendDetailId, + appendMultipleDetailIds, removeDetailId, clearAllDetailIds, cleanAllParams, diff --git a/packages/client/src/pages/MainPage/containers/StatementEditorBox/StatementEditor/StatementEditor.tsx b/packages/client/src/pages/MainPage/containers/StatementEditorBox/StatementEditor/StatementEditor.tsx index 3630a0821..717e64162 100644 --- a/packages/client/src/pages/MainPage/containers/StatementEditorBox/StatementEditor/StatementEditor.tsx +++ b/packages/client/src/pages/MainPage/containers/StatementEditorBox/StatementEditor/StatementEditor.tsx @@ -93,8 +93,13 @@ export const StatementEditor: React.FC = ({ updateStatementDataMutation, moveStatementMutation, }) => { - const { statementId, territoryId, setTerritoryId, appendDetailId } = - useSearchParams(); + const { + statementId, + territoryId, + setTerritoryId, + appendDetailId, + appendMultipleDetailIds, + } = useSearchParams(); const queryClient = useQueryClient(); @@ -550,6 +555,14 @@ export const StatementEditor: React.FC = ({ ); const dispatch = useAppDispatch(); + useEffect(() => { + if (showWarnings && statement.data.actions.length > 0) { + appendMultipleDetailIds( + Array.from(new Set(statement.data.actions.map((a) => a.actionId))) + ); + } + }, [showWarnings]); + return ( <>