mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-16 14:05:55 +08:00
fix: new dashboard menu items are flickering (#4039)
This commit is contained in:
parent
7c87310fa6
commit
ec8a74d385
@ -1,13 +1,5 @@
|
|||||||
import { PlusOutlined } from '@ant-design/icons';
|
import { PlusOutlined } from '@ant-design/icons';
|
||||||
import {
|
import { Card, Col, Dropdown, Input, Row, TableColumnProps } from 'antd';
|
||||||
Card,
|
|
||||||
Col,
|
|
||||||
Dropdown,
|
|
||||||
Input,
|
|
||||||
MenuProps,
|
|
||||||
Row,
|
|
||||||
TableColumnProps,
|
|
||||||
} from 'antd';
|
|
||||||
import { ItemType } from 'antd/es/menu/hooks/useItems';
|
import { ItemType } from 'antd/es/menu/hooks/useItems';
|
||||||
import createDashboard from 'api/dashboard/create';
|
import createDashboard from 'api/dashboard/create';
|
||||||
import { AxiosError } from 'axios';
|
import { AxiosError } from 'axios';
|
||||||
@ -30,7 +22,6 @@ import { generatePath } from 'react-router-dom';
|
|||||||
import { AppState } from 'store/reducers';
|
import { AppState } from 'store/reducers';
|
||||||
import { Dashboard } from 'types/api/dashboard/getAll';
|
import { Dashboard } from 'types/api/dashboard/getAll';
|
||||||
import AppReducer from 'types/reducer/app';
|
import AppReducer from 'types/reducer/app';
|
||||||
import { popupContainer } from 'utils/selectPopupContainer';
|
|
||||||
|
|
||||||
import DateComponent from '../../components/ResizeTable/TableComponent/DateComponent';
|
import DateComponent from '../../components/ResizeTable/TableComponent/DateComponent';
|
||||||
import ImportJSON from './ImportJSON';
|
import ImportJSON from './ImportJSON';
|
||||||
@ -49,8 +40,8 @@ function ListOfAllDashboard(): JSX.Element {
|
|||||||
|
|
||||||
const { role } = useSelector<AppState, AppReducer>((state) => state.app);
|
const { role } = useSelector<AppState, AppReducer>((state) => state.app);
|
||||||
|
|
||||||
const [action, createNewDashboard, newDashboard] = useComponentPermission(
|
const [action, createNewDashboard] = useComponentPermission(
|
||||||
['action', 'create_new_dashboards', 'new_dashboard'],
|
['action', 'create_new_dashboards'],
|
||||||
role,
|
role,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -234,9 +225,22 @@ function ListOfAllDashboard(): JSX.Element {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getMenuItems = useMemo(() => {
|
const getMenuItems = useMemo(() => {
|
||||||
const menuItems: ItemType[] = [];
|
const menuItems: ItemType[] = [
|
||||||
|
{
|
||||||
|
key: t('import_json').toString(),
|
||||||
|
label: t('import_json'),
|
||||||
|
onClick: (): void => onModalHandler(false),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: t('import_grafana_json').toString(),
|
||||||
|
label: t('import_grafana_json'),
|
||||||
|
onClick: (): void => onModalHandler(true),
|
||||||
|
disabled: true,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
if (createNewDashboard) {
|
if (createNewDashboard) {
|
||||||
menuItems.push({
|
menuItems.unshift({
|
||||||
key: t('create_dashboard').toString(),
|
key: t('create_dashboard').toString(),
|
||||||
label: t('create_dashboard'),
|
label: t('create_dashboard'),
|
||||||
disabled: isDashboardListLoading,
|
disabled: isDashboardListLoading,
|
||||||
@ -244,29 +248,9 @@ function ListOfAllDashboard(): JSX.Element {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
menuItems.push({
|
|
||||||
key: t('import_json').toString(),
|
|
||||||
label: t('import_json'),
|
|
||||||
onClick: (): void => onModalHandler(false),
|
|
||||||
});
|
|
||||||
|
|
||||||
menuItems.push({
|
|
||||||
key: t('import_grafana_json').toString(),
|
|
||||||
label: t('import_grafana_json'),
|
|
||||||
onClick: (): void => onModalHandler(true),
|
|
||||||
disabled: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
return menuItems;
|
return menuItems;
|
||||||
}, [createNewDashboard, isDashboardListLoading, onNewDashboardHandler, t]);
|
}, [createNewDashboard, isDashboardListLoading, onNewDashboardHandler, t]);
|
||||||
|
|
||||||
const menu: MenuProps = useMemo(
|
|
||||||
() => ({
|
|
||||||
items: getMenuItems,
|
|
||||||
}),
|
|
||||||
[getMenuItems],
|
|
||||||
);
|
|
||||||
|
|
||||||
const searchArrayOfObjects = (searchValue: string): any[] => {
|
const searchArrayOfObjects = (searchValue: string): any[] => {
|
||||||
// Convert the searchValue to lowercase for case-insensitive search
|
// Convert the searchValue to lowercase for case-insensitive search
|
||||||
const searchValueLowerCase = searchValue.toLowerCase();
|
const searchValueLowerCase = searchValue.toLowerCase();
|
||||||
@ -318,25 +302,23 @@ function ListOfAllDashboard(): JSX.Element {
|
|||||||
url: 'https://signoz.io/docs/userguide/dashboards',
|
url: 'https://signoz.io/docs/userguide/dashboards',
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{newDashboard && (
|
|
||||||
<Dropdown
|
|
||||||
getPopupContainer={popupContainer}
|
|
||||||
disabled={isDashboardListLoading}
|
|
||||||
trigger={['click']}
|
|
||||||
menu={menu}
|
|
||||||
>
|
|
||||||
<NewDashboardButton
|
|
||||||
icon={<PlusOutlined />}
|
|
||||||
type="primary"
|
|
||||||
data-testid="create-new-dashboard"
|
|
||||||
loading={newDashboardState.loading}
|
|
||||||
danger={newDashboardState.error}
|
|
||||||
>
|
|
||||||
{getText()}
|
|
||||||
</NewDashboardButton>
|
|
||||||
</Dropdown>
|
|
||||||
)}
|
|
||||||
</ButtonContainer>
|
</ButtonContainer>
|
||||||
|
|
||||||
|
<Dropdown
|
||||||
|
menu={{ items: getMenuItems }}
|
||||||
|
disabled={isDashboardListLoading}
|
||||||
|
placement="bottomRight"
|
||||||
|
>
|
||||||
|
<NewDashboardButton
|
||||||
|
icon={<PlusOutlined />}
|
||||||
|
type="primary"
|
||||||
|
data-testid="create-new-dashboard"
|
||||||
|
loading={newDashboardState.loading}
|
||||||
|
danger={newDashboardState.error}
|
||||||
|
>
|
||||||
|
{getText()}
|
||||||
|
</NewDashboardButton>
|
||||||
|
</Dropdown>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
),
|
),
|
||||||
@ -345,8 +327,7 @@ function ListOfAllDashboard(): JSX.Element {
|
|||||||
isDashboardListLoading,
|
isDashboardListLoading,
|
||||||
handleSearch,
|
handleSearch,
|
||||||
isFilteringDashboards,
|
isFilteringDashboards,
|
||||||
newDashboard,
|
getMenuItems,
|
||||||
menu,
|
|
||||||
newDashboardState.loading,
|
newDashboardState.loading,
|
||||||
newDashboardState.error,
|
newDashboardState.error,
|
||||||
getText,
|
getText,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user