Merge pull request #1243 from pranshuchittora/pranshuchittora/feat/dashboard-save-rbac

feat(FE): save dashboard with RBAC permissions
This commit is contained in:
palash-signoz 2022-06-09 12:23:18 +05:30 committed by GitHub
commit 99d38860cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 26 deletions

View File

@ -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,
],
);

View File

@ -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'],