|
|
|
@ -17,17 +17,30 @@ interface ExistingRuleEditorProps { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function ExistingRuleEditor({ identifier, prefill }: ExistingRuleEditorProps) { |
|
|
|
|
const [queryParams] = useQueryParams(); |
|
|
|
|
const isManualRestore = Boolean(queryParams.isManualRestore); |
|
|
|
|
|
|
|
|
|
const { |
|
|
|
|
loading: loadingAlertRule, |
|
|
|
|
result: ruleWithLocation, |
|
|
|
|
error, |
|
|
|
|
error: fetchRuleError, |
|
|
|
|
} = useRuleWithLocation({ ruleIdentifier: identifier }); |
|
|
|
|
const [queryParams] = useQueryParams(); |
|
|
|
|
const isManualRestore = Boolean(queryParams.isManualRestore); |
|
|
|
|
|
|
|
|
|
const ruleSourceName = ruleId.ruleIdentifierToRuleSourceName(identifier); |
|
|
|
|
const { |
|
|
|
|
isEditable, |
|
|
|
|
loading: loadingEditable, |
|
|
|
|
error: errorEditable, |
|
|
|
|
} = useIsRuleEditable(ruleSourceName, ruleWithLocation?.rule); |
|
|
|
|
|
|
|
|
|
const { isEditable, loading: loadingEditable } = useIsRuleEditable(ruleSourceName, ruleWithLocation?.rule); |
|
|
|
|
// error handling for fetching rule and rule RBAC
|
|
|
|
|
if (fetchRuleError || errorEditable) { |
|
|
|
|
return ( |
|
|
|
|
<Alert severity="error" title="Failed to load rule"> |
|
|
|
|
{stringifyErrorLike(errorEditable ?? fetchRuleError)} |
|
|
|
|
</Alert> |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const loading = loadingAlertRule || loadingEditable; |
|
|
|
|
|
|
|
|
@ -35,14 +48,6 @@ export function ExistingRuleEditor({ identifier, prefill }: ExistingRuleEditorPr |
|
|
|
|
return <LoadingPlaceholder text="Loading rule..." />; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (error) { |
|
|
|
|
return ( |
|
|
|
|
<Alert severity="error" title="Failed to load rule"> |
|
|
|
|
{stringifyErrorLike(error)} |
|
|
|
|
</Alert> |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!ruleWithLocation && !loading) { |
|
|
|
|
return <AlertWarning title="Rule not found">Sorry! This rule does not exist.</AlertWarning>; |
|
|
|
|
} |
|
|
|
|