Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed some console errors for standard user #12479

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion shell/components/ResourceDetail/Masthead.vue
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ export default {
{{ parent.displayName }}:
</router-link>
<span v-else>{{ parent.displayName }}:</span>
<span v-if="value.detailPageHeaderActionOverride && value.detailPageHeaderActionOverride(realMode)">{{ value.detailPageHeaderActionOverride(realMode) }}</span>
<span v-if="value?.detailPageHeaderActionOverride && value?.detailPageHeaderActionOverride(realMode)">{{ value?.detailPageHeaderActionOverride(realMode) }}</span>
<t
v-else
class="masthead-resource-title"
Expand Down
63 changes: 56 additions & 7 deletions shell/components/ResourceDetail/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { clone, diff } from '@shell/utils/object';
import IconMessage from '@shell/components/IconMessage';
import ForceDirectedTreeChart from '@shell/components/fleet/ForceDirectedTreeChart';
import { checkSchemasForFindAllHash } from '@shell/utils/auth';
import { stringify } from '@shell/utils/error';
import { Banner } from '@components/Banner';

function modeFor(route) {
if ( route.query?.mode === _IMPORT ) {
Expand Down Expand Up @@ -48,6 +50,7 @@ export default {
ResourceYaml,
Masthead,
IconMessage,
Banner
},

mixins: [CreateEditView],
Expand Down Expand Up @@ -209,13 +212,23 @@ export default {
if (realMode === _VIEW) {
model = liveModel;
} else {
model = await store.dispatch(`${ inStore }/clone`, { resource: liveModel });
try {
model = await store.dispatch(`${ inStore }/clone`, { resource: liveModel });
} catch (e) {
this.errors.push(e);
}
}
try {
initialModel = await store.dispatch(`${ inStore }/clone`, { resource: liveModel });
} catch (e) {
this.errors.push(e);
}

initialModel = await store.dispatch(`${ inStore }/clone`, { resource: liveModel });

if ( as === _YAML ) {
yaml = await getYaml(this.$store, liveModel);
try {
yaml = await getYaml(this.$store, liveModel);
} catch (e) {
this.errors.push(e);
}
Comment on lines +215 to +231
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we can wrap all of these statements into a single try...catch block:

      try {
        if (realMode === _VIEW) {
          model = liveModel;
        } else {
          model = await store.dispatch(`${ inStore }/clone`, { resource: liveModel });
        }

        initialModel = await store.dispatch(`${ inStore }/clone`, { resource: liveModel });

        if ( as === _YAML ) {
          yaml = await getYaml(this.$store, liveModel);
        }
      } catch (e) {
        this.errors.push(e);
      }

}

if ( as === _GRAPH ) {
Expand All @@ -229,7 +242,9 @@ export default {
}

// Ensure common properties exists
model = await store.dispatch(`${ inStore }/cleanForDetail`, model);
try {
model = await store.dispatch(`${ inStore }/cleanForDetail`, model);
} catch (e) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we intentionally performing a noop in the catch block?


const out = {
hasGraph,
Expand Down Expand Up @@ -276,6 +291,7 @@ export default {
notFound: null,
canViewChart: true,
canViewYaml: null,
errors: []
};
},

Expand Down Expand Up @@ -315,6 +331,18 @@ export default {

return null;
},
hasErrors() {
return this.errors?.length && Array.isArray(this.errors);
},
mappedErrors() {
return !this.errors ? {} : this.errorsMap || this.errors.reduce((acc, error) => ({
...acc,
[error]: {
message: error?.data?.message || error,
icon: null
}
}), {});
},
},

watch: {
Expand Down Expand Up @@ -364,6 +392,7 @@ export default {
},

methods: {
stringify,
setSubtype(subtype) {
this.resourceSubtype = subtype;
},
Expand All @@ -375,6 +404,9 @@ export default {
m[act]();
}
},
closeError(index) {
this.errors = this.errors.filter((_, i) => i !== index);
},
}
};
</script>
Expand Down Expand Up @@ -402,6 +434,22 @@ export default {
:value="liveModel"
/>
</Masthead>
<div
v-if="hasErrors"
id="cru-errors"
class="cru__errors"
>
<Banner
v-for="(err, i) in errors"
:key="i"
color="error"
:data-testid="`error-banner${i}`"
:label="stringify(mappedErrors[err].message)"
:icon="mappedErrors[err].icon"
:closable="true"
@close="closeError(i)"
/>
</div>

<ForceDirectedTreeChart
v-if="isGraph && canViewChart"
Expand All @@ -417,9 +465,10 @@ export default {
:yaml="yaml"
:offer-preview="offerPreview"
:done-route="doneRoute"
:done-override="value.doneOverride"
:done-override="value ? value.doneOverride : null"
:class="{'flex-content': flexContent}"
@update:value="$emit('input', $event)"
@error="e=>errors.push(e)"
/>

<component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ export default {
required: true,
},
},
emits: ['error'],

async fetch() {
const inStore = this.$store.getters['currentStore']();

try {
// Fetch storage classes so we can determine if a PVC can be expanded
this.$store.dispatch(`${ inStore }/findAll`, { type: STORAGE_CLASS });

await this.$store.dispatch(`${ inStore }/findAll`, { type: STORAGE_CLASS });
} catch (e) {
this.$emit('error', e?.data || e);
}
await this.$fetchType(this.resource);
}
};
Expand Down
4 changes: 2 additions & 2 deletions shell/models/nodedriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ export default class NodeDriver extends Driver {
icon: 'icon icon-play',
bulkable: true,
bulkAction: 'activateBulk',
enabled: !!this.actions.activate && this.state === 'inactive',
enabled: !!this.actions?.activate && this.state === 'inactive',
},
{
action: 'deactivate',
label: this.t('action.deactivate'),
icon: 'icon icon-pause',
bulkable: true,
bulkAction: 'deactivateBulk',
enabled: !!this.actions.deactivate && this.state === 'active',
enabled: !!this.actions?.deactivate && this.state === 'active',
weight: -1,
},
{ divider: true },
Expand Down
Loading