Merge pull request #3488 from nwmac/resource-not-found

Catch resource not found on ResourceDetail view
This commit is contained in:
Neil MacDougall 2021-07-19 09:56:54 +01:00 committed by GitHub
commit a96fac92a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 5 deletions

View File

@ -16,6 +16,7 @@ generic:
disabled: Disabled disabled: Disabled
done: Done done: Done
enabled: Enabled enabled: Enabled
id: ID
ignored: Ignored ignored: Ignored
invalidCron: Invalid cron schedule invalidCron: Invalid cron schedule
labelsAndAnnotations: Labels & Annotations labelsAndAnnotations: Labels & Annotations

View File

@ -52,6 +52,7 @@ export default {
align-items: center; align-items: center;
justify-content: center; justify-content: center;
flex: 1; flex: 1;
flex-direction: column;
> I { > I {
font-size: 64px; font-size: 64px;

View File

@ -11,6 +11,7 @@ import { createYaml } from '@/utils/create-yaml';
import Masthead from '@/components/ResourceDetail/Masthead'; import Masthead from '@/components/ResourceDetail/Masthead';
import DetailTop from '@/components/DetailTop'; import DetailTop from '@/components/DetailTop';
import { clone, set, diff } from '@/utils/object'; import { clone, set, diff } from '@/utils/object';
import IconMessage from '@/components/IconMessage';
function modeFor(route) { function modeFor(route) {
if ( route.query?.mode === _IMPORT ) { if ( route.query?.mode === _IMPORT ) {
@ -41,6 +42,7 @@ export default {
DetailTop, DetailTop,
ResourceYaml, ResourceYaml,
Masthead, Masthead,
IconMessage,
}, },
mixins: [CreateEditView], mixins: [CreateEditView],
@ -84,6 +86,7 @@ export default {
// As determines what component will be rendered // As determines what component will be rendered
const requested = route.query[AS]; const requested = route.query[AS];
let as; let as;
let notFound = false;
if ( mode === _VIEW && hasCustomDetail && (!requested || requested === _DETAIL) ) { if ( mode === _VIEW && hasCustomDetail && (!requested || requested === _DETAIL) ) {
as = _DETAIL; as = _DETAIL;
@ -129,11 +132,16 @@ export default {
fqid = `${ namespace }/${ fqid }`; fqid = `${ namespace }/${ fqid }`;
} }
originalModel = await store.dispatch(`${ inStore }/find`, { try {
type: resource, originalModel = await store.dispatch(`${ inStore }/find`, {
id: fqid, type: resource,
opt: { watch: true } id: fqid,
}); opt: { watch: true }
});
} catch (e) {
originalModel = {};
notFound = fqid;
}
if (realMode === _VIEW) { if (realMode === _VIEW) {
model = originalModel; model = originalModel;
@ -173,6 +181,7 @@ export default {
originalModel, originalModel,
mode, mode,
value: model, value: model,
notFound,
}; };
for ( const key in out ) { for ( const key in out ) {
@ -296,6 +305,17 @@ export default {
<template> <template>
<Loading v-if="$fetchState.pending" /> <Loading v-if="$fetchState.pending" />
<div v-else-if="notFound">
<IconMessage icon="icon-warning">
<template v-slot:message>
{{ t('generic.notFound') }}
<div>
<div>{{ t('generic.type') }}: {{ resource }}</div>
<div>{{ t('generic.id') }}: {{ notFound }}</div>
</div>
</template>
</IconMessage>
</div>
<div v-else> <div v-else>
<Masthead <Masthead
:resource="resource" :resource="resource"