rusackas commented on code in PR #44101: URL: https://github.com/apache/superset/pull/44101#discussion_r4131844293
########## superset-frontend/src/core/contributions.ts: ########## @@ -0,0 +1,53 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +/** + * Global (non-SQL-Lab-scoped) view/menu locations for extension + * integration, mirroring the pattern in `src/SqlLab/contributions.ts`. + * + * @example + * // In extension.json: + * { + * "contributions": { + * "views": { + * "global": { + * "settingsPanel": [{ "id": "my-ext.settings", "name": "My Settings" }] Review Comment: Good catch, that `global` scope was never real. Fixed the example to show the actual `registerView`/`registerMenuItem` path. `settings.panel` wiring is intentionally manual for now, matches `ExtensionView`'s own docstring. ########## superset-frontend/src/core/views/index.ts: ########## @@ -96,6 +96,44 @@ export const resolveView = (id: string): React.ReactElement => { ); }; +/** + * Reactive counterpart to `resolveView`, for hosting a single + * extension-registered view (see `src/pages/ExtensionView`). + * + * `resolveView` reads the registry once, synchronously, at call time. + * That's a real gap for a host page reached by direct/full navigation + * (a bookmark, a page refresh, or an extension's own menu command using + * `window.location.assign` -- see `ExtensionView`'s own docstring): the + * extension providing the view loads asynchronously (its remote entry is + * fetched over the network), so on first render the registry is still + * empty and a plain `resolveView` call permanently commits to the + * "could not be loaded" placeholder, with nothing to trigger a re-render + * once the extension actually finishes loading and registers. Subscribing + * via `useSyncExternalStore` (the same registry-change events `useViews` + * already subscribes to) re-renders once that registration lands. + * + * Snapshots the registered `component` itself, not a freshly + * `React.createElement`-ed result -- `useSyncExternalStore` requires a + * `getSnapshot` that returns a stable reference when nothing changed, and + * `entry.component` is exactly that (unlike a new element object created + * fresh on every call). + */ +export const useResolveView = (id: string): React.ReactElement => { Review Comment: Added a test that renders before the view registers, then registers it and asserts the placeholder swaps out reactively. ########## superset/views/core.py: ########## @@ -797,6 +797,34 @@ def file_handler(self) -> FlaskResponse: return self.render_app_template(extra_bootstrap_data=payload) + @has_access + @event_logger.log_this + @expose("/extensions/view/<path:view_id>") + def extension_view(self, view_id: str) -> FlaskResponse: Review Comment: Added request tests for both, an authenticated user gets the SPA shell and an anonymous one gets redirected to login. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
