-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(dashboard): for kpi/status disable add of RE when an property is …
…already added
- Loading branch information
Showing
4 changed files
with
101 additions
and
2 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
...es/dashboard/src/components/queryEditor/iotSiteWiseQueryEditor/footer/disableAdd.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
packages/dashboard/src/components/queryEditor/iotSiteWiseQueryEditor/footer/disableAdd.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters