mirror of
https://github.com/Kingsrook/qqq-frontend-material-dashboard.git
synced 2025-07-21 14:48:43 +00:00
Compare commits
2 Commits
snapshot-f
...
snapshot-f
Author | SHA1 | Date | |
---|---|---|---|
575ffe761f | |||
0949ee9f78 |
26
src/App.tsx
26
src/App.tsx
@ -62,7 +62,7 @@ export const SESSION_UUID_COOKIE_NAME = "sessionUUID";
|
|||||||
|
|
||||||
export default function App()
|
export default function App()
|
||||||
{
|
{
|
||||||
const [, setCookie, removeCookie] = useCookies([SESSION_UUID_COOKIE_NAME]);
|
const [cookies, setCookie, removeCookie] = useCookies([SESSION_UUID_COOKIE_NAME]);
|
||||||
const {user, getAccessTokenSilently, logout} = useAuth0();
|
const {user, getAccessTokenSilently, logout} = useAuth0();
|
||||||
const [loadingToken, setLoadingToken] = useState(false);
|
const [loadingToken, setLoadingToken] = useState(false);
|
||||||
const [isFullyAuthenticated, setIsFullyAuthenticated] = useState(false);
|
const [isFullyAuthenticated, setIsFullyAuthenticated] = useState(false);
|
||||||
@ -75,8 +75,15 @@ export default function App()
|
|||||||
|
|
||||||
const shouldStoreNewToken = (newToken: string, oldToken: string): boolean =>
|
const shouldStoreNewToken = (newToken: string, oldToken: string): boolean =>
|
||||||
{
|
{
|
||||||
|
if (!cookies[SESSION_UUID_COOKIE_NAME])
|
||||||
|
{
|
||||||
|
console.log("No session uuid cookie - so we should store a new one.");
|
||||||
|
return (true);
|
||||||
|
}
|
||||||
|
|
||||||
if (!oldToken)
|
if (!oldToken)
|
||||||
{
|
{
|
||||||
|
console.log("No accessToken in localStorage - so we should store a new one.");
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +98,7 @@ export default function App()
|
|||||||
const oldExp = oldJSON["exp"];
|
const oldExp = oldJSON["exp"];
|
||||||
if(oldExp * 1000 < (new Date().getTime()))
|
if(oldExp * 1000 < (new Date().getTime()))
|
||||||
{
|
{
|
||||||
console.log("Access token in local storage was expired.");
|
console.log("Access token in local storage was expired - so we should store a new one.");
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +114,7 @@ export default function App()
|
|||||||
const different = JSON.stringify(newJSON) !== JSON.stringify(oldJSON);
|
const different = JSON.stringify(newJSON) !== JSON.stringify(oldJSON);
|
||||||
if(different)
|
if(different)
|
||||||
{
|
{
|
||||||
console.log("Latest access token from auth0 has changed vs localStorage.");
|
console.log("Latest access token from auth0 has changed vs localStorage - so we should store a new one.");
|
||||||
}
|
}
|
||||||
return (different);
|
return (different);
|
||||||
}
|
}
|
||||||
@ -146,8 +153,18 @@ export default function App()
|
|||||||
{
|
{
|
||||||
console.log("Sending accessToken to backend, requesting a sessionUUID...");
|
console.log("Sending accessToken to backend, requesting a sessionUUID...");
|
||||||
const newSessionUuid = await qController.manageSession(accessToken, null);
|
const newSessionUuid = await qController.manageSession(accessToken, null);
|
||||||
setCookie(SESSION_UUID_COOKIE_NAME, newSessionUuid, {path: "/"});
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// the request to the backend should send a header to set the cookie, so we don't need to do it ourselves. //
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// setCookie(SESSION_UUID_COOKIE_NAME, newSessionUuid, {path: "/"});
|
||||||
|
|
||||||
localStorage.setItem("accessToken", accessToken);
|
localStorage.setItem("accessToken", accessToken);
|
||||||
|
console.log("Got new sessionUUID from backend, and stored new accessToken");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
console.log("Using existing sessionUUID cookie");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -673,7 +690,6 @@ export default function App()
|
|||||||
appName={branding.appName}
|
appName={branding.appName}
|
||||||
branding={branding}
|
branding={branding}
|
||||||
routes={sideNavRoutes}
|
routes={sideNavRoutes}
|
||||||
pathToLabelMap={pathToLabelMap}
|
|
||||||
onMouseEnter={handleOnMouseEnter}
|
onMouseEnter={handleOnMouseEnter}
|
||||||
onMouseLeave={handleOnMouseLeave}
|
onMouseLeave={handleOnMouseLeave}
|
||||||
/>
|
/>
|
||||||
|
@ -34,6 +34,7 @@ import DialogContent from "@mui/material/DialogContent";
|
|||||||
import DialogTitle from "@mui/material/DialogTitle";
|
import DialogTitle from "@mui/material/DialogTitle";
|
||||||
import Grid from "@mui/material/Grid";
|
import Grid from "@mui/material/Grid";
|
||||||
import Icon from "@mui/material/Icon";
|
import Icon from "@mui/material/Icon";
|
||||||
|
import IconButton from "@mui/material/IconButton";
|
||||||
import TextField from "@mui/material/TextField";
|
import TextField from "@mui/material/TextField";
|
||||||
import React, {useState} from "react";
|
import React, {useState} from "react";
|
||||||
import {useNavigate} from "react-router-dom";
|
import {useNavigate} from "react-router-dom";
|
||||||
@ -195,8 +196,17 @@ function GotoRecordDialog(props: Props): JSX.Element
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={props.isOpen} onClose={() => closeRequested} onKeyPress={(e) => keyPressed(e)} fullWidth maxWidth={"sm"}>
|
<Dialog open={props.isOpen} onClose={() => closeRequested} onKeyPress={(e) => keyPressed(e)} fullWidth maxWidth={"sm"}>
|
||||||
<DialogTitle>Go To...</DialogTitle>
|
<DialogTitle sx={{display: "flex"}}>
|
||||||
|
<Box sx={{display: "flex", flexGrow: 1}}>
|
||||||
|
Go To...
|
||||||
|
</Box>
|
||||||
|
<Box sx={{display: "flex"}}>
|
||||||
|
<IconButton onClick={() =>
|
||||||
|
{
|
||||||
|
document.location.href = "/";
|
||||||
|
}}><Icon sx={{align: "right"}} fontSize="small">close</Icon></IconButton>
|
||||||
|
</Box>
|
||||||
|
</DialogTitle>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
{props.subHeader}
|
{props.subHeader}
|
||||||
{
|
{
|
||||||
|
@ -55,7 +55,7 @@ import {DataGridPro, GridCallbackDetails, GridColDef, GridColumnMenuContainer, G
|
|||||||
import {GridRowModel} from "@mui/x-data-grid/models/gridRows";
|
import {GridRowModel} from "@mui/x-data-grid/models/gridRows";
|
||||||
import FormData from "form-data";
|
import FormData from "form-data";
|
||||||
import React, {forwardRef, useContext, useEffect, useReducer, useRef, useState} from "react";
|
import React, {forwardRef, useContext, useEffect, useReducer, useRef, useState} from "react";
|
||||||
import {useLocation, useNavigate, useSearchParams} from "react-router-dom";
|
import {Navigate, NavigateFunction, useLocation, useNavigate, useSearchParams} from "react-router-dom";
|
||||||
import QContext from "QContext";
|
import QContext from "QContext";
|
||||||
import {QActionsMenuButton, QCancelButton, QCreateNewButton, QSaveButton} from "qqq/components/buttons/DefaultButtons";
|
import {QActionsMenuButton, QCancelButton, QCreateNewButton, QSaveButton} from "qqq/components/buttons/DefaultButtons";
|
||||||
import MenuButton from "qqq/components/buttons/MenuButton";
|
import MenuButton from "qqq/components/buttons/MenuButton";
|
||||||
@ -752,26 +752,62 @@ function RecordQuery({table, launchProcess}: Props): JSX.Element
|
|||||||
console.log(`Received error for query ${thisQueryId}`);
|
console.log(`Received error for query ${thisQueryId}`);
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// special case for variant errors, if 500 and certain message, just clear out //
|
||||||
|
// local storage of variant and reload the page (rather than black page of death) //
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////
|
||||||
var errorMessage;
|
var errorMessage;
|
||||||
if (error && error.message)
|
if(tableMetaData?.usesVariants)
|
||||||
{
|
{
|
||||||
errorMessage = error.message;
|
if (error.status == "500" && error.message.indexOf("Could not find Backend Variant") != -1)
|
||||||
}
|
{
|
||||||
else if (error && error.response && error.response.data && error.response.data.error)
|
if (table)
|
||||||
{
|
{
|
||||||
errorMessage = error.response.data.error;
|
const tableVariantLocalStorageKey = `${TABLE_VARIANT_LOCAL_STORAGE_KEY_ROOT}.${table.name}`;
|
||||||
|
localStorage.removeItem(tableVariantLocalStorageKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (error && error.message)
|
||||||
|
{
|
||||||
|
errorMessage = error.message;
|
||||||
|
}
|
||||||
|
else if (error && error.response && error.response.data && error.response.data.error)
|
||||||
|
{
|
||||||
|
errorMessage = error.response.data.error;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
errorMessage = "Unexpected error running query";
|
||||||
|
}
|
||||||
|
|
||||||
|
setAlertContent(errorMessage);
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
errorMessage = "Unexpected error running query";
|
if (error && error.message)
|
||||||
|
{
|
||||||
|
errorMessage = error.message;
|
||||||
|
}
|
||||||
|
else if (error && error.response && error.response.data && error.response.data.error)
|
||||||
|
{
|
||||||
|
errorMessage = error.response.data.error;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
errorMessage = "Unexpected error running query";
|
||||||
|
}
|
||||||
|
|
||||||
|
queryErrors[thisQueryId] = errorMessage;
|
||||||
|
setQueryErrors(queryErrors);
|
||||||
|
setReceivedQueryErrorTimestamp(new Date());
|
||||||
|
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
|
})
|
||||||
queryErrors[thisQueryId] = errorMessage;
|
|
||||||
setQueryErrors(queryErrors);
|
|
||||||
setReceivedQueryErrorTimestamp(new Date());
|
|
||||||
|
|
||||||
throw error;
|
|
||||||
});
|
|
||||||
})();
|
})();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1889,7 +1925,7 @@ function RecordQuery({table, launchProcess}: Props): JSX.Element
|
|||||||
{
|
{
|
||||||
return (
|
return (
|
||||||
<BaseLayout>
|
<BaseLayout>
|
||||||
<TableVariantDialog table={tableMetaData} isOpen={true} closeHandler={(value: QTableVariant) =>
|
<TableVariantDialog navigate={navigate} table={tableMetaData} isOpen={true} closeHandler={(value: QTableVariant) =>
|
||||||
{
|
{
|
||||||
setTableVariantPromptOpen(false);
|
setTableVariantPromptOpen(false);
|
||||||
setTableVariant(value);
|
setTableVariant(value);
|
||||||
@ -2059,7 +2095,7 @@ function RecordQuery({table, launchProcess}: Props): JSX.Element
|
|||||||
|
|
||||||
{
|
{
|
||||||
tableMetaData &&
|
tableMetaData &&
|
||||||
<TableVariantDialog table={tableMetaData} isOpen={tableVariantPromptOpen} closeHandler={(value: QTableVariant) =>
|
<TableVariantDialog navigate={navigate} table={tableMetaData} isOpen={tableVariantPromptOpen} closeHandler={(value: QTableVariant) =>
|
||||||
{
|
{
|
||||||
setTableVariantPromptOpen(false);
|
setTableVariantPromptOpen(false);
|
||||||
setTableVariant(value);
|
setTableVariant(value);
|
||||||
@ -2091,7 +2127,7 @@ function RecordQuery({table, launchProcess}: Props): JSX.Element
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// mini-component that is the dialog for the user to select a variant on tables with variant backends //
|
// mini-component that is the dialog for the user to select a variant on tables with variant backends //
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
function TableVariantDialog(props: {isOpen: boolean; table: QTableMetaData; closeHandler: (value?: QTableVariant) => void})
|
function TableVariantDialog(props: {navigate: NavigateFunction, isOpen: boolean; table: QTableMetaData; closeHandler: (value?: QTableVariant) => void})
|
||||||
{
|
{
|
||||||
const [value, setValue] = useState(null)
|
const [value, setValue] = useState(null)
|
||||||
const [dropDownOpen, setDropDownOpen] = useState(false)
|
const [dropDownOpen, setDropDownOpen] = useState(false)
|
||||||
@ -2140,7 +2176,17 @@ function TableVariantDialog(props: {isOpen: boolean; table: QTableMetaData; clos
|
|||||||
|
|
||||||
return variants && (
|
return variants && (
|
||||||
<Dialog open={props.isOpen} onKeyPress={(e) => keyPressed(e)}>
|
<Dialog open={props.isOpen} onKeyPress={(e) => keyPressed(e)}>
|
||||||
<DialogTitle>{props.table.variantTableLabel}</DialogTitle>
|
<DialogTitle sx={{display: "flex"}}>
|
||||||
|
<Box sx={{display: "flex", flexGrow: 1}}>
|
||||||
|
{props.table.variantTableLabel}
|
||||||
|
</Box>
|
||||||
|
<Box sx={{display: "flex"}}>
|
||||||
|
<IconButton onClick={() =>
|
||||||
|
{
|
||||||
|
document.location.href = "/";
|
||||||
|
}}><Icon sx={{align: "right"}} fontSize="small">close</Icon></IconButton>
|
||||||
|
</Box>
|
||||||
|
</DialogTitle>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<DialogContentText>Select the {props.table.variantTableLabel} to be used on this table:</DialogContentText>
|
<DialogContentText>Select the {props.table.variantTableLabel} to be used on this table:</DialogContentText>
|
||||||
<Autocomplete
|
<Autocomplete
|
||||||
|
@ -441,17 +441,20 @@ function RecordView({table, launchProcess}: Props): JSX.Element
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setPageHeader(record.recordLabel);
|
if(record)
|
||||||
|
|
||||||
if(!launchingProcess)
|
|
||||||
{
|
{
|
||||||
try
|
setPageHeader(record.recordLabel);
|
||||||
|
|
||||||
|
if(!launchingProcess)
|
||||||
{
|
{
|
||||||
HistoryUtils.push({label: `${tableMetaData?.label}: ${record.recordLabel}`, path: location.pathname, iconName: table.iconName});
|
try
|
||||||
}
|
{
|
||||||
catch(e)
|
HistoryUtils.push({label: `${tableMetaData?.label}: ${record.recordLabel}`, path: location.pathname, iconName: table.iconName});
|
||||||
{
|
}
|
||||||
console.error("Error pushing history: " + e);
|
catch(e)
|
||||||
|
{
|
||||||
|
console.error("Error pushing history: " + e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user