AAfghahi commented on code in PR #21241:
URL: https://github.com/apache/superset/pull/21241#discussion_r971188521


##########
superset-frontend/src/views/CRUD/data/dataset/AddDataset/Footer/index.tsx:
##########
@@ -17,7 +17,103 @@
  * under the License.
  */
 import React from 'react';
+import Button from 'src/components/Button';
+import { t } from '@superset-ui/core';
+import { useSingleViewResource } from 'src/views/CRUD/hooks';
+import { logEvent } from 'src/logger/actions';
+import withToasts from 'src/components/MessageToasts/withToasts';
+import {
+  LOG_ACTIONS_DATASET_CREATION_EMPTY_CANCELLATION,
+  LOG_ACTIONS_DATASET_CREATION_DATABASE_CANCELLATION,
+  LOG_ACTIONS_DATASET_CREATION_SCHEMA_CANCELLATION,
+  LOG_ACTIONS_DATASET_CREATION_TABLE_CANCELLATION,
+  LOG_ACTIONS_DATASET_CREATION_SUCCESS,
+} from 'src/logger/LogUtils';
+import { DatasetObject } from '../types';
 
-export default function Footer() {
-  return <div>Footer</div>;
+const INPUT_FIELDS = ['db', 'schema', 'table_name'];
+const LOG_ACTIONS = [
+  LOG_ACTIONS_DATASET_CREATION_EMPTY_CANCELLATION,
+  LOG_ACTIONS_DATASET_CREATION_DATABASE_CANCELLATION,
+  LOG_ACTIONS_DATASET_CREATION_SCHEMA_CANCELLATION,
+  LOG_ACTIONS_DATASET_CREATION_TABLE_CANCELLATION,
+];
+interface FooterProps {
+  url: string;
+  addDangerToast: () => void;
+  datasetObject?: Partial<DatasetObject> | null;
+  onDatasetAdd?: (dataset: DatasetObject) => void;
 }
+
+function Footer({ url, datasetObject, addDangerToast }: FooterProps) {
+  const { createResource } = useSingleViewResource<Partial<DatasetObject>>(
+    'dataset',
+    t('dataset'),
+    addDangerToast,
+  );
+
+  const createLogAction = (dataset: Partial<DatasetObject>) => {
+    let totalCount = 0;
+    const value = Object.keys(dataset).reduce((total, key) => {
+      if (INPUT_FIELDS.includes(key) && dataset[key]) {
+        totalCount += 1;
+      }
+      return totalCount;
+    }, 0);
+
+    return LOG_ACTIONS[value];
+  };
+  const goToPreviousUrl = () => {
+    // this is a placeholder url until the final feature gets implemented
+    // at that point we will be passing in the url of the previous location.
+    window.location.href = url;
+  };
+
+  const cancelButtonOnClick = () => {
+    if (!datasetObject) {
+      logEvent(LOG_ACTIONS_DATASET_CREATION_EMPTY_CANCELLATION, {});
+    } else {
+      const logAction = createLogAction(datasetObject);
+      logEvent(logAction, datasetObject);
+    }
+    goToPreviousUrl();
+  };
+
+  const tooltipText = t('Select a database table.');
+
+  const onSave = () => {
+    if (datasetObject) {
+      const data = {
+        database: datasetObject.db?.id,
+        schema: datasetObject.schema,
+        table_name: datasetObject.table_name,
+      };
+      createResource(data).then(response => {
+        if (!response) {
+          return;
+        }
+        if (typeof response === 'number') {
+          logEvent(LOG_ACTIONS_DATASET_CREATION_SUCCESS, datasetObject);
+          // When a dataset is created the response we get is its ID number
+          goToPreviousUrl();
+        }
+      });
+    }
+  };
+
+  return (
+    <>
+      <Button onClick={cancelButtonOnClick}>Cancel</Button>
+      <Button
+        buttonStyle="primary"
+        disabled={!datasetObject?.table_name}
+        tooltip={!datasetObject?.table_name ? tooltipText : undefined}

Review Comment:
   The type wants undefined, I originally tried it with null but got ts errors. 



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