Skip to content

Commit 0c2fec5

Browse files
committed
refactor(admin): drop dead style-provider settings; base style is env-only
The web map selects its base style from NEXT_PUBLIC_STYLE_PROVIDER (maptiler | openmapx), read at runtime via the EnvProvider context. The admin "Style Provider" (MAP_STYLE_PROVIDER) and "Custom Style URL" (CUSTOM_STYLE_URL) fields were keyed to different variables with a different value set and were read by no code — saving them changed nothing. Remove both. The Map group now keeps only the MapTiler API Key (env MAPTILER_KEY), consumed by the server-side /api/maptiler proxy; drop its now-orphaned showWhen gate so it always renders.
1 parent 06d888f commit 0c2fec5

4 files changed

Lines changed: 24 additions & 64 deletions

File tree

apps/api/src/routes/__tests__/admin-settings.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,25 @@ describe("GET /admin/settings", () => {
176176
}
177177
});
178178

179+
it("keeps the live MapTiler key but drops the dead style-provider controls from the map group", async () => {
180+
const res = await app.inject({ method: "GET", url: "/admin/settings" });
181+
const body = res.json();
182+
183+
const map = body.groups.find((g: { id: string }) => g.id === "map");
184+
const keys = map.settings.map((s: { key: string }) => s.key);
185+
186+
// The base style provider is env-only (NEXT_PUBLIC_STYLE_PROVIDER); the old
187+
// MAP_STYLE_PROVIDER / CUSTOM_STYLE_URL admin fields drove nothing and are gone.
188+
expect(keys).toContain("maptilerApiKey");
189+
expect(keys).not.toContain("styleProvider");
190+
expect(keys).not.toContain("customStyleUrl");
191+
192+
// With the provider dropdown gone, the key must not be gated behind a
193+
// (now non-existent) styleProvider value — it always renders.
194+
const apiKey = map.settings.find((s: { key: string }) => s.key === "maptilerApiKey");
195+
expect(apiKey.showWhen).toBeUndefined();
196+
});
197+
179198
it("rejects unauthenticated requests with 401", async () => {
180199
mockRequireAdmin.mockRejectedValueOnce(
181200
Object.assign(new Error("Authentication required"), { statusCode: 401 }),

apps/api/src/routes/admin-settings.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ interface SettingDef {
2727
/**
2828
* Show this setting only when another setting in the same group has a
2929
* matching value. Evaluated client-side against the current local form
30-
* state. Used in the Map panel so MapTiler / Custom-style fields don't
31-
* render when the chosen Style Provider doesn't need them.
30+
* state — lets a panel hide fields that don't apply to the current choice.
3231
*/
3332
showWhen?: { key: string; equals: unknown | unknown[] };
3433
}
@@ -205,35 +204,15 @@ const SETTING_DEFS: SettingDef[] = [
205204
default: true,
206205
},
207206
// Map
208-
{
209-
group: "map",
210-
key: "styleProvider",
211-
label: "Style Provider",
212-
description: "Where to load the base map style from.",
213-
type: "select",
214-
options: ["maptiler", "self-hosted", "custom"],
215-
env: "MAP_STYLE_PROVIDER",
216-
default: "maptiler",
217-
},
218207
{
219208
group: "map",
220209
key: "maptilerApiKey",
221210
label: "MapTiler API Key",
211+
description: "MapTiler Cloud API key for the built-in MapTiler tile and style proxy.",
222212
type: "string",
223213
secret: true,
224214
env: "MAPTILER_KEY",
225215
default: "",
226-
showWhen: { key: "styleProvider", equals: "maptiler" },
227-
},
228-
{
229-
group: "map",
230-
key: "customStyleUrl",
231-
label: "Custom Style URL",
232-
description: "Used when style provider is set to 'custom'.",
233-
type: "string",
234-
env: "CUSTOM_STYLE_URL",
235-
default: "",
236-
showWhen: { key: "styleProvider", equals: "custom" },
237216
},
238217
// Data-Use Policy
239218
{

apps/web/src/components/admin/settings/SystemSettings.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,9 @@ function SettingsGroupPanel({
288288
const body: Record<string, unknown> = {};
289289
for (const s of group.settings) {
290290
if (s.envOverride) continue;
291-
// Don't write fields hidden by their showWhen predicate — we'd
292-
// otherwise clobber the stored value of the inactive provider
293-
// (e.g. saving with styleProvider=self-hosted shouldn't reset
294-
// maptilerApiKey or customStyleUrl).
291+
// Don't write fields hidden by their showWhen predicate — saving while
292+
// a field is hidden would clobber the stored value of the option that
293+
// isn't currently active.
295294
if (!isVisible(s, localValues)) continue;
296295
body[s.key] = localValues[s.key];
297296
}

apps/web/src/components/admin/settings/__tests__/SystemSettings.test.tsx

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -41,43 +41,6 @@ afterEach(() => {
4141
});
4242

4343
describe("SystemSettings env-override handling", () => {
44-
it("hides the env-overrides badge when the only override is hidden by showWhen", async () => {
45-
// Mirrors the Map panel: Style Provider is DB-sourced and visible, while
46-
// the env-overridden MapTiler key is hidden because the provider isn't
47-
// "maptiler". The panel must not claim an env override the operator can't see.
48-
mockGroup("Map", [
49-
{
50-
group: "map",
51-
key: "styleProvider",
52-
label: "Style Provider",
53-
type: "select",
54-
options: ["maptiler", "self-hosted", "custom"],
55-
secret: false,
56-
value: "self-hosted",
57-
source: "database",
58-
envVar: "MAP_STYLE_PROVIDER",
59-
envOverride: false,
60-
},
61-
{
62-
group: "map",
63-
key: "maptilerApiKey",
64-
label: "MapTiler API Key",
65-
type: "string",
66-
secret: true,
67-
value: "***",
68-
source: "env",
69-
envVar: "MAPTILER_KEY",
70-
envOverride: true,
71-
showWhen: { key: "styleProvider", equals: "maptiler" },
72-
},
73-
]);
74-
75-
render(<SystemSettings />, { wrapper: createQueryWrapper() });
76-
77-
await screen.findByRole("button", { name: /save map/i });
78-
expect(screen.queryByText("env overrides")).toBeNull();
79-
});
80-
8144
it("shows the env-overrides badge and disables a visible env-overridden field", async () => {
8245
mockGroup("Data-Use Policy", [
8346
{

0 commit comments

Comments
 (0)