fix(ui): align Lighthouse business context limit

This commit is contained in:
alejandrobailo
2026-06-30 17:20:10 +02:00
parent 636cd988d5
commit a91e21deb2
4 changed files with 36 additions and 19 deletions
@@ -89,16 +89,16 @@ describe("LighthouseV2BusinessContextForm", () => {
/>,
);
// When: paste in one event instead of 1001 keystrokes
// When: paste in one event instead of 5001 keystrokes
await user.click(
screen.getByRole("textbox", { name: /Business context/i }),
);
await user.paste("a".repeat(1001));
await user.paste("a".repeat(5001));
// Then
expect(screen.getByText("1001/1000")).toBeInTheDocument();
expect(screen.getByText("5001/5000")).toBeInTheDocument();
expect(
screen.getByText("Business context cannot exceed 1000 characters."),
screen.getByText("Business context cannot exceed 5000 characters."),
).toBeInTheDocument();
expect(
screen.getByRole("button", { name: "Save business context" }),
@@ -35,18 +35,24 @@ export function LighthouseV2BusinessContextForm({
setSaving(true);
setError(null);
const result = await updateLighthouseV2Configuration(configurationId, {
businessContext,
});
setSaving(false);
if ("error" in result) {
setError(result.error);
return;
try {
const result = await updateLighthouseV2Configuration(configurationId, {
businessContext,
});
if ("error" in result) {
setError(result.error);
return;
}
setSavedContext(result.data.businessContext);
setBusinessContext(result.data.businessContext);
} catch {
setError("Something went wrong while saving. Please try again.");
} finally {
setSaving(false);
}
setSavedContext(result.data.businessContext);
setBusinessContext(result.data.businessContext);
};
return (
@@ -69,11 +69,21 @@ export function LighthouseV2ConfigPage({
providers.find((provider) => provider.id === selectedProvider) ??
providers[0];
// Replace in place (don't filter+append): the shared business-context editor
// is anchored to localConfigurations[0], so reordering on every save/test
// would silently retarget it to a different provider's configuration.
const upsertConfiguration = (configuration: LighthouseV2Configuration) => {
setLocalConfigurations((current) => [
...current.filter((config) => config.id !== configuration.id),
configuration,
]);
setLocalConfigurations((current) => {
const index = current.findIndex(
(config) => config.id === configuration.id,
);
if (index === -1) {
return [...current, configuration];
}
const next = [...current];
next[index] = configuration;
return next;
});
};
const handleConfigurationSaved = (
@@ -134,6 +144,7 @@ export function LighthouseV2ConfigPage({
>
{businessContextConfig ? (
<LighthouseV2BusinessContextForm
key={businessContextConfig.id}
configurationId={businessContextConfig.id}
initialBusinessContext={businessContextConfig.businessContext}
/>
+1 -1
View File
@@ -11,7 +11,7 @@ import {
type LighthouseV2ProviderType,
} from "@/app/(prowler)/lighthouse/_types";
export const BUSINESS_CONTEXT_LIMIT = 1000;
export const BUSINESS_CONTEXT_LIMIT = 5000;
export const CONNECTION_STATUS = {
CONNECTED: "connected",