aminghadersohi commented on code in PR #44851:
URL: https://github.com/apache/superset/pull/44851#discussion_r4161665330


##########
superset-frontend/src/explore/actions/exploreActions.ts:
##########
@@ -272,6 +284,75 @@ export function syncDatasourceMetadata(datasource: 
Dataset) {
   return { type: SYNC_DATASOURCE_METADATA, datasource };
 }
 
+export const SYNC_SEMANTIC_METADATA = 'explore/SYNC_SEMANTIC_METADATA';
+/** Rebuild metadata-derived controls without recording a chart edit. */
+export function syncSemanticMetadata(
+  datasource: Dataset,
+  formData: QueryFormData,
+): {
+  type: typeof SYNC_SEMANTIC_METADATA;
+  datasource: Dataset;
+  formData: QueryFormData;
+} {
+  return { type: SYNC_SEMANTIC_METADATA, datasource, formData };
+}
+
+/** Refresh the active view's metadata without saving or running the chart. */
+export function refreshSemanticMetadata(
+  viewId: number,
+  sessionIsCurrent: () => boolean,
+) {
+  return async (
+    dispatch: Dispatch,
+    getState: () => Pick<ExplorePageState, 'explore'>,
+  ) => {
+    const isCurrent = () => {
+      const { datasource } = getState().explore;
+      return (
+        sessionIsCurrent() &&
+        Number(datasource.id) === viewId &&
+        String(datasource.type) === 'semantic_view'
+      );
+    };
+    if (!isCurrent()) return;
+    // A pre-sync compatibility response cannot replace a post-sync answer.
+    compatibilityRequestSeq += 1;
+    const { json } = await SupersetClient.get({
+      endpoint: 
`/fetch_datasource_metadata?datasourceKey=${viewId}__semantic_view`,
+    });
+    if (!isCurrent()) return;
+    const formData = getFormDataFromControls(getState().explore.controls);
+    // Rebuild the controls against fresh fields using their existing values 
and
+    // normal removed-member validation, without rewriting form_data or 
querying.
+    dispatch(syncSemanticMetadata(json as Dataset, formData));
+    const selectedMetrics = [
+      ...new Set(
+        [...ensureIsArray(formData.metrics), formData.metric].filter(
+          (value): value is string => typeof value === 'string',
+        ),
+      ),
+    ];
+    const selectedDimensions = [
+      ...new Set(
+        [
+          ...ensureIsArray(formData.groupby),
+          ...ensureIsArray(formData.columns),
+          formData.x_axis,
+        ].filter((value): value is string => typeof value === 'string'),
+      ),
+    ];
+    const verified = await fetchCompatibility(
+      'semantic_view',
+      viewId,
+      selectedMetrics,
+      selectedDimensions,
+      isCurrent,
+    )(dispatch);
+    if (verified === false && isCurrent())

Review Comment:
   Deleting this check keeps all 109 tests in this layer green, so the 
publish-succeeded/compatibility-failed path that should raise 'Reload fields' 
is unpinned. A test where SupersetClient.post rejects and 
refreshSemanticMetadata(7, () => true)(...) must reject passes here and fails 
on that deletion.



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