2022-11-14 14:29:13 +05:30
|
|
|
import { Menu, Space } from 'antd';
|
|
|
|
|
import Spinner from 'components/Spinner';
|
2023-01-11 14:39:06 +05:30
|
|
|
import { useIsDarkMode } from 'hooks/useDarkMode';
|
2023-05-19 13:14:32 +05:30
|
|
|
import { lazy, Suspense, useMemo } from 'react';
|
2022-11-14 14:29:13 +05:30
|
|
|
import { ConfigProps } from 'types/api/dynamicConfigs/getDynamicConfigs';
|
|
|
|
|
|
|
|
|
|
import ErrorLink from './ErrorLink';
|
|
|
|
|
import LinkContainer from './Link';
|
|
|
|
|
|
|
|
|
|
function HelpToolTip({ config }: HelpToolTipProps): JSX.Element {
|
|
|
|
|
const sortedConfig = useMemo(
|
|
|
|
|
() => config.components.sort((a, b) => a.position - b.position),
|
|
|
|
|
[config.components],
|
|
|
|
|
);
|
|
|
|
|
|
2023-01-11 14:39:06 +05:30
|
|
|
const isDarkMode = useIsDarkMode();
|
2022-11-14 14:29:13 +05:30
|
|
|
|
2023-03-03 12:09:24 +01:00
|
|
|
const items = sortedConfig.map((item) => {
|
|
|
|
|
const iconName = `${isDarkMode ? item.darkIcon : item.lightIcon}`;
|
2023-05-19 13:14:32 +05:30
|
|
|
const Component = lazy(
|
2023-03-03 12:09:24 +01:00
|
|
|
() => import(`@ant-design/icons/es/icons/${iconName}.js`),
|
|
|
|
|
);
|
|
|
|
|
return {
|
|
|
|
|
key: item.text + item.href,
|
|
|
|
|
label: (
|
|
|
|
|
<ErrorLink key={item.text + item.href}>
|
|
|
|
|
<Suspense fallback={<Spinner height="5vh" />}>
|
|
|
|
|
<LinkContainer href={item.href}>
|
|
|
|
|
<Space size="small" align="start">
|
|
|
|
|
<Component />
|
|
|
|
|
{item.text}
|
|
|
|
|
</Space>
|
|
|
|
|
</LinkContainer>
|
|
|
|
|
</Suspense>
|
|
|
|
|
</ErrorLink>
|
|
|
|
|
),
|
|
|
|
|
};
|
|
|
|
|
});
|
2022-11-14 14:29:13 +05:30
|
|
|
|
2023-03-03 12:09:24 +01:00
|
|
|
return <Menu items={items} />;
|
2022-11-14 14:29:13 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface HelpToolTipProps {
|
|
|
|
|
config: ConfigProps;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default HelpToolTip;
|