Skip to content

Commit 575dc36

Browse files
committed
address review comments #1656
1 parent bd50c90 commit 575dc36

12 files changed

+199
-71
lines changed

src/api/api.types.tsx

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export interface Rule {
2626
export interface SparesDefinition {
2727
system_types: SystemType[];
2828
}
29+
30+
// ------------------------------------- IN USE -----------------------------------------------------
31+
32+
export type InUseDefinition = SparesDefinition;
2933
// ------------------------------------ MANUFACTURERS -----------------------------------------------
3034

3135
interface AddressPost {
@@ -46,14 +50,14 @@ export interface ManufacturerPost {
4650
telephone?: string | null;
4751
}
4852

49-
export interface ManufacturerPatch
50-
extends Partial<Omit<ManufacturerPost, 'address'>> {
53+
export interface ManufacturerPatch extends Partial<
54+
Omit<ManufacturerPost, 'address'>
55+
> {
5156
address?: AddressPatch;
5257
}
5358

5459
export interface Manufacturer
55-
extends Required<Omit<ManufacturerPost, 'address'>>,
56-
CreatedModifiedMixin {
60+
extends Required<Omit<ManufacturerPost, 'address'>>, CreatedModifiedMixin {
5761
id: string;
5862
code: string;
5963
address: Address;
@@ -138,8 +142,7 @@ export interface CatalogueCategoryPostProperty {
138142
allowed_values?: AllowedValues | null;
139143
}
140144

141-
export interface CatalogueCategoryPropertyPost
142-
extends CatalogueCategoryPostProperty {
145+
export interface CatalogueCategoryPropertyPost extends CatalogueCategoryPostProperty {
143146
// eslint-disable-next-line @typescript-eslint/no-explicit-any
144147
default_value: any;
145148
}
@@ -150,8 +153,7 @@ export interface CatalogueCategoryPropertyPatch {
150153
unit_id?: string | null;
151154
}
152155

153-
export interface CatalogueCategoryProperty
154-
extends Required<CatalogueCategoryPostProperty> {
156+
export interface CatalogueCategoryProperty extends Required<CatalogueCategoryPostProperty> {
155157
id: string;
156158
unit: string | null;
157159
}
@@ -166,7 +168,8 @@ export interface CatalogueCategoryPost {
166168
export type CatalogueCategoryPatch = Partial<CatalogueCategoryPost>;
167169

168170
export interface CatalogueCategory
169-
extends Required<Omit<CatalogueCategoryPost, 'properties'>>,
171+
extends
172+
Required<Omit<CatalogueCategoryPost, 'properties'>>,
170173
CreatedModifiedMixin {
171174
id: string;
172175
code: string;
@@ -208,7 +211,8 @@ export interface CatalogueItemPost {
208211

209212
export type CatalogueItemPatch = Partial<CatalogueItemPost>;
210213
export interface CatalogueItem
211-
extends CreatedModifiedMixin,
214+
extends
215+
CreatedModifiedMixin,
212216
Required<Omit<CatalogueItemPost, 'properties'>> {
213217
id: string;
214218
properties: Property[];
@@ -237,8 +241,7 @@ export interface ItemPost {
237241
export type ItemPatch = Partial<ItemPost>;
238242

239243
export interface Item
240-
extends CreatedModifiedMixin,
241-
Required<Omit<ItemPost, 'properties'>> {
244+
extends CreatedModifiedMixin, Required<Omit<ItemPost, 'properties'>> {
242245
id: string;
243246
usage_status: string;
244247
properties: Property[];
@@ -268,8 +271,7 @@ export interface AttachmentUploadInfo {
268271
}
269272

270273
export interface AttachmentMetadata
271-
extends Required<AttachmentPostMetadata>,
272-
CreatedModifiedMixin {
274+
extends Required<AttachmentPostMetadata>, CreatedModifiedMixin {
273275
id: string;
274276
}
275277

@@ -291,8 +293,7 @@ export interface ImagePost extends ObjectFileUploadMetadata {
291293
}
292294

293295
export interface APIImage
294-
extends Required<Omit<ImagePost, 'upload_file'>>,
295-
CreatedModifiedMixin {
296+
extends Required<Omit<ImagePost, 'upload_file'>>, CreatedModifiedMixin {
296297
id: string;
297298
primary: boolean;
298299
thumbnail_base64: string;

src/api/settings.test.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { renderHook, waitFor } from '@testing-library/react';
22
import SystemTypesJSON from '../mocks/SystemTypes.json';
33
import { hooksWrapperWithProviders } from '../testUtils';
44

5-
import { useGetSparesDefinition } from './settings';
5+
import { useGetInUseDefinition, useGetSparesDefinition } from './settings';
66

77
describe('settings api functions', () => {
88
afterEach(() => {
@@ -24,4 +24,20 @@ describe('settings api functions', () => {
2424
});
2525
});
2626
});
27+
28+
describe('useGetInUseDefinition', () => {
29+
it('sends request to fetch the in use definition and returns successful response', async () => {
30+
const { result } = renderHook(() => useGetInUseDefinition(), {
31+
wrapper: hooksWrapperWithProviders(),
32+
});
33+
34+
await waitFor(() => {
35+
expect(result.current.isSuccess).toBeTruthy();
36+
});
37+
38+
expect(result.current.data).toEqual({
39+
system_types: [SystemTypesJSON[1]],
40+
});
41+
});
42+
});
2743
});

src/api/settings.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useQuery, UseQueryResult } from '@tanstack/react-query';
22
import { AxiosError } from 'axios';
33
import { imsApi } from './api';
4-
import { SparesDefinition } from './api.types';
4+
import { InUseDefinition, SparesDefinition } from './api.types';
55

66
// This request can return a 204 status, in which case it returns an empty string.
77
const getSparesDefinition = async (): Promise<SparesDefinition | ''> => {
@@ -21,3 +21,22 @@ export const useGetSparesDefinition = (): UseQueryResult<
2121
},
2222
});
2323
};
24+
25+
// This request can return a 204 status, in which case it returns an empty string.
26+
const getInUseDefinition = async (): Promise<InUseDefinition | ''> => {
27+
return imsApi.get('/v1/settings/in-use-definition').then((response) => {
28+
return response.data;
29+
});
30+
};
31+
32+
export const useGetInUseDefinition = (): UseQueryResult<
33+
InUseDefinition | '',
34+
AxiosError
35+
> => {
36+
return useQuery({
37+
queryKey: ['InUseDefinition'],
38+
queryFn: () => {
39+
return getInUseDefinition();
40+
},
41+
});
42+
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ describe('CardView', () => {
357357
).toBeInTheDocument();
358358
});
359359

360-
it('does not show criticality states for catalogue categories and the filter button', async () => {
360+
it('does not show criticality states or the critical filter button for catalogue categories', async () => {
361361
server.use(
362362
http.get('/v1/settings/spares-definition', () => {
363363
return HttpResponse.json(undefined, { status: 204 });

src/catalogue/category/catalogueCategoryTableView.component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const CatalogueCategoryTableView = (props: CatalogueCategoryTableViewProps) => {
7171
catalogueCategoryData?.map((item) => item.name) || [];
7272

7373
const noResultsTxt = 'No catalogue categories found';
74-
console.log(isSparesDefinitionDefined);
74+
7575
const columns = React.useMemo<MRT_ColumnDef<CatalogueCategory>[]>(() => {
7676
return [
7777
...(isSparesDefinitionDefined

src/catalogue/items/catalogueItemLayout.component.test.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { screen, waitFor } from '@testing-library/react';
22
import userEvent, { UserEvent } from '@testing-library/user-event';
3+
import { http, HttpResponse } from 'msw';
4+
import APIConfigProvider from '../../apiConfigProvider.component';
5+
import { server } from '../../mocks/server';
36
import { URLPathKeyType } from '../../paths';
47
import { RootState } from '../../state/store';
58
import { renderComponentWithRouterProvider } from '../../testUtils';
@@ -17,7 +20,9 @@ describe('Catalogue Item Layout', () => {
1720
preloadedState?: Partial<RootState>
1821
) => {
1922
return renderComponentWithRouterProvider(
20-
<CatalogueItemLayout />,
23+
<APIConfigProvider>
24+
<CatalogueItemLayout />
25+
</APIConfigProvider>,
2126
urlPathKey,
2227
path,
2328
preloadedState
@@ -48,6 +53,24 @@ describe('Catalogue Item Layout', () => {
4853
).toBeInTheDocument();
4954
});
5055

56+
it('renders catalogue items landing page title correctly when spares definition is not defined', async () => {
57+
server.use(
58+
http.get('/v1/settings/spares-definition', () => {
59+
return HttpResponse.json(undefined, { status: 204 });
60+
})
61+
);
62+
createView('/catalogue/6/items/10', 'catalogueItem', {
63+
criticality: { isCriticalMode: true },
64+
});
65+
await waitFor(() => {
66+
expect(screen.getByText('Wavefront Sensors 31')).toBeInTheDocument();
67+
});
68+
69+
await waitFor(() =>
70+
expect(screen.queryByTestId('ErrorIcon')).not.toBeInTheDocument()
71+
);
72+
});
73+
5174
it('renders catalogue items landing page title correctly when is_flagged is null (critical mode)', async () => {
5275
createView('/catalogue/6/items/9', 'catalogueItem', {
5376
criticality: { isCriticalMode: true },

src/catalogue/items/catalogueItemLayout.component.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import Box from '@mui/material/Box';
22
import Typography from '@mui/material/Typography';
3+
import React from 'react';
34
import { Outlet, useLocation, useParams } from 'react-router';
45
import { useGetCatalogueItem } from '../../api/catalogueItems';
6+
import { APISettingsContext } from '../../apiConfigProvider.component';
57
import CriticalityTooltipIcon from '../../common/criticalityTooltipIcon.component';
68
import { useAppSelector } from '../../state/hook';
79
import { selectCriticality } from '../../state/slices/criticalitySlice';
@@ -14,6 +16,8 @@ function CatalogueItemLayout() {
1416
const { data: catalogueItem } = useGetCatalogueItem(catalogueItemId);
1517
const location = useLocation();
1618
const { isCriticalMode } = useAppSelector(selectCriticality);
19+
const apiSettings = React.useContext(APISettingsContext);
20+
const isSparesDefinitionDefined = !!apiSettings.spares;
1721

1822
const showFlagged = catalogueItem?.is_flagged ?? null;
1923

@@ -53,10 +57,11 @@ function CatalogueItemLayout() {
5357
gap: 1,
5458
padding: 1,
5559
...(isCriticalMode &&
60+
isSparesDefinitionDefined &&
5661
criticalityHeaderStyle({ theme, showFlagged })),
5762
})}
5863
>
59-
{isCriticalMode && (
64+
{isCriticalMode && isSparesDefinitionDefined && (
6065
<CriticalityTooltipIcon
6166
label={getCICriticalityLabel(showFlagged)}
6267
showFlagged={showFlagged}

src/catalogue/items/catalogueItemsDetailsPanel.component.tsx

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined';
21
import {
32
Box,
43
Collapse,
54
Link as MuiLink,
65
Tab,
76
Tabs,
8-
Tooltip,
97
Typography,
108
} from '@mui/material';
119
import Grid from '@mui/material/Grid2';
@@ -21,7 +19,10 @@ import PrimaryImage from '../../common/images/primaryImage.component';
2119
import { useAppSelector } from '../../state/hook';
2220
import { selectCriticality } from '../../state/slices/criticalitySlice';
2321
import { formatDateTimeStrings, roundUpTenth } from '../../utils';
24-
import { CriticalityInfoToolTip } from './catalogueItemsLandingPage.component';
22+
import {
23+
CriticalityInfoToolTip,
24+
NumberOfSparesRequiredInfoToolTip,
25+
} from './catalogueItemsLandingPage.component';
2526
import CatalogueLink from './catalogueLink.component';
2627

2728
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -197,20 +198,7 @@ function CatalogueItemsDetailsPanel(props: CatalogueItemsDetailsPanelProps) {
197198
) ?? 'None'}
198199
</Typography>
199200
{catalogueItemIdData.number_of_spares_required ===
200-
null && (
201-
<Tooltip
202-
title={
203-
'Unable to determine if the number of spares required for this catalogue item. If the expected lifetime is "None" please update this field. Otherwise wait until this is recalculated.'
204-
}
205-
placement="top"
206-
enterTouchDelay={0}
207-
arrow
208-
aria-label="number of spares required warning"
209-
sx={{ ml: 2 }}
210-
>
211-
<InfoOutlinedIcon />
212-
</Tooltip>
213-
)}
201+
null && <NumberOfSparesRequiredInfoToolTip />}
214202
</Box>
215203
</Grid>
216204
)}

src/catalogue/items/catalogueItemsLandingPage.component.tsx

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,23 @@ export const CriticalityInfoToolTip = () => {
4343
</Tooltip>
4444
);
4545
};
46+
47+
export const NumberOfSparesRequiredInfoToolTip = () => {
48+
return (
49+
<Tooltip
50+
title={
51+
'Unable to determine if the number of spares required for this catalogue item. If the expected lifetime is "None" please update this field. Otherwise wait until this is recalculated.'
52+
}
53+
placement="top"
54+
enterTouchDelay={0}
55+
arrow
56+
aria-label="number of spares required warning"
57+
sx={{ ml: 2 }}
58+
>
59+
<InfoOutlinedIcon />
60+
</Tooltip>
61+
);
62+
};
4663
const CatalogueItemsActionMenu = (props: {
4764
catalogueItem: CatalogueItem;
4865
catalogueCategory: CatalogueCategory;
@@ -134,9 +151,12 @@ function CatalogueItemsLandingPage() {
134151
{isSparesDefinitionDefined && (
135152
<>
136153
<Box sx={{ display: 'flex', alignItems: 'center' }}>
137-
<Typography variant="h6">Number of spares:</Typography>
154+
<Typography component="p" variant="h6">
155+
Number of spares:
156+
</Typography>
138157

139158
<Typography
159+
component="p"
140160
variant="h6"
141161
sx={{
142162
color: 'text.secondary',
@@ -159,9 +179,12 @@ function CatalogueItemsLandingPage() {
159179
<Box
160180
sx={{ display: 'flex', alignItems: 'center', mt: 2 }}
161181
>
162-
<Typography variant="h6">Criticality:</Typography>
182+
<Typography component="p" variant="h6">
183+
Criticality:
184+
</Typography>
163185

164186
<Typography
187+
component="p"
165188
variant="h6"
166189
sx={{
167190
color: 'text.secondary',
@@ -181,7 +204,12 @@ function CatalogueItemsLandingPage() {
181204
)}
182205
</>
183206
)}
184-
<Typography variant="h6" gutterBottom sx={{ my: 2 }}>
207+
<Typography
208+
component="p"
209+
variant="h6"
210+
gutterBottom
211+
sx={{ my: 2 }}
212+
>
185213
Description:
186214
</Typography>
187215
<Typography
@@ -344,18 +372,7 @@ function CatalogueItemsLandingPage() {
344372
</Typography>
345373
{catalogueItemIdData.number_of_spares_required ===
346374
null && (
347-
<Tooltip
348-
title={
349-
'Unable to determine if the number of spares required for this catalogue item. If the expected lifetime is "None" please update this field. Otherwise wait until this is recalculated.'
350-
}
351-
placement="top"
352-
enterTouchDelay={0}
353-
arrow
354-
aria-label="number of spares required warning"
355-
sx={{ ml: 2 }}
356-
>
357-
<InfoOutlinedIcon />
358-
</Tooltip>
375+
<NumberOfSparesRequiredInfoToolTip />
359376
)}
360377
</Box>
361378
</Grid>

0 commit comments

Comments
 (0)