Skip to content

Commit 62adef4

Browse files
committed
Plumb experimental editor toolbar env var to client-side
1 parent 4a389fb commit 62adef4

File tree

6 files changed

+37
-1
lines changed

6 files changed

+37
-1
lines changed

demo/text.py

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def text():
1212
me.text(text="headline-2: Hello, world!", type="headline-2")
1313
me.text(text="headline-3: Hello, world!", type="headline-3")
1414
me.text(text="headline-4: Hello, world!", type="headline-4")
15+
me.button("Button", type="flat") # Added button here
1516
me.text(text="headline-5: Hello, world!", type="headline-5")
1617
me.text(text="headline-6: Hello, world!", type="headline-6")
1718
me.text(text="subtitle-1: Hello, world!", type="subtitle-1")

mesop/protos/ui.proto

+6
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ message RenderEvent {
143143

144144
// Only sent in editor mode:
145145
repeated ComponentConfig component_configs = 5;
146+
// Only sent in initial render:
147+
optional ExperimentSettings experiment_settings = 7;
148+
}
149+
150+
message ExperimentSettings {
151+
optional bool experimental_editor_toolbar_enabled = 1;
146152
}
147153

148154
// UI response event for updating state.

mesop/server/server.py

+8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
os.environ.get("MESOP_EXPERIMENTAL_EDITOR_TOOLBAR", "false").lower() == "true"
3131
)
3232

33+
print(
34+
"EXPERIMENTAL_EDITOR_TOOLBAR_ENABLED", EXPERIMENTAL_EDITOR_TOOLBAR_ENABLED
35+
)
3336

3437
LOCALHOSTS = (
3538
# For IPv4 localhost
@@ -92,6 +95,11 @@ def render_loop(
9295
f"/{WEB_COMPONENTS_PATH_SEGMENT}{js_module}"
9396
for js_module in js_modules
9497
],
98+
experiment_settings=pb.ExperimentSettings(
99+
experimental_editor_toolbar_enabled=EXPERIMENTAL_EDITOR_TOOLBAR_ENABLED,
100+
)
101+
if init_request
102+
else None,
95103
)
96104
)
97105
yield serialize(data)

mesop/web/src/editor/editor.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
DebugErrorDialogService,
3737
ErrorDialogService,
3838
} from '../services/error_dialog_service';
39+
import {ExperimentService} from '../services/experiment_service';
3940
// Keep the following comment to ensure there's a hook for adding TS imports in the downstream sync.
4041
// ADD_TS_IMPORT_HERE
4142

@@ -80,6 +81,7 @@ class Editor {
8081
private router: Router,
8182
private editorService: EditorService,
8283
private channel: Channel,
84+
private experimentService: ExperimentService,
8385
) {
8486
iconRegistry.setDefaultFontSetClass('material-symbols-rounded');
8587
this.renderer.setAttribute(
@@ -163,7 +165,7 @@ class Editor {
163165
}
164166

165167
showEditorToolbar(): boolean {
166-
return Boolean(window.localStorage.getItem('MESOP://SHOW_EDITOR_TOOLBAR'));
168+
return this.experimentService.experimentalEditorToolbarEnabled;
167169
}
168170
}
169171

mesop/web/src/services/channel.ts

+11
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {applyComponentDiff, applyStateDiff} from '../utils/diff';
1919
import {getViewportSize} from '../utils/viewport_size';
2020
import {ThemeService} from './theme_service';
2121
import {getQueryParams} from '../utils/query_params';
22+
import {ExperimentService} from './experiment_service';
2223

2324
// Pick 500ms as the minimum duration before showing a progress/busy indicator
2425
// for the channel.
@@ -63,6 +64,7 @@ export class Channel {
6364
private logger: Logger,
6465
private title: Title,
6566
private themeService: ThemeService,
67+
private experimentService: ExperimentService,
6668
) {
6769
this.themeService.setOnChangePrefersColorScheme(() => {
6870
const userEvent = new UserEvent();
@@ -199,6 +201,15 @@ export class Channel {
199201
this.rootComponent = rootComponent;
200202
}
201203

204+
const experimentSettings = uiResponse
205+
.getRender()!
206+
.getExperimentSettings();
207+
if (experimentSettings) {
208+
this.experimentService.experimentalEditorToolbarEnabled =
209+
experimentSettings.getExperimentalEditorToolbarEnabled() ??
210+
false;
211+
}
212+
202213
this.componentConfigs = uiResponse
203214
.getRender()!
204215
.getComponentConfigsList();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {Injectable} from '@angular/core';
2+
3+
@Injectable({
4+
providedIn: 'root',
5+
})
6+
export class ExperimentService {
7+
experimentalEditorToolbarEnabled = false;
8+
}

0 commit comments

Comments
 (0)