Skip to content

Commit

Permalink
fix(dashboard): for kpi/status disable add of RE when an property is …
Browse files Browse the repository at this point in the history
…already added
  • Loading branch information
mnischay authored and diehbria committed Jan 5, 2024
1 parent 48cd9ef commit eff3282
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { disableAdd } from '~/components/queryEditor/iotSiteWiseQueryEditor/footer/disableAdd';

describe('testing disableAdd', () => {
beforeEach(() => {
jest.resetAllMocks();
});
it('should return true if no selected widgets', () => {
expect(disableAdd([], 0)).toBeTruthy();
});

it('should return true if no results', () => {
expect(
disableAdd([{ id: '1', type: 'status', x: 0, y: 0, z: 0, properties: {}, height: 500, width: 800 }], 0)
).toBeTruthy();
});

it('should return true if status is selected and has a assets already added', () => {
expect(
disableAdd(
[
{
id: '1',
type: 'status',
x: 0,
y: 0,
z: 0,
properties: { queryConfig: { query: {} } },
height: 500,
width: 800,
},
],
10
)
).toBeTruthy();
});
it('should return false if status is selected and has NO assets already added', () => {
expect(
disableAdd(
[
{
id: '1',
type: 'status',
x: 0,
y: 0,
z: 0,
properties: { queryConfig: { query: undefined } },
height: 500,
width: 800,
},
],
10
)
).toBeFalsy();
});

it('should return false if x-y-plot is selected and has assets already added', () => {
expect(
disableAdd(
[
{
id: '1',
type: 'x-y-plot',
x: 0,
y: 0,
z: 0,
properties: { queryConfig: { query: undefined } },
height: 500,
width: 800,
},
],
10
)
).toBeFalsy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { get } from 'lodash';
import { DashboardWidget } from '~/types';

export const disableAdd = (
selectedWidgets: DashboardWidget<Record<string, unknown>>[],
collectionPropsLength?: number
) => {
const selectedWidget = selectedWidgets?.at(0);
const currWidgetType = selectedWidget?.type;

let widgetBasedDisable = false;
switch (currWidgetType) {
case 'status':
case 'kpi':
if (get(selectedWidget, 'properties.queryConfig.query')) {
widgetBasedDisable = true;
}
break;
default:
}
return collectionPropsLength === 0 || selectedWidgets.length !== 1 || widgetBasedDisable;
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { SelectedAsset } from '../../types';
import { ResourceExplorerErrorState } from '../../components/resourceExplorerErrorState';
import { getPlugin } from '@iot-app-kit/core';
import { isInValidProperty } from './util/resourceExplorerTableLabels';
import { disableAdd } from '~/components/queryEditor/iotSiteWiseQueryEditor/footer/disableAdd';

export interface ModeledDataStreamTableProps {
onClickAddModeledDataStreams: (modeledDataStreams: ModeledDataStream[]) => void;
Expand Down Expand Up @@ -158,7 +159,7 @@ export function ModeledDataStreamTable({
<ResourceExplorerFooter
resetDisabled={collectionProps.selectedItems?.length === 0}
onReset={() => actions.setSelectedItems([])}
addDisabled={collectionProps.selectedItems?.length === 0 || selectedWidgets.length !== 1}
addDisabled={disableAdd(selectedWidgets, collectionProps?.selectedItems?.length)}
onAdd={() => {
onClickAddModeledDataStreams(collectionProps.selectedItems as unknown as ModeledDataStream[]);
metricsRecorder?.record({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { DashboardState } from '~/store/state';
import { getFormattedDateTimeFromEpoch } from '~/components/util/dateTimeUtil';
import { ResourceExplorerFooter } from '../../footer/footer';
import { getPlugin } from '@iot-app-kit/core';
import { disableAdd } from '~/components/queryEditor/iotSiteWiseQueryEditor/footer/disableAdd';

export interface UnmodeledDataStreamTableProps {
onClickAdd: (unmodeledDataStreams: UnmodeledDataStream[]) => void;
Expand Down Expand Up @@ -114,7 +115,7 @@ export function UnmodeledDataStreamTable({
<ResourceExplorerFooter
resetDisabled={collectionProps.selectedItems?.length === 0}
onReset={() => actions.setSelectedItems([])}
addDisabled={collectionProps.selectedItems?.length === 0 || selectedWidgets.length !== 1}
addDisabled={disableAdd(selectedWidgets, collectionProps.selectedItems?.length)}
onAdd={() => {
onClickAdd(collectionProps.selectedItems as unknown as UnmodeledDataStream[]);
metricsRecorder?.record({
Expand Down

0 comments on commit eff3282

Please sign in to comment.