mirror of
https://github.com/maputnik/editor.git
synced 2026-12-05 16:24:20 +00:00
Fixes #738. The layer editor's Type field was a read-only text box (`disabled={true}` on `FieldType`), so changing a layer's type meant editing the JSON. It's a dropdown again, the same one the Add Layer dialog uses. The `onChange` was already wired to `changeType()`, which keeps the paint and layout properties the new type supports and drops the rest. That's the behaviour agreed in the thread: keep what's shared, and the rest falls back to the spec defaults. Undo brings back the old layer. `changeType()` now also drops `source`, `source-layer` and `filter` when the new type is `background`, since a background layer can't have them and the style would otherwise fail validation. Other types keep all three. For example, a heatmap on a vector source still needs its `source-layer`. **Before / after** (layer editor, Type field): | Before | After | |---|---| | <img src="https://raw.githubusercontent.com/KhadeerBasha1232/maputnik/pr-assets/pr-738/before-layer-type.png" width="400"> | <img src="https://raw.githubusercontent.com/KhadeerBasha1232/maputnik/pr-assets/pr-738/after-layer-type.png" width="400"> | **Performance:** no impact. The change only runs when you pick a new type. ## Launch Checklist - [x] Briefly describe the changes in this PR. - [x] Link to related issues: fixes #738. - [x] Include before/after visuals or gifs if this PR includes visual changes. - [x] Write tests for all new functionality: `should change the layer type` in `layer-editor.spec.ts` (fails on `main`, where the field is a disabled text box), plus two `changeType` unit tests in `layer.test.ts` for the background case and for keeping source keys between other types. - [x] Add an entry to `CHANGELOG.md` under the `## main` section. Tested locally: `npm run lint` clean, `npx tsc --noEmit` clean, `npx vitest run` (59 passed) and the full `npx playwright test` suite (221 passed). With `main`'s `LayerEditor.tsx` and `layer.ts` put back, the new e2e test and the background unit test both fail. Assisted-By: Claude Opus 5.5 (Claude Code). It helped write the change, the tests and this description. I've reviewed and tested the change and can answer questions about it. Co-authored-by: Harel M <harel.mazor@gmail.com>