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



##########
File path: superset-frontend/src/SqlLab/components/ScheduleQueryButton.tsx
##########
@@ -0,0 +1,208 @@
+/**
+ * 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,
+};
+
+const 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 {};
+};
+
+const getUISchema = () => window.featureFlags.SCHEDULED_QUERIES?.UISCHEMA;
+
+const getValidationRules = () =>
+  window.featureFlags.SCHEDULED_QUERIES?.VALIDATION || [];
+
+const 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`

Review comment:
       You can also (for consistency) call this `StyledButtonComponent` and 
then instead of use a div to wrap the button, you can do styled(Button)` and 
then you don't have to wrap this around the button element, but just use this 
as the tag.
   Example: 
https://github.com/apache/superset/blob/9a05d6afe537d9b2bc605f515590c8461a8e95e4/superset-frontend/src/explore/components/DataTableControl.tsx#L38
   (Assume it's called StyledCopyButton though :))




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