moved error display to own component w/ burnettk

This commit is contained in:
jasquat 2022-12-30 15:05:22 -05:00
parent 4b16e0df59
commit f93a64f126
4 changed files with 129 additions and 55 deletions

View File

@ -15,6 +15,7 @@ import { ErrorForDisplay } from './interfaces';
import { AbilityContext } from './contexts/Can'; import { AbilityContext } from './contexts/Can';
import UserService from './services/UserService'; import UserService from './services/UserService';
import { Notification } from './components/Notification'; import { Notification } from './components/Notification';
import ErrorDisplay from './components/ErrorDisplay';
export default function App() { export default function App() {
const [errorObject, setErrorObject] = useState<ErrorForDisplay | null>(null); const [errorObject, setErrorObject] = useState<ErrorForDisplay | null>(null);
@ -31,51 +32,51 @@ export default function App() {
const ability = defineAbility(() => {}); const ability = defineAbility(() => {});
let errorTag = null; // let errorTag = null;
if (errorObject) { // if (errorObject) {
let sentryLinkTag = null; // let sentryLinkTag = null;
if (errorObject.sentry_link) { // if (errorObject.sentry_link) {
sentryLinkTag = ( // sentryLinkTag = (
<span> // <span>
{ // {
': Find details about this error here (it may take a moment to become available): ' // ': Find details about this error here (it may take a moment to become available): '
} // }
<a href={errorObject.sentry_link} target="_blank" rel="noreferrer"> // <a href={errorObject.sentry_link} target="_blank" rel="noreferrer">
{errorObject.sentry_link} // {errorObject.sentry_link}
</a> // </a>
</span> // </span>
); // );
} // }
//
let message = <div>{errorObject.message}</div>; // let message = <div>{errorObject.message}</div>;
let title = 'Error:'; // let title = 'Error:';
if ('task_name' in errorObject && errorObject.task_name) { // if ('task_name' in errorObject && errorObject.task_name) {
title = `Error in python script:`; // title = 'Error in python script:';
message = ( // message = (
<> // <>
<br /> // <br />
<div> // <div>
Task: {errorObject.task_name} ({errorObject.task_id}) // Task: {errorObject.task_name} ({errorObject.task_id})
</div> // </div>
<div>File name: {errorObject.file_name}</div> // <div>File name: {errorObject.file_name}</div>
<div>Line number in script task: {errorObject.line_number}</div> // <div>Line number in script task: {errorObject.line_number}</div>
<br /> // <br />
<div>{errorObject.message}</div> // <div>{errorObject.message}</div>
</> // </>
); // );
} // }
//
errorTag = ( // errorTag = (
<Notification // <Notification
title={title} // title={title}
onClose={() => setErrorObject(null)} // onClose={() => setErrorObject(null)}
type="error" // type="error"
> // >
{message} // {message}
{sentryLinkTag} // {sentryLinkTag}
</Notification> // </Notification>
); // );
} // }
return ( return (
<div className="cds--white"> <div className="cds--white">
@ -85,7 +86,7 @@ export default function App() {
<BrowserRouter> <BrowserRouter>
<NavigationBar /> <NavigationBar />
<Content> <Content>
{errorTag} <ErrorDisplay />
<ErrorBoundary> <ErrorBoundary>
<Routes> <Routes>
<Route path="/*" element={<HomePageRoutes />} /> <Route path="/*" element={<HomePageRoutes />} />

View File

@ -0,0 +1,55 @@
import { useContext } from 'react';
import ErrorContext from 'src/contexts/ErrorContext';
import { Notification } from './Notification';
export default function ErrorDisplay() {
const [errorObject, setErrorObject] = (useContext as any)(ErrorContext);
let errorTag = null;
if (errorObject) {
let sentryLinkTag = null;
if (errorObject.sentry_link) {
sentryLinkTag = (
<span>
{
': Find details about this error here (it may take a moment to become available): '
}
<a href={errorObject.sentry_link} target="_blank" rel="noreferrer">
{errorObject.sentry_link}
</a>
</span>
);
}
let message = <div>{errorObject.message}</div>;
let title = 'Error:';
if ('task_name' in errorObject && errorObject.task_name) {
title = 'Error in python script:';
message = (
<>
<br />
<div>
Task: {errorObject.task_name} ({errorObject.task_id})
</div>
<div>File name: {errorObject.file_name}</div>
<div>Line number in script task: {errorObject.line_number}</div>
<br />
<div>{errorObject.message}</div>
</>
);
}
errorTag = (
<Notification
title={title}
onClose={() => setErrorObject(null)}
type="error"
>
{message}
{sentryLinkTag}
</Notification>
);
}
return errorTag;
}

View File

@ -35,6 +35,14 @@ export const usePermissionFetcher = (
} }
}); });
ability.update(rules); ability.update(rules);
console.log('SETTING PERMISSIONS');
const thePERMMap = (ability as any).j;
console.log(
'thePERMMAP',
thePERMMap.get(
'/v1.0/process-models/misc:category_number_one:workflow_one/files'
)
);
setPermissionsLoaded(true); setPermissionsLoaded(true);
}; };
if (Object.keys(permissionsToCheck).length !== 0) { if (Object.keys(permissionsToCheck).length !== 0) {
@ -47,5 +55,5 @@ export const usePermissionFetcher = (
} }
}); });
return { ability, permissionsLoaded }; return { ability, permissionsLoaded, setPermissionsLoaded };
}; };

View File

@ -73,9 +73,8 @@ export default function ProcessModelShow() {
[targetUris.processInstanceCreatePath]: ['POST'], [targetUris.processInstanceCreatePath]: ['POST'],
[targetUris.processModelFileCreatePath]: ['POST', 'PUT', 'GET', 'DELETE'], [targetUris.processModelFileCreatePath]: ['POST', 'PUT', 'GET', 'DELETE'],
}; };
const { ability, permissionsLoaded } = usePermissionFetcher( const { ability, permissionsLoaded, setPermissionsLoaded } =
permissionRequestData usePermissionFetcher(permissionRequestData);
);
const modifiedProcessModelId = modifyProcessIdentifierForPathParam( const modifiedProcessModelId = modifyProcessIdentifierForPathParam(
`${params.process_model_id}` `${params.process_model_id}`
@ -234,6 +233,10 @@ export default function ProcessModelShow() {
const elements = []; const elements = [];
let icon = View; let icon = View;
let actionWord = 'View'; let actionWord = 'View';
console.log(
'targetUris.processModelFileCreatePath',
targetUris.processModelFileCreatePath
);
if (ability.can('PUT', targetUris.processModelFileCreatePath)) { if (ability.can('PUT', targetUris.processModelFileCreatePath)) {
icon = Edit; icon = Edit;
actionWord = 'Edit'; actionWord = 'Edit';
@ -306,6 +309,17 @@ export default function ProcessModelShow() {
if (!processModel || !permissionsLoaded) { if (!processModel || !permissionsLoaded) {
return null; return null;
} }
const permLoad = JSON.stringify(permissionsLoaded);
console.log('permLoad', permLoad);
const theMap = (ability as any).j;
// console.log('theMap', theMap[targetUris.processModelFileCreatePath]);
// console.log('theMap', theMap);
console.log(
'theMap',
theMap.get(
'/v1.0/process-models/misc:category_number_one:workflow_one/files'
)
);
let constructedTag; let constructedTag;
const tags = processModel.files.map((processModelFile: ProcessFile) => { const tags = processModel.files.map((processModelFile: ProcessFile) => {
const isPrimaryBpmnFile = const isPrimaryBpmnFile =
@ -327,11 +341,7 @@ export default function ProcessModelShow() {
let fileLink = null; let fileLink = null;
const fileUrl = profileModelFileEditUrl(processModelFile); const fileUrl = profileModelFileEditUrl(processModelFile);
if (fileUrl) { if (fileUrl) {
if (ability.can('GET', targetUris.processModelFileCreatePath)) { fileLink = <Link to={fileUrl}>{processModelFile.name}</Link>;
fileLink = <Link to={fileUrl}>{processModelFile.name}</Link>;
} else {
fileLink = <span>{processModelFile.name}</span>;
}
} }
constructedTag = ( constructedTag = (
<TableRow key={processModelFile.name}> <TableRow key={processModelFile.name}>