fix(chat): preserve style defaults for omitted agent overrides
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
import { parseApplyLayerStylePayload } from "./toolCallStyleHelpers";
|
import { parseApplyLayerStylePayload } from "./toolCallStyleHelpers";
|
||||||
|
import { createDefaultLayerStyleState } from "@components/olmap/core/Controls/styleEditorPresets";
|
||||||
|
import { validateStyleConfig } from "@components/olmap/core/Controls/styleEditorUtils";
|
||||||
|
|
||||||
describe("parseApplyLayerStylePayload", () => {
|
describe("parseApplyLayerStylePayload", () => {
|
||||||
it("accepts a valid snake_case interval contract", () => {
|
it("accepts a valid snake_case interval contract", () => {
|
||||||
@@ -47,4 +49,17 @@ describe("parseApplyLayerStylePayload", () => {
|
|||||||
}),
|
}),
|
||||||
).toMatchObject({ layerId: "junctions", styleConfig: { opacity: 0.5 } });
|
).toMatchObject({ layerId: "junctions", styleConfig: { opacity: 0.5 } });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("preserves default palette indexes when only some style fields are provided", () => {
|
||||||
|
const payload = parseApplyLayerStylePayload({
|
||||||
|
layer_id: "pipes",
|
||||||
|
style_config: { property: "flow", color_type: "gradient" },
|
||||||
|
});
|
||||||
|
expect(payload).not.toBeNull();
|
||||||
|
const merged = {
|
||||||
|
...createDefaultLayerStyleState("pipes").styleConfig,
|
||||||
|
...payload?.styleConfig,
|
||||||
|
};
|
||||||
|
expect(validateStyleConfig(merged)).toEqual({ valid: true, errors: [] });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -198,10 +198,15 @@ export const parseApplyLayerStylePayload = (
|
|||||||
) return null;
|
) return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const definedStyleConfig = styleConfig
|
||||||
|
? (Object.fromEntries(
|
||||||
|
Object.entries(styleConfig).filter(([, value]) => value !== undefined),
|
||||||
|
) as Partial<StyleConfig>)
|
||||||
|
: undefined;
|
||||||
const hasStyleOverrides =
|
const hasStyleOverrides =
|
||||||
styleConfig &&
|
definedStyleConfig &&
|
||||||
Object.values(styleConfig).some((value) =>
|
Object.values(definedStyleConfig).some((value) =>
|
||||||
Array.isArray(value) ? value.length > 0 : value !== undefined,
|
Array.isArray(value) ? value.length > 0 : true,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!resetToDefault && !hasStyleOverrides) {
|
if (!resetToDefault && !hasStyleOverrides) {
|
||||||
@@ -211,7 +216,7 @@ export const parseApplyLayerStylePayload = (
|
|||||||
return {
|
return {
|
||||||
layerId,
|
layerId,
|
||||||
resetToDefault,
|
resetToDefault,
|
||||||
styleConfig: hasStyleOverrides ? styleConfig : undefined,
|
styleConfig: hasStyleOverrides ? definedStyleConfig : undefined,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user