fix: [GH-4075]: block action on the view section if the dashboard is locked (#4089)

* fix: [GH-4075]: block action on the view section if the dashboard is locked
This commit is contained in:
Vikrant Gupta 2023-11-29 00:02:51 +05:30 committed by GitHub
parent b6a79ab22c
commit 01df53074c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 36 additions and 7 deletions

View File

@ -4,6 +4,7 @@ import { Button, Input } from 'antd';
import { CheckboxChangeEvent } from 'antd/es/checkbox'; import { CheckboxChangeEvent } from 'antd/es/checkbox';
import { ResizeTable } from 'components/ResizeTable'; import { ResizeTable } from 'components/ResizeTable';
import { useNotifications } from 'hooks/useNotifications'; import { useNotifications } from 'hooks/useNotifications';
import { useDashboard } from 'providers/Dashboard/Dashboard';
import { memo, useCallback, useState } from 'react'; import { memo, useCallback, useState } from 'react';
import { getGraphManagerTableColumns } from './TableRender/GraphManagerColumns'; import { getGraphManagerTableColumns } from './TableRender/GraphManagerColumns';
@ -29,6 +30,7 @@ function GraphManager({
); );
const { notifications } = useNotifications(); const { notifications } = useNotifications();
const { isDashboardLocked } = useDashboard();
const checkBoxOnChangeHandler = useCallback( const checkBoxOnChangeHandler = useCallback(
(e: CheckboxChangeEvent, index: number): void => { (e: CheckboxChangeEvent, index: number): void => {
@ -66,6 +68,7 @@ function GraphManager({
graphVisibilityState: graphsVisibilityStates, graphVisibilityState: graphsVisibilityStates,
labelClickedHandler, labelClickedHandler,
yAxisUnit, yAxisUnit,
isGraphDisabled: isDashboardLocked,
}); });
const filterHandler = useCallback( const filterHandler = useCallback(

View File

@ -9,6 +9,7 @@ function CustomCheckBox({
index, index,
graphVisibilityState = [], graphVisibilityState = [],
checkBoxOnChangeHandler, checkBoxOnChangeHandler,
disabled = false,
}: CheckBoxProps): JSX.Element { }: CheckBoxProps): JSX.Element {
const onChangeHandler = (e: CheckboxChangeEvent): void => { const onChangeHandler = (e: CheckboxChangeEvent): void => {
checkBoxOnChangeHandler(e, index); checkBoxOnChangeHandler(e, index);
@ -28,7 +29,11 @@ function CustomCheckBox({
}, },
}} }}
> >
<Checkbox onChange={onChangeHandler} checked={isChecked} /> <Checkbox
onChange={onChangeHandler}
checked={isChecked}
disabled={disabled}
/>
</ConfigProvider> </ConfigProvider>
); );
} }

View File

@ -5,12 +5,14 @@ import Label from './Label';
export const getLabel = ( export const getLabel = (
labelClickedHandler: (labelIndex: number) => void, labelClickedHandler: (labelIndex: number) => void,
disabled?: boolean,
): ColumnType<DataSetProps> => ({ ): ColumnType<DataSetProps> => ({
render: (label: string, record): JSX.Element => ( render: (label: string, record): JSX.Element => (
<Label <Label
label={label} label={label}
labelIndex={record.index} labelIndex={record.index}
labelClickedHandler={labelClickedHandler} labelClickedHandler={labelClickedHandler}
disabled={disabled}
/> />
), ),
}); });

View File

@ -13,6 +13,7 @@ export const getGraphManagerTableColumns = ({
graphVisibilityState, graphVisibilityState,
labelClickedHandler, labelClickedHandler,
yAxisUnit, yAxisUnit,
isGraphDisabled,
}: GetGraphManagerTableColumnsProps): ColumnType<DataSetProps>[] => [ }: GetGraphManagerTableColumnsProps): ColumnType<DataSetProps>[] => [
{ {
title: '', title: '',
@ -25,6 +26,7 @@ export const getGraphManagerTableColumns = ({
index={record.index} index={record.index}
checkBoxOnChangeHandler={checkBoxOnChangeHandler} checkBoxOnChangeHandler={checkBoxOnChangeHandler}
graphVisibilityState={graphVisibilityState} graphVisibilityState={graphVisibilityState}
disabled={isGraphDisabled}
/> />
), ),
}, },
@ -33,7 +35,7 @@ export const getGraphManagerTableColumns = ({
width: 300, width: 300,
dataIndex: ColumnsKeyAndDataIndex.Label, dataIndex: ColumnsKeyAndDataIndex.Label,
key: ColumnsKeyAndDataIndex.Label, key: ColumnsKeyAndDataIndex.Label,
...getLabel(labelClickedHandler), ...getLabel(labelClickedHandler, isGraphDisabled),
}, },
{ {
title: getGraphManagerTableHeaderTitle( title: getGraphManagerTableHeaderTitle(
@ -79,4 +81,5 @@ interface GetGraphManagerTableColumnsProps {
labelClickedHandler: (labelIndex: number) => void; labelClickedHandler: (labelIndex: number) => void;
graphVisibilityState: boolean[]; graphVisibilityState: boolean[];
yAxisUnit?: string; yAxisUnit?: string;
isGraphDisabled?: boolean;
} }

View File

@ -8,6 +8,7 @@ function Label({
labelClickedHandler, labelClickedHandler,
labelIndex, labelIndex,
label, label,
disabled = false,
}: LabelProps): JSX.Element { }: LabelProps): JSX.Element {
const isDarkMode = useIsDarkMode(); const isDarkMode = useIsDarkMode();
@ -19,6 +20,7 @@ function Label({
<LabelContainer <LabelContainer
isDarkMode={isDarkMode} isDarkMode={isDarkMode}
type="button" type="button"
disabled={disabled}
onClick={onClickHandler} onClick={onClickHandler}
> >
{getAbbreviatedLabel(label)} {getAbbreviatedLabel(label)}

View File

@ -18,6 +18,10 @@
border-radius: 3px; border-radius: 3px;
} }
.disabled {
height: calc(100% - 65px);
}
.graph-manager-container { .graph-manager-container {
height: calc(40% - 40px); height: calc(40% - 40px);

View File

@ -52,7 +52,7 @@ function FullView({
const [chartOptions, setChartOptions] = useState<uPlot.Options>(); const [chartOptions, setChartOptions] = useState<uPlot.Options>();
const { selectedDashboard } = useDashboard(); const { selectedDashboard, isDashboardLocked } = useDashboard();
const getSelectedTime = useCallback( const getSelectedTime = useCallback(
() => () =>
@ -155,7 +155,12 @@ function FullView({
)} )}
</div> </div>
<div className="graph-container" ref={fullViewRef}> <div
className={
isDashboardLocked ? 'graph-container disabled' : 'graph-container'
}
ref={fullViewRef}
>
{chartOptions && ( {chartOptions && (
<GraphContainer <GraphContainer
style={{ height: '90%' }} style={{ height: '90%' }}
@ -178,7 +183,7 @@ function FullView({
)} )}
</div> </div>
{canModifyChart && chartOptions && ( {canModifyChart && chartOptions && !isDashboardLocked && (
<GraphManager <GraphManager
data={chartData} data={chartData}
name={name} name={name}

View File

@ -31,9 +31,12 @@ export const GraphContainer = styled.div<GraphContainerProps>`
isGraphLegendToggleAvailable ? '50%' : '100%'}; isGraphLegendToggleAvailable ? '50%' : '100%'};
`; `;
export const LabelContainer = styled.button<{ isDarkMode?: boolean }>` export const LabelContainer = styled.button<{
isDarkMode?: boolean;
disabled?: boolean;
}>`
max-width: 18.75rem; max-width: 18.75rem;
cursor: pointer; cursor: ${(props): string => (props.disabled ? 'no-drop' : 'pointer')};
border: none; border: none;
background-color: transparent; background-color: transparent;
color: ${(props): string => color: ${(props): string =>

View File

@ -42,6 +42,7 @@ export interface LabelProps {
labelClickedHandler: (labelIndex: number) => void; labelClickedHandler: (labelIndex: number) => void;
labelIndex: number; labelIndex: number;
label: string; label: string;
disabled?: boolean;
} }
export interface FullViewProps { export interface FullViewProps {
@ -74,6 +75,7 @@ export interface CheckBoxProps {
index: number; index: number;
graphVisibilityState: boolean[]; graphVisibilityState: boolean[];
checkBoxOnChangeHandler: (e: CheckboxChangeEvent, index: number) => void; checkBoxOnChangeHandler: (e: CheckboxChangeEvent, index: number) => void;
disabled?: boolean;
} }
export interface SaveLegendEntriesToLocalStoreProps { export interface SaveLegendEntriesToLocalStoreProps {