Compare commits

...

2 Commits

Author SHA1 Message Date
575ffe761f CE-704: updates to better handling selecting variants on 'integrations', or if not valid, etc. 2023-10-19 17:00:22 -05:00
0949ee9f78 session cookie fix - to say we need it if it isn't set.
also, just let backend request set it (it already was sending header).  also, log more.  also, remove unused attribute `pathToLabelMap` from `SideNav` (was issuing warnings)
2023-10-13 08:37:19 -05:00
4 changed files with 110 additions and 35 deletions

View File

@ -62,7 +62,7 @@ export const SESSION_UUID_COOKIE_NAME = "sessionUUID";
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 [loadingToken, setLoadingToken] = useState(false);
const [isFullyAuthenticated, setIsFullyAuthenticated] = useState(false);
@ -75,8 +75,15 @@ export default function App()
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)
{
console.log("No accessToken in localStorage - so we should store a new one.");
return (true);
}
@ -91,7 +98,7 @@ export default function App()
const oldExp = oldJSON["exp"];
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);
}
@ -107,7 +114,7 @@ export default function App()
const different = JSON.stringify(newJSON) !== JSON.stringify(oldJSON);
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);
}
@ -146,8 +153,18 @@ export default function App()
{
console.log("Sending accessToken to backend, requesting a sessionUUID...");
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);
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}
branding={branding}
routes={sideNavRoutes}
pathToLabelMap={pathToLabelMap}
onMouseEnter={handleOnMouseEnter}
onMouseLeave={handleOnMouseLeave}
/>

View File

@ -34,6 +34,7 @@ import DialogContent from "@mui/material/DialogContent";
import DialogTitle from "@mui/material/DialogTitle";
import Grid from "@mui/material/Grid";
import Icon from "@mui/material/Icon";
import IconButton from "@mui/material/IconButton";
import TextField from "@mui/material/TextField";
import React, {useState} from "react";
import {useNavigate} from "react-router-dom";
@ -195,8 +196,17 @@ function GotoRecordDialog(props: Props): JSX.Element
return (
<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>
{props.subHeader}
{

View File

@ -55,7 +55,7 @@ import {DataGridPro, GridCallbackDetails, GridColDef, GridColumnMenuContainer, G
import {GridRowModel} from "@mui/x-data-grid/models/gridRows";
import FormData from "form-data";
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 {QActionsMenuButton, QCancelButton, QCreateNewButton, QSaveButton} from "qqq/components/buttons/DefaultButtons";
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(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;
if (error && error.message)
if(tableMetaData?.usesVariants)
{
errorMessage = error.message;
}
else if (error && error.response && error.response.data && error.response.data.error)
{
errorMessage = error.response.data.error;
if (error.status == "500" && error.message.indexOf("Could not find Backend Variant") != -1)
{
if (table)
{
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
{
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 (
<BaseLayout>
<TableVariantDialog table={tableMetaData} isOpen={true} closeHandler={(value: QTableVariant) =>
<TableVariantDialog navigate={navigate} table={tableMetaData} isOpen={true} closeHandler={(value: QTableVariant) =>
{
setTableVariantPromptOpen(false);
setTableVariant(value);
@ -2059,7 +2095,7 @@ function RecordQuery({table, launchProcess}: Props): JSX.Element
{
tableMetaData &&
<TableVariantDialog table={tableMetaData} isOpen={tableVariantPromptOpen} closeHandler={(value: QTableVariant) =>
<TableVariantDialog navigate={navigate} table={tableMetaData} isOpen={tableVariantPromptOpen} closeHandler={(value: QTableVariant) =>
{
setTableVariantPromptOpen(false);
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 //
////////////////////////////////////////////////////////////////////////////////////////////////////////
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 [dropDownOpen, setDropDownOpen] = useState(false)
@ -2140,7 +2176,17 @@ function TableVariantDialog(props: {isOpen: boolean; table: QTableMetaData; clos
return variants && (
<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>
<DialogContentText>Select the {props.table.variantTableLabel} to be used on this table:</DialogContentText>
<Autocomplete

View File

@ -441,17 +441,20 @@ function RecordView({table, launchProcess}: Props): JSX.Element
}
}
setPageHeader(record.recordLabel);
if(!launchingProcess)
if(record)
{
try
setPageHeader(record.recordLabel);
if(!launchingProcess)
{
HistoryUtils.push({label: `${tableMetaData?.label}: ${record.recordLabel}`, path: location.pathname, iconName: table.iconName});
}
catch(e)
{
console.error("Error pushing history: " + e);
try
{
HistoryUtils.push({label: `${tableMetaData?.label}: ${record.recordLabel}`, path: location.pathname, iconName: table.iconName});
}
catch(e)
{
console.error("Error pushing history: " + e);
}
}
}