beenhead commented on code in PR #19547:
URL: https://github.com/apache/druid/pull/19547#discussion_r3389145846


##########
web-console/src/dialogs/supervisor-to-sql-dialog/supervisor-to-sql-dialog.tsx:
##########
@@ -0,0 +1,303 @@
+/*
+ * 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 { Button, Classes, Dialog, FormGroup, Intent, Radio, RadioGroup, 
TextArea, InputGroup } from '@blueprintjs/core';
+import { IconNames } from '@blueprintjs/icons';
+import React, { useState } from 'react';
+
+import { ExternalLink } from '../../components';
+import { convertSupervisorToSql } from '../../helpers/supervisor-conversion';
+import { AppToaster } from '../../singletons';
+import { Api } from '../../singletons';
+import { deepGet } from '../../utils';
+
+import './supervisor-to-sql-dialog.scss';
+
+interface SupervisorSpec {
+  type: string;
+  spec: {
+    dataSchema: {
+      dataSource: string;
+      timestampSpec: {
+        column: string;
+        format: string;
+      };
+      dimensionsSpec: {
+        dimensions: Array<string | { name: string; type: string }>;
+      };
+      metricsSpec: Array<{ name?: string; fieldName?: string; type: string }>;
+    };
+    ioConfig?: {
+      topic?: string;
+      inputSource?: {
+        type: string;
+        uris?: string[];
+        baseDir?: string;
+      };
+    };
+  };
+}
+
+export interface SupervisorToSqlDialogProps {
+  onConvert(sql: string): void;
+  onClose(): void;
+}
+
+export const SupervisorToSqlDialog = React.memo(function SupervisorToSqlDialog(
+  props: SupervisorToSqlDialogProps,
+) {
+  const { onConvert, onClose } = props;
+
+  const [supervisorSource, setSupervisorSource] = useState<'select' | 
'paste'>('select');
+  const [selectedSupervisor, setSelectedSupervisor] = useState<string>('');
+  const [pastedSupervisor, setPastedSupervisor] = useState<string>('');
+  const [availableSupervisors, setAvailableSupervisors] = 
useState<string[]>([]);
+  const [supervisorSpec, setSupervisorSpec] = useState<SupervisorSpec | 
undefined>();
+  
+  const [fileLocation, setFileLocation] = useState<string>('');
+  const [fileType, setFileType] = useState<string>('json');
+  
+  const [loading, setLoading] = useState(false);
+  const [error, setError] = useState<string | undefined>();
+
+  React.useEffect(() => {
+    void loadSupervisors();
+  }, []);
+
+  async function loadSupervisors() {
+    try {
+      const supervisors = await 
Api.instance.get<string[]>('/druid/indexer/v1/supervisor');
+      setAvailableSupervisors(supervisors.data);
+      if (supervisors.data.length > 0) {
+        setSelectedSupervisor(supervisors.data[0]);
+      }
+    } catch (e) {
+      setError(`Failed to load supervisors: ${e.message}`);
+    }
+  }
+
+  async function loadSupervisorSpec(supervisorId: string) {
+    if (!supervisorId) return;
+    
+    setLoading(true);
+    setError(undefined);
+    
+    try {
+      const resp = await Api.instance.get<SupervisorSpec>(
+        `/druid/indexer/v1/supervisor/${Api.encodePath(supervisorId)}`,
+      );
+      setSupervisorSpec(resp.data);
+      
+      // Auto-populate file location from ioConfig if available
+      const ioConfig = deepGet(resp.data, 'spec.ioConfig');
+      if (ioConfig?.inputSource?.uris) {
+        setFileLocation(ioConfig.inputSource.uris[0] || '');
+      } else if (ioConfig?.inputSource?.baseDir) {
+        setFileLocation(ioConfig.inputSource.baseDir);
+      }
+    } catch (e) {
+      setError(`Failed to load supervisor spec: ${e.message}`);
+    } finally {
+      setLoading(false);
+    }
+  }
+
+  function parsePastedSupervisor() {
+    if (!pastedSupervisor.trim()) {

Review Comment:
   Fixed. `parsePastedSupervisor` now clears `supervisorSpec` (and the error) 
when the textarea is empty, and the paste effect always reparses — so switching 
from select to paste mode, or clearing a valid paste, drops the previously 
loaded spec and disables `Generate SQL`. The select effect likewise clears the 
spec when nothing is selected.



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