From b94954ef5b23bae6cd644ffa8f0c2ebef03d9c9b Mon Sep 17 00:00:00 2001 From: Piotr Gawron <p.gawron@atcomp.pl> Date: Thu, 31 Oct 2024 11:30:37 +0100 Subject: [PATCH] when loading a plugin with panel don't put info in the right panel --- .../LoadPlugin/LoadPlugin.component.tsx | 4 +++- .../LoadPlugin/hooks/useLoadPlugin.ts | 6 +++--- .../PluginHeaderInfo/PluginHeaderInfo.component.tsx | 4 +++- .../LoadPluginElement/LoadPluginElement.component.tsx | 4 +++- .../PluginSingleTab/PluginSingleTab.component.tsx | 4 +++- .../Map/PluginsDrawer/PluginsTabs/PluginsTabs.component.tsx | 4 ++-- src/models/pluginSchema.ts | 1 + src/redux/plugins/plugins.reducers.ts | 6 ++++-- src/redux/plugins/plugins.selectors.ts | 4 ++++ 9 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/components/Map/Drawer/AvailablePluginsDrawer/LoadPlugin/LoadPlugin.component.tsx b/src/components/Map/Drawer/AvailablePluginsDrawer/LoadPlugin/LoadPlugin.component.tsx index b074ab0a..84828eeb 100644 --- a/src/components/Map/Drawer/AvailablePluginsDrawer/LoadPlugin/LoadPlugin.component.tsx +++ b/src/components/Map/Drawer/AvailablePluginsDrawer/LoadPlugin/LoadPlugin.component.tsx @@ -16,7 +16,9 @@ export const LoadPlugin = ({ plugin }: Props): JSX.Element => { hash: plugin.hash, pluginUrl: plugin.urls[0], onPluginLoaded: () => { - dispatch(setCurrentDrawerPluginHash(plugin.hash)); + if (!plugin.withoutPanel) { + dispatch(setCurrentDrawerPluginHash(plugin.hash)); + } }, }); diff --git a/src/components/Map/Drawer/AvailablePluginsDrawer/LoadPlugin/hooks/useLoadPlugin.ts b/src/components/Map/Drawer/AvailablePluginsDrawer/LoadPlugin/hooks/useLoadPlugin.ts index 2277454a..7d067485 100644 --- a/src/components/Map/Drawer/AvailablePluginsDrawer/LoadPlugin/hooks/useLoadPlugin.ts +++ b/src/components/Map/Drawer/AvailablePluginsDrawer/LoadPlugin/hooks/useLoadPlugin.ts @@ -3,7 +3,7 @@ import { useAppSelector } from '@/redux/hooks/useAppSelector'; import { isActiveLegendSelector } from '@/redux/legend/legend.selectors'; import { removePluginLegend, setDefaultLegendId } from '@/redux/legend/legend.slice'; import { - allActivePluginsSelector, + allActivePluginsWithPanelSelector, isPluginActiveSelector, isPluginLoadingSelector, isPluginSelectedSelector, @@ -42,12 +42,12 @@ export const useLoadPlugin = ({ const isPluginLoading = useAppSelector(state => isPluginLoadingSelector(state, hash)); const isPluginSelected = useAppSelector(state => isPluginSelectedSelector(state, hash)); const isActivePluginLegend = useAppSelector(state => isActiveLegendSelector(state, hash)); - const allActivePlugins = useAppSelector(allActivePluginsSelector); + const allActivePluginsWithPanel = useAppSelector(allActivePluginsWithPanelSelector); const dispatch = useAppDispatch(); const setLastPluginAsCurrentActivePlugin = (): void => { - const newAllActivePlugins = allActivePlugins.filter(p => p.hash !== hash); + const newAllActivePlugins = allActivePluginsWithPanel.filter(p => p.hash !== hash); const lastActivePlugin = newAllActivePlugins.pop(); if (lastActivePlugin) { dispatch(setCurrentDrawerPluginHash(lastActivePlugin.hash)); diff --git a/src/components/Map/PluginsDrawer/PluginsHeader/PluginHeaderInfo/PluginHeaderInfo.component.tsx b/src/components/Map/PluginsDrawer/PluginsHeader/PluginHeaderInfo/PluginHeaderInfo.component.tsx index 7e5df8a4..02093290 100644 --- a/src/components/Map/PluginsDrawer/PluginsHeader/PluginHeaderInfo/PluginHeaderInfo.component.tsx +++ b/src/components/Map/PluginsDrawer/PluginsHeader/PluginHeaderInfo/PluginHeaderInfo.component.tsx @@ -17,7 +17,9 @@ export const PluginHeaderInfo = ({ plugin }: Props): JSX.Element => { hash: plugin.hash, pluginUrl: plugin.urls[FIRST_ARRAY_ELEMENT], onPluginLoaded: () => { - dispatch(setCurrentDrawerPluginHash(plugin.hash)); + if (!plugin.withoutPanel) { + dispatch(setCurrentDrawerPluginHash(plugin.hash)); + } }, }); diff --git a/src/components/Map/PluginsDrawer/PluginsHeader/PluginOpenButton/LoadPluginElement/LoadPluginElement.component.tsx b/src/components/Map/PluginsDrawer/PluginsHeader/PluginOpenButton/LoadPluginElement/LoadPluginElement.component.tsx index cdd827c8..24fd5bae 100644 --- a/src/components/Map/PluginsDrawer/PluginsHeader/PluginOpenButton/LoadPluginElement/LoadPluginElement.component.tsx +++ b/src/components/Map/PluginsDrawer/PluginsHeader/PluginOpenButton/LoadPluginElement/LoadPluginElement.component.tsx @@ -19,7 +19,9 @@ export const LoadPluginElement = ({ plugin }: LoadPluginButtonProps): JSX.Elemen hash, pluginUrl: urls[FIRST_ARRAY_ELEMENT], onPluginLoaded: () => { - dispatch(setCurrentDrawerPluginHash(hash)); + if (!plugin.withoutPanel) { + dispatch(setCurrentDrawerPluginHash(hash)); + } }, }); diff --git a/src/components/Map/PluginsDrawer/PluginsTabs/PluginSingleTab/PluginSingleTab.component.tsx b/src/components/Map/PluginsDrawer/PluginsTabs/PluginSingleTab/PluginSingleTab.component.tsx index 39e12e5b..1b08cb64 100644 --- a/src/components/Map/PluginsDrawer/PluginsTabs/PluginSingleTab/PluginSingleTab.component.tsx +++ b/src/components/Map/PluginsDrawer/PluginsTabs/PluginSingleTab/PluginSingleTab.component.tsx @@ -21,7 +21,9 @@ export const PluginSingleTab = ({ plugin }: Props): JSX.Element => { }); const onPluginTabClick = (): void => { - dispatch(setCurrentDrawerPluginHash(plugin.hash)); + if (!plugin.withoutPanel) { + dispatch(setCurrentDrawerPluginHash(plugin.hash)); + } }; const onPluginUnload = (event: React.MouseEvent<HTMLDivElement>): void => { diff --git a/src/components/Map/PluginsDrawer/PluginsTabs/PluginsTabs.component.tsx b/src/components/Map/PluginsDrawer/PluginsTabs/PluginsTabs.component.tsx index 90e8f679..a37a3e9d 100644 --- a/src/components/Map/PluginsDrawer/PluginsTabs/PluginsTabs.component.tsx +++ b/src/components/Map/PluginsDrawer/PluginsTabs/PluginsTabs.component.tsx @@ -1,12 +1,12 @@ /* eslint-disable jsx-a11y/click-events-have-key-events */ import { ZERO } from '@/constants/common'; import { useAppSelector } from '@/redux/hooks/useAppSelector'; -import { allActivePluginsSelector } from '@/redux/plugins/plugins.selectors'; +import { allActivePluginsWithPanelSelector } from '@/redux/plugins/plugins.selectors'; import { useMemo } from 'react'; import { PluginSingleTab } from './PluginSingleTab'; export const PluginsTabs = (): JSX.Element => { - const allActivePlugins = useAppSelector(allActivePluginsSelector); + const allActivePlugins = useAppSelector(allActivePluginsWithPanelSelector); const isPluginsEmpty = allActivePlugins.length === ZERO; const pluginsTabs = allActivePlugins.map(plugin => ( diff --git a/src/models/pluginSchema.ts b/src/models/pluginSchema.ts index 2cfb0725..16720603 100644 --- a/src/models/pluginSchema.ts +++ b/src/models/pluginSchema.ts @@ -7,5 +7,6 @@ export const pluginSchema = z.object({ version: z.string(), isPublic: z.boolean(), isDefault: z.boolean(), + withoutPanel: z.boolean().nullable().optional(), urls: z.array(z.string().min(1)), }); diff --git a/src/redux/plugins/plugins.reducers.ts b/src/redux/plugins/plugins.reducers.ts index f3d74473..a4a03692 100644 --- a/src/redux/plugins/plugins.reducers.ts +++ b/src/redux/plugins/plugins.reducers.ts @@ -22,10 +22,12 @@ export const registerPluginReducer = (builder: ActionReducerMapBuilder<PluginsSt }); builder.addCase(registerPlugin.fulfilled, (state, action) => { if (action.payload) { - const { hash } = action.meta.arg; + const { hash, withoutPanel } = action.meta.arg; state.activePlugins.data[hash] = action.payload; - state.drawer.currentPluginHash = hash; + if (!withoutPanel) { + state.drawer.currentPluginHash = hash; + } } }); builder.addCase(registerPlugin.rejected, state => { diff --git a/src/redux/plugins/plugins.selectors.ts b/src/redux/plugins/plugins.selectors.ts index b07eb8e9..caa5d392 100644 --- a/src/redux/plugins/plugins.selectors.ts +++ b/src/redux/plugins/plugins.selectors.ts @@ -53,6 +53,10 @@ export const allActivePluginsSelector = createSelector( }, ); +export const allActivePluginsWithPanelSelector = createSelector(allActivePluginsSelector, data => { + return data.filter(plugin => !plugin.withoutPanel); +}); + export const privateActivePluginsSelector = createSelector( allActivePluginsSelector, activePlugins => { -- GitLab