Skip to content

Commit 6e666d3

Browse files
committed
improve visibility for other flagged states #1659
1 parent 65e9f49 commit 6e666d3

11 files changed

+288
-78
lines changed

cypress/e2e/with_mock_data/catalogueCategories.cy.ts

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,28 @@ describe('Catalogue Category', () => {
5757
cy.findByText('Actuators').should('not.exist');
5858
});
5959

60-
it('shows critical catalogue categories and filter button', () => {
60+
it('shows all criticality states of catalogue categories and the filter button', () => {
6161
cy.visit('/catalogue');
6262
cy.setMode({ critical: true });
6363

64-
cy.findByRole('button', { name: 'Show Critical Items' }).should('exist');
65-
cy.findByTestId('WarningIcon').should('exist');
66-
cy.findByTestId('WarningIcon').trigger('mouseover');
67-
cy.findByText(
68-
'A catalogue category is considered critical if any of its nested child categories or catalogue items are flagged as critical.'
64+
cy.findByRole('button', { name: 'Show Critical Categories' }).should(
65+
'exist'
6966
);
70-
cy.findByText('Beam Characterization').click();
67+
cy.findByTestId('ErrorIcon').should('exist');
68+
cy.findByTestId('ErrorIcon').trigger('mouseover');
69+
cy.findByText('This catalogue category is critical.');
7170

7271
cy.findByTestId('WarningIcon').should('exist');
7372
cy.findByTestId('WarningIcon').trigger('mouseover');
7473
cy.findByText(
75-
'A catalogue category is considered critical if any of its nested child categories or catalogue items are flagged as critical.'
74+
'Unable to determine if this catalogue category is critical. Please contact support.'
7675
);
76+
77+
cy.findAllByTestId('CheckCircleIcon').first().trigger('mouseover');
78+
cy.findByText('This catalogue category is not critical.');
7779
});
7880

79-
it('shows critical catalogue categories in the move and copy to catalogue category table', () => {
81+
it('shows all criticality states of catalogue categories in the move and copy to catalogue category table', () => {
8082
cy.visit('/catalogue');
8183
cy.setMode({ critical: true });
8284

@@ -95,11 +97,27 @@ describe('Catalogue Category', () => {
9597
cy.findByRole('dialog')
9698
.should('be.visible')
9799
.within(() => {
98-
cy.findByTestId('WarningIcon').should('exist');
99-
cy.findByTestId('WarningIcon').trigger('mouseover');
100+
cy.findByTestId('ErrorIcon').should('exist');
101+
cy.findByTestId('ErrorIcon').trigger('mouseover');
102+
});
103+
cy.findByText('This catalogue category is critical.');
104+
105+
cy.findByRole('dialog')
106+
.should('be.visible')
107+
.within(() => {
108+
cy.findAllByTestId('CheckCircleIcon').first().trigger('mouseover');
109+
});
110+
cy.findByText('This catalogue category is not critical.');
111+
112+
cy.findByRole('button', { name: 'Go to page 2' }).click();
113+
114+
cy.findByRole('dialog')
115+
.should('be.visible')
116+
.within(() => {
117+
cy.findAllByTestId('WarningIcon').first().trigger('mouseover');
100118
});
101119
cy.findByText(
102-
'A catalogue category is considered critical if any of its nested child categories or catalogue items are flagged as critical.'
120+
'Unable to determine if this catalogue category is critical. Please contact support.'
103121
);
104122
});
105123

src/catalogue/category/catalogueCard.component.tsx

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
alpha,
32
Button,
43
Card,
54
CardActions,
@@ -18,13 +17,28 @@ import { CatalogueCategory } from '../../api/api.types';
1817
import CriticalityTooltipIcon from '../../common/criticalityTooltipIcon.component';
1918
import { useAppSelector } from '../../state/hook';
2019
import { selectCriticality } from '../../state/slices/criticalitySlice';
21-
import { formatDateTimeStrings, OverflowTip } from '../../utils';
22-
import { CriticalTooltipText } from './catalogueCardView.component';
20+
import {
21+
formatDateTimeStrings,
22+
getCriticalityColor,
23+
OverflowTip,
24+
} from '../../utils';
2325
export interface CatalogueCardProps {
2426
table: MRT_TableInstance<CatalogueCategory>;
2527
card: MRT_Cell<CatalogueCategory>;
2628
}
2729

30+
export const getCriticalityLabel = (isCritical: boolean | null) => {
31+
if (isCritical === true) {
32+
return 'This catalogue category is critical.';
33+
}
34+
35+
if (isCritical === false) {
36+
return 'This catalogue category is not critical.';
37+
}
38+
39+
return 'Unable to determine if this catalogue category is critical. Please contact support.';
40+
};
41+
2842
function CatalogueCard(props: CatalogueCardProps) {
2943
const { table, card } = props;
3044
const selectedCategories = table
@@ -37,7 +51,7 @@ function CatalogueCard(props: CatalogueCardProps) {
3751

3852
const { isCriticalMode } = useAppSelector(selectCriticality);
3953

40-
const showFlagged = isCriticalMode && card.row.original.is_flagged;
54+
const showFlagged = card.row.original.is_flagged;
4155
return (
4256
<Button
4357
component={Link}
@@ -52,23 +66,24 @@ function CatalogueCard(props: CatalogueCardProps) {
5266
}}
5367
>
5468
<Card
55-
sx={(theme) => ({
56-
width: '100%',
57-
display: 'flex',
58-
flexDirection: 'row',
59-
height: '100px',
60-
backgroundColor: isSelected
61-
? table.options.mrtTheme.selectedRowBackgroundColor
62-
: undefined,
69+
sx={(theme) => {
70+
const color = isCriticalMode
71+
? getCriticalityColor({ theme, showFlagged })
72+
: undefined;
73+
return {
74+
width: '100%',
75+
display: 'flex',
76+
flexDirection: 'row',
77+
height: '100px',
78+
backgroundColor: isSelected
79+
? table.options.mrtTheme.selectedRowBackgroundColor
80+
: undefined,
6381

64-
border: showFlagged
65-
? `2px solid ${theme.palette.error.main}`
66-
: undefined,
82+
border: isCriticalMode ? `2px solid ${color}` : undefined,
6783

68-
boxShadow: showFlagged
69-
? `0 0 10px 3px ${alpha(theme.palette.error.main, 0.53)}` // ~53% opacity for fuzzy glow
70-
: undefined,
71-
})}
84+
boxShadow: isCriticalMode ? `0 0 10px 3px ${color}` : undefined, // ~53% opacity for fuzzy glow
85+
};
86+
}}
7287
>
7388
<CardActions>
7489
<MRT_SelectCheckbox
@@ -81,8 +96,11 @@ function CatalogueCard(props: CatalogueCardProps) {
8196
/>
8297
</CardActions>
8398
<CardContent sx={{ display: 'flex', alignItems: 'center', padding: 0 }}>
84-
{showFlagged && (
85-
<CriticalityTooltipIcon label={CriticalTooltipText} />
99+
{isCriticalMode && (
100+
<CriticalityTooltipIcon
101+
showFlagged={showFlagged}
102+
label={getCriticalityLabel(showFlagged)}
103+
/>
86104
)}
87105
</CardContent>
88106
<CardContent

src/catalogue/category/catalogueCardView.component.test.tsx

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ describe('CardView', () => {
316316
});
317317
});
318318

319-
it('shows critical catalogue categories and filter button', async () => {
319+
it('shows all criticality states for catalogue categories and the filter button', async () => {
320320
createView('/catalogue', undefined, {
321321
criticality: { isCriticalMode: true },
322322
});
@@ -326,7 +326,21 @@ describe('CardView', () => {
326326
});
327327

328328
expect(
329-
screen.getByRole('button', { name: 'Show Critical Items' })
329+
screen.getByRole('button', { name: 'Show Critical Categories' })
330+
).toBeInTheDocument();
331+
332+
expect(screen.getByTestId('ErrorIcon')).toBeInTheDocument();
333+
334+
await user.hover(screen.getByTestId('ErrorIcon'));
335+
336+
expect(
337+
await screen.findByText('This catalogue category is critical.')
338+
).toBeInTheDocument();
339+
340+
await user.hover(screen.getAllByTestId('CheckCircleIcon')[0]);
341+
342+
expect(
343+
await screen.findByText('This catalogue category is not critical.')
330344
).toBeInTheDocument();
331345

332346
expect(screen.getByTestId('WarningIcon')).toBeInTheDocument();
@@ -335,12 +349,12 @@ describe('CardView', () => {
335349

336350
expect(
337351
await screen.findByText(
338-
'A catalogue category is considered critical if any of its nested child categories or catalogue items are flagged as critical.'
352+
'Unable to determine if this catalogue category is critical. Please contact support.'
339353
)
340354
).toBeInTheDocument();
341355
});
342356

343-
it('clicks on shows critical Items filter button', async () => {
357+
it('clicks on shows critical Categories filter button', async () => {
344358
createView('/catalogue', undefined, {
345359
criticality: { isCriticalMode: true },
346360
});
@@ -350,7 +364,7 @@ describe('CardView', () => {
350364
});
351365

352366
await user.click(
353-
screen.getByRole('button', { name: 'Show Critical Items' })
367+
screen.getByRole('button', { name: 'Show Critical Categories' })
354368
);
355369

356370
await waitFor(() => {
@@ -359,14 +373,12 @@ describe('CardView', () => {
359373

360374
expect(screen.getByText('Critical Filter Applied')).toBeInTheDocument();
361375

362-
expect(screen.getByTestId('WarningIcon')).toBeInTheDocument();
376+
expect(screen.getByTestId('ErrorIcon')).toBeInTheDocument();
363377

364-
await user.hover(screen.getByTestId('WarningIcon'));
378+
await user.hover(screen.getByTestId('ErrorIcon'));
365379

366380
expect(
367-
await screen.findByText(
368-
'A catalogue category is considered critical if any of its nested child categories or catalogue items are flagged as critical.'
369-
)
381+
await screen.findByText('This catalogue category is critical.')
370382
).toBeInTheDocument();
371383
});
372384
describe('pagination', () => {

src/catalogue/category/catalogueCardView.component.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,11 @@ function CatalogueCardView() {
460460
{isCriticalMode && (
461461
<Button
462462
sx={{ mx: 0.5 }}
463+
startIcon={
464+
<Tooltip title={CriticalTooltipText}>
465+
<InfoOutlined />
466+
</Tooltip>
467+
}
463468
variant="outlined"
464469
disabled={isCriticalFilterApplied}
465470
onClick={() => {
@@ -468,7 +473,7 @@ function CatalogueCardView() {
468473
]);
469474
}}
470475
>
471-
Show Critical Items
476+
Show Critical Categories
472477
</Button>
473478
)}
474479
<Button

src/catalogue/category/catalogueCategoryTableView.component.test.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ describe('CatalogueCategoryTableView', () => {
142142
name: 'Energy Meters',
143143
parent_id: '1',
144144
code: 'energy-meters',
145-
is_flagged: false,
145+
is_flagged: null,
146146
is_leaf: true,
147147
properties: [
148148
{
@@ -397,14 +397,25 @@ describe('CatalogueCategoryTableView', () => {
397397
});
398398

399399
await waitFor(() => {
400-
expect(screen.getByTestId('WarningIcon')).toBeInTheDocument();
400+
expect(screen.getByTestId('ErrorIcon')).toBeInTheDocument();
401401
});
402402

403+
await user.hover(screen.getByTestId('ErrorIcon'));
404+
405+
expect(
406+
await screen.findByText('This catalogue category is critical.')
407+
).toBeInTheDocument();
408+
await user.hover(screen.getAllByTestId('CheckCircleIcon')[0]);
409+
410+
expect(
411+
await screen.findByText('This catalogue category is not critical.')
412+
).toBeInTheDocument();
413+
403414
await user.hover(screen.getByTestId('WarningIcon'));
404415

405416
expect(
406417
await screen.findByText(
407-
'A catalogue category is considered critical if any of its nested child categories or catalogue items are flagged as critical.'
418+
'Unable to determine if this catalogue category is critical. Please contact support.'
408419
)
409420
).toBeInTheDocument();
410421
});

0 commit comments

Comments
 (0)