do not iterate over callers if undefined w/ burnettk

This commit is contained in:
jasquat 2023-04-24 17:06:28 -04:00
parent 80eabe0eb7
commit 849232be33
3 changed files with 14 additions and 5 deletions

View File

@ -64,7 +64,7 @@ import {
modifyProcessIdentifierForPathParam, modifyProcessIdentifierForPathParam,
} from '../helpers'; } from '../helpers';
import { useUriListForPermissions } from '../hooks/UriListForPermissions'; import { useUriListForPermissions } from '../hooks/UriListForPermissions';
import { PermissionsToCheck, Task } from '../interfaces'; import { PermissionsToCheck, ProcessModelCaller, Task } from '../interfaces';
import { usePermissionFetcher } from '../hooks/PermissionService'; import { usePermissionFetcher } from '../hooks/PermissionService';
type OwnProps = { type OwnProps = {
@ -89,7 +89,7 @@ type OwnProps = {
onSearchProcessModels?: (..._args: any[]) => any; onSearchProcessModels?: (..._args: any[]) => any;
onElementsChanged?: (..._args: any[]) => any; onElementsChanged?: (..._args: any[]) => any;
url?: string; url?: string;
callers?: any; callers?: ProcessModelCaller[];
}; };
// https://codesandbox.io/s/quizzical-lake-szfyo?file=/src/App.js was a handy reference // https://codesandbox.io/s/quizzical-lake-szfyo?file=/src/App.js was a handy reference
@ -575,6 +575,9 @@ export default function ReactDiagramEditor({
const canViewXml = fileName !== undefined; const canViewXml = fileName !== undefined;
const showReferences = () => { const showReferences = () => {
if (!callers) {
return null;
}
return ( return (
<Modal <Modal
open={showingReferences} open={showingReferences}
@ -583,7 +586,7 @@ export default function ReactDiagramEditor({
passiveModal passiveModal
> >
<UnorderedList> <UnorderedList>
{callers.map((ref: any) => ( {callers.map((ref: ProcessModelCaller) => (
<li> <li>
<Link <Link
size="lg" size="lg"
@ -602,7 +605,7 @@ export default function ReactDiagramEditor({
}; };
const getReferencesButton = () => { const getReferencesButton = () => {
if (callers.length > 0) { if (callers && callers.length > 0) {
let buttonText = `View ${callers.length} Reference`; let buttonText = `View ${callers.length} Reference`;
if (callers.length > 1) buttonText += 's'; if (callers.length > 1) buttonText += 's';
return ( return (

View File

@ -330,3 +330,8 @@ export interface ProcessInstanceLogEntry {
user_id?: number; user_id?: number;
username?: string; username?: string;
} }
export interface ProcessModelCaller {
display_name: string;
process_model_id: string;
}

View File

@ -34,6 +34,7 @@ import {
CarbonComboBoxProcessSelection, CarbonComboBoxProcessSelection,
ProcessFile, ProcessFile,
ProcessModel, ProcessModel,
ProcessModelCaller,
ProcessReference, ProcessReference,
} from '../interfaces'; } from '../interfaces';
import ProcessSearch from '../components/ProcessSearch'; import ProcessSearch from '../components/ProcessSearch';
@ -119,7 +120,7 @@ export default function ProcessModelEditDiagram() {
const processModelPath = `process-models/${modifiedProcessModelId}`; const processModelPath = `process-models/${modifiedProcessModelId}`;
const [callers, setCallers] = useState<Array<string>>([]); const [callers, setCallers] = useState<ProcessModelCaller[]>([]);
usePrompt('Changes you made may not be saved.', diagramHasChanges); usePrompt('Changes you made may not be saved.', diagramHasChanges);