Skip to content

Commit

Permalink
take into account deleted rules
Browse files Browse the repository at this point in the history
  • Loading branch information
maximpn committed Apr 21, 2023
1 parent 543fbe5 commit ede1b07
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
Expand Up @@ -18,13 +18,17 @@ interface RuleDetailsSnoozeBadge {
}

export function RuleDetailsSnoozeSettings({ id }: RuleDetailsSnoozeBadge): JSX.Element {
const { data: [snoozeSettings] = [undefined], isError: isSnoozeSettingsFetchError } =
useFetchRulesSnoozeSettings([id]);
const { data: rulesSnoozeSettings, isFetching, isError } = useFetchRulesSnoozeSettings([id]);
const snoozeSettings = rulesSnoozeSettings?.[0];

return (
<RuleSnoozeBadge
snoozeSettings={snoozeSettings}
error={isSnoozeSettingsFetchError ? i18n.UNABLE_TO_FETCH_RULE_SNOOZE_SETTINGS : undefined}
error={
isError || (!snoozeSettings && !isFetching)
? i18n.UNABLE_TO_FETCH_RULE_SNOOZE_SETTINGS
: undefined
}
showTooltipInline={true}
/>
);
Expand Down
Expand Up @@ -40,8 +40,18 @@ import { RuleSource } from './rules_table_saved_state';
import { useRulesTableSavedState } from './use_rules_table_saved_state';

interface RulesSnoozeSettings {
data: Record<string, RuleSnoozeSettings>; // The key is a rule SO's id (not ruleId)
/**
* Rule SO's id (not ruleId) to snooze settings map,
*/
data: Record<string, RuleSnoozeSettings>;
/**
* Sets to true during the first data loading
*/
isLoading: boolean;
/**
* Sets to true during data loading
*/
isFetching: boolean;
isError: boolean;
}

Expand Down Expand Up @@ -290,6 +300,7 @@ export const RulesTableContextProvider = ({ children }: RulesTableContextProvide
const {
data: rulesSnoozeSettings,
isLoading: isSnoozeSettingsLoading,
isFetching: isSnoozeSettingsFetching,
isError: isSnoozeSettingsFetchError,
refetch: refetchSnoozeSettings,
} = useFetchRulesSnoozeSettings(
Expand Down Expand Up @@ -349,6 +360,7 @@ export const RulesTableContextProvider = ({ children }: RulesTableContextProvide
rulesSnoozeSettings: {
data: rulesSnoozeSettingsMap,
isLoading: isSnoozeSettingsLoading,
isFetching: isSnoozeSettingsFetching,
isError: isSnoozeSettingsFetchError,
},
pagination: {
Expand Down Expand Up @@ -382,6 +394,7 @@ export const RulesTableContextProvider = ({ children }: RulesTableContextProvide
rules,
rulesSnoozeSettings,
isSnoozeSettingsLoading,
isSnoozeSettingsFetching,
isSnoozeSettingsFetchError,
page,
perPage,
Expand Down
Expand Up @@ -117,16 +117,21 @@ const useRuleSnoozeColumn = (): TableColumn => {
() => ({
field: 'snooze',
name: i18n.COLUMN_SNOOZE,
render: (_, rule: Rule) => (
<RuleSnoozeBadge
snoozeSettings={rulesSnoozeSettings.data[rule.id]}
error={
rulesSnoozeSettings.isError
? rulesTableI18n.UNABLE_TO_FETCH_RULES_SNOOZE_SETTINGS
: undefined
}
/>
),
render: (_, rule: Rule) => {
const snoozeSettings = rulesSnoozeSettings.data[rule.id];
const { isFetching, isError } = rulesSnoozeSettings;

return (
<RuleSnoozeBadge
snoozeSettings={snoozeSettings}
error={
isError || (!snoozeSettings && !isFetching)
? rulesTableI18n.UNABLE_TO_FETCH_RULES_SNOOZE_SETTINGS
: undefined
}
/>
);
},
width: '100px',
sortable: false,
}),
Expand Down

0 comments on commit ede1b07

Please sign in to comment.