Skip to content

Commit 00440d1

Browse files
committed
Add alert banner to system items dialog #1608
1 parent 97082de commit 00440d1

File tree

4 files changed

+50
-24
lines changed

4 files changed

+50
-24
lines changed

cypress/e2e/with_api/systems/functions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ export const moveItemToSystem = (values: {
160160
cy.findByText('Storage 2').click();
161161
});
162162

163-
// eslint-disable-next-line cypress/no-unnecessary-waiting
164-
cy.wait(4000);
163+
cy.findByText('Item Moving Rule Applied').should('exist');
164+
165165
cy.findByRole('button', { name: 'Move here' }).should('not.be.disabled');
166166
cy.findByRole('button', { name: 'Move here' }).click();
167167
cy.findByRole('dialog').should('not.exist', { timeout: 10000 });

cypress/e2e/with_mock_data/systems.cy.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -990,8 +990,7 @@ describe('Systems', () => {
990990
cy.findByRole('button', { name: 'navigate to systems home' }).click();
991991
cy.findByLabelText('Storage row').click();
992992

993-
// eslint-disable-next-line cypress/no-unnecessary-waiting
994-
cy.wait(4000);
993+
cy.findByText('Item Moving Rule Applied').should('exist');
995994
cy.findByRole('button', { name: 'Move here' }).click();
996995
});
997996

@@ -1069,8 +1068,7 @@ describe('Systems', () => {
10691068
cy.findByLabelText('Row Actions').first().click();
10701069
cy.findByText('Edit').click();
10711070

1072-
// eslint-disable-next-line cypress/no-unnecessary-waiting
1073-
cy.wait(100);
1071+
cy.findByText('Item Moving Rule Applied').should('exist');
10741072

10751073
cy.findByRole('button', { name: 'Next' }).click();
10761074

@@ -1102,8 +1100,7 @@ describe('Systems', () => {
11021100
cy.findByLabelText('Row Actions').first().click();
11031101
cy.findByText('Duplicate').click();
11041102

1105-
// eslint-disable-next-line cypress/no-unnecessary-waiting
1106-
cy.wait(100);
1103+
cy.findByText('Item Creation Rule Applied').should('exist');
11071104

11081105
cy.findByRole('button', { name: 'Next' }).click();
11091106
cy.findByRole('button', { name: 'Next' }).click();

src/systems/systemItemsDialog.component.test.tsx

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -222,31 +222,36 @@ describe('SystemItemsDialog', () => {
222222
await user.click(screen.getByLabelText('navigate to systems home'));
223223

224224
await waitFor(() => {
225-
expect(screen.getByText('Giant laser')).toBeInTheDocument();
225+
expect(screen.getByText('Pulse Laser')).toBeInTheDocument();
226226
});
227227

228-
await user.click(screen.getByText('Giant laser'));
228+
await user.click(screen.getByText('Pulse Laser'));
229229

230-
await waitFor(() => {
231-
expect(screen.getByText('Smaller laser')).toBeInTheDocument();
232-
});
230+
expect(
231+
await screen.findByText('Item Moving Rule Applied')
232+
).toBeInTheDocument();
233+
expect(
234+
await screen.findByLabelText(
235+
'The items usage statuses will be updated to In Use, as defined by the rules'
236+
)
237+
).toBeInTheDocument();
233238

234239
await user.click(screen.getByRole('button', { name: 'Move here' }));
235240

236241
expect(axiosPatchSpy).toHaveBeenCalledWith('/v1/items/KvT2Ox7n', {
237-
system_id: '65328f34a40ff5301575a4e3',
242+
system_id: '656da8ef9cba7a76c6f81a5d',
238243
usage_status_id: '1',
239244
});
240245
expect(axiosPatchSpy).toHaveBeenCalledWith('/v1/items/G463gOIA', {
241-
system_id: '65328f34a40ff5301575a4e3',
246+
system_id: '656da8ef9cba7a76c6f81a5d',
242247
usage_status_id: '1',
243248
});
244249

245250
expect(mockOnClose).toHaveBeenCalled();
246251
expect(mockOnChangeSelectedItems).toHaveBeenCalledWith({});
247252
}, 10000);
248253

249-
it('moves selected systems (to non-root system)', async () => {
254+
it('moves selected systems (to non-root system with the same system type)', async () => {
250255
props.parentSystemId = SystemsJSON[2].id;
251256
createView();
252257

@@ -257,22 +262,28 @@ describe('SystemItemsDialog', () => {
257262
await user.click(screen.getByLabelText('navigate to systems home'));
258263

259264
await waitFor(() => {
260-
expect(screen.getByText('Giant laser')).toBeInTheDocument();
265+
expect(screen.getByText('Pulse Laser')).toBeInTheDocument();
261266
});
262267

263-
await user.click(screen.getByText('Giant laser'));
268+
await user.click(screen.getByText('Pulse Laser'));
264269

265-
await waitFor(() => {
266-
expect(screen.getByText('Smaller laser')).toBeInTheDocument();
267-
});
270+
expect(
271+
await screen.findByText('Item Moving Rule Applied')
272+
).toBeInTheDocument();
273+
274+
expect(
275+
await screen.findByLabelText(
276+
'The items usage statuses we remain the same, as defined by the rules'
277+
)
278+
).toBeInTheDocument();
268279

269280
await user.click(screen.getByRole('button', { name: 'Move here' }));
270281

271282
expect(axiosPatchSpy).toHaveBeenCalledWith('/v1/items/KvT2Ox7n', {
272-
system_id: '65328f34a40ff5301575a4e3',
283+
system_id: '656da8ef9cba7a76c6f81a5d',
273284
});
274285
expect(axiosPatchSpy).toHaveBeenCalledWith('/v1/items/G463gOIA', {
275-
system_id: '65328f34a40ff5301575a4e3',
286+
system_id: '656da8ef9cba7a76c6f81a5d',
276287
});
277288

278289
expect(mockOnClose).toHaveBeenCalled();

src/systems/systemItemsDialog.component.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
useGetSystems,
1919
useGetSystemsBreadcrumbs,
2020
} from '../api/systems';
21+
import MRTTopTableAlert from '../common/mrtTopTableAlert.component';
2122
import handleTransferState from '../handleTransferState';
2223
import Breadcrumbs from '../view/breadcrumbs.component';
2324
import { SystemsTableView } from './systemsTableView.component';
@@ -61,7 +62,8 @@ const SystemItemsDialog = React.memo((props: SystemItemsDialogProps) => {
6162
const { data: tableRules } = useGetRules(srcSystemTypeId);
6263

6364
// This should be a list of 1 rule
64-
const { data: selectedRules } = useGetRules(srcSystemTypeId, dstSystemTypeId);
65+
const { data: selectedRules, isLoading: isSelectedRulesLoading } =
66+
useGetRules(srcSystemTypeId, dstSystemTypeId);
6567

6668
const [placeIntoSystemError, setPlaceIntoSystemError] = React.useState<
6769
string | undefined
@@ -168,6 +170,22 @@ const SystemItemsDialog = React.memo((props: SystemItemsDialogProps) => {
168170
/>
169171
</Grid>
170172
<Grid size={12}>
173+
{parentSystemId &&
174+
selectedItems.length !== 0 &&
175+
parentSystemId !== selectedItems[0].system_id &&
176+
!isSelectedRulesLoading &&
177+
!systemsDataLoading && (
178+
<MRTTopTableAlert
179+
title="Item Moving Rule Applied"
180+
showInfoTooltip
181+
infoTooltipTitle={
182+
selectedRules && selectedRules[0]
183+
? `The items usage statuses will be updated to ${selectedRules[0].dst_usage_status?.value}, as defined by the rules`
184+
: 'The items usage statuses we remain the same, as defined by the rules'
185+
}
186+
alertProps={{ elevation: 1 }}
187+
/>
188+
)}
171189
<SystemsTableView
172190
systemsData={systemsData}
173191
systemsDataLoading={systemsDataLoading}

0 commit comments

Comments
 (0)