Skip to content
Snippets Groups Projects
Commit d3520992 authored by Adrian Orłów's avatar Adrian Orłów
Browse files

feat: add rfc changes

parent 57276abb
No related branches found
No related tags found
2 merge requests!223reset the pin numbers before search results are fetch (so the results will be...,!122feat: add main plugins drawer with tabs (MIN-232)
Pipeline #85422 passed
Showing
with 51 additions and 17 deletions
/* eslint-disable no-magic-numbers */ /* eslint-disable no-magic-numbers */
import { useAppDispatch } from '@/redux/hooks/useAppDispatch';
import { setCurrentDrawerPluginHash } from '@/redux/plugins/plugins.slice';
import { Button } from '@/shared/Button'; import { Button } from '@/shared/Button';
import { MinervaPlugin } from '@/types/models'; import { MinervaPlugin } from '@/types/models';
import { useLoadPlugin } from './hooks/useLoadPlugin'; import { useLoadPlugin } from './hooks/useLoadPlugin';
...@@ -8,9 +10,14 @@ export interface Props { ...@@ -8,9 +10,14 @@ export interface Props {
} }
export const LoadPlugin = ({ plugin }: Props): JSX.Element => { export const LoadPlugin = ({ plugin }: Props): JSX.Element => {
const dispatch = useAppDispatch();
const { isPluginActive, togglePlugin, isPluginLoading } = useLoadPlugin({ const { isPluginActive, togglePlugin, isPluginLoading } = useLoadPlugin({
hash: plugin.hash, hash: plugin.hash,
pluginUrl: plugin.urls[0], pluginUrl: plugin.urls[0],
onPluginLoaded: () => {
dispatch(setCurrentDrawerPluginHash(plugin.hash));
},
}); });
return ( return (
......
...@@ -22,9 +22,14 @@ type UseLoadPluginReturnType = { ...@@ -22,9 +22,14 @@ type UseLoadPluginReturnType = {
type UseLoadPluginProps = { type UseLoadPluginProps = {
hash: string; hash: string;
pluginUrl: string; pluginUrl: string;
onPluginLoaded?(): void;
}; };
export const useLoadPlugin = ({ hash, pluginUrl }: UseLoadPluginProps): UseLoadPluginReturnType => { export const useLoadPlugin = ({
hash,
pluginUrl,
onPluginLoaded,
}: UseLoadPluginProps): UseLoadPluginReturnType => {
const isPluginActive = useAppSelector(state => isPluginActiveSelector(state, hash)); const isPluginActive = useAppSelector(state => isPluginActiveSelector(state, hash));
const isPluginLoading = useAppSelector(state => isPluginLoadingSelector(state, hash)); const isPluginLoading = useAppSelector(state => isPluginLoadingSelector(state, hash));
const isPluginSelected = useAppSelector(state => isPluginSelectedSelector(state, hash)); const isPluginSelected = useAppSelector(state => isPluginSelectedSelector(state, hash));
...@@ -44,6 +49,10 @@ export const useLoadPlugin = ({ hash, pluginUrl }: UseLoadPluginProps): UseLoadP ...@@ -44,6 +49,10 @@ export const useLoadPlugin = ({ hash, pluginUrl }: UseLoadPluginProps): UseLoadP
}); });
loadPlugin(); loadPlugin();
if (onPluginLoaded) {
onPluginLoaded();
}
}; };
const handleUnloadPlugin = (): void => { const handleUnloadPlugin = (): void => {
......
import { useLoadPlugin } from '@/components/Map/Drawer/AvailablePluginsDrawer/LoadPlugin/hooks/useLoadPlugin'; import { useLoadPlugin } from '@/components/Map/Drawer/AvailablePluginsDrawer/LoadPlugin/hooks/useLoadPlugin';
import { FIRST_ARRAY_ELEMENT } from '@/constants/common'; import { FIRST_ARRAY_ELEMENT } from '@/constants/common';
import { useAppDispatch } from '@/redux/hooks/useAppDispatch';
import { setCurrentDrawerPluginHash } from '@/redux/plugins/plugins.slice';
import { Icon } from '@/shared/Icon'; import { Icon } from '@/shared/Icon';
import { MinervaPlugin } from '@/types/models'; import { MinervaPlugin } from '@/types/models';
import { RELOAD_PLUGIN_DRAWER_BUTTON_ROLE } from './PluginHeaderInfo.constants'; import { RELOAD_PLUGIN_DRAWER_BUTTON_ROLE } from './PluginHeaderInfo.constants';
...@@ -9,9 +11,14 @@ interface Props { ...@@ -9,9 +11,14 @@ interface Props {
} }
export const PluginHeaderInfo = ({ plugin }: Props): JSX.Element => { export const PluginHeaderInfo = ({ plugin }: Props): JSX.Element => {
const dispatch = useAppDispatch();
const { reloadPlugin } = useLoadPlugin({ const { reloadPlugin } = useLoadPlugin({
hash: plugin.hash, hash: plugin.hash,
pluginUrl: plugin.urls[FIRST_ARRAY_ELEMENT], pluginUrl: plugin.urls[FIRST_ARRAY_ELEMENT],
onPluginLoaded: () => {
dispatch(setCurrentDrawerPluginHash(plugin.hash));
},
}); });
return ( return (
......
export { LoadPluginButton } from './LoadPluginButton.component';
...@@ -15,7 +15,7 @@ import { render, screen, waitFor } from '@testing-library/react'; ...@@ -15,7 +15,7 @@ import { render, screen, waitFor } from '@testing-library/react';
import axios, { HttpStatusCode } from 'axios'; import axios, { HttpStatusCode } from 'axios';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import { MockStoreEnhanced } from 'redux-mock-store'; import { MockStoreEnhanced } from 'redux-mock-store';
import { LoadPluginButton } from './LoadPluginButton.component'; import { LoadPluginElement } from './LoadPluginElement.component';
const mockedAxiosClient = new MockAdapter(axios); const mockedAxiosClient = new MockAdapter(axios);
...@@ -27,7 +27,7 @@ const renderComponent = ( ...@@ -27,7 +27,7 @@ const renderComponent = (
return ( return (
render( render(
<Wrapper> <Wrapper>
<LoadPluginButton plugin={plugin} /> <LoadPluginElement plugin={plugin} />
</Wrapper>, </Wrapper>,
), ),
{ {
......
/* eslint-disable jsx-a11y/no-static-element-interactions */ /* eslint-disable jsx-a11y/no-static-element-interactions */
/* eslint-disable jsx-a11y/click-events-have-key-events */ /* eslint-disable jsx-a11y/click-events-have-key-events */
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */
import { useLoadPlugin } from '@/components/Map/Drawer/AvailablePluginsDrawer/LoadPlugin/hooks/useLoadPlugin'; import { useLoadPlugin } from '@/components/Map/Drawer/AvailablePluginsDrawer/LoadPlugin/hooks/useLoadPlugin';
import { FIRST_ARRAY_ELEMENT } from '@/constants/common'; import { FIRST_ARRAY_ELEMENT } from '@/constants/common';
import { useAppDispatch } from '@/redux/hooks/useAppDispatch';
import { setCurrentDrawerPluginHash } from '@/redux/plugins/plugins.slice';
import { MinervaPlugin } from '@/types/models'; import { MinervaPlugin } from '@/types/models';
interface LoadPluginButtonProps { interface LoadPluginButtonProps {
plugin: MinervaPlugin; plugin: MinervaPlugin;
} }
export const LoadPluginButton = ({ plugin }: LoadPluginButtonProps): JSX.Element => { export const LoadPluginElement = ({ plugin }: LoadPluginButtonProps): JSX.Element => {
const { hash, name } = plugin; const { hash, name, urls } = plugin;
const dispatch = useAppDispatch();
const { loadPlugin } = useLoadPlugin({ const { loadPlugin } = useLoadPlugin({
hash: plugin.hash, hash,
pluginUrl: plugin.urls[FIRST_ARRAY_ELEMENT], pluginUrl: urls[FIRST_ARRAY_ELEMENT],
onPluginLoaded: () => {
dispatch(setCurrentDrawerPluginHash(hash));
},
}); });
return ( return (
<div <li
key={hash} key={hash}
className="flex cursor-pointer flex-col border-t px-4 py-2 shadow-sm" className="flex cursor-pointer flex-col border-t px-4 py-2 shadow-sm"
onClick={loadPlugin} onClick={loadPlugin}
> >
{name} {name}
</div> </li>
); );
}; };
export { LoadPluginElement } from './LoadPluginElement.component';
...@@ -4,7 +4,7 @@ import { Button } from '@/shared/Button'; ...@@ -4,7 +4,7 @@ import { Button } from '@/shared/Button';
import { MinervaPlugin } from '@/types/models'; import { MinervaPlugin } from '@/types/models';
import { useSelect } from 'downshift'; import { useSelect } from 'downshift';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import { LoadPluginButton } from './LoadPluginButton'; import { LoadPluginElement } from './LoadPluginElement';
export const PluginOpenButton = (): JSX.Element | null => { export const PluginOpenButton = (): JSX.Element | null => {
const publicPlugins = useSelector(publicPluginsListWithoutActiveSelector); const publicPlugins = useSelector(publicPluginsListWithoutActiveSelector);
...@@ -21,13 +21,13 @@ export const PluginOpenButton = (): JSX.Element | null => { ...@@ -21,13 +21,13 @@ export const PluginOpenButton = (): JSX.Element | null => {
Open new plugin Open new plugin
</Button> </Button>
<ul <ul
className={`absolute left-[-50%] z-10 max-h-80 w-48 translate-x-1/4 overflow-x-hidden overflow-y-scroll rounded-sm border bg-white p-0 ps-0 ${ className={`absolute -left-1/2 z-10 max-h-80 w-48 translate-x-1/4 overflow-x-hidden overflow-y-scroll rounded-sm border bg-white p-0 ps-0 ${
!isOpen && 'hidden' !isOpen && 'hidden'
}`} }`}
{...getMenuProps()} {...getMenuProps()}
> >
{publicPlugins.map((plugin: MinervaPlugin) => ( {publicPlugins.map((plugin: MinervaPlugin) => (
<LoadPluginButton key={plugin.hash} plugin={plugin} /> <LoadPluginElement key={plugin.hash} plugin={plugin} />
))} ))}
</ul> </ul>
</> </>
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import { ZERO } from '@/constants/common'; import { ZERO } from '@/constants/common';
import { useAppSelector } from '@/redux/hooks/useAppSelector'; import { useAppSelector } from '@/redux/hooks/useAppSelector';
import { allActivePluginsSelector } from '@/redux/plugins/plugins.selectors'; import { allActivePluginsSelector } from '@/redux/plugins/plugins.selectors';
import { useMemo } from 'react';
import { PluginSingleTab } from './PluginSingleTab'; import { PluginSingleTab } from './PluginSingleTab';
export const PluginsTabs = (): JSX.Element => { export const PluginsTabs = (): JSX.Element => {
...@@ -12,10 +13,13 @@ export const PluginsTabs = (): JSX.Element => { ...@@ -12,10 +13,13 @@ export const PluginsTabs = (): JSX.Element => {
<PluginSingleTab plugin={plugin} key={plugin.hash} /> <PluginSingleTab plugin={plugin} key={plugin.hash} />
)); ));
const pluginsEmptyInfo = ( const pluginsEmptyInfo = useMemo(
<div className="flex h-10 items-center px-4 text-[#979797]"> () => (
You don&apos;t have any opened plugin yet <div className="flex h-10 items-center px-4 text-[#979797]">
</div> You don&apos;t have any opened plugin yet
</div>
),
[],
); );
return ( return (
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment