fix: updating dashboard variables is not allowed for viewer role (#2910)

Co-authored-by: Prashant Shahi <prashant@signoz.io>
This commit is contained in:
Palash Gupta 2023-06-15 19:46:08 +05:30 committed by GitHub
parent 86c6c43f95
commit 9aa8148269
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 12 deletions

View File

@ -10,6 +10,7 @@ import { UpdateDashboardVariables } from 'store/actions/dashboard/updatedDashboa
import { AppState } from 'store/reducers';
import AppActions from 'types/actions';
import { IDashboardVariable } from 'types/api/dashboard/getAll';
import AppReducer from 'types/reducer/app';
import DashboardReducer from 'types/reducer/dashboards';
import VariableItem from './VariableItem';
@ -29,6 +30,8 @@ function DashboardVariableSelection({
const [lastUpdatedVar, setLastUpdatedVar] = useState<string>('');
const { notifications } = useNotifications();
const { role } = useSelector<AppState, AppReducer>((state) => state.app);
const onVarChanged = (name: string): void => {
setLastUpdatedVar(name);
setUpdate(!update);
@ -36,19 +39,15 @@ function DashboardVariableSelection({
const onValueUpdate = (
name: string,
value:
| string
| string[]
| number
| number[]
| boolean
| boolean[]
| null
| undefined,
value: IDashboardVariable['selectedValue'],
): void => {
const updatedVariablesData = { ...variables };
updatedVariablesData[name].selectedValue = value;
updateDashboardVariables(updatedVariablesData, notifications);
if (role !== 'VIEWER') {
updateDashboardVariables(updatedVariablesData, notifications);
}
onVarChanged(name);
};
const onAllSelectedUpdate = (
@ -57,7 +56,10 @@ function DashboardVariableSelection({
): void => {
const updatedVariablesData = { ...variables };
updatedVariablesData[name].allSelected = value;
updateDashboardVariables(updatedVariablesData, notifications);
if (role !== 'VIEWER') {
updateDashboardVariables(updatedVariablesData, notifications);
}
onVarChanged(name);
};

View File

@ -1,6 +1,8 @@
import { IDashboardVariable } from '../getAll';
export type PayloadVariables = Record<
string,
undefined | null | string | number | boolean | (string | number | boolean)[]
IDashboardVariable['selectedValue']
>;
export type Props = {