msyavuz commented on code in PR #34276:
URL: https://github.com/apache/superset/pull/34276#discussion_r2253923480


##########
superset-frontend/packages/superset-ui-chart-controls/package.json:
##########
@@ -27,7 +27,8 @@
     "@react-icons/all-files": "^4.1.0",
     "@types/react": "*",
     "lodash": "^4.17.21",
-    "prop-types": "^15.8.1"
+    "prop-types": "^15.8.1",
+    "react-dnd": "^16.0.1"

Review Comment:
   Why is this necessary?



##########
superset-frontend/plugins/legacy-preset-chart-deckgl/src/utilities/HandlebarsRenderer.tsx:
##########
@@ -0,0 +1,219 @@
+/**
+ * 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 { useEffect, useState } from 'react';
+import { styled, t } from '@superset-ui/core';
+import Handlebars from 'handlebars';
+import dayjs from 'dayjs';
+import { isPlainObject } from 'lodash';
+
+export interface HandlebarsRendererProps {
+  templateSource: string;
+  data: any;
+}
+
+const ErrorContainer = styled.pre`
+  white-space: pre-wrap;
+  color: ${({ theme }) => theme.colors.error.base};
+  background-color: ${({ theme }) => theme.colors.error.light2};
+  padding: ${({ theme }) => theme.sizeUnit * 2}px;
+  border-radius: ${({ theme }) => theme.borderRadius}px;
+`;
+
+export const HandlebarsRenderer: React.FC<HandlebarsRendererProps> = ({
+  templateSource,
+  data,
+}) => {
+  const [renderedTemplate, setRenderedTemplate] = useState('');
+  const [error, setError] = useState('');
+
+  useEffect(() => {
+    try {
+      const template = Handlebars.compile(templateSource);
+      const result = template(data);
+      setRenderedTemplate(result);
+      setError('');
+    } catch (error) {
+      setRenderedTemplate('');
+      setError(error.message || 'Unknown template error');
+    }
+  }, [templateSource, data]);

Review Comment:
   I think you are missing the htmlSanitization step from the same 
implementation in Handlebars chart



##########
superset-frontend/plugins/legacy-preset-chart-deckgl/src/DeckGLContainer.tsx:
##########
@@ -132,6 +134,19 @@ export const DeckGLContainer = memo(
       return props.layers as Layer[];
     }, [props.layers, props.mapStyle]);
 
+    const isCustomTooltip = (content: ReactNode): boolean =>
+      isValidElement(content) && content.type === CustomTooltipWrapper;

Review Comment:
   We can probably check other stuff for custom tooltips



##########
superset-frontend/plugins/legacy-preset-chart-deckgl/src/utilities/TooltipTemplateControl.tsx:
##########
@@ -0,0 +1,227 @@
+/**
+ * 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 { useCallback, useEffect, useState } from 'react';
+import { styled, t } from '@superset-ui/core';
+import { TooltipTemplateEditor } from './TooltipTemplateEditor';
+
+const StyledContainer = styled.div`
+  ${({ theme }) => `
+    .tooltip-template-control {
+      margin-bottom: ${theme.sizeUnit * 2}px;
+    }
+
+    .control-header {
+      display: flex;
+      justify-content: space-between;
+      align-items: center;
+      margin-bottom: ${theme.sizeUnit * 2}px;
+
+      h5 {
+        margin: 0;
+        font-size: ${theme.fontSizeSM}px;
+        font-weight: bold;
+        color: ${theme.colors.grayscale.dark1};

Review Comment:
   We should use top level theme tokens like `theme.colorText`. This goes for 
all the styles in the pr. You can find relevant tokens and their values in:
   
   https://ant.design/docs/react/customize-theme#theme



##########
superset-frontend/plugins/legacy-preset-chart-deckgl/src/layers/Heatmap/Heatmap.tsx:
##########
@@ -72,8 +131,10 @@ export const getLayer: GetLayerType<HeatmapLayer> = ({
     colorScale,
   })?.reverse();
 
+  const tooltipContent = setTooltipContent(fd);
+
   return new HeatmapLayer({
-    id: `heatmap-layer-${fd.slice_id}` as const,
+    id: `heatmap-layer-${fd.slice_id || 'temp'}` as const,

Review Comment:
   Is this used? `slice_id` should be present all the time this is rendered.



##########
superset-frontend/plugins/legacy-preset-chart-deckgl/src/components/CustomTooltipWrapper.tsx:
##########
@@ -0,0 +1,35 @@
+/**
+ * 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 { ReactNode } from 'react';
+
+interface CustomTooltipWrapperProps {
+  children: ReactNode;
+}
+
+/**
+ * Wrapper component to explicitly mark custom tooltips.
+ * This component doesn't render any additional DOM elements,
+ * it just serves as a marker for tooltip type detection.
+ */
+export default function CustomTooltipWrapper({
+  children,
+}: CustomTooltipWrapperProps) {
+  return <>{children}</>;
+}

Review Comment:
   Do we need this marker?



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