Skip to content

Commit d159b10

Browse files
committed
fix(rp-connect): clamp onboarding topic RF to broker count
The RPCN onboarding Add Topic step spread TOPIC_FORM_DEFAULTS (replicationFactor: 3) into the form and renders the RF field as readOnly in AdvancedTopicSettings. On single-broker clusters (local-byoc dev environments) that meant the user saw RF=3 with no way to edit, and CreateTopic failed with "not enough replicas". Override replicationFactor at form init with min(default, brokersOnline) via useGetKafkaInfoQuery so the readOnly value matches what the broker can actually satisfy.
1 parent b4a4220 commit d159b10

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

frontend/src/components/pages/rp-connect/onboarding/add-topic-step.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { ListTopicsRequestSchema } from 'protogen/redpanda/api/dataplane/v1/topi
2525
import { listTopics } from 'protogen/redpanda/api/dataplane/v1/topic-TopicService_connectquery';
2626
import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useState } from 'react';
2727
import { useForm, useWatch } from 'react-hook-form';
28+
import { useGetKafkaInfoQuery } from 'react-query/api/cluster-status';
2829
import { useLegacyListTopicsQuery } from 'react-query/api/topic';
2930
import { LONG_LIVED_CACHE_STALE_TIME } from 'react-query/react-query.utils';
3031
import { isFalsy } from 'utils/falsy';
@@ -104,12 +105,23 @@ export const AddTopicStep = forwardRef<BaseStepRef<AddTopicFormData>, AddTopicSt
104105

105106
const isPending = createTopicMutation.isPending;
106107

108+
// The RF field is readOnly in advanced-topic-settings, so the default is
109+
// also the final value. Clamp to broker count so single-broker clusters
110+
// (e.g. local-byoc) don't hit "not enough replicas" on CreateTopic.
111+
const { data: kafkaInfo } = useGetKafkaInfoQuery();
112+
const brokersOnline = kafkaInfo?.brokersOnline ?? 0;
113+
const defaultReplicationFactor =
114+
brokersOnline > 0
115+
? Math.min(TOPIC_FORM_DEFAULTS.replicationFactor, brokersOnline)
116+
: TOPIC_FORM_DEFAULTS.replicationFactor;
117+
107118
const defaultValues = useMemo(
108119
() => ({
109120
...TOPIC_FORM_DEFAULTS,
121+
replicationFactor: defaultReplicationFactor,
110122
topicName: defaultTopicName || TOPIC_FORM_DEFAULTS.topicName,
111123
}),
112-
[defaultTopicName]
124+
[defaultTopicName, defaultReplicationFactor]
113125
);
114126

115127
const form = useForm<AddTopicFormData>({

0 commit comments

Comments
 (0)