Skip to content

Commit 9926521

Browse files
committed
coderabbit fixes
1 parent 147195b commit 9926521

6 files changed

Lines changed: 31 additions & 37 deletions

File tree

apps/webapp/app/components/admin/backOffice/ApiRateLimitSection.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
import {
22
RateLimitSection,
3-
type EffectiveRateLimit,
3+
type RateLimitWrapperProps,
44
} from "./RateLimitSection";
55

66
export const API_RATE_LIMIT_INTENT = "set-rate-limit";
77
export const API_RATE_LIMIT_SAVED_VALUE = "rate-limit";
88

9-
type FieldErrors = Record<string, string[] | undefined> | null;
10-
11-
type Props = {
12-
effective: EffectiveRateLimit;
13-
errors: FieldErrors;
14-
savedJustNow: boolean;
15-
isSubmitting: boolean;
16-
};
17-
18-
export function ApiRateLimitSection(props: Props) {
9+
export function ApiRateLimitSection(props: RateLimitWrapperProps) {
1910
return (
2011
<RateLimitSection
2112
title="API rate limit"

apps/webapp/app/components/admin/backOffice/BatchRateLimitSection.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
import {
22
RateLimitSection,
3-
type EffectiveRateLimit,
3+
type RateLimitWrapperProps,
44
} from "./RateLimitSection";
55

66
export const BATCH_RATE_LIMIT_INTENT = "set-batch-rate-limit";
77
export const BATCH_RATE_LIMIT_SAVED_VALUE = "batch-rate-limit";
88

9-
type FieldErrors = Record<string, string[] | undefined> | null;
10-
11-
type Props = {
12-
effective: EffectiveRateLimit;
13-
errors: FieldErrors;
14-
savedJustNow: boolean;
15-
isSubmitting: boolean;
16-
};
17-
18-
export function BatchRateLimitSection(props: Props) {
9+
export function BatchRateLimitSection(props: RateLimitWrapperProps) {
1910
return (
2011
<RateLimitSection
2112
title="Batch rate limit"

apps/webapp/app/components/admin/backOffice/MaxProjectsSection.server.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { MAX_PROJECTS_INTENT } from "./MaxProjectsSection";
55

66
const SetMaxProjectsSchema = z.object({
77
intent: z.literal(MAX_PROJECTS_INTENT),
8-
maximumProjectCount: z.coerce.number().int().min(1),
8+
// Capped at PostgreSQL INTEGER max (Prisma Int) so oversized input fails
9+
// validation cleanly instead of crashing the update.
10+
maximumProjectCount: z.coerce.number().int().min(1).max(2_147_483_647),
911
});
1012

1113
export type MaxProjectsActionResult =

apps/webapp/app/components/admin/backOffice/MaxProjectsSection.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ export function MaxProjectsSection({
3030
const fieldError = (field: string) =>
3131
errors && field in errors ? errors[field]?.[0] : undefined;
3232

33-
const [isEditing, setIsEditing] = useState(false);
33+
const [isEditing, setIsEditing] = useState(hasFieldErrors);
3434
const [value, setValue] = useState(String(maximumProjectCount));
3535

3636
useEffect(() => {
3737
if (hasFieldErrors) setIsEditing(true);
3838
}, [hasFieldErrors]);
3939

4040
useEffect(() => {
41-
if (savedJustNow) setIsEditing(false);
42-
}, [savedJustNow]);
41+
if (savedJustNow && !hasFieldErrors) setIsEditing(false);
42+
}, [savedJustNow, hasFieldErrors]);
4343

4444
return (
4545
<section className="flex flex-col gap-3 rounded-md border border-charcoal-700 bg-charcoal-800 p-4">

apps/webapp/app/components/admin/backOffice/RateLimitSection.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,21 @@ export type EffectiveRateLimit = {
2828
config: RateLimitConfig;
2929
};
3030

31-
type FieldErrors = Record<string, string[] | undefined> | null;
31+
export type FieldErrors = Record<string, string[] | undefined> | null;
3232

33-
type Props = {
34-
title: string;
35-
intent: string;
33+
// Props shared by every per-domain wrapper (Api / Batch / future ones).
34+
export type RateLimitWrapperProps = {
3635
effective: EffectiveRateLimit;
3736
errors: FieldErrors;
3837
savedJustNow: boolean;
3938
isSubmitting: boolean;
4039
};
4140

41+
type Props = RateLimitWrapperProps & {
42+
title: string;
43+
intent: string;
44+
};
45+
4246
export function RateLimitSection({
4347
title,
4448
intent,
@@ -54,7 +58,7 @@ export function RateLimitSection({
5458
const current =
5559
effective.config.type === "tokenBucket" ? effective.config : null;
5660

57-
const [isEditing, setIsEditing] = useState(false);
61+
const [isEditing, setIsEditing] = useState(hasFieldErrors);
5862
const [refillRate, setRefillRate] = useState(
5963
current ? String(current.refillRate) : ""
6064
);
@@ -70,8 +74,8 @@ export function RateLimitSection({
7074
}, [hasFieldErrors]);
7175

7276
useEffect(() => {
73-
if (savedJustNow) setIsEditing(false);
74-
}, [savedJustNow]);
77+
if (savedJustNow && !hasFieldErrors) setIsEditing(false);
78+
}, [savedJustNow, hasFieldErrors]);
7579

7680
const currentDescription = current
7781
? describeRateLimit(

apps/webapp/app/routes/admin.back-office.orgs.$orgId.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,13 @@ export default function BackOfficeOrgPage() {
140140
useTypedLoaderData<typeof loader>();
141141
const actionData = useTypedActionData<typeof action>();
142142
const navigation = useNavigation();
143-
const isSubmitting = navigation.state !== "idle";
143+
const submittingIntent = navigation.formData?.get("intent");
144+
const isSubmittingApi =
145+
navigation.state !== "idle" && submittingIntent === API_RATE_LIMIT_INTENT;
146+
const isSubmittingBatch =
147+
navigation.state !== "idle" && submittingIntent === BATCH_RATE_LIMIT_INTENT;
148+
const isSubmittingMaxProjects =
149+
navigation.state !== "idle" && submittingIntent === MAX_PROJECTS_INTENT;
144150

145151
const errorSection =
146152
actionData && "section" in actionData ? actionData.section : null;
@@ -185,21 +191,21 @@ export default function BackOfficeOrgPage() {
185191
effective={apiEffective}
186192
errors={errorSection === API_RATE_LIMIT_SAVED_VALUE ? errors : null}
187193
savedJustNow={savedSection === API_RATE_LIMIT_SAVED_VALUE}
188-
isSubmitting={isSubmitting}
194+
isSubmitting={isSubmittingApi}
189195
/>
190196

191197
<BatchRateLimitSection
192198
effective={batchEffective}
193199
errors={errorSection === BATCH_RATE_LIMIT_SAVED_VALUE ? errors : null}
194200
savedJustNow={savedSection === BATCH_RATE_LIMIT_SAVED_VALUE}
195-
isSubmitting={isSubmitting}
201+
isSubmitting={isSubmittingBatch}
196202
/>
197203

198204
<MaxProjectsSection
199205
maximumProjectCount={org.maximumProjectCount}
200206
errors={errorSection === MAX_PROJECTS_SAVED_VALUE ? errors : null}
201207
savedJustNow={savedSection === MAX_PROJECTS_SAVED_VALUE}
202-
isSubmitting={isSubmitting}
208+
isSubmitting={isSubmittingMaxProjects}
203209
/>
204210
</div>
205211
);

0 commit comments

Comments
 (0)