diff --git a/web-console/src/components/json-input/json-input.tsx b/web-console/src/components/json-input/json-input.tsx
index b206db77e995..f4ffddc11142 100644
--- a/web-console/src/components/json-input/json-input.tsx
+++ b/web-console/src/components/json-input/json-input.tsx
@@ -66,7 +66,7 @@ interface InternalValue {
interface JsonInputProps {
value: any;
- onChange: (value: any) => void;
+ onChange?: (value: any) => void;
setError?: (error: Error | undefined) => void;
placeholder?: string;
focus?: boolean;
@@ -123,7 +123,7 @@ export const JsonInput = React.memo(function JsonInput(props: JsonInputProps) {
setError?.(error);
if (!error) {
- onChange(value);
+ onChange?.(value);
}
if (showErrorIfNeeded) {
@@ -131,6 +131,7 @@ export const JsonInput = React.memo(function JsonInput(props: JsonInputProps) {
}
}}
onBlur={() => setShowErrorIfNeeded(true)}
+ readOnly={!onChange}
focus={focus}
fontSize={12}
width={width || '100%'}
diff --git a/web-console/src/components/rule-editor/rule-editor.tsx b/web-console/src/components/rule-editor/rule-editor.tsx
index 52eb5b805c94..3f72a8ca4119 100644
--- a/web-console/src/components/rule-editor/rule-editor.tsx
+++ b/web-console/src/components/rule-editor/rule-editor.tsx
@@ -42,22 +42,23 @@ const PERIOD_SUGGESTIONS: string[] = ['P1D', 'P7D', 'P1M', 'P1Y', 'P1000Y'];
export interface RuleEditorProps {
rule: Rule;
tiers: string[];
- onChange(newRule: Rule): void;
- onDelete(): void;
- moveUp: (() => void) | undefined;
- moveDown: (() => void) | undefined;
+ onChange?: (newRule: Rule) => void;
+ onDelete?: () => void;
+ moveUp?: () => void;
+ moveDown?: () => void;
}
export const RuleEditor = React.memo(function RuleEditor(props: RuleEditorProps) {
const { rule, onChange, tiers, onDelete, moveUp, moveDown } = props;
const [isOpen, setIsOpen] = useState(true);
+ const disabled = !onChange;
function removeTier(key: string) {
const newTierReplicants = { ...rule.tieredReplicants };
delete newTierReplicants[key];
const newRule = { ...rule, tieredReplicants: newTierReplicants };
- onChange(newRule);
+ onChange?.(newRule);
}
function addTier() {
@@ -72,7 +73,7 @@ export const RuleEditor = React.memo(function RuleEditor(props: RuleEditorProps)
}
}
- onChange(RuleUtil.addTieredReplicant(rule, newTierName, 1));
+ onChange?.(RuleUtil.addTieredReplicant(rule, newTierName, 1));
}
function renderTiers() {
@@ -90,14 +91,15 @@ export const RuleEditor = React.memo(function RuleEditor(props: RuleEditorProps)
{tieredReplicantsList.map(([tier, replication]) => (
-
))}
@@ -131,7 +134,7 @@ export const RuleEditor = React.memo(function RuleEditor(props: RuleEditorProps)
}
function renderTierAdder() {
- const { rule, tiers } = props;
+ if (!onChange) return;
const disabled = Object.keys(rule.tieredReplicants || {}).length >= Object.keys(tiers).length;
return (
@@ -163,7 +166,7 @@ export const RuleEditor = React.memo(function RuleEditor(props: RuleEditorProps)
{moveUp && }
{moveDown && }
-
+ {onDelete && }
@@ -172,7 +175,8 @@ export const RuleEditor = React.memo(function RuleEditor(props: RuleEditorProps)
onChange(RuleUtil.changeRuleType(rule, e.target.value))}
+ disabled={disabled}
+ onChange={(e: any) => onChange?.(RuleUtil.changeRuleType(rule, e.target.value))}
>
{RuleUtil.TYPES.map(type => (