rusackas commented on code in PR #44101:
URL: https://github.com/apache/superset/pull/44101#discussion_r4141934356


##########
superset-frontend/src/core/contributions.ts:
##########
@@ -0,0 +1,56 @@
+/**
+ * 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. Unlike `src/SqlLab/contributions.ts`, these locations
+ * aren't declared via the manifest `contributions.views`/`contributions.menus`
+ * field -- `ViewContributions`/`MenuContributions` in `superset-core`
+ * only accept a `sqllab` scope today -- so extensions register against
+ * them imperatively instead.
+ *
+ * @example
+ * ```typescript
+ * import { menus, views } from '@apache-superset/core';
+ *
+ * views.registerView(
+ *   { id: 'my-ext.settings', name: 'My Settings' },
+ *   GlobalLocations.settings.panel,

Review Comment:
   Good catch, fixed. Swapped the example to the literal location strings since 
`GlobalLocations` isn't exported from the public package, and switched the 
group to `primary` since that's the only one the Settings host renders.



##########
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 => {
+  const component = useSyncExternalStore(
+    subscribe,
+    () => viewRegistry.get(id)?.component,
+    () => undefined,
+  );
+  if (!component) {
+    return React.createElement(ExtensionPlaceholder, { id });
+  }
+  return React.createElement(

Review Comment:
   Good catch, fixed. Keyed the boundary by view id so a fresh one mounts when 
the route switches views.



-- 
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]

Reply via email to