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

Add Event schema null checks #13478

Merged
merged 3 commits into from
Feb 26, 2025
Merged
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
28 changes: 15 additions & 13 deletions shell/components/form/ResourceTabs/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,25 @@ export default {
const inStore = this.$store.getters['currentStore'](EVENT);
const eventSchema = this.$store.getters[`${ inStore }/schemaFor`](EVENT); // @TODO be smarter about which resources actually ever have events

const paginationHeaders = eventSchema ? [
Copy link
Member Author

Choose a reason for hiding this comment

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

paginationHeaders can be an empty array since the UI shows events only if event schema is not null:

    showEvents() {
      return this.isView && this.needEvents && this.eventSchema;
    },

STEVE_EVENT_LAST_SEEN,
STEVE_EVENT_TYPE,
REASON,
headerFromSchemaColString('Subobject', eventSchema, this.$store.getters, true),
headerFromSchemaColString('Source', eventSchema, this.$store.getters, true),
MESSAGE,
headerFromSchemaColString('First Seen', eventSchema, this.$store.getters, true),
headerFromSchemaColString('Count', eventSchema, this.$store.getters, true),
STEVE_NAME_COL,
] : [];

return {
eventSchema,
EVENT,
selectedTab: this.defaultTab,
selectedTab: this.defaultTab,
inStore,
showConditions: false,
paginationHeaders: [
STEVE_EVENT_LAST_SEEN,
STEVE_EVENT_TYPE,
REASON,
headerFromSchemaColString('Subobject', eventSchema, this.$store.getters, true),
headerFromSchemaColString('Source', eventSchema, this.$store.getters, true),
MESSAGE,
headerFromSchemaColString('First Seen', eventSchema, this.$store.getters, true),
headerFromSchemaColString('Count', eventSchema, this.$store.getters, true),
STEVE_NAME_COL,
]
showConditions: false,
paginationHeaders
};
},

Expand Down
5 changes: 3 additions & 2 deletions shell/pages/c/_cluster/explorer/EventsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default {

const schema = this.$store.getters['cluster/schemaFor'](EVENT);

const paginationHeaders = [
const paginationHeaders = schema ? [
Copy link
Member

Choose a reason for hiding this comment

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

Are changes to this file needed? the events table isn't shown if the type can't been seen

Copy link
Member Author

@torchiaf torchiaf Feb 24, 2025

Choose a reason for hiding this comment

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

In theory no, this is just a null check for the component itself. It doesn't hurt, I would keep it, so that if the EventTable is shown by any mistake, the UI doesn't crash.

reason,
STEVE_EVENT_OBJECT,
MESSAGE,
Expand All @@ -49,7 +49,7 @@ export default {
defaultSort: true,
},
headerFromSchemaColString('Count', schema, this.$store.getters, true),
];
] : [];

return {
schema,
Expand Down Expand Up @@ -88,6 +88,7 @@ export default {

<template>
<PaginatedResourceTable
v-if="!!schema"
:schema="schema"
:headers="eventHeaders"
:pagination-headers="paginationHeaders"
Expand Down
4 changes: 4 additions & 0 deletions shell/store/type-map.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ export function createHeaders(
* Given a schema's attribute.column value create a header
*/
export function headerFromSchemaColString(colName: string, schema: Schema, rootGetters: VuexStoreGetters, pagination: boolean, ageColumn: TableColumn): TableColumn {
if (!schema) {
throw new Error(`Unable to create header for column '${ colName }' from schema: schema is missing`);
}

const col = schema.attributes.columns.find((c) => c.name === colName);

if (!col) {
Expand Down