From 992652113d512ae6825cd7f593d3aba2091f320c Mon Sep 17 00:00:00 2001 From: isshaddad Date: Wed, 29 Apr 2026 16:59:44 -0400 Subject: [PATCH] coderabbit fixes --- .../admin/backOffice/ApiRateLimitSection.tsx | 13 ++----------- .../admin/backOffice/BatchRateLimitSection.tsx | 13 ++----------- .../backOffice/MaxProjectsSection.server.ts | 4 +++- .../admin/backOffice/MaxProjectsSection.tsx | 6 +++--- .../admin/backOffice/RateLimitSection.tsx | 18 +++++++++++------- .../routes/admin.back-office.orgs.$orgId.tsx | 14 ++++++++++---- 6 files changed, 31 insertions(+), 37 deletions(-) diff --git a/apps/webapp/app/components/admin/backOffice/ApiRateLimitSection.tsx b/apps/webapp/app/components/admin/backOffice/ApiRateLimitSection.tsx index 18ece8a73..b27956f43 100644 --- a/apps/webapp/app/components/admin/backOffice/ApiRateLimitSection.tsx +++ b/apps/webapp/app/components/admin/backOffice/ApiRateLimitSection.tsx @@ -1,21 +1,12 @@ import { RateLimitSection, - type EffectiveRateLimit, + type RateLimitWrapperProps, } from "./RateLimitSection"; export const API_RATE_LIMIT_INTENT = "set-rate-limit"; export const API_RATE_LIMIT_SAVED_VALUE = "rate-limit"; -type FieldErrors = Record | null; - -type Props = { - effective: EffectiveRateLimit; - errors: FieldErrors; - savedJustNow: boolean; - isSubmitting: boolean; -}; - -export function ApiRateLimitSection(props: Props) { +export function ApiRateLimitSection(props: RateLimitWrapperProps) { return ( | null; - -type Props = { - effective: EffectiveRateLimit; - errors: FieldErrors; - savedJustNow: boolean; - isSubmitting: boolean; -}; - -export function BatchRateLimitSection(props: Props) { +export function BatchRateLimitSection(props: RateLimitWrapperProps) { return ( errors && field in errors ? errors[field]?.[0] : undefined; - const [isEditing, setIsEditing] = useState(false); + const [isEditing, setIsEditing] = useState(hasFieldErrors); const [value, setValue] = useState(String(maximumProjectCount)); useEffect(() => { @@ -38,8 +38,8 @@ export function MaxProjectsSection({ }, [hasFieldErrors]); useEffect(() => { - if (savedJustNow) setIsEditing(false); - }, [savedJustNow]); + if (savedJustNow && !hasFieldErrors) setIsEditing(false); + }, [savedJustNow, hasFieldErrors]); return (
diff --git a/apps/webapp/app/components/admin/backOffice/RateLimitSection.tsx b/apps/webapp/app/components/admin/backOffice/RateLimitSection.tsx index ec7973d0f..c17658976 100644 --- a/apps/webapp/app/components/admin/backOffice/RateLimitSection.tsx +++ b/apps/webapp/app/components/admin/backOffice/RateLimitSection.tsx @@ -28,17 +28,21 @@ export type EffectiveRateLimit = { config: RateLimitConfig; }; -type FieldErrors = Record | null; +export type FieldErrors = Record | null; -type Props = { - title: string; - intent: string; +// Props shared by every per-domain wrapper (Api / Batch / future ones). +export type RateLimitWrapperProps = { effective: EffectiveRateLimit; errors: FieldErrors; savedJustNow: boolean; isSubmitting: boolean; }; +type Props = RateLimitWrapperProps & { + title: string; + intent: string; +}; + export function RateLimitSection({ title, intent, @@ -54,7 +58,7 @@ export function RateLimitSection({ const current = effective.config.type === "tokenBucket" ? effective.config : null; - const [isEditing, setIsEditing] = useState(false); + const [isEditing, setIsEditing] = useState(hasFieldErrors); const [refillRate, setRefillRate] = useState( current ? String(current.refillRate) : "" ); @@ -70,8 +74,8 @@ export function RateLimitSection({ }, [hasFieldErrors]); useEffect(() => { - if (savedJustNow) setIsEditing(false); - }, [savedJustNow]); + if (savedJustNow && !hasFieldErrors) setIsEditing(false); + }, [savedJustNow, hasFieldErrors]); const currentDescription = current ? describeRateLimit( diff --git a/apps/webapp/app/routes/admin.back-office.orgs.$orgId.tsx b/apps/webapp/app/routes/admin.back-office.orgs.$orgId.tsx index fc41c5f6b..d203a8bda 100644 --- a/apps/webapp/app/routes/admin.back-office.orgs.$orgId.tsx +++ b/apps/webapp/app/routes/admin.back-office.orgs.$orgId.tsx @@ -140,7 +140,13 @@ export default function BackOfficeOrgPage() { useTypedLoaderData(); const actionData = useTypedActionData(); const navigation = useNavigation(); - const isSubmitting = navigation.state !== "idle"; + const submittingIntent = navigation.formData?.get("intent"); + const isSubmittingApi = + navigation.state !== "idle" && submittingIntent === API_RATE_LIMIT_INTENT; + const isSubmittingBatch = + navigation.state !== "idle" && submittingIntent === BATCH_RATE_LIMIT_INTENT; + const isSubmittingMaxProjects = + navigation.state !== "idle" && submittingIntent === MAX_PROJECTS_INTENT; const errorSection = actionData && "section" in actionData ? actionData.section : null; @@ -185,21 +191,21 @@ export default function BackOfficeOrgPage() { effective={apiEffective} errors={errorSection === API_RATE_LIMIT_SAVED_VALUE ? errors : null} savedJustNow={savedSection === API_RATE_LIMIT_SAVED_VALUE} - isSubmitting={isSubmitting} + isSubmitting={isSubmittingApi} /> );