refactor(workbench): use persistent mode switch
This commit is contained in:
1 parent
c804a373ca
commit
00d5f7650f
5 files changed
+20
-41
No files matched your search
@@ -1,36 +1,3 @@
|
||||
// The `directEdit` kill switch.
|
||||
//
|
||||
// Default off, per design.md's rollout shape: with it off the workbench must
|
||||
// behave exactly like main — no edit interaction registered, no manifest
|
||||
// request, and none of the three edit sources created. Callers check this once
|
||||
// and skip the whole subsystem, rather than guarding individual call sites.
|
||||
//
|
||||
// Opt in per browser session with `?directEdit=1`, or persistently with
|
||||
// `localStorage.setItem('directEdit', '1')`. A query parameter of `0` wins over
|
||||
// stored state so a tab can always be forced back to the shipped behaviour.
|
||||
|
||||
const STORAGE_KEY = 'directEdit';
|
||||
|
||||
function readFlag(): boolean {
|
||||
if (typeof window === 'undefined') return false;
|
||||
const parameter = new URLSearchParams(window.location.search).get(STORAGE_KEY);
|
||||
if (parameter === '1' || parameter === 'true') return true;
|
||||
if (parameter === '0' || parameter === 'false') return false;
|
||||
try {
|
||||
return window.localStorage.getItem(STORAGE_KEY) === '1';
|
||||
} catch {
|
||||
// Private mode can throw on storage access; treat it as "off".
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolved once at module load so a single render pass cannot see the flag flip
|
||||
* halfway through and build a half-wired map.
|
||||
*/
|
||||
/** Initial mode for compatibility with the old URL opt-in. The UI may switch it at runtime. */
|
||||
export const directEditEnabled = readFlag();
|
||||
|
||||
/**
|
||||
* Whether a `road-interval` constraint actually applies to its interval.
|
||||
*
|
||||
|
||||
@@ -5,8 +5,7 @@
|
||||
// never keeps a second copy of the constraint model. This class owns both the
|
||||
// source and that lookup index, which is why they cannot drift apart.
|
||||
//
|
||||
// Baseline layers are untouched. This source is additive and is only created
|
||||
// when the `directEdit` flag is on.
|
||||
// Baseline layers are untouched. This source is additive and follows edit mode.
|
||||
|
||||
import Feature from 'ol/Feature';
|
||||
import Point from 'ol/geom/Point';
|
||||
|
||||
Reference in new issue
Block a user