mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-18 04:25:57 +08:00
delete widget is added for admin and editor (#1066)
This commit is contained in:
parent
b7adc27f02
commit
6c5a48082b
@ -5,9 +5,13 @@ import {
|
|||||||
FullscreenOutlined,
|
FullscreenOutlined,
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import { Dropdown, Menu, Typography } from 'antd';
|
import { Dropdown, Menu, Typography } from 'antd';
|
||||||
|
import useComponentPermission from 'hooks/useComponentPermission';
|
||||||
import history from 'lib/history';
|
import history from 'lib/history';
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
|
import { useSelector } from 'react-redux';
|
||||||
|
import { AppState } from 'store/reducers';
|
||||||
import { Widgets } from 'types/api/dashboard/getAll';
|
import { Widgets } from 'types/api/dashboard/getAll';
|
||||||
|
import AppReducer from 'types/reducer/app';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ArrowContainer,
|
ArrowContainer,
|
||||||
@ -59,6 +63,9 @@ function WidgetHeader({
|
|||||||
const onMenuItemSelectHandler = ({ key }: { key: TWidgetOptions }): void => {
|
const onMenuItemSelectHandler = ({ key }: { key: TWidgetOptions }): void => {
|
||||||
keyMethodMapping[key]?.method();
|
keyMethodMapping[key]?.method();
|
||||||
};
|
};
|
||||||
|
const { role } = useSelector<AppState, AppReducer>((state) => state.app);
|
||||||
|
|
||||||
|
const [deleteWidget] = useComponentPermission(['delete_widget'], role);
|
||||||
|
|
||||||
const menu = (
|
const menu = (
|
||||||
<Menu onClick={onMenuItemSelectHandler}>
|
<Menu onClick={onMenuItemSelectHandler}>
|
||||||
@ -72,12 +79,17 @@ function WidgetHeader({
|
|||||||
<span>Edit</span> <EditFilled />
|
<span>Edit</span> <EditFilled />
|
||||||
</MenuItemContainer>
|
</MenuItemContainer>
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
|
|
||||||
|
{deleteWidget && (
|
||||||
|
<>
|
||||||
<Menu.Divider />
|
<Menu.Divider />
|
||||||
<Menu.Item key={keyMethodMapping.delete.key} danger>
|
<Menu.Item key={keyMethodMapping.delete.key} danger>
|
||||||
<MenuItemContainer>
|
<MenuItemContainer>
|
||||||
<span>Delete</span> <DeleteOutlined />
|
<span>Delete</span> <DeleteOutlined />
|
||||||
</MenuItemContainer>
|
</MenuItemContainer>
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</Menu>
|
</Menu>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -12,7 +12,8 @@ export type ComponentTypes =
|
|||||||
| 'set_retention_period'
|
| 'set_retention_period'
|
||||||
| 'action'
|
| 'action'
|
||||||
| 'save_layout'
|
| 'save_layout'
|
||||||
| 'edit_dashboard';
|
| 'edit_dashboard'
|
||||||
|
| 'delete_widget';
|
||||||
|
|
||||||
export const componentPermission: Record<ComponentTypes, ROLES[]> = {
|
export const componentPermission: Record<ComponentTypes, ROLES[]> = {
|
||||||
current_org_settings: ['ADMIN'],
|
current_org_settings: ['ADMIN'],
|
||||||
@ -26,6 +27,7 @@ export const componentPermission: Record<ComponentTypes, ROLES[]> = {
|
|||||||
action: ['ADMIN', 'EDITOR'],
|
action: ['ADMIN', 'EDITOR'],
|
||||||
save_layout: ['ADMIN', 'EDITOR'],
|
save_layout: ['ADMIN', 'EDITOR'],
|
||||||
edit_dashboard: ['ADMIN', 'EDITOR'],
|
edit_dashboard: ['ADMIN', 'EDITOR'],
|
||||||
|
delete_widget: ['ADMIN', 'EDITOR'],
|
||||||
};
|
};
|
||||||
|
|
||||||
export const routePermission: Record<keyof typeof ROUTES, ROLES[]> = {
|
export const routePermission: Record<keyof typeof ROUTES, ROLES[]> = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user