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


##########
superset-frontend/plugins/preset-chart-deckgl/src/Multi/Multi.tsx:
##########
@@ -409,8 +515,50 @@ const DeckMulti = (props: DeckMultiProps) => {
   const prevDeckSlices = usePrevious(props.formData.deck_slices);
   const prevVisibleLayersRedux = usePrevious(visibleDeckLayersFromRedux);
 
+  const fetchSubslices = useCallback(
+    (sliceIds: number[]) =>
+      Promise.all<({ slice_id: number } & JsonObject) | null>(
+        sliceIds.map(sliceId =>

Review Comment:
   Good catch, and yeah this is a real regression, not just a hardening nit. 
Old `viz.py.get_data()` raised `QueryObjectValidationError` before fanning out 
if `len(slice_ids) > DECK_MULTI_MAX_SLICES`, and that cap never made it into 
the client rewrite. Pushed a fix: `DECK_MULTI_MAX_SLICES` is now exposed to the 
frontend via `FRONTEND_CONF_KEYS`/bootstrap conf, and `Multi.tsx` checks 
`deck_slices.length` against it before calling `fetchSubslices`, surfacing the 
same "too many sub-slices" message as an alert instead of firing off the fanout.



##########
superset-frontend/plugins/preset-chart-deckgl/src/Multi/Multi.tsx:
##########
@@ -336,35 +363,114 @@ const DeckMulti = (props: DeckMultiProps) => {
         },
       } as any as JsonObject & { slice_id: number };
 
-      const url = getExploreLongUrl(subsliceCopy.form_data, 'json');
-
-      if (url) {
-        SupersetClient.get({ endpoint: url })
-          .then(({ json }) => {
-            const layer = createLayerFromData(subsliceCopy, json);
+      const vizType = subsliceCopy.form_data.viz_type as string;
+      Promise.all([
+        getChartBuildQueryRegistry().get(vizType),
+        getChartTransformPropsRegistry().get(vizType),
+      ])
+        .then(([layerBuildQuery, layerTransformProps]) => {
+          if (
+            typeof layerBuildQuery !== 'function' ||
+            typeof layerTransformProps !== 'function'
+          ) {
+            throw new Error(`Unknown deck.gl layer type: ${vizType}`);
+          }
+          const queryContext = layerBuildQuery(
+            subsliceCopy.form_data as QueryFormData,
+          );
+          return SupersetClient.post({
+            endpoint: '/api/v1/chart/data',
+            jsonPayload: {
+              ...queryContext,
+              result_format: 'json',
+              result_type: 'full',
+            },
+          }).then(({ json }) => {
+            // A newer loadLayers call (deck_slices or the visibility filter
+            // changed again) has already reset state; this response belongs
+            // to an abandoned generation and must not write into it.
+            if (loadGenerationRef.current !== generation) {
+              return;
+            }
+            const chartProps = new ChartProps({
+              width: props.width,
+              height: props.height,
+              datasource: props.datasource as unknown as JsonObject,
+              formData: subsliceCopy.form_data,
+              queriesData: (json as JsonObject).result,
+              theme,
+              hooks: {},
+              initialValues: {},
+            });
+            const layerProps = layerTransformProps(chartProps) as JsonObject;
+            const layer = createLayerFromData(subsliceCopy, 
layerProps.payload);
             setSubSlicesLayers(subSlicesLayers => ({
               ...subSlicesLayers,
               [subsliceCopy.slice_id]: layer,
             }));
-          })
-          .catch(error => {
-            throw new Error(
-              `Error loading layer for slice ${subsliceCopy.slice_id}: 
${error}`,
-            );
+
+            // Refit the viewport to the data now that this layer's features 
are
+            // known (unless autozoom is off). The initial getAdjustedViewport
+            // could not do this because the v1 payload carries no features.
+            const layerFeatures = (layerProps.payload as JsonObject | 
undefined)
+              ?.data?.features;
+            if (formData.autozoom !== false && Array.isArray(layerFeatures)) {
+              layerFeaturesRef.current = {
+                ...layerFeaturesRef.current,
+                [vizType]: layerFeatures,

Review Comment:
   You're right, that's a real bug. I keyed the accumulator by slice_id now 
(still bucketing by viz_type internally for , which needs the buckets), so two 
same-type layers get concatenated instead of the second clobbering the first. 
Pushed the fix.



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