hughhhh commented on a change in pull request #13443:
URL: https://github.com/apache/superset/pull/13443#discussion_r589690598



##########
File path: superset-frontend/src/SqlLab/components/ScheduleQueryButton.tsx
##########
@@ -0,0 +1,212 @@
+/**
+ * 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 React, { FunctionComponent, useState } from 'react';
+import Form, { FormValidation } from 'react-jsonschema-form';
+import { Col, FormControl, FormGroup, Row } from 'react-bootstrap';
+import { t, styled } from '@superset-ui/core';
+import chrono from 'chrono-node';
+import ModalTrigger from 'src/components/ModalTrigger';
+import FormLabel from 'src/components/FormLabel';
+import './ScheduleQueryButton.less';
+import Button from 'src/components/Button';
+
+const validators = {
+  greater: (a: number, b: number) => a > b,
+  greater_equal: (a: number, b: number) => a >= b,
+  less: (a: number, b: number) => a < b,
+  less_equal: (a: number, b: number) => a <= b,
+};
+
+function getJSONSchema() {
+  const jsonSchema = window.featureFlags.SCHEDULED_QUERIES?.JSONSCHEMA;
+  // parse date-time into usable value (eg, 'today' => `new Date()`)
+  if (jsonSchema) {
+    Object.entries(jsonSchema.properties).forEach(
+      ([key, value]: [string, any]) => {
+        if (value.default && value.format === 'date-time') {
+          jsonSchema.properties[key] = {
+            ...value,
+            default: chrono.parseDate(value.default).toISOString(),
+          };
+        }
+      },
+    );
+    return jsonSchema;
+  }
+  return {};
+}
+
+function getUISchema() {
+  return window.featureFlags.SCHEDULED_QUERIES?.UISCHEMA;
+}
+
+function getValidationRules() {
+  return window.featureFlags.SCHEDULED_QUERIES?.VALIDATION || [];
+}
+
+function getValidator() {
+  const rules: any = getValidationRules();
+  return (formData: Record<string, any>, errors: FormValidation) => {
+    rules.forEach((rule: any) => {
+      const test = validators[rule.name];
+      const args = rule.arguments.map((name: string) => formData[name]);
+      const container = rule.container || rule.arguments.slice(-1)[0];
+      if (!test(...args)) {
+        errors[container].addError(rule.message);
+      }
+    });
+    return errors;
+  };
+}
+
+interface ScheduleQueryButtonProps {
+  defaultLabel?: string;
+  sql: string;
+  schema?: string;
+  dbId: number;
+  animation?: boolean;
+  onSchedule?: Function;
+  scheduleQueryWarning: string | null;
+  disabled: boolean;
+  tooltip: string;
+}
+
+const StyledRow = styled(Row)`
+  padding-bottom: ${({ theme }) => theme.gridUnit * 2}px;
+`;
+
+const ButtonComponent = styled.div`
+  background-color: none;
+  .ant-btn.superset-button {
+    color: rgba(0, 0, 0, 0.85);
+    text-transform: none;
+    padding-right: 0px;
+    padding: 0px;
+    font-size: 14px;
+    height: 22px;
+    font-weight: ${({ theme }) => theme.typography.weights.normal};
+    &:first-child {
+      background: none;
+    }
+  }
+`;
+
+const ScheduleQueryButton: FunctionComponent<ScheduleQueryButtonProps> = ({
+  defaultLabel = t('Undefined'),
+  sql,
+  schema,
+  dbId,
+  onSchedule = () => {},
+  scheduleQueryWarning = null,
+  tooltip = '',
+}) => {
+  const [description, setDescription] = useState('');
+  const [label, setLabel] = useState(defaultLabel);
+  const [showSchedule, setShowSchedule] = useState(false);
+  let saveModal: any;
+  // this is for the ref that is created in the modal trigger. the modal is 
created in order to use the .close() function on it.

Review comment:
       is this comment still valid?




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

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