mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-06 01:16:03 +08:00
Merge pull request #1243 from pranshuchittora/pranshuchittora/feat/dashboard-save-rbac
feat(FE): save dashboard with RBAC permissions
This commit is contained in:
commit
99d38860cb
@ -1,6 +1,7 @@
|
||||
/* eslint-disable react/no-unstable-nested-components */
|
||||
import { notification } from 'antd';
|
||||
import updateDashboardApi from 'api/dashboard/update';
|
||||
import useComponentPermission from 'hooks/useComponentPermission';
|
||||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
import { Layout } from 'react-grid-layout';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
@ -15,6 +16,7 @@ import { AppState } from 'store/reducers';
|
||||
import AppActions from 'types/actions';
|
||||
import { UPDATE_DASHBOARD } from 'types/actions/dashboard';
|
||||
import { Dashboard, Widgets } from 'types/api/dashboard/getAll';
|
||||
import AppReducer from 'types/reducer/app';
|
||||
import DashboardReducer from 'types/reducer/dashboards';
|
||||
|
||||
import Graph from './Graph';
|
||||
@ -49,6 +51,9 @@ function GridGraph(props: Props): JSX.Element {
|
||||
const { dashboards, isAddWidget } = useSelector<AppState, DashboardReducer>(
|
||||
(state) => state.dashboards,
|
||||
);
|
||||
const { role } = useSelector<AppState, AppReducer>((state) => state.app);
|
||||
|
||||
const [saveLayoutPermission] = useComponentPermission(['save_layout'], role);
|
||||
const [saveLayoutState, setSaveLayoutState] = useState<State>({
|
||||
loading: false,
|
||||
error: false,
|
||||
@ -109,6 +114,8 @@ function GridGraph(props: Props): JSX.Element {
|
||||
loading: true,
|
||||
}));
|
||||
|
||||
// Save layout only when users has the has the permission to do so.
|
||||
if (saveLayoutPermission) {
|
||||
const response = await updateDashboardApi({
|
||||
data: {
|
||||
title: data.title,
|
||||
@ -135,6 +142,7 @@ function GridGraph(props: Props): JSX.Element {
|
||||
loading: false,
|
||||
}));
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
@ -145,6 +153,7 @@ function GridGraph(props: Props): JSX.Element {
|
||||
data.tags,
|
||||
data.title,
|
||||
data.widgets,
|
||||
saveLayoutPermission,
|
||||
selectedDashboard.uuid,
|
||||
],
|
||||
);
|
||||
|
@ -49,7 +49,7 @@ export const routePermission: Record<keyof typeof ROUTES, ROLES[]> = {
|
||||
APPLICATION: ['ADMIN', 'EDITOR', 'VIEWER'],
|
||||
CHANNELS_EDIT: ['ADMIN'],
|
||||
CHANNELS_NEW: ['ADMIN'],
|
||||
DASHBOARD: ['ADMIN', 'EDITOR', 'EDITOR'],
|
||||
DASHBOARD: ['ADMIN', 'EDITOR', 'VIEWER'],
|
||||
DASHBOARD_WIDGET: ['ADMIN', 'EDITOR', 'VIEWER'],
|
||||
EDIT_ALERTS: ['ADMIN'],
|
||||
ERROR_DETAIL: ['ADMIN', 'EDITOR', 'VIEWER'],
|
||||
|
Loading…
x
Reference in New Issue
Block a user