Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit 7747b3e

Browse files
committed
update: fix error Alert disapearing when change resources (one is not found)
1 parent b071e34 commit 7747b3e

File tree

2 files changed

+153
-171
lines changed

2 files changed

+153
-171
lines changed

src/shared/containers/ResourceViewContainer.tsx

Lines changed: 144 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,8 @@ const ResourceViewContainer: React.FunctionComponent<{
124124
}
125125
) => {
126126
const { revision, tab, expanded } = opt;
127-
const pushRoute = `/${orgLabel}/${projectLabel}/resources/${resourceId}${
128-
revision ? `?rev=${revision}` : ''
129-
}${expanded ? '&expanded=true' : ''}${tab ? tab : ''}`;
127+
const pushRoute = `/${orgLabel}/${projectLabel}/resources/${resourceId}${revision ? `?rev=${revision}` : ''
128+
}${expanded ? '&expanded=true' : ''}${tab ? tab : ''}`;
130129
history.push(pushRoute, location.state);
131130
};
132131

@@ -144,12 +143,12 @@ const ResourceViewContainer: React.FunctionComponent<{
144143
busy: boolean;
145144
resource: Resource | null;
146145
error:
147-
| (Error & {
148-
action?: 'update' | 'view';
149-
rejections?: { reason: string }[];
150-
wasUpdated?: boolean;
151-
})
152-
| null;
146+
| (Error & {
147+
action?: 'update' | 'view';
148+
rejections?: { reason: string }[];
149+
wasUpdated?: boolean;
150+
})
151+
| null;
153152
}>({
154153
busy: false,
155154
resource: null,
@@ -275,13 +274,7 @@ const ResourceViewContainer: React.FunctionComponent<{
275274
busy: true,
276275
});
277276
try {
278-
const options = tag
279-
? {
280-
tag: tag.toString(),
281-
}
282-
: {
283-
rev: Number(rev),
284-
};
277+
const options = tag ? { tag: tag.toString(), } : { rev: Number(rev), };
285278
const resource = (await nexus.Resource.get(
286279
orgLabel,
287280
projectLabel,
@@ -291,11 +284,11 @@ const ResourceViewContainer: React.FunctionComponent<{
291284
const selectedResource: Resource =
292285
rev || tag
293286
? ((await nexus.Resource.get(
294-
orgLabel,
295-
projectLabel,
296-
resourceId,
297-
options
298-
)) as Resource)
287+
orgLabel,
288+
projectLabel,
289+
resourceId,
290+
options
291+
)) as Resource)
299292
: resource;
300293

301294
const expandedResources = (await nexus.Resource.get(
@@ -559,155 +552,151 @@ const ResourceViewContainer: React.FunctionComponent<{
559552
{ key: 'jira', name: 'jira', pluginComponent: jiraPlugin },
560553
{ key: 'analysis', name: 'Analysis', pluginComponent: analysisPlugin },
561554
];
562-
563555
return (
564556
<>
565557
<div className="resource-details">
566-
<>
567-
<Helmet
568-
title={`${
569-
resource ? getResourceLabel(resource) : resourceId
558+
<Helmet
559+
title={`${resource ? getResourceLabel(resource) : resourceId
570560
} | ${projectLabel} | ${orgLabel} | Nexus Web`}
571-
meta={[
572-
{
573-
name: 'description',
574-
content: resource
575-
? getResourceLabel(resource)
576-
: labelOf(decodeURIComponent(resourceId)),
577-
},
578-
]}
579-
/>
580-
{resource && (
581-
<ResourceViewActionsContainer
582-
resource={resource}
583-
latestResource={latestResource as Resource}
584-
isLatest={isLatest}
585-
orgLabel={orgLabel}
586-
projectLabel={projectLabel}
587-
/>
588-
)}
589-
<h1 className="name">
590-
<Link
591-
to={makeResourceUri(
592-
orgLabel,
593-
projectLabel,
594-
decodeURIComponent(resourceId),
595-
{}
596-
)}
597-
target="_blank"
598-
rel="noopener noreferrer"
599-
>
600-
{resource
561+
meta={[
562+
{
563+
name: 'description',
564+
content: resource
601565
? getResourceLabel(resource)
602-
: labelOf(decodeURIComponent(resourceId))}
603-
</Link>
604-
</h1>
605-
</>
566+
: labelOf(decodeURIComponent(resourceId)),
567+
},
568+
]}
569+
/>
606570

607571
<Spin spinning={busy}>
608-
{!!error && (
609-
<>
610-
<Alert
611-
message={
612-
error.wasUpdated ? 'Resource updated with errors' : 'Error'
613-
}
614-
showIcon
615-
closable
616-
type="error"
617-
description={
618-
<>
619-
<Typography.Paragraph
620-
ellipsis={{ rows: 2, expandable: true }}
621-
>
622-
{error.message}
623-
</Typography.Paragraph>
624-
{error.rejections && (
625-
<Collapse bordered={false} ghost>
626-
<Collapse.Panel key={1} header="More detail...">
627-
<>
628-
<ul>
629-
{error.rejections.map((el, ix) => (
630-
<li key={ix}>{el.reason}</li>
631-
))}
632-
</ul>
633-
634-
<p>
635-
For further information please refer to the API
636-
documentation,{' '}
637-
<a
638-
target="_blank"
639-
href="https://bluebrainnexus.io/docs/delta/api/"
640-
>
641-
https://bluebrainnexus.io/docs/delta/api/
642-
</a>
643-
</p>
644-
</>
645-
</Collapse.Panel>
646-
</Collapse>
647-
)}
648-
</>
649-
}
650-
/>
651-
<br />
652-
</>
653-
)}
654-
{resource && (
655-
<ResourceMetadata
656-
orgLabel={orgLabel}
657-
projectLabel={projectLabel}
658-
resource={resource}
572+
{!!error ? (
573+
<Alert
574+
message={
575+
error.wasUpdated ? 'Resource updated with errors' : 'Error'
576+
}
577+
showIcon
578+
closable
579+
style={{ marginTop: 40 }}
580+
type="error"
581+
description={
582+
<>
583+
<Typography.Paragraph
584+
ellipsis={{ rows: 2, expandable: true }}
585+
>
586+
{error.message}
587+
</Typography.Paragraph>
588+
{error.rejections && (
589+
<Collapse bordered={false} ghost>
590+
<Collapse.Panel key={1} header="More detail...">
591+
<>
592+
<ul>
593+
{error.rejections.map((el, ix) => (
594+
<li key={ix}>{el.reason}</li>
595+
))}
596+
</ul>
597+
598+
<p>
599+
For further information please refer to the API
600+
documentation,{' '}
601+
<a
602+
target="_blank"
603+
href="https://bluebrainnexus.io/docs/delta/api/"
604+
>
605+
https://bluebrainnexus.io/docs/delta/api/
606+
</a>
607+
</p>
608+
</>
609+
</Collapse.Panel>
610+
</Collapse>
611+
)}
612+
</>
613+
}
659614
/>
660-
)}
661-
<Divider />
662-
{!!resource && !!latestResource && (
663-
<>
664-
{!isLatest && (
665-
<Alert
666-
type="warning"
667-
message="You are viewing an older version of this resource."
668-
closable
615+
) :
616+
(<>
617+
{resource && (
618+
<ResourceViewActionsContainer
619+
resource={resource}
620+
latestResource={latestResource as Resource}
621+
isLatest={isLatest}
622+
orgLabel={orgLabel}
623+
projectLabel={projectLabel}
624+
/>
625+
)}
626+
<h1 className="name">
627+
<Link
628+
to={makeResourceUri(
629+
orgLabel,
630+
projectLabel,
631+
decodeURIComponent(resourceId),
632+
{}
633+
)}
634+
target="_blank"
635+
rel="noopener noreferrer"
636+
>
637+
{resource
638+
? getResourceLabel(resource)
639+
: labelOf(decodeURIComponent(resourceId))}
640+
</Link>
641+
</h1>
642+
{resource && (
643+
<ResourceMetadata
644+
orgLabel={orgLabel}
645+
projectLabel={projectLabel}
646+
resource={resource}
669647
/>
670648
)}
671-
{isDeprecated(resource) && (
649+
<Divider />
650+
{!!resource && !!latestResource && (
672651
<>
673-
<Alert
674-
type="error"
675-
message={
676-
<>
677-
<DeleteOutlined /> This resource is deprecated. You
678-
cannot modify it.
679-
</>
652+
{!isLatest && (
653+
<Alert
654+
type="warning"
655+
message="You are viewing an older version of this resource."
656+
closable
657+
/>
658+
)}
659+
{isDeprecated(resource) && (
660+
<>
661+
<Alert
662+
type="error"
663+
message={
664+
<>
665+
<DeleteOutlined /> This resource is deprecated. You
666+
cannot modify it.
667+
</>
668+
}
669+
/>
670+
<br />
671+
</>
672+
)}
673+
<ResourcePlugins
674+
resource={resource}
675+
goToResource={goToSelfResource}
676+
openPlugins={openPlugins}
677+
studioDefinedPluginsToInclude={
678+
studioPlugins && studioPlugins.customise
679+
? studioPlugins.plugins.map(p => p.key)
680+
: undefined
681+
}
682+
builtInPlugins={builtInPlugins}
683+
handleCollapseChange={pluginName =>
684+
pluginCollapsedToggle(pluginName)
680685
}
681686
/>
682-
<br />
687+
{!!resource['@type'] &&
688+
typeof resource['@type'] === 'string' &&
689+
nonEditableResourceTypes.includes(resource['@type']) && (
690+
<p>
691+
<Alert
692+
message="This resource is not editable because it is of the type 'File'. For further information please contact the administrator."
693+
type="info"
694+
/>
695+
</p>
696+
)}
683697
</>
684698
)}
685-
<ResourcePlugins
686-
resource={resource}
687-
goToResource={goToSelfResource}
688-
openPlugins={openPlugins}
689-
studioDefinedPluginsToInclude={
690-
studioPlugins && studioPlugins.customise
691-
? studioPlugins.plugins.map(p => p.key)
692-
: undefined
693-
}
694-
builtInPlugins={builtInPlugins}
695-
handleCollapseChange={pluginName =>
696-
pluginCollapsedToggle(pluginName)
697-
}
698-
/>
699-
{!!resource['@type'] &&
700-
typeof resource['@type'] === 'string' &&
701-
nonEditableResourceTypes.includes(resource['@type']) && (
702-
<p>
703-
<Alert
704-
message="This resource is not editable because it is of the type 'File'. For further information please contact the administrator."
705-
type="info"
706-
/>
707-
</p>
708-
)}
709-
</>
710-
)}
699+
</>)}
711700
</Spin>
712701
</div>
713702
</>

0 commit comments

Comments
 (0)