Skip to content

Commit

Permalink
fix(dashboard): kpi/status bug to stop adding more than 1 property
Browse files Browse the repository at this point in the history
  • Loading branch information
mnischay authored and corteggiano committed Jan 31, 2024
1 parent 0529abd commit f68c5eb
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { ResourceExplorerFooter } from '../../../footer/footer';
import { useSelector } from 'react-redux';
import { DashboardState } from '~/store/state';
import { isModeledPropertyInvalid } from '~/components/queryEditor/helpers/isModeledPropertyInvalid';
import { disableAdd } from '~/components/queryEditor/iotSiteWiseQueryEditor/footer/disableAdd';

export interface AssetTableProps {
onClickNextPage: () => void;
Expand Down Expand Up @@ -132,7 +133,8 @@ export function AssetModelPropertiesTable({
footer={
<ResourceExplorerFooter
addDisabled={
saveDisabled || collectionProps.selectedItems?.length === 0
saveDisabled ||
disableAdd(selectedWidgets, collectionProps.selectedItems?.length)
}
onAdd={onSave}
onReset={() => actions.setSelectedItems([])}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { disableAdd } from '~/components/queryEditor/iotSiteWiseQueryEditor/footer/disableAdd';
import { SiteWiseQueryConfig } from '~/customization/widgets/types';

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

it('should return true if no results', () => {
const commonTests = ({
objectWithoutProperties,
objectWithProperties,
}: {
objectWithoutProperties: { queryConfig: SiteWiseQueryConfig };
objectWithProperties: { queryConfig: SiteWiseQueryConfig };
}) => {
it('should return true if no results, with or without properties', () => {
expect(
disableAdd(
[
Expand All @@ -15,7 +18,24 @@ describe(disableAdd, () => {
x: 0,
y: 0,
z: 0,
properties: {},
properties: objectWithoutProperties,
height: 500,
width: 800,
},
],
0
)
).toBeTruthy();
expect(
disableAdd(
[
{
id: '1',
type: 'status',
x: 0,
y: 0,
z: 0,
properties: objectWithProperties,
height: 500,
width: 800,
},
Expand All @@ -25,7 +45,7 @@ describe(disableAdd, () => {
).toBeTruthy();
});

it('should return true if status is selected and has a assets already added', () => {
it('should return true if status/kpi is selected and has a property already added', () => {
expect(
disableAdd(
[
Expand All @@ -35,16 +55,14 @@ describe(disableAdd, () => {
x: 0,
y: 0,
z: 0,
properties: { queryConfig: { query: { assets: [{ id: '1' }] } } },
properties: objectWithProperties,
height: 500,
width: 800,
},
],
10
)
).toBeTruthy();
});
it('should return true if KPI is selected and has a assets already added', () => {
expect(
disableAdd(
[
Expand All @@ -54,7 +72,7 @@ describe(disableAdd, () => {
x: 0,
y: 0,
z: 0,
properties: { queryConfig: { query: { assets: [{ id: '1' }] } } },
properties: objectWithProperties,
height: 500,
width: 800,
},
Expand All @@ -64,7 +82,7 @@ describe(disableAdd, () => {
).toBeTruthy();
});

it('should return false if status is selected and has NO assets already added', () => {
it('should return false if status/kpi is selected and has NO property already added', () => {
expect(
disableAdd(
[
Expand All @@ -74,7 +92,45 @@ describe(disableAdd, () => {
x: 0,
y: 0,
z: 0,
properties: { queryConfig: { query: { assets: [] } } },
properties: objectWithoutProperties,
height: 500,
width: 800,
},
],
1
)
).toBeFalsy();

expect(
disableAdd(
[
{
id: '1',
type: 'kpi',
x: 0,
y: 0,
z: 0,
properties: objectWithoutProperties,
height: 500,
width: 800,
},
],
1
)
).toBeFalsy();
});

it('should return false if x-y-plot is selected and has property already added', () => {
expect(
disableAdd(
[
{
id: '1',
type: 'x-y-plot',
x: 0,
y: 0,
z: 0,
properties: objectWithoutProperties,
height: 500,
width: 800,
},
Expand All @@ -84,7 +140,7 @@ describe(disableAdd, () => {
).toBeFalsy();
});

it('should return false if KPI is selected and has NO assets already added', () => {
it('should return true if KPI(with or without property) is selected and more than 1 property selected', () => {
expect(
disableAdd(
[
Expand All @@ -94,17 +150,34 @@ describe(disableAdd, () => {
x: 0,
y: 0,
z: 0,
properties: { queryConfig: { query: { assets: [] } } },
properties: {},
height: 500,
width: 800,
},
],
10
)
).toBeFalsy();
).toBeTruthy();
expect(
disableAdd(
[
{
id: '1',
type: 'kpi',
x: 0,
y: 0,
z: 0,
properties: objectWithProperties,
height: 500,
width: 800,
},
],
10
)
).toBeTruthy();
});

it('should return false if x-y-plot is selected and has assets already added', () => {
it('should return false if x-y-plot(with or without properties) is selected and more than 1 property selected', () => {
expect(
disableAdd(
[
Expand All @@ -114,13 +187,66 @@ describe(disableAdd, () => {
x: 0,
y: 0,
z: 0,
properties: { queryConfig: { query: { assets: [{ id: '1' }] } } },
properties: objectWithoutProperties,
height: 500,
width: 800,
},
],
10
)
).toBeFalsy();

expect(
disableAdd(
[
{
id: '1',
type: 'x-y-plot',
x: 0,
y: 0,
z: 0,
properties: objectWithProperties,
height: 500,
width: 800,
},
],
10
)
).toBeFalsy();
});
};
describe(disableAdd, () => {
it('should return true if no selected widgets', () => {
expect(disableAdd([], 0)).toBeTruthy();
});

describe('For modeled data', () => {
const objectWithoutProperties = {
queryConfig: { query: { assets: [] } },
} as unknown as { queryConfig: SiteWiseQueryConfig };
const objectWithProperties = {
queryConfig: { query: { assets: [{ id: '1' }] } },
} as unknown as { queryConfig: SiteWiseQueryConfig };

commonTests({ objectWithoutProperties, objectWithProperties });
});

describe('For unmodeled data', () => {
const objectWithoutProperties = {
queryConfig: { query: { properties: [] } },
} as unknown as { queryConfig: SiteWiseQueryConfig };
const objectWithProperties = {
queryConfig: { query: { properties: [{ id: '1' }] } },
} as unknown as { queryConfig: SiteWiseQueryConfig };
commonTests({ objectWithoutProperties, objectWithProperties });
});
describe('For asset model data', () => {
const objectWithoutProperties = {
queryConfig: { query: { assetModels: [] } },
} as unknown as { queryConfig: SiteWiseQueryConfig };
const objectWithProperties = {
queryConfig: { query: { assetModels: [{ id: '1' }] } },
} as unknown as { queryConfig: SiteWiseQueryConfig };
commonTests({ objectWithoutProperties, objectWithProperties });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,26 @@ export const disableAdd = (
switch (currWidgetType) {
case 'status':
case 'kpi': {
const assets =
const modeledProperties =
get(selectedWidget, 'properties.queryConfig.query.assets') ?? [];
if (assets.length) {
const unmodeledProperties =
get(selectedWidget, 'properties.queryConfig.query.properties') ?? [];
const assetModelProperties =
get(selectedWidget, 'properties.queryConfig.query.assetModels') ?? [];
if (
modeledProperties.length ||
unmodeledProperties.length ||
assetModelProperties.length ||
collectionPropsLength !== 1
) {
widgetBasedDisable = true;
}
break;
}
default:
}
return (
collectionPropsLength === undefined ||
collectionPropsLength === 0 ||
selectedWidgets.length !== 1 ||
widgetBasedDisable
Expand Down

0 comments on commit f68c5eb

Please sign in to comment.