Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,12 @@ export function Layout() {
function handler(e: Event): void {
// attempt to re-render the plugin if we get told to
const action = (e as CustomEvent).detail;
console.log(action);
if (requestPluginRerender.match(action)) forceUpdate();
else if (tokenRefreshed.match(action)) retryFailedAuthRequests();
else if (broadcastSignOut.match(action)) clearFailedAuthRequestsQueue();
else if (tokenRefreshed.match(action)) {
retryFailedAuthRequests();
window.dispatchEvent(new CustomEvent('tokenChanged')); // triggers refresh in authProvider
} else if (broadcastSignOut.match(action)) clearFailedAuthRequestsQueue();
}

React.useEffect(() => {
Expand Down
16 changes: 8 additions & 8 deletions src/authProvider.component.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import { getUserRole } from './parseTokens';
import { InventoryManagementSystemSettingsContext } from './configProvider.component';
import { isRunningInDevelopment } from './utils';
import { MicroFrontendId } from './app.types';
// import { tokenRefreshed } from './state/scigateway.actions';

const AuthContext = React.createContext<{
role: string;
Expand Down Expand Up @@ -31,14 +32,13 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
React.useEffect(() => {
setAuthorisationState();

// if dev mode add event listener for if token in localstorage changes
if (isRunningInDevelopment()) {
window.addEventListener('tokenChanged', setAuthorisationState);
// add event listener for if token in localstorage changes

return () => {
window.removeEventListener('tokenChanged', setAuthorisationState);
};
}
window.addEventListener(MicroFrontendId, setAuthorisationState);
return () => {
window.removeEventListener(MicroFrontendId, setAuthorisationState);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [setAuthorisationState]);

return (
Expand Down
36 changes: 18 additions & 18 deletions src/items/__snapshots__/itemDialog.component.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1400,15 +1400,15 @@ exports[`ItemDialog > Edit Item > displays warning when in admin mode for edit 1
tabindex="-1"
>
<div
aria-labelledby=":r3ic:"
aria-labelledby=":r3js:"
aria-modal="true"
class="MuiPaper-root MuiPaper-elevation MuiPaper-rounded MuiPaper-elevation24 MuiDialog-paper MuiDialog-paperScrollPaper MuiDialog-paperWidthXl MuiDialog-paperFullWidth css-ji9sn5-MuiPaper-root-MuiDialog-paper"
role="dialog"
style="--Paper-shadow: 0px 11px 15px -7px rgba(0,0,0,0.2),0px 24px 38px 3px rgba(0,0,0,0.14),0px 9px 46px 8px rgba(0,0,0,0.12);"
>
<h2
class="MuiTypography-root MuiTypography-h6 MuiDialogTitle-root css-19csis5-MuiTypography-root-MuiDialogTitle-root"
id=":r3ic:"
id=":r3js:"
>
Edit Item as Admin
<svg
Expand Down Expand Up @@ -1897,12 +1897,12 @@ exports[`ItemDialog > Edit Item > displays warning when in admin mode for edit 1
</span>
</div>
<input
aria-describedby=":r3in:-helper-text"
aria-describedby=":r3k7:-helper-text"
aria-invalid="false"
aria-label="Filter by Name"
autocomplete="off"
class="MuiInputBase-input MuiInput-input MuiInputBase-inputAdornedStart MuiInputBase-inputAdornedEnd css-110vr2a-MuiInputBase-input-MuiInput-input"
id=":r3in:"
id=":r3k7:"
placeholder="Filter by Name"
title="Filter by Name"
type="text"
Expand Down Expand Up @@ -1940,7 +1940,7 @@ exports[`ItemDialog > Edit Item > displays warning when in admin mode for edit 1
</div>
<p
class="MuiFormHelperText-root MuiFormHelperText-sizeMedium css-v98l45-MuiFormHelperText-root"
id=":r3in:-helper-text"
id=":r3k7:-helper-text"
>
<label>
Filter Mode: Fuzzy
Expand Down Expand Up @@ -2085,13 +2085,13 @@ exports[`ItemDialog > Edit Item > displays warning when in admin mode for edit 1
</span>
</div>
<div
aria-describedby=":r3j0:-helper-text"
aria-describedby=":r3kg:-helper-text"
aria-expanded="false"
aria-haspopup="listbox"
aria-label="Filter by Type"
aria-labelledby=":r3j0:"
aria-labelledby=":r3kg:"
class="MuiSelect-select MuiSelect-standard MuiSelect-multiple MuiInputBase-input MuiInput-input MuiInputBase-inputAdornedStart MuiInputBase-inputAdornedEnd css-10y8whu-MuiSelect-select-MuiInputBase-input-MuiInput-input"
id=":r3j0:"
id=":r3kg:"
role="combobox"
tabindex="0"
>
Expand Down Expand Up @@ -2153,7 +2153,7 @@ exports[`ItemDialog > Edit Item > displays warning when in admin mode for edit 1
</div>
<p
class="MuiFormHelperText-root MuiFormHelperText-sizeMedium css-v98l45-MuiFormHelperText-root"
id=":r3j0:-helper-text"
id=":r3kg:-helper-text"
>
<label>
Filter Mode: Includes any
Expand Down Expand Up @@ -2260,11 +2260,11 @@ exports[`ItemDialog > Edit Item > displays warning when in admin mode for edit 1
class="MuiInputBase-root MuiInput-root MuiInput-underline MuiInputBase-colorPrimary MuiInputBase-fullWidth MuiInputBase-formControl MuiInputBase-adornedEnd css-6h9cc6-MuiInputBase-root-MuiInput-root"
>
<input
aria-describedby=":r3j9:-helper-text"
aria-describedby=":r3kp:-helper-text"
aria-invalid="false"
autocomplete="off"
class="MuiInputBase-input MuiInput-input MuiInputBase-inputAdornedEnd css-1yrc8ca-MuiInputBase-input-MuiInput-input"
id=":r3j9:"
id=":r3kp:"
inputmode="text"
placeholder="Min"
type="text"
Expand Down Expand Up @@ -2295,7 +2295,7 @@ exports[`ItemDialog > Edit Item > displays warning when in admin mode for edit 1
</div>
<p
class="MuiFormHelperText-root MuiFormHelperText-sizeMedium css-18y2hez-MuiFormHelperText-root"
id=":r3j9:-helper-text"
id=":r3kp:-helper-text"
>
<label>
Filter Mode: Between Inclusive
Expand All @@ -2312,7 +2312,7 @@ exports[`ItemDialog > Edit Item > displays warning when in admin mode for edit 1
aria-invalid="false"
autocomplete="off"
class="MuiInputBase-input MuiInput-input MuiInputBase-inputAdornedEnd css-1yrc8ca-MuiInputBase-input-MuiInput-input"
id=":r3jc:"
id=":r3ks:"
inputmode="text"
placeholder="Max"
type="text"
Expand Down Expand Up @@ -2384,7 +2384,7 @@ exports[`ItemDialog > Edit Item > displays warning when in admin mode for edit 1
>
<label
class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-animated MuiFormLabel-colorPrimary MuiInputLabel-root MuiInputLabel-animated css-10j3yc8-MuiFormLabel-root-MuiInputLabel-root"
for="mrt-rows-per-page-:r3ig:"
for="mrt-rows-per-page-:r3k0:"
>
Rows per page
</label>
Expand All @@ -2405,7 +2405,7 @@ exports[`ItemDialog > Edit Item > displays warning when in admin mode for edit 1
aria-hidden="true"
aria-invalid="false"
class="MuiSelect-nativeInput css-j0riat-MuiSelect-nativeInput"
id="mrt-rows-per-page-:r3ig:"
id="mrt-rows-per-page-:r3k0:"
tabindex="-1"
value="5"
/>
Expand Down Expand Up @@ -2515,17 +2515,17 @@ exports[`ItemDialog > Edit Item > displays warning when in admin mode for edit 1
/>
</div>
<div
class="MuiPopper-root MuiTooltip-popper MuiTooltip-popperInteractive MuiTooltip-popperArrow css-jycagz-MuiPopper-root-MuiTooltip-popper"
class="MuiPopper-root MuiTooltip-popper MuiTooltip-popperInteractive MuiTooltip-popperArrow css-s8pgp9-MuiPopper-root-MuiTooltip-popper"
data-popper-escaped=""
data-popper-placement="top"
data-popper-reference-hidden=""
id=":r3id:"
id=":r3jt:"
role="tooltip"
style="position: absolute; top: auto; left: 0px; margin: 0px; right: auto; bottom: 0px; transform: translate(0px, 0px);"
>
<div
class="MuiTooltip-tooltip MuiTooltip-tooltipArrow MuiTooltip-tooltipPlacementTop css-1eex93v-MuiTooltip-tooltip"
style="opacity: 1; transform: scale(1, 1); transition: opacity 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,transform 133ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;"
style="opacity: 0; transform: scale(0.75, 0.5625); transition: opacity 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,transform 133ms cubic-bezier(0.4, 0, 0.2, 1) 67ms;"
>
As an admin, you can bypass rules that restrict item placement for other users, and you can modify the item's usage status
<span
Expand Down
2 changes: 2 additions & 0 deletions src/items/itemDialog.component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,8 @@ describe('ItemDialog', () => {
).toBeInTheDocument();
});

await user.unhover(infoIcon);

expect(baseElement).toMatchSnapshot();
});

Expand Down
4 changes: 2 additions & 2 deletions src/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from 'material-react-table';
import React from 'react';
import { useGetSparesDefinition } from './api/settings';
import { MicroFrontendToken } from './app.types';
import { MicroFrontendId, MicroFrontendToken } from './app.types';
import { SparesFilterStateType } from './app.types';

/* Returns a name avoiding duplicates by appending _copy_n for nth copy */
Expand Down Expand Up @@ -78,7 +78,7 @@ export const setLocalStorageToken = (useAdminToken: boolean) => {
);

// notify the authProvider class via new window event. This will trigger a reload.
window.dispatchEvent(new CustomEvent('tokenChanged'));
window.dispatchEvent(new CustomEvent(MicroFrontendId));
};

/* Returns a calc function giving the page height excluding SciGateway related components
Expand Down
Loading