feat: make the ignore rule dialog and the ignored checks clearer (#1255)

* feat: make the ignore rule dialog and the ignored checks clearer

In the ignore rule dialog, "Ignore for" becomes "Expiration" and
"Entire check" becomes "All resources". Editing an expired rule now
opens with a warning at the top that says when it expired, and only
its expiration can change until a new one is set. The warning that
the rule stays expired, shown at the bottom after a change, is gone.

In the Components table, "+ N ignored" is a link like "+ N more" and
shows that check's ignored resources. The checkbox only brings back the
checks ignored as a whole, reads "Show ignored checks" and counts them
in a badge. Checks with anything ignored get the warning banner's
background, and the filter also finds ignored resources.

Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com>

* fix: put Expiration first and keep a locked Scope from changing

An expired rule's fields wait for a new expiration, so Expiration is
now the first field of the dialog instead of coming after the fields it
unlocks.

The shell's RadioGroup still takes the Up and Down keys once it is
clicked, even when it is disabled or in view mode. So on an expired rule
a click and Up switched the locked Scope, and Save then widened a rule
for some resources to the whole check. The dialog now ignores a scope
change while the rule is locked or only viewed.

Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com>

---------

Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com>
This commit is contained in:
Marcelo Fukumoto authored and GitHub committed 2026-11-16 11:16:36 +01:00
1 parent f3ca9e4c44
commit 97ce1e90f6
6 files changed
+271 -164

No files matched your search

@@ -10,7 +10,7 @@ import { _CREATE, _EDIT, _VIEW } from '@shell/config/query-params';
import { HCI } from '../../types'; import { HCI } from '../../types';
import { import {
AFFECTED_RESOURCES_TRUNCATE_COUNT, MESSAGE_TRUNCATE_LENGTH, activeAffectedResourceNames, affectedResourceLabel, AFFECTED_RESOURCES_TRUNCATE_COUNT, MESSAGE_TRUNCATE_LENGTH, activeAffectedResourceNames, affectedResourceLabel,
allAffectedResourceNames, ignoreRuleName, ignoredResourceCount, resourceIgnoredBy, severityColor allAffectedResourceNames, hasIgnored, ignoreRuleName, ignoredResourceCount, resourceIgnoredBy, severityColor
} from '../../utils/component-health'; } from '../../utils/component-health';
const props = defineProps({ const props = defineProps({
@@ -22,10 +22,6 @@ const props = defineProps({
type: Array, type: Array,
default: () => [], default: () => [],
}, },
showIgnored: {
type: Boolean,
default: false,
},
// what is typed in the filter box of the table this one sits in // what is typed in the filter box of the table this one sits in
filterText: { filterText: {
type: String, type: String,
@@ -133,9 +129,17 @@ const hasActions = computed(() => rowsWithActions.value.some((row) => row.availa
const expandedMessageIds = ref([]); const expandedMessageIds = ref([]);
const expandedResourceIds = ref([]); const expandedResourceIds = ref([]);
const shownIgnoredIds = ref([]);
function affectedResourceNames(row) { // a check ignored as a whole lists all its resources, the others only the ones still reported
return props.showIgnored ? allAffectedResourceNames(row) : activeAffectedResourceNames(row); function listedResourceNames(row) {
return row.ignored ? allAffectedResourceNames(row) : activeAffectedResourceNames(row);
}
function ignoredResourceNames(row) {
const active = activeAffectedResourceNames(row);
return allAffectedResourceNames(row).filter((name) => !active.includes(name));
} }
// called from the template, where the refs are unwrapped, so the array is changed in place // called from the template, where the refs are unwrapped, so the array is changed in place
@@ -157,23 +161,25 @@ function displayedMessage(row, message) {
return expandedMessageIds.value.includes(row.id) || !isMessageTruncated(message) ? message : message.slice(0, MESSAGE_TRUNCATE_LENGTH); return expandedMessageIds.value.includes(row.id) || !isMessageTruncated(message) ? message : message.slice(0, MESSAGE_TRUNCATE_LENGTH);
} }
// the ignored resources come after the others, once their link is used
function visibleAffectedResourceNames(row) { function visibleAffectedResourceNames(row) {
const names = affectedResourceNames(row); const names = listedResourceNames(row);
const shown = expandedResourceIds.value.includes(row.id) ? names : names.slice(0, AFFECTED_RESOURCES_TRUNCATE_COUNT);
return expandedResourceIds.value.includes(row.id) ? names : names.slice(0, AFFECTED_RESOURCES_TRUNCATE_COUNT); return shownIgnoredIds.value.includes(row.id) ? [...shown, ...ignoredResourceNames(row)] : shown;
} }
function remainingAffectedResourcesCount(row) { function remainingAffectedResourcesCount(row) {
return Math.max(affectedResourceNames(row).length - AFFECTED_RESOURCES_TRUNCATE_COUNT, 0); return Math.max(listedResourceNames(row).length - AFFECTED_RESOURCES_TRUNCATE_COUNT, 0);
} }
function isResourceIgnored(row, name) { function isResourceIgnored(row, name) {
return row.ignored || !!resourceIgnoredBy(row, name); return row.ignored || !!resourceIgnoredBy(row, name);
} }
// the ignored resources that are left out of the list // the ignored resources of a check that is still reported, which have a link of their own
function hiddenIgnoredCount(row) { function ignoredLinkCount(row) {
return props.showIgnored ? 0 : ignoredResourceCount(row); return row.ignored ? 0 : ignoredResourceCount(row);
} }
</script> </script>
@@ -204,7 +210,7 @@ function hiddenIgnoredCount(row) {
/> />
</template> </template>
<template #cell:checkName="{row, value}"> <template #cell:checkName="{row, value}">
<span :class="{ 'text-muted': row.ignored }"> <span :class="{ 'text-muted': row.ignored, 'has-ignored': hasIgnored(row) }">
{{ value }} {{ value }}
<template v-if="row.ignored"> <template v-if="row.ignored">
({{ t('harvester.dashboard.sections.componentHealth.ignore.ignored') }}) ({{ t('harvester.dashboard.sections.componentHealth.ignore.ignored') }})
@@ -228,7 +234,7 @@ function hiddenIgnoredCount(row) {
</template> </template>
<template #cell:affectedCount="{row, value}"> <template #cell:affectedCount="{row, value}">
<div <div
v-if="affectedResourceNames(row).length" v-if="allAffectedResourceNames(row).length"
class="affected-resources" class="affected-resources"
> >
<div class="affected-title"> <div class="affected-title">
@@ -255,22 +261,31 @@ function hiddenIgnoredCount(row) {
</span> </span>
</RcTag> </RcTag>
</div> </div>
<RcButton <div
v-if="remainingAffectedResourcesCount(row)" v-if="remainingAffectedResourcesCount(row) || ignoredLinkCount(row)"
variant="link" class="affected-links"
size="small"
class="compact-link"
:aria-expanded="expandedResourceIds.includes(row.id)"
@click="toggleId(expandedResourceIds, row.id)"
> >
{{ expandedResourceIds.includes(row.id) ? t('generic.showLess') : t('generic.plusMore', { n: remainingAffectedResourcesCount(row) }) }} <RcButton
</RcButton> v-if="remainingAffectedResourcesCount(row)"
<span variant="link"
v-if="hiddenIgnoredCount(row)" size="small"
class="hidden-ignored text-muted" class="compact-link more-link"
> :aria-expanded="expandedResourceIds.includes(row.id)"
{{ t('harvester.dashboard.sections.componentHealth.ignore.plusIgnored', { n: hiddenIgnoredCount(row) }) }} @click="toggleId(expandedResourceIds, row.id)"
</span> >
{{ expandedResourceIds.includes(row.id) ? t('generic.showLess') : t('generic.plusMore', { n: remainingAffectedResourcesCount(row) }) }}
</RcButton>
<RcButton
v-if="ignoredLinkCount(row)"
variant="link"
size="small"
class="compact-link ignored-link"
:aria-expanded="shownIgnoredIds.includes(row.id)"
@click="toggleId(shownIgnoredIds, row.id)"
>
{{ shownIgnoredIds.includes(row.id) ? t('harvester.dashboard.sections.componentHealth.ignore.hideIgnored') : t('harvester.dashboard.sections.componentHealth.ignore.plusIgnored', { n: ignoredLinkCount(row) }) }}
</RcButton>
</div>
</div> </div>
<span v-else> <span v-else>
{{ t('harvester.dashboard.sections.componentHealth.noAffectedResources') }} {{ t('harvester.dashboard.sections.componentHealth.noAffectedResources') }}
@@ -280,6 +295,11 @@ function hiddenIgnoredCount(row) {
</template> </template>
<style lang="scss" scoped> <style lang="scss" scoped>
// a check with anything ignored stands out, in the colour of a warning banner
:deep(tbody tr.main-row:has(.has-ignored)) {
background-color: var(--warning-banner-bg);
}
// these sit next to text, so they line up with it // these sit next to text, so they line up with it
.compact-link { .compact-link {
--rc-button-padding: 0; --rc-button-padding: 0;
@@ -305,9 +325,10 @@ function hiddenIgnoredCount(row) {
font-size: 12px; font-size: 12px;
} }
// the same size as the "+ N more" link above it .affected-links {
.hidden-ignored { display: flex;
font-size: 12px; flex-wrap: wrap;
gap: 12px;
} }
.affected-names { .affected-names {
@@ -8,13 +8,14 @@ import { exceptionToErrorsArray } from '@shell/utils/error';
import Banner from '@components/Banner/Banner.vue'; import Banner from '@components/Banner/Banner.vue';
import { BadgeState } from '@components/BadgeState'; import { BadgeState } from '@components/BadgeState';
import { Checkbox } from '@components/Form/Checkbox'; import { Checkbox } from '@components/Form/Checkbox';
import { RcCounterBadge } from '@components/Pill';
import { RcButton } from '@components/RcButton'; import { RcButton } from '@components/RcButton';
import { useModal } from '@components/RcModal'; import { useModal } from '@components/RcModal';
import ComponentChecksTable from './ComponentChecksTable.vue'; import ComponentChecksTable from './ComponentChecksTable.vue';
import IgnoreRuleModal from './IgnoreRuleModal.vue'; import IgnoreRuleModal from './IgnoreRuleModal.vue';
import { import {
COMPONENT_HEALTH_SEVERITIES, HEALTH_SUMMARY_SEVERITY_RANK, activeAffectedResourceNames, affectedResourceKind, COMPONENT_HEALTH_SEVERITIES, HEALTH_SUMMARY_SEVERITY_RANK, affectedResourceKind, affectedResourceLabel,
affectedResourceLabel, allAffectedResourceNames, componentOf, healthSummarySeverity, ignoredCounts, severityColor allAffectedResourceNames, componentOf, healthSummarySeverity, severityColor
} from '../../utils/component-health'; } from '../../utils/component-health';
const store = useStore(); const store = useStore();
@@ -111,22 +112,13 @@ const shownChecks = computed(() => checks.value.filter((check) => showIgnored.va
check.affectedResources?.apiVersion, check.affectedResources?.apiVersion,
affectedResourceKind(check), affectedResourceKind(check),
affectedResourceLabel(check, store), affectedResourceLabel(check, store),
...(showIgnored.value ? allAffectedResourceNames(check) : activeAffectedResourceNames(check)), // the ignored resources too, they are behind a link like the ones past the first few
...allAffectedResourceNames(check),
].join(' ').toLowerCase(), ].join(' ').toLowerCase(),
}))); })));
const ignored = computed(() => ignoredCounts(checks.value)); // the checks ignored as a whole, the ones the checkbox brings back
const hasIgnored = computed(() => ignored.value.checks + ignored.value.resources > 0); const ignoredCheckCount = computed(() => checks.value.filter((check) => check.ignored).length);
// says what turning it on brings back, the same whether it is on or off
const showIgnoredLabel = computed(() => {
const counts = [
ignored.value.checks && t('harvester.dashboard.sections.componentHealth.ignoredChecks', { count: ignored.value.checks }),
ignored.value.resources && t('harvester.dashboard.sections.componentHealth.ignoredResources', { count: ignored.value.resources }),
].filter(Boolean).join(', ');
return t('harvester.dashboard.sections.componentHealth.showIgnored', { counts });
});
const rows = computed(() => { const rows = computed(() => {
const result = []; const result = [];
@@ -212,14 +204,25 @@ function collapseAll() {
> >
<template #header-left> <template #header-left>
<div <div
v-if="hasIgnored" v-if="ignoredCheckCount"
class="show-ignored" class="show-ignored"
> >
<!-- the label holds the badge, so the checkbox is named here -->
<Checkbox <Checkbox
v-model:value="showIgnored" v-model:value="showIgnored"
type="checkbox" type="checkbox"
:label="showIgnoredLabel" :alternate-label="`${ t('harvester.dashboard.sections.componentHealth.showIgnored') } ${ ignoredCheckCount }`"
/> >
<template #label>
<span class="show-ignored-label">
{{ t('harvester.dashboard.sections.componentHealth.showIgnored') }}
<RcCounterBadge
:count="ignoredCheckCount"
type="inactive"
/>
</span>
</template>
</Checkbox>
</div> </div>
</template> </template>
<template #header-right> <template #header-right>
@@ -267,7 +270,6 @@ function collapseAll() {
class="sub-table" class="sub-table"
:rows="row.checks" :rows="row.checks"
:ignore-rules="ignoreRules" :ignore-rules="ignoreRules"
:show-ignored="showIgnored"
:filter-text="filterText" :filter-text="filterText"
:load-failed="!!loadErrors.componentHealths" :load-failed="!!loadErrors.componentHealths"
@open-rule="openRuleModal" @open-rule="openRuleModal"
@@ -292,6 +294,12 @@ function collapseAll() {
height: 100%; height: 100%;
} }
.show-ignored-label {
display: inline-flex;
align-items: center;
gap: 6px;
}
.expand-actions { .expand-actions {
display: flex; display: flex;
align-items: center; align-items: center;
@@ -55,8 +55,11 @@ const resourceOptions = computed(() => [...new Set([...allAffectedResourceNames(
const chosenScope = ref(props.rule && !ruleResources.length ? 'check' : null); const chosenScope = ref(props.rule && !ruleResources.length ? 'check' : null);
const scope = computed({ const scope = computed({
get: () => chosenScope.value || (resourceOptions.value.length ? 'resources' : 'check'), get: () => chosenScope.value || (resourceOptions.value.length ? 'resources' : 'check'),
// the shell's RadioGroup still takes the arrow keys once it is clicked, even when disabled
set: (value) => { set: (value) => {
chosenScope.value = value; if (!locked.value && !isView.value) {
chosenScope.value = value;
}
}, },
}); });
// null selects every resource, the ones that are not selected are kept visible // null selects every resource, the ones that are not selected are kept visible
@@ -121,11 +124,11 @@ const editable = (ruleSpec) => ({
const hasChanges = computed(() => !props.rule || !isEqual(editable(spec.value), editable(props.rule.spec))); const hasChanges = computed(() => !props.rule || !isEqual(editable(spec.value), editable(props.rule.spec)));
// a rule that lists no resource would ignore the entire check // an expired rule applies to nothing, so it only takes changes once it has a new expiration
const canSave = computed(() => (scope.value === 'check' || selectedResources.value.length > 0) && hasChanges.value); const locked = computed(() => hasExpired && !isView.value && !duration.value);
// saving something else on an expired rule leaves it expired // a rule that lists no resource would ignore the entire check
const staysExpired = computed(() => hasExpired && !duration.value && hasChanges.value); const canSave = computed(() => !locked.value && (scope.value === 'check' || selectedResources.value.length > 0) && hasChanges.value);
const currentExpiry = computed(() => { const currentExpiry = computed(() => {
if (!expiresAt) { if (!expiresAt) {
@@ -189,6 +192,13 @@ async function save() {
@close="close" @close="close"
@primary-action="save" @primary-action="save"
> >
<Banner
v-if="hasExpired && !isView"
class="m-0"
color="warning"
data-testid="component-health-ignore-expired"
:label="t('harvester.dashboard.sections.componentHealth.ignore.expiredBanner', { date: dateTimeFormat(expiresAt, store) })"
/>
<div class="row"> <div class="row">
<div class="col span-6"> <div class="col span-6">
<LabelValue <LabelValue
@@ -203,34 +213,7 @@ async function save() {
/> />
</div> </div>
</div> </div>
<div v-if="resourceOptions.length"> <!-- first, as an expired rule's other fields wait for it -->
<RcHeading :size="4">
{{ t('harvester.dashboard.sections.componentHealth.ignore.scope') }}
</RcHeading>
<RadioGroup
v-model:value="scope"
name="ignore-scope"
:aria-label="t('harvester.dashboard.sections.componentHealth.ignore.scope')"
:mode="mode"
:options="scopeOptions"
/>
<div
v-if="scope === 'resources'"
class="ignore-resources"
>
<LabeledSelect
:value="selectedResources"
:label="t('harvester.dashboard.sections.componentHealth.ignore.resources')"
:mode="mode"
:options="resourceOptions"
:multiple="true"
:close-on-select="false"
:clearable="false"
:required="!isView"
@update:value="selected = $event"
/>
</div>
</div>
<div> <div>
<RcHeading :size="4"> <RcHeading :size="4">
{{ t('harvester.dashboard.sections.componentHealth.ignore.duration') }} {{ t('harvester.dashboard.sections.componentHealth.ignore.duration') }}
@@ -260,11 +243,42 @@ async function save() {
</p> </p>
</template> </template>
</div> </div>
<div v-if="resourceOptions.length">
<RcHeading :size="4">
{{ t('harvester.dashboard.sections.componentHealth.ignore.scope') }}
</RcHeading>
<RadioGroup
v-model:value="scope"
name="ignore-scope"
:aria-label="t('harvester.dashboard.sections.componentHealth.ignore.scope')"
:mode="mode"
:disabled="locked"
:options="scopeOptions"
/>
<div
v-if="scope === 'resources'"
class="ignore-resources"
>
<LabeledSelect
:value="selectedResources"
:label="t('harvester.dashboard.sections.componentHealth.ignore.resources')"
:mode="mode"
:options="resourceOptions"
:multiple="true"
:close-on-select="false"
:clearable="false"
:required="!isView"
:disabled="locked"
@update:value="selected = $event"
/>
</div>
</div>
<LabeledInput <LabeledInput
v-model:value="reason" v-model:value="reason"
:label="t('harvester.dashboard.sections.componentHealth.ignore.reason')" :label="t('harvester.dashboard.sections.componentHealth.ignore.reason')"
:placeholder="isView ? '' : t('harvester.dashboard.sections.componentHealth.ignore.reasonPlaceholder')" :placeholder="isView ? '' : t('harvester.dashboard.sections.componentHealth.ignore.reasonPlaceholder')"
:mode="mode" :mode="mode"
:disabled="locked"
/> />
<Banner <Banner
v-for="(err, i) in errors" v-for="(err, i) in errors"
@@ -273,13 +287,6 @@ async function save() {
color="error" color="error"
:label="err" :label="err"
/> />
<Banner
v-if="staysExpired"
class="m-0"
color="warning"
data-testid="component-health-ignore-stays-expired"
:label="t('harvester.dashboard.sections.componentHealth.ignore.staysExpired', { date: dateTimeFormat(expiresAt, store) })"
/>
<template <template
v-if="isView" v-if="isView"
@@ -9,7 +9,7 @@ import { RcCounterBadge, RcTag } from '@components/Pill';
import { RcModal } from '@components/RcModal'; import { RcModal } from '@components/RcModal';
import LabeledSelect from '@shell/components/form/LabeledSelect'; import LabeledSelect from '@shell/components/form/LabeledSelect';
import { HCI } from '../../../types'; import { HCI } from '../../../types';
import { affectedResourceLabel, ignoreRuleName, ignoredCounts, totalErrorCount } from '../../../utils/component-health'; import { affectedResourceLabel, hasIgnored, ignoreRuleName, totalErrorCount } from '../../../utils/component-health';
import HealthSummaryTable from '../HealthSummaryTable.vue'; import HealthSummaryTable from '../HealthSummaryTable.vue';
import ComponentChecksTable from '../ComponentChecksTable.vue'; import ComponentChecksTable from '../ComponentChecksTable.vue';
import IgnoreRuleModal from '../IgnoreRuleModal.vue'; import IgnoreRuleModal from '../IgnoreRuleModal.vue';
@@ -178,6 +178,7 @@ const mountRuleModal = ({
onClose, onClose,
confirm: () => w.find('[data-testid="component-health-ignore-confirm"]'), confirm: () => w.find('[data-testid="component-health-ignore-confirm"]'),
duration: () => w.findAllComponents(RadioGroup).find((group) => group.props('name') === 'ignore-duration'), duration: () => w.findAllComponents(RadioGroup).find((group) => group.props('name') === 'ignore-duration'),
scopeGroup: () => w.findAllComponents(RadioGroup).find((group) => group.props('name') === 'ignore-scope'),
currentExpiry: () => w.find('[data-testid="component-health-ignore-current-expiry"]'), currentExpiry: () => w.find('[data-testid="component-health-ignore-current-expiry"]'),
newExpiry: () => w.find('[data-testid="component-health-ignore-new-expiry"]'), newExpiry: () => w.find('[data-testid="component-health-ignore-new-expiry"]'),
warning: () => w.findAllComponents(Banner).find((banner) => banner.props('color') === 'warning'), warning: () => w.findAllComponents(Banner).find((banner) => banner.props('color') === 'warning'),
@@ -290,12 +291,7 @@ describe('health components', () => {
}); });
const filterText = () => w.findComponent(summaryTable).props('rows')[0].checksFilterText; const filterText = () => w.findComponent(summaryTable).props('rows')[0].checksFilterText;
['x', 'warning', 'a', 'some message', 'kubevirt.io/v1', 'virtualmachine', 'label of', 'vm-shown'].forEach((text) => expect(filterText()).toContain(text)); ['x', 'warning', 'a', 'some message', 'kubevirt.io/v1', 'virtualmachine', 'label of', 'vm-shown', 'vm-hidden'].forEach((text) => expect(filterText()).toContain(text));
expect(filterText()).not.toContain('vm-hidden');
await w.findComponent(Checkbox).vm.$emit('update:value', true);
expect(filterText()).toContain('vm-hidden');
}); });
it('leaves the rows as they are when filtering', async() => { it('leaves the rows as they are when filtering', async() => {
toggleExpand.mockClear(); toggleExpand.mockClear();
@@ -338,7 +334,8 @@ describe('health components', () => {
const shownRows = () => w.findComponent(ComponentChecksTable).props('rows').map((r) => r.id); const shownRows = () => w.findComponent(ComponentChecksTable).props('rows').map((r) => r.id);
expect(shownRows()).toStrictEqual(['h/b']); expect(shownRows()).toStrictEqual(['h/b']);
expect(w.text()).toContain('showIgnored'); expect(w.findComponent(Checkbox).text()).toContain('showIgnored');
expect(w.findComponent(Checkbox).findComponent(RcCounterBadge).props('count')).toBe(1);
await w.findComponent(Checkbox).vm.$emit('update:value', true); await w.findComponent(Checkbox).vm.$emit('update:value', true);
@@ -348,8 +345,14 @@ describe('health components', () => {
healthSummaries: [summaryOf({ x: { warningCount: 1 } })], healthSummaries: [summaryOf({ x: { warningCount: 1 } })],
componentHealths: [healthOf('h', 'x', { b: { severity: 'Warning' } })], componentHealths: [healthOf('h', 'x', { b: { severity: 'Warning' } })],
}); });
// its ignored resources have a link of their own in the row
const resourcesOnly = await mountSummary({
healthSummaries: [summaryOf({ x: { warningCount: 1 } })],
componentHealths: [healthOf('h', 'x', { b: { severity: 'Warning', affectedResources: { names: { one: { ignored: true }, two: {} } } } })],
});
expect(clean.text()).not.toContain('showIgnored'); expect(clean.findComponent(Checkbox).exists()).toBe(false);
expect(resourcesOnly.findComponent(Checkbox).exists()).toBe(false);
}); });
it('expands a long message', async() => { it('expands a long message', async() => {
const message = 'x'.repeat(150); const message = 'x'.repeat(150);
@@ -381,31 +384,67 @@ describe('health components', () => {
expect(w.findComponent(RcCounterBadge).props('count')).toBe(7); expect(w.findComponent(RcCounterBadge).props('count')).toBe(7);
expect(w.findAllComponents(RcTag).map((tag) => tag.text())).toStrictEqual(['two']); expect(w.findAllComponents(RcTag).map((tag) => tag.text())).toStrictEqual(['two']);
}); });
it('keeps the full count and says how many ignored resources it leaves out', () => { it('keeps the full count and shows the ignored resources from their own link', async() => {
const table = { props: ['rows'], template: '<div><slot name="cell:affectedCount" :row="rows[0]" :value="rows[0].affectedCount" /></div>' }; const table = { props: ['rows'], template: '<div><slot name="cell:affectedCount" :row="rows[0]" :value="rows[0].affectedCount" /></div>' };
const row = { const row = {
...CHECK, affectedCount: 2, affectedResources: { kind: 'Volume', names: { one: { ignored: true, ignoredBy: 'r' }, two: {} } } ...CHECK, affectedCount: 2, affectedResources: { kind: 'Volume', names: { one: { ignored: true, ignoredBy: 'r' }, two: {} } }
}; };
const hidden = mountChecks({ rows: [row] }, { SortableTable: table }); const w = mountChecks({ rows: [row] }, { SortableTable: table });
const shown = mountChecks({ rows: [row], showIgnored: true }, { SortableTable: table }); const link = () => w.find('.ignored-link');
expect(hidden.findComponent(RcCounterBadge).props('count')).toBe(2); expect(w.findComponent(RcCounterBadge).props('count')).toBe(2);
expect(hidden.find('.hidden-ignored').text()).toContain('ignore.plusIgnored'); expect(w.findAllComponents(RcTag).map((tag) => tag.find('.name').text())).toStrictEqual(['two']);
expect(shown.findComponent(RcCounterBadge).props('count')).toBe(2); expect(link().text()).toContain('ignore.plusIgnored');
expect(shown.find('.hidden-ignored').exists()).toBe(false); expect(link().attributes('aria-expanded')).toBe('false');
await link().trigger('click');
expect(w.findAllComponents(RcTag).map((tag) => tag.find('.name').text())).toStrictEqual(['two', 'one']);
expect(link().text()).toContain('ignore.hideIgnored');
expect(link().attributes('aria-expanded')).toBe('true');
await link().trigger('click');
expect(w.findAllComponents(RcTag)).toHaveLength(1);
}); });
it('counts what "Show ignored" brings back, each thing once', () => { it('puts the ignored link after the more link, and leaves it out when the whole check is ignored', () => {
const check = (ignored, names) => ({ ignored, affectedResources: { names } }); const table = { props: ['rows'], template: '<div><slot name="cell:affectedCount" :row="rows[0]" :value="rows[0].affectedCount" /></div>' };
const names = Object.fromEntries(['a', 'b', 'c', 'd'].map((name) => [name, {}]));
const row = {
...CHECK,
affectedCount: 6,
affectedResources: {
kind: 'Volume',
names: {
...names, e: { ignored: true }, f: { ignored: true }
}
}
};
const links = (r) => mountChecks({ rows: [r] }, { SortableTable: table }).findAll('.affected-links button').map((button) => (button.classes('ignored-link') ? 'ignored' : 'more'));
expect(ignoredCounts([ expect(links(row)).toStrictEqual(['more', 'ignored']);
check(true, { a: { ignored: true }, b: { ignored: true } }), expect(links({ ...row, ignored: true })).toStrictEqual(['more']);
check(false, { c: { ignored: true }, d: {} }), });
check(false, { it('tells which checks have anything ignored', () => {
e: { ignored: true }, f: { ignored: true }, g: {} expect(hasIgnored({ ignored: true })).toBe(true);
}), expect(hasIgnored({ affectedResources: { names: { a: { ignored: true }, b: {} } } })).toBe(true);
check(false, { h: {} }), expect(hasIgnored({ affectedResources: { names: { a: {} } } })).toBe(false);
])).toStrictEqual({ checks: 1, resources: 3 }); expect(hasIgnored(undefined)).toBe(false);
expect(ignoredCounts(undefined)).toStrictEqual({ checks: 0, resources: 0 }); });
it('marks the checks that have anything ignored, for their background', () => {
const table = { props: ['rows'], template: '<div><slot v-for="row in rows" name="cell:checkName" :row="row" :value="row.checkName" /></div>' };
const rows = [
{
...CHECK, id: 'whole', ignored: true
},
{
...CHECK, id: 'partly', affectedResources: { kind: 'Volume', names: { one: { ignored: true }, two: {} } }
},
{ ...CHECK, id: 'clean' },
];
const w = mountChecks({ rows }, { SortableTable: table });
expect(w.findAll('span').filter((span) => span.text().startsWith('a')).map((span) => span.classes().includes('has-ignored'))).toStrictEqual([true, true, false]);
}); });
it('names the rule of a check after it', () => { it('names the rule of a check after it', () => {
expect(ignoreRuleName('harvester-controller-vmimage', 'ImageRetryLimitExceeded')).toBe('harvester-controller-vmimage.imageretrylimitexceeded'); expect(ignoreRuleName('harvester-controller-vmimage', 'ImageRetryLimitExceeded')).toBe('harvester-controller-vmimage.imageretrylimitexceeded');
@@ -414,7 +453,7 @@ describe('health components', () => {
expect(ignoreRuleName('harvester-controller-schedulevmbackup', 'Proactive Schedule Suspend')).toBe('harvester-controller-schedulevmbackup.proactive-schedule-suspend'); expect(ignoreRuleName('harvester-controller-schedulevmbackup', 'Proactive Schedule Suspend')).toBe('harvester-controller-schedulevmbackup.proactive-schedule-suspend');
expect(ignoreRuleName('h', ' Reach_Max Failure! ')).toBe('h.reach-max-failure'); expect(ignoreRuleName('h', ' Reach_Max Failure! ')).toBe('h.reach-max-failure');
}); });
it('tells the ignored resources apart, and all of them when the check is ignored', () => { it('tells the ignored resources apart, and all of them when the check is ignored', async() => {
const table = { props: ['rows'], template: '<div><slot name="cell:severity" :row="rows[0]" /><slot name="cell:affectedCount" :row="rows[0]" :value="2" /></div>' }; const table = { props: ['rows'], template: '<div><slot name="cell:severity" :row="rows[0]" /><slot name="cell:affectedCount" :row="rows[0]" :value="2" /></div>' };
const row = { const row = {
...CHECK, severity: 'Error', affectedResources: { kind: 'Volume', names: { one: { ignored: true, ignoredBy: 'r' }, two: {} } } ...CHECK, severity: 'Error', affectedResources: { kind: 'Volume', names: { one: { ignored: true, ignoredBy: 'r' }, two: {} } }
@@ -425,15 +464,17 @@ describe('health components', () => {
const tags = (w) => w.findAllComponents(RcTag).map((tag) => ({ const tags = (w) => w.findAllComponents(RcTag).map((tag) => ({
ignored: tag.classes().includes('ignored'), disabled: tag.props('disabled'), says: tag.text().includes('ignore.ignored') ignored: tag.classes().includes('ignored'), disabled: tag.props('disabled'), says: tag.text().includes('ignore.ignored')
})); }));
const partly = mountChecks({ rows: [row], showIgnored: true }, { SortableTable: table }); const partly = mountChecks({ rows: [row] }, { SortableTable: table });
const whole = mountChecks({ rows: [wholeRow], showIgnored: true }, { SortableTable: table }); const whole = mountChecks({ rows: [wholeRow] }, { SortableTable: table });
await partly.find('.ignored-link').trigger('click');
expect(tags(partly)).toStrictEqual([ expect(tags(partly)).toStrictEqual([
{ {
ignored: true, disabled: true, says: true ignored: false, disabled: false, says: false
}, },
{ {
ignored: false, disabled: false, says: false ignored: true, disabled: true, says: true
}, },
]); ]);
expect(partly.findComponent(BadgeState).props('color')).toBe('bg-error'); expect(partly.findComponent(BadgeState).props('color')).toBe('bg-error');
@@ -518,17 +559,25 @@ describe('health components', () => {
expect(onFindAll.mock.calls.map(([type]) => type)).toStrictEqual([HCI.HEALTH_SUMMARY, HCI.COMPONENT_HEALTH]); expect(onFindAll.mock.calls.map(([type]) => type)).toStrictEqual([HCI.HEALTH_SUMMARY, HCI.COMPONENT_HEALTH]);
}); });
it('marks a check and the resources that are ignored', () => { it('marks a check and the resources that are ignored', async() => {
const table = { const table = {
props: ['rows'], props: ['rows'],
template: '<div><slot name="cell:checkName" :row="rows[0]" :value="rows[0].checkName" /><slot name="cell:affectedCount" :row="rows[0]" :value="2" /></div>', template: '<div><slot name="cell:checkName" :row="rows[0]" :value="rows[0].checkName" /><slot name="cell:affectedCount" :row="rows[0]" :value="2" /></div>',
}; };
const row = { ...CHECK, affectedResources: { kind: 'VirtualMachine', names: { one: { ignored: true, ignoredBy: 'r' }, two: {} } } }; const row = { ...CHECK, affectedResources: { kind: 'VirtualMachine', names: { one: { ignored: true, ignoredBy: 'r' }, two: {} } } };
const textOf = (props) => mountChecks({ showIgnored: true, ...props }, { SortableTable: table }).text().replace(/\s+/g, ' '); const textOf = async(props) => {
const w = mountChecks(props, { SortableTable: table });
expect(textOf({ rows: [row] })).toMatch(/one ?\(%harvester\.dashboard\.sections\.componentHealth\.ignore\.ignored%\) ?two/); await w.find('.ignored-link').trigger('click');
expect(textOf({ rows: [row] })).not.toContain('a (%harvester');
expect(textOf({ rows: [{ ...row, ignored: true }] })).toContain('a (%harvester.dashboard.sections.componentHealth.ignore.ignored%)'); return w.text().replace(/\s+/g, ' ');
};
const partlyText = await textOf({ rows: [row] });
expect(partlyText).toMatch(/two ?one ?\(%harvester\.dashboard\.sections\.componentHealth\.ignore\.ignored%\)/);
expect(partlyText).not.toContain('a (%harvester');
expect(mountChecks({ rows: [{ ...row, ignored: true }] }, { SortableTable: table }).text().replace(/\s+/g, ' ')).toContain('a (%harvester.dashboard.sections.componentHealth.ignore.ignored%)');
}); });
describe('the actions of a check', () => { describe('the actions of a check', () => {
@@ -665,8 +714,9 @@ describe('health components', () => {
expect(confirm().attributes('disabled')).toBeUndefined(); expect(confirm().attributes('disabled')).toBeUndefined();
}); });
it('ignores the entire check forever without listing its resources', async() => { it('ignores the entire check forever without listing its resources', async() => {
const { w, confirm } = mountRuleModal(); const { confirm, scopeGroup, duration: durationGroup } = mountRuleModal();
const [scope, duration] = w.findAllComponents(RadioGroup); const scope = scopeGroup();
const duration = durationGroup();
await scope.vm.$emit('update:value', 'check'); await scope.vm.$emit('update:value', 'check');
await duration.vm.$emit('update:value', 'forever'); await duration.vm.$emit('update:value', 'forever');
@@ -736,9 +786,9 @@ describe('health components', () => {
resources: ['two'], expiresAt: IN_A_WEEK, reason: 'known issue' resources: ['two'], expiresAt: IN_A_WEEK, reason: 'known issue'
}); });
const { const {
w, duration, currentExpiry, newExpiry w, duration, currentExpiry, newExpiry, scopeGroup
} = mountRuleModal({ rule, mode: 'edit' }); } = mountRuleModal({ rule, mode: 'edit' });
const [scope] = w.findAllComponents(RadioGroup); const scope = scopeGroup();
expect(scope.props('value')).toBe('resources'); expect(scope.props('value')).toBe('resources');
expect(w.findComponent(LabeledSelect).props('value')).toStrictEqual(['two']); expect(w.findComponent(LabeledSelect).props('value')).toStrictEqual(['two']);
@@ -794,7 +844,7 @@ describe('health components', () => {
}), }),
mode: 'edit' mode: 'edit'
}); });
const [scope] = w.findAllComponents(RadioGroup); const scope = w.findAllComponents(RadioGroup).find((group) => group.props('name') === 'ignore-scope');
await scope.vm.$emit('update:value', 'check'); await scope.vm.$emit('update:value', 'check');
await duration().vm.$emit('update:value', 'forever'); await duration().vm.$emit('update:value', 'forever');
@@ -822,34 +872,59 @@ describe('health components', () => {
expect(new Date(editedRule.spec.expiresAt).getTime()).toBeGreaterThan(new Date(IN_A_WEEK).getTime()); expect(new Date(editedRule.spec.expiresAt).getTime()).toBeGreaterThan(new Date(IN_A_WEEK).getTime());
}); });
it('warns that an expired rule stays expired when only something else changes', async() => { it('opens an expired rule with a warning on top, and only its expiration can change until a new one is set', async() => {
const { w, duration, warning } = mountRuleModal({ rule: ruleOf({ expiresAt: LAST_WEEK }), mode: 'edit' }); const {
w, confirm, duration, warning, scopeGroup
} = mountRuleModal({ rule: ruleOf({ expiresAt: LAST_WEEK, resources: ['one'] }), mode: 'edit' });
const locked = () => ({
scope: w.findAllComponents(RadioGroup).find((group) => group.props('name') === 'ignore-scope').props('disabled'),
resources: w.findComponent(LabeledSelect).props('disabled'),
reason: w.findComponent(LabeledInput).props('disabled'),
expiration: duration().props('disabled'),
save: confirm().attributes('disabled') !== undefined,
});
expect(warning()).toBeUndefined(); expect(warning().props('label')).toContain('ignore.expiredBanner');
expect(w.find('[data-testid="rc-modal-body"]').element.firstElementChild.getAttribute('data-testid')).toBe('component-health-ignore-expired');
expect(locked()).toStrictEqual({
scope: true, resources: true, reason: true, expiration: false, save: true
});
expect(w.findAllComponents(RadioGroup).map((group) => group.props('name'))).toStrictEqual(['ignore-duration', 'ignore-scope']);
await w.findComponent(LabeledInput).vm.$emit('update:value', 'known issue'); // what the shell's RadioGroup sends for a click and the Up key, although it is disabled
await scopeGroup().vm.$emit('update:value', 'check');
await flushPromises(); await flushPromises();
expect(warning().props('label')).toContain('ignore.staysExpired'); expect(scopeGroup().props('value')).toBe('resources');
await duration().vm.$emit('update:value', 'days7'); await duration().vm.$emit('update:value', 'days7');
await flushPromises(); await flushPromises();
expect(warning()).toBeUndefined(); expect(locked()).toStrictEqual({
}); scope: false, resources: false, reason: false, expiration: false, save: false
it('does not warn about a rule that has not expired', async() => { });
const { w, warning } = mountRuleModal({ rule: ruleOf({ expiresAt: IN_A_WEEK }), mode: 'edit' }); expect(warning().props('label')).toContain('ignore.expiredBanner');
await w.findComponent(LabeledInput).vm.$emit('update:value', 'known issue'); await scopeGroup().vm.$emit('update:value', 'check');
await flushPromises(); await flushPromises();
expect(scopeGroup().props('value')).toBe('check');
});
it('neither warns nor locks a rule that has not expired, or an expired one that is only viewed', async() => {
const { w, warning } = mountRuleModal({ rule: ruleOf({ expiresAt: IN_A_WEEK }), mode: 'edit' });
expect(warning()).toBeUndefined(); expect(warning()).toBeUndefined();
expect(w.findComponent(LabeledInput).props('disabled')).toBe(false);
const viewed = mountRuleModal({ rule: ruleOf({ expiresAt: LAST_WEEK }), mode: 'view' });
expect(viewed.warning()).toBeUndefined();
}); });
it('opens a rule without resources on the entire check, and selects them all when asked', async() => { it('opens a rule without resources on the entire check, and selects them all when asked', async() => {
const { const {
w, confirm, duration, currentExpiry w, confirm, duration, currentExpiry, scopeGroup
} = mountRuleModal({ rule: ruleOf(), mode: 'edit' }); } = mountRuleModal({ rule: ruleOf(), mode: 'edit' });
const [scope] = w.findAllComponents(RadioGroup); const scope = scopeGroup();
expect(scope.props('value')).toBe('check'); expect(scope.props('value')).toBe('check');
expect(currentExpiry().text()).toContain('ignore.neverExpires'); expect(currentExpiry().text()).toContain('ignore.neverExpires');
@@ -885,7 +960,7 @@ describe('health components', () => {
describe('viewing a rule', () => { describe('viewing a rule', () => {
it('shows what the rule has without letting it change', async() => { it('shows what the rule has without letting it change', async() => {
const { const {
w, onClose, confirm, duration, currentExpiry w, onClose, confirm, duration, currentExpiry, scopeGroup
} = mountRuleModal({ } = mountRuleModal({
rule: ruleOf({ rule: ruleOf({
resources: ['two'], expiresAt: IN_A_WEEK, reason: 'known issue' resources: ['two'], expiresAt: IN_A_WEEK, reason: 'known issue'
@@ -893,6 +968,11 @@ describe('health components', () => {
mode: 'view' mode: 'view'
}); });
await scopeGroup().vm.$emit('update:value', 'check');
await flushPromises();
expect(scopeGroup().props('value')).toBe('resources');
[...w.findAllComponents(RadioGroup), w.findComponent(LabeledSelect), w.findComponent(LabeledInput)].forEach((field) => { [...w.findAllComponents(RadioGroup), w.findComponent(LabeledSelect), w.findComponent(LabeledInput)].forEach((field) => {
expect(field.props('mode')).toBe('view'); expect(field.props('mode')).toBe('view');
}); });
+5 -6
View File
@@ -531,9 +531,7 @@ harvester:
noAffectedResources: No affected resources noAffectedResources: No affected resources
noIssues: No issues detected noIssues: No issues detected
checksNotLoaded: Unable to load the checks checksNotLoaded: Unable to load the checks
showIgnored: 'Show ignored ({counts})' showIgnored: Show ignored checks
ignoredChecks: '{count, plural, =1 {1 check} other {# checks}}'
ignoredResources: '{count, plural, =1 {1 resource} other {# resources}}'
loadFailed: loadFailed:
healthSummaries: 'Unable to load the health summary: {error}' healthSummaries: 'Unable to load the health summary: {error}'
componentHealths: 'Unable to load the checks: {error}' componentHealths: 'Unable to load the checks: {error}'
@@ -545,11 +543,12 @@ harvester:
delete: Delete Ignore Rule delete: Delete Ignore Rule
ignored: Ignored ignored: Ignored
plusIgnored: '+ {n} ignored' plusIgnored: '+ {n} ignored'
hideIgnored: Hide ignored
scope: Scope scope: Scope
scopeResources: Selected resources scopeResources: Selected resources
scopeCheck: Entire check scopeCheck: All resources
resources: Resources resources: Resources
duration: Ignore for duration: Expiration
days7: 7 days days7: 7 days
days30: 30 days days30: 30 days
forever: Forever forever: Forever
@@ -558,7 +557,7 @@ harvester:
neverExpires: Never expires neverExpires: Never expires
willExpireOn: 'Will expire on {date}' willExpireOn: 'Will expire on {date}'
willNeverExpire: Will never expire willNeverExpire: Will never expire
staysExpired: 'This rule expired on {date} and stays expired unless you choose how long to ignore for.' expiredBanner: 'This rule expired on {date}. To make any changes, set a new expiration to re-enable this rule.'
reason: Reason reason: Reason
reasonPlaceholder: Why is it ignored? (optional) reasonPlaceholder: Why is it ignored? (optional)
created: The ignore rule of {name} is created created: The ignore rule of {name} is created
+3 -11
View File
@@ -73,17 +73,9 @@ export function ignoredResourceCount(row) {
return allAffectedResourceNames(row).length - activeAffectedResourceNames(row).length; return allAffectedResourceNames(row).length - activeAffectedResourceNames(row).length;
} }
// what "Show ignored" brings back: the checks ignored as a whole, and the ignored resources of the other checks // the check is ignored as a whole, or some of its resources are
export function ignoredCounts(checks) { export function hasIgnored(check) {
return (checks || []).reduce((counts, check) => { return !!check?.ignored || ignoredResourceCount(check) > 0;
if (check.ignored) {
counts.checks += 1;
} else {
counts.resources += ignoredResourceCount(check);
}
return counts;
}, { checks: 0, resources: 0 });
} }
// the UI keeps one rule per check under this name, so Kubernetes refuses a second one for the same check. // the UI keeps one rule per check under this name, so Kubernetes refuses a second one for the same check.