coderabbit fixes
This commit is contained in:
@@ -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<string, string[] | undefined> | null;
|
||||
|
||||
type Props = {
|
||||
effective: EffectiveRateLimit;
|
||||
errors: FieldErrors;
|
||||
savedJustNow: boolean;
|
||||
isSubmitting: boolean;
|
||||
};
|
||||
|
||||
export function ApiRateLimitSection(props: Props) {
|
||||
export function ApiRateLimitSection(props: RateLimitWrapperProps) {
|
||||
return (
|
||||
<RateLimitSection
|
||||
title="API rate limit"
|
||||
|
||||
@@ -1,21 +1,12 @@
|
||||
import {
|
||||
RateLimitSection,
|
||||
type EffectiveRateLimit,
|
||||
type RateLimitWrapperProps,
|
||||
} from "./RateLimitSection";
|
||||
|
||||
export const BATCH_RATE_LIMIT_INTENT = "set-batch-rate-limit";
|
||||
export const BATCH_RATE_LIMIT_SAVED_VALUE = "batch-rate-limit";
|
||||
|
||||
type FieldErrors = Record<string, string[] | undefined> | null;
|
||||
|
||||
type Props = {
|
||||
effective: EffectiveRateLimit;
|
||||
errors: FieldErrors;
|
||||
savedJustNow: boolean;
|
||||
isSubmitting: boolean;
|
||||
};
|
||||
|
||||
export function BatchRateLimitSection(props: Props) {
|
||||
export function BatchRateLimitSection(props: RateLimitWrapperProps) {
|
||||
return (
|
||||
<RateLimitSection
|
||||
title="Batch rate limit"
|
||||
|
||||
@@ -5,7 +5,9 @@ import { MAX_PROJECTS_INTENT } from "./MaxProjectsSection";
|
||||
|
||||
const SetMaxProjectsSchema = z.object({
|
||||
intent: z.literal(MAX_PROJECTS_INTENT),
|
||||
maximumProjectCount: z.coerce.number().int().min(1),
|
||||
// Capped at PostgreSQL INTEGER max (Prisma Int) so oversized input fails
|
||||
// validation cleanly instead of crashing the update.
|
||||
maximumProjectCount: z.coerce.number().int().min(1).max(2_147_483_647),
|
||||
});
|
||||
|
||||
export type MaxProjectsActionResult =
|
||||
|
||||
@@ -30,7 +30,7 @@ export function MaxProjectsSection({
|
||||
const fieldError = (field: string) =>
|
||||
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 (
|
||||
<section className="flex flex-col gap-3 rounded-md border border-charcoal-700 bg-charcoal-800 p-4">
|
||||
|
||||
@@ -28,17 +28,21 @@ export type EffectiveRateLimit = {
|
||||
config: RateLimitConfig;
|
||||
};
|
||||
|
||||
type FieldErrors = Record<string, string[] | undefined> | null;
|
||||
export type FieldErrors = Record<string, string[] | undefined> | 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(
|
||||
|
||||
@@ -140,7 +140,13 @@ export default function BackOfficeOrgPage() {
|
||||
useTypedLoaderData<typeof loader>();
|
||||
const actionData = useTypedActionData<typeof action>();
|
||||
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}
|
||||
/>
|
||||
|
||||
<BatchRateLimitSection
|
||||
effective={batchEffective}
|
||||
errors={errorSection === BATCH_RATE_LIMIT_SAVED_VALUE ? errors : null}
|
||||
savedJustNow={savedSection === BATCH_RATE_LIMIT_SAVED_VALUE}
|
||||
isSubmitting={isSubmitting}
|
||||
isSubmitting={isSubmittingBatch}
|
||||
/>
|
||||
|
||||
<MaxProjectsSection
|
||||
maximumProjectCount={org.maximumProjectCount}
|
||||
errors={errorSection === MAX_PROJECTS_SAVED_VALUE ? errors : null}
|
||||
savedJustNow={savedSection === MAX_PROJECTS_SAVED_VALUE}
|
||||
isSubmitting={isSubmitting}
|
||||
isSubmitting={isSubmittingMaxProjects}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user