{"size": 2401, "ext": "js", "max_stars_repo_path": "client/src/project/datasets/delete/DeleteDataset.container.js", "max_stars_repo_name": "noeleont/renku-ui", "max_stars_repo_stars_event_min_datetime": "2017-11-09T09:39:55.000Z", "max_stars_repo_stars_event_max_datetime": "2018-04-18T08:44:23.000Z", "max_issues_repo_path": "client/src/project/datasets/delete/DeleteDataset.container.js", "max_issues_repo_name": "noeleont/renku-ui", "max_issues_repo_issues_event_min_datetime": "2017-09-19T08:43:12.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-16T12:10:53.000Z", "max_forks_repo_path": "client/src/project/datasets/delete/DeleteDataset.container.js", "max_forks_repo_name": "noeleont/renku-ui", "max_forks_repo_forks_event_min_datetime": "2017-09-28T15:44:09.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-20T16:08:40.000Z"}
{"max_stars_count": 6, "max_issues_count": 108, "max_forks_count": 3, "avg_line_length": 30.0125, "max_line_length": 90, "alphanum_fraction": 0.6793002915}
/*!
 * Copyright 2020 - Swiss Data Science Center (SDSC)
 * A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and
 * Eidgenössische Technische Hochschule Zürich (ETHZ).
 *
 * Licensed 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.
 */

/**
 *  incubator-renku-ui
 *
 *  DeleteDataset.container.js
 *  Container component for removing a dataset.
 */


import React, { useState } from "react";
import DeleteDatasetPresent from "./DeleteDataset.present";


function DeleteDataset(props) {

  const [serverErrors, setServerErrors] = useState(undefined);
  const [submitLoader, setSubmitLoader] = useState(false);
  const [submitLoaderText, setSubmitLoaderText] = useState("Deleting dataset...");


  const closeModal = () =>{
    if (!submitLoader) {
      setServerErrors(undefined);
      props.setModalOpen(false);
    }
  };

  const deleteDataset = () => {
    setServerErrors(undefined);
    setSubmitLoader(true);
    setSubmitLoaderText("Deleting dataset...");
    props.client.deleteDataset(props.httpProjectUrl, props.dataset.name, props.versionUrl)
      .then(response => {
        if (response.data.error !== undefined) {
          setSubmitLoader(false);
          setServerErrors(response.data.error);
        }
        else {
          setSubmitLoaderText("Dataset deleted, you will be redirected soon...");
          setSubmitLoader(false);
          props.history.push({
            pathname: `/projects/${props.projectPathWithNamespace}/datasets`,
            state: { reload: true }
          });
        }
      });
  };

  return (
    <DeleteDatasetPresent
      dataset={props.dataset}
      modalOpen={props.modalOpen}
      closeModal={closeModal}
      deleteDataset={deleteDataset}
      serverErrors={serverErrors}
      submitLoader={{ value: submitLoader, text: submitLoaderText }}
      history={props.history}
    />
  );
}

export default DeleteDataset;
