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


##########
superset-frontend/src/explore/components/controls/LayerConfigsControl/geoStylerUtil.ts:
##########
@@ -0,0 +1,183 @@
+/**
+ * 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 { FeatureCollection, GeoJsonGeometryTypes } from 'geojson';
+import { VectorData } from 'geostyler-data';
+import { GeoStylerContextInterface, GeoStylerLocale, locale } from 'geostyler';
+
+import { Style, Symbolizer } from 'geostyler-style';
+import { ColTypeMapping } from './types';
+import { SupersetTheme } from '@apache-superset/core/theme';
+
+/**
+ * Map Superset column type to GeoStyler column type.
+ * @param colType The Superset columntype
+ * @returns The GeoStyler column type.
+ */
+export const colTypeToGeoStylerType = (colType: string) => {
+  // TODO add missing types
+  switch (colType) {
+    case 'LONGINTEGER':
+    case 'INTEGER':
+      return 'integer';
+    case 'STRING':
+      return 'string';
+    case 'DATETIME':
+    case 'DATE':
+    case 'FLOAT':
+    case 'DECIMAL':
+      return 'number';
+    default:
+      return colType;
+  }
+};
+
+/**
+ * Map Superset column types to GeoStyler data.
+ * @param colTypes The superset column types.
+ * @returns A geotyler-data object.
+ */
+export const colTypesToGeoStylerData = (
+  colTypes: ColTypeMapping,
+  dataFeatureCollection: FeatureCollection = {
+    type: 'FeatureCollection',
+    features: [],
+  },
+) => {
+  const data: VectorData = {
+    schema: {
+      type: 'object',
+      properties: Object.keys(colTypes).reduce(
+        (prev, cur) => ({
+          ...prev,
+          [cur]: {
+            type: colTypeToGeoStylerType(colTypes[cur]),
+          },
+        }),
+        {},
+      ),
+    },
+    exampleFeatures: dataFeatureCollection,
+  };
+  return data;
+};
+
+/**
+ * Create a GeoStylerContext.
+ *
+ * Sets the locales, GsData, and enables and disables certain features
+ * depending on given data and their geometries.
+ *
+ * @param gsLocale The locales of the active language.
+ * @param data The GeoStyler Data.
+ * @param geomTypes List of distinct geometry types.
+ * @returns The GeoStylerContext.
+ */
+export const createGeoStylerContext = (
+  gsLocale: GeoStylerLocale,
+  data: VectorData | undefined,
+  composition: GeoStylerContextInterface['composition'],
+) => {
+  const context: GeoStylerContextInterface = {
+    locale: gsLocale,
+    composition: composition ?? {},
+  };
+
+  if (data) {
+    context.data = data;
+  }
+
+  if (!context.composition!.Rules) {
+    context.composition!.Rules = {};
+  }
+  context.composition!.Rules.disableClassification =

Review Comment:
   This unconditionally overwrites `composition.Rules.disableClassification` 
with the data-derived value, so an operator who sets `MAP_GEOSTYLER_COMPOSITION 
= {"Rules": {"disableClassification": True}}` gets classification re-enabled as 
soon as any WFS sample features load. It also mutates the object passed in as 
`composition`. Should an explicit `true` from the configuration be preserved 
(and the composition copied rather than mutated)?



##########
superset-frontend/src/explore/components/controls/LayerConfigsControl/FlatLayerTree.tsx:
##########
@@ -81,7 +104,85 @@ export const StyledLayerTreeItem = styled(LayerTreeItem)`
   `}
 `;
 
-// forwardRef is needed here in order for emotion and antd tree to work 
properly
+interface DraggableLayerTreeItemProps {
+  layerConf: LayerConfWithId;
+  index: number;
+  draggable?: boolean;
+  onEditLayer: (layerConf: LayerConfWithId, idx: number) => void;
+  onRemoveLayer: (idx: number) => void;
+  onMoveLayerByIndex: (dragIndex: number, hoverIndex: number) => void;
+}
+
+const DraggableLayerTreeItem: FC<DraggableLayerTreeItemProps> = ({
+  layerConf,
+  index,
+  draggable = false,
+  onEditLayer,
+  onRemoveLayer,
+  onMoveLayerByIndex,
+}) => {
+  const ref = useRef<HTMLDivElement>(null);
+
+  const [, drag] = useDrag<DragItem, void, unknown>({

Review Comment:
   `useDrag`/`useDrop` now require a react-dnd provider, but the existing 
`LayerConfigsControl.test.tsx` `setup()` renders without `{ useDnd: true }`, so 
any test that renders a non-empty layer list hits "Expected drag drop context". 
Its reorder test also still looks up `.ant-tree-treenode` (line ~258), which 
this rewrite no longer renders. Could the harness be updated to render with the 
DnD provider and the reorder test rewritten to drive the new drag/drop boundary 
and assert the emitted layer order?



##########
superset-frontend/plugins/plugin-chart-cartodiagram/src/components/OlChartMap.tsx:
##########
@@ -196,6 +325,10 @@ export const OlChartMap = (props: OlChartMapProps) => {
     addLayers(layerConfigs);
   }, [olMap, layerConfigs]);
 
+  useEffect(() => {
+    applyMapExtentView(olMap, currentMapMaxExtent);

Review Comment:
   `applyMapExtentView` calls `olMap.setView(new View(...))`, but the 
`change:resolution` listener in the chart-size effect further down is bound to 
`olMap.getView()` at the time that effect ran, and its deps (`olMap`, 
`setControlValue`, `chartSize`) don't change when the extent does. After 
toggling Max. Extent (NONE/CUSTOM) and then zooming, the old view fires the 
events, so `chart_size.configs.zoom` stops updating and later size edits use a 
stale reference zoom. Could the listener be re-bound when the view is replaced 
(e.g. include `currentMapMaxExtent` in that effect's deps)?



##########
superset-frontend/plugins/plugin-chart-cartodiagram/src/util/layerUtil.tsx:
##########
@@ -158,6 +173,35 @@ export const createWfsLayer = async (wfsLayerConf: 
WfsLayerConf) => {
   });
 };
 
+/**
+ * Create a DATA layer.
+ *
+ * @param dataLayerConf The layer configuration
+ *
+ * @returns The created DATA layer
+ */
+export const createDataLayer = async (dataLayerConf: DataLayerConf) => {
+  const { attribution, style } = dataLayerConf;
+  const dataSource = new VectorSource({
+    attributions: attribution,

Review Comment:
   Unlike the WMS/WFS/XYZ constructors above, this branch passes `attribution` 
to the source without `escapeAttribution()`. OpenLayers renders attributions 
through `innerHTML`, so a chart saved through the API with 
`{"type":"DATA","attribution":"<img src=x onerror=...>"}` (the UI selector for 
DATA being disabled doesn't stop API-supplied `layer_configs`) would inject 
markup for every viewer wherever CSP allows inline handlers. Should this use 
`escapeAttribution(attribution)` like the other layer types?
   
   ```suggestion
       attributions: escapeAttribution(attribution),
   ```



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