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


##########
superset-frontend/src/extensions/ExtensionContext.test.ts:
##########
@@ -49,12 +49,3 @@ test('createExtensionContext creates context with lazy 
storage', () => {
   expect(ctx.storage.session).toBeDefined();
   expect(ctx.storage.ephemeral).toBeDefined();
 });

Review Comment:
   This drops `different extensions get different contexts`, but nothing in the 
PR changes how `createExtensionContext` builds per-extension contexts now that 
`window` moved out of the context. With it gone, the remaining tests only 
exercise a single extension, so a regression that shares or caches one context 
across extension ids would pass. Was the removal intentional, or can the test 
be restored?



##########
superset-frontend/src/core/window/index.ts:
##########
@@ -0,0 +1,64 @@
+/**
+ * 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.
+ */
+
+import type { window as windowApi } from '@apache-superset/core';
+import {
+  addDangerToast,
+  addInfoToast,
+  addWarningToast,
+} from 'src/components/MessageToasts/actions';
+import { store } from 'src/views/store';
+
+/**
+ * Only `duration` is part of the SDK contract, so pick it out rather than
+ * forwarding the whole options object, and omit it when unset so the
+ * host's per-severity default applies.
+ */
+const toToastOptions = (options?: windowApi.MessageOptions) =>
+  options?.duration === undefined ? undefined : { duration: options.duration };
+
+// Dispatched against the app-level `store` singleton directly, not via a
+// `useDispatch()` hook, since these surfaces must also work from
+// non-component extension code (e.g. a registered command's callback).
+const showInformationMessage: typeof windowApi.showInformationMessage = (
+  message,
+  options,
+) => {
+  store.dispatch(addInfoToast(message, toToastOptions(options)));
+};
+
+const showWarningMessage: typeof windowApi.showWarningMessage = (
+  message,
+  options,
+) => {
+  store.dispatch(addWarningToast(message, toToastOptions(options)));
+};
+
+const showErrorMessage: typeof windowApi.showErrorMessage = (
+  message,
+  options,
+) => {
+  store.dispatch(addDangerToast(message, toToastOptions(options)));
+};
+
+export const window: typeof windowApi = {

Review Comment:
   Extensions never receive this implementation: `ExtensionsStartup` builds 
`window.superset` from an explicit namespace list (`authentication`, `chat`, 
`core`, `commands`, ..., `views`) and `window` isn't in it. The 
`...supersetCore` spread only supplies the declaration-only stubs from 
`packages/superset-core/src/window`, so `import { window } from 
'@apache-superset/core'; window.showInformationMessage('hi')` in an extension 
resolves to `undefined` and throws a `TypeError` instead of showing a toast. 
The unit tests import `src/core/window` directly, so they stay green. Should 
`window` be imported from `src/core` and added to that object, ideally with a 
test that asserts `window.superset.window.showInformationMessage` is callable 
after startup?



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