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

* 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.



* 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.



---------


(cherry picked from commit 97ce1e90f6)

Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com>
Co-authored-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com>
This commit is contained in:
mergify[bot]andMarcelo Fukumoto authored and GitHub committed 2026-11-20 19:52:45 +08:00
1 parent 47a9de7661
commit 38473b1e90
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 {
AFFECTED_RESOURCES_TRUNCATE_COUNT, MESSAGE_TRUNCATE_LENGTH, activeAffectedResourceNames, affectedResourceLabel,
allAffectedResourceNames, ignoreRuleName, ignoredResourceCount, resourceIgnoredBy, severityColor
allAffectedResourceNames, hasIgnored, ignoreRuleName, ignoredResourceCount, resourceIgnoredBy, severityColor
} from '../../utils/component-health';
const props = defineProps({
@@ -22,10 +22,6 @@ const props = defineProps({
type: Array,
default: () => [],
},
showIgnored: {
type: Boolean,
default: false,
},
// what is typed in the filter box of the table this one sits in
filterText: {
type: String,
@@ -133,9 +129,17 @@ const hasActions = computed(() => rowsWithActions.value.some((row) => row.availa
const expandedMessageIds = ref([]);
const expandedResourceIds = ref([]);
const shownIgnoredIds = ref([]);
function affectedResourceNames(row) {
return props.showIgnored ? allAffectedResourceNames(row) : activeAffectedResourceNames(row);
// a check ignored as a whole lists all its resources, the others only the ones still reported
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
@@ -157,23 +161,25 @@ function displayedMessage(row, message) {
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) {
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) {
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) {
return row.ignored || !!resourceIgnoredBy(row, name);
}
// the ignored resources that are left out of the list
function hiddenIgnoredCount(row) {
return props.showIgnored ? 0 : ignoredResourceCount(row);
// the ignored resources of a check that is still reported, which have a link of their own
function ignoredLinkCount(row) {
return row.ignored ? 0 : ignoredResourceCount(row);
}
</script>
@@ -204,7 +210,7 @@ function hiddenIgnoredCount(row) {
/>
</template>
<template #cell:checkName="{row, value}">
<span :class="{ 'text-muted': row.ignored }">
<span :class="{ 'text-muted': row.ignored, 'has-ignored': hasIgnored(row) }">
{{ value }}
<template v-if="row.ignored">
({{ t('harvester.dashboard.sections.componentHealth.ignore.ignored') }})
@@ -228,7 +234,7 @@ function hiddenIgnoredCount(row) {
</template>
<template #cell:affectedCount="{row, value}">
<div
v-if="affectedResourceNames(row).length"
v-if="allAffectedResourceNames(row).length"
class="affected-resources"
>
<div class="affected-title">
@@ -255,22 +261,31 @@ function hiddenIgnoredCount(row) {
</span>
</RcTag>
</div>
<RcButton
v-if="remainingAffectedResourcesCount(row)"
variant="link"
size="small"
class="compact-link"
:aria-expanded="expandedResourceIds.includes(row.id)"
@click="toggleId(expandedResourceIds, row.id)"
<div
v-if="remainingAffectedResourcesCount(row) || ignoredLinkCount(row)"
class="affected-links"
>
{{ expandedResourceIds.includes(row.id) ? t('generic.showLess') : t('generic.plusMore', { n: remainingAffectedResourcesCount(row) }) }}
</RcButton>
<span
v-if="hiddenIgnoredCount(row)"
class="hidden-ignored text-muted"
>
{{ t('harvester.dashboard.sections.componentHealth.ignore.plusIgnored', { n: hiddenIgnoredCount(row) }) }}
</span>
<RcButton
v-if="remainingAffectedResourcesCount(row)"
variant="link"
size="small"
class="compact-link more-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="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>
<span v-else>
{{ t('harvester.dashboard.sections.componentHealth.noAffectedResources') }}
@@ -280,6 +295,11 @@ function hiddenIgnoredCount(row) {
</template>
<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
.compact-link {
--rc-button-padding: 0;
@@ -305,9 +325,10 @@ function hiddenIgnoredCount(row) {
font-size: 12px;
}
// the same size as the "+ N more" link above it
.hidden-ignored {
font-size: 12px;
.affected-links {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
.affected-names {
@@ -8,13 +8,14 @@ import { exceptionToErrorsArray } from '@shell/utils/error';
import Banner from '@components/Banner/Banner.vue';
import { BadgeState } from '@components/BadgeState';
import { Checkbox } from '@components/Form/Checkbox';
import { RcCounterBadge } from '@components/Pill';
import { RcButton } from '@components/RcButton';
import { useModal } from '@components/RcModal';
import ComponentChecksTable from './ComponentChecksTable.vue';
import IgnoreRuleModal from './IgnoreRuleModal.vue';
import {
COMPONENT_HEALTH_SEVERITIES, HEALTH_SUMMARY_SEVERITY_RANK, activeAffectedResourceNames, affectedResourceKind,
affectedResourceLabel, allAffectedResourceNames, componentOf, healthSummarySeverity, ignoredCounts, severityColor
COMPONENT_HEALTH_SEVERITIES, HEALTH_SUMMARY_SEVERITY_RANK, affectedResourceKind, affectedResourceLabel,
allAffectedResourceNames, componentOf, healthSummarySeverity, severityColor
} from '../../utils/component-health';
const store = useStore();
@@ -111,22 +112,13 @@ const shownChecks = computed(() => checks.value.filter((check) => showIgnored.va
check.affectedResources?.apiVersion,
affectedResourceKind(check),
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(),
})));
const ignored = computed(() => ignoredCounts(checks.value));
const hasIgnored = computed(() => ignored.value.checks + ignored.value.resources > 0);
// 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 });
});
// the checks ignored as a whole, the ones the checkbox brings back
const ignoredCheckCount = computed(() => checks.value.filter((check) => check.ignored).length);
const rows = computed(() => {
const result = [];
@@ -212,14 +204,25 @@ function collapseAll() {
>
<template #header-left>
<div
v-if="hasIgnored"
v-if="ignoredCheckCount"
class="show-ignored"
>
<!-- the label holds the badge, so the checkbox is named here -->
<Checkbox
v-model:value="showIgnored"
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>
</template>
<template #header-right>
@@ -267,7 +270,6 @@ function collapseAll() {
class="sub-table"
:rows="row.checks"
:ignore-rules="ignoreRules"
:show-ignored="showIgnored"
:filter-text="filterText"
:load-failed="!!loadErrors.componentHealths"
@open-rule="openRuleModal"
@@ -292,6 +294,12 @@ function collapseAll() {
height: 100%;
}
.show-ignored-label {
display: inline-flex;
align-items: center;
gap: 6px;
}
.expand-actions {
display: flex;
align-items: center;
@@ -55,8 +55,11 @@ const resourceOptions = computed(() => [...new Set([...allAffectedResourceNames(
const chosenScope = ref(props.rule && !ruleResources.length ? 'check' : null);
const scope = computed({
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) => {
chosenScope.value = value;
if (!locked.value && !isView.value) {
chosenScope.value = value;
}
},
});
// 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)));
// a rule that lists no resource would ignore the entire check
const canSave = computed(() => (scope.value === 'check' || selectedResources.value.length > 0) && hasChanges.value);
// an expired rule applies to nothing, so it only takes changes once it has a new expiration
const locked = computed(() => hasExpired && !isView.value && !duration.value);
// saving something else on an expired rule leaves it expired
const staysExpired = computed(() => hasExpired && !duration.value && hasChanges.value);
// a rule that lists no resource would ignore the entire check
const canSave = computed(() => !locked.value && (scope.value === 'check' || selectedResources.value.length > 0) && hasChanges.value);
const currentExpiry = computed(() => {
if (!expiresAt) {
@@ -189,6 +192,13 @@ async function save() {
@close="close"
@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="col span-6">
<LabelValue
@@ -203,34 +213,7 @@ async function save() {
/>
</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"
: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>
<!-- first, as an expired rule's other fields wait for it -->
<div>
<RcHeading :size="4">
{{ t('harvester.dashboard.sections.componentHealth.ignore.duration') }}
@@ -260,11 +243,42 @@ async function save() {
</p>
</template>
</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
v-model:value="reason"
:label="t('harvester.dashboard.sections.componentHealth.ignore.reason')"
:placeholder="isView ? '' : t('harvester.dashboard.sections.componentHealth.ignore.reasonPlaceholder')"
:mode="mode"
:disabled="locked"
/>
<Banner
v-for="(err, i) in errors"
@@ -273,13 +287,6 @@ async function save() {
color="error"
: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
v-if="isView"
@@ -9,7 +9,7 @@ import { RcCounterBadge, RcTag } from '@components/Pill';
import { RcModal } from '@components/RcModal';
import LabeledSelect from '@shell/components/form/LabeledSelect';
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 ComponentChecksTable from '../ComponentChecksTable.vue';
import IgnoreRuleModal from '../IgnoreRuleModal.vue';
@@ -178,6 +178,7 @@ const mountRuleModal = ({
onClose,
confirm: () => w.find('[data-testid="component-health-ignore-confirm"]'),
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"]'),
newExpiry: () => w.find('[data-testid="component-health-ignore-new-expiry"]'),
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;
['x', 'warning', 'a', 'some message', 'kubevirt.io/v1', 'virtualmachine', 'label of', 'vm-shown'].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');
['x', 'warning', 'a', 'some message', 'kubevirt.io/v1', 'virtualmachine', 'label of', 'vm-shown', 'vm-hidden'].forEach((text) => expect(filterText()).toContain(text));
});
it('leaves the rows as they are when filtering', async() => {
toggleExpand.mockClear();
@@ -338,7 +334,8 @@ describe('health components', () => {
const shownRows = () => w.findComponent(ComponentChecksTable).props('rows').map((r) => r.id);
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);
@@ -348,8 +345,14 @@ describe('health components', () => {
healthSummaries: [summaryOf({ x: { warningCount: 1 } })],
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() => {
const message = 'x'.repeat(150);
@@ -381,31 +384,67 @@ describe('health components', () => {
expect(w.findComponent(RcCounterBadge).props('count')).toBe(7);
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 row = {
...CHECK, affectedCount: 2, affectedResources: { kind: 'Volume', names: { one: { ignored: true, ignoredBy: 'r' }, two: {} } }
};
const hidden = mountChecks({ rows: [row] }, { SortableTable: table });
const shown = mountChecks({ rows: [row], showIgnored: true }, { SortableTable: table });
const w = mountChecks({ rows: [row] }, { SortableTable: table });
const link = () => w.find('.ignored-link');
expect(hidden.findComponent(RcCounterBadge).props('count')).toBe(2);
expect(hidden.find('.hidden-ignored').text()).toContain('ignore.plusIgnored');
expect(shown.findComponent(RcCounterBadge).props('count')).toBe(2);
expect(shown.find('.hidden-ignored').exists()).toBe(false);
expect(w.findComponent(RcCounterBadge).props('count')).toBe(2);
expect(w.findAllComponents(RcTag).map((tag) => tag.find('.name').text())).toStrictEqual(['two']);
expect(link().text()).toContain('ignore.plusIgnored');
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', () => {
const check = (ignored, names) => ({ ignored, affectedResources: { names } });
it('puts the ignored link after the more link, and leaves it out when the whole check is ignored', () => {
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([
check(true, { a: { ignored: true }, b: { ignored: true } }),
check(false, { c: { ignored: true }, d: {} }),
check(false, {
e: { ignored: true }, f: { ignored: true }, g: {}
}),
check(false, { h: {} }),
])).toStrictEqual({ checks: 1, resources: 3 });
expect(ignoredCounts(undefined)).toStrictEqual({ checks: 0, resources: 0 });
expect(links(row)).toStrictEqual(['more', 'ignored']);
expect(links({ ...row, ignored: true })).toStrictEqual(['more']);
});
it('tells which checks have anything ignored', () => {
expect(hasIgnored({ ignored: true })).toBe(true);
expect(hasIgnored({ affectedResources: { names: { a: { ignored: true }, b: {} } } })).toBe(true);
expect(hasIgnored({ affectedResources: { names: { a: {} } } })).toBe(false);
expect(hasIgnored(undefined)).toBe(false);
});
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', () => {
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('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 row = {
...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) => ({
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 whole = mountChecks({ rows: [wholeRow], showIgnored: true }, { SortableTable: table });
const partly = mountChecks({ rows: [row] }, { SortableTable: table });
const whole = mountChecks({ rows: [wholeRow] }, { SortableTable: table });
await partly.find('.ignored-link').trigger('click');
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');
@@ -518,17 +559,25 @@ describe('health components', () => {
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 = {
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>',
};
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/);
expect(textOf({ rows: [row] })).not.toContain('a (%harvester');
expect(textOf({ rows: [{ ...row, ignored: true }] })).toContain('a (%harvester.dashboard.sections.componentHealth.ignore.ignored%)');
await w.find('.ignored-link').trigger('click');
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', () => {
@@ -665,8 +714,9 @@ describe('health components', () => {
expect(confirm().attributes('disabled')).toBeUndefined();
});
it('ignores the entire check forever without listing its resources', async() => {
const { w, confirm } = mountRuleModal();
const [scope, duration] = w.findAllComponents(RadioGroup);
const { confirm, scopeGroup, duration: durationGroup } = mountRuleModal();
const scope = scopeGroup();
const duration = durationGroup();
await scope.vm.$emit('update:value', 'check');
await duration.vm.$emit('update:value', 'forever');
@@ -736,9 +786,9 @@ describe('health components', () => {
resources: ['two'], expiresAt: IN_A_WEEK, reason: 'known issue'
});
const {
w, duration, currentExpiry, newExpiry
w, duration, currentExpiry, newExpiry, scopeGroup
} = mountRuleModal({ rule, mode: 'edit' });
const [scope] = w.findAllComponents(RadioGroup);
const scope = scopeGroup();
expect(scope.props('value')).toBe('resources');
expect(w.findComponent(LabeledSelect).props('value')).toStrictEqual(['two']);
@@ -794,7 +844,7 @@ describe('health components', () => {
}),
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 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());
});
it('warns that an expired rule stays expired when only something else changes', async() => {
const { w, duration, warning } = mountRuleModal({ rule: ruleOf({ expiresAt: LAST_WEEK }), mode: 'edit' });
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, 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();
expect(warning().props('label')).toContain('ignore.staysExpired');
expect(scopeGroup().props('value')).toBe('resources');
await duration().vm.$emit('update:value', 'days7');
await flushPromises();
expect(warning()).toBeUndefined();
});
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(locked()).toStrictEqual({
scope: false, resources: false, reason: false, expiration: false, save: false
});
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();
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(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() => {
const {
w, confirm, duration, currentExpiry
w, confirm, duration, currentExpiry, scopeGroup
} = mountRuleModal({ rule: ruleOf(), mode: 'edit' });
const [scope] = w.findAllComponents(RadioGroup);
const scope = scopeGroup();
expect(scope.props('value')).toBe('check');
expect(currentExpiry().text()).toContain('ignore.neverExpires');
@@ -885,7 +960,7 @@ describe('health components', () => {
describe('viewing a rule', () => {
it('shows what the rule has without letting it change', async() => {
const {
w, onClose, confirm, duration, currentExpiry
w, onClose, confirm, duration, currentExpiry, scopeGroup
} = mountRuleModal({
rule: ruleOf({
resources: ['two'], expiresAt: IN_A_WEEK, reason: 'known issue'
@@ -893,6 +968,11 @@ describe('health components', () => {
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) => {
expect(field.props('mode')).toBe('view');
});
+5 -6
View File
@@ -531,9 +531,7 @@ harvester:
noAffectedResources: No affected resources
noIssues: No issues detected
checksNotLoaded: Unable to load the checks
showIgnored: 'Show ignored ({counts})'
ignoredChecks: '{count, plural, =1 {1 check} other {# checks}}'
ignoredResources: '{count, plural, =1 {1 resource} other {# resources}}'
showIgnored: Show ignored checks
loadFailed:
healthSummaries: 'Unable to load the health summary: {error}'
componentHealths: 'Unable to load the checks: {error}'
@@ -545,11 +543,12 @@ harvester:
delete: Delete Ignore Rule
ignored: Ignored
plusIgnored: '+ {n} ignored'
hideIgnored: Hide ignored
scope: Scope
scopeResources: Selected resources
scopeCheck: Entire check
scopeCheck: All resources
resources: Resources
duration: Ignore for
duration: Expiration
days7: 7 days
days30: 30 days
forever: Forever
@@ -558,7 +557,7 @@ harvester:
neverExpires: Never expires
willExpireOn: 'Will expire on {date}'
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
reasonPlaceholder: Why is it ignored? (optional)
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;
}
// what "Show ignored" brings back: the checks ignored as a whole, and the ignored resources of the other checks
export function ignoredCounts(checks) {
return (checks || []).reduce((counts, check) => {
if (check.ignored) {
counts.checks += 1;
} else {
counts.resources += ignoredResourceCount(check);
}
return counts;
}, { checks: 0, resources: 0 });
// the check is ignored as a whole, or some of its resources are
export function hasIgnored(check) {
return !!check?.ignored || ignoredResourceCount(check) > 0;
}
// the UI keeps one rule per check under this name, so Kubernetes refuses a second one for the same check.