From 7689b14603f08d5f9733103b592857e64c81a9b1 Mon Sep 17 00:00:00 2001 From: illia-prokopchuk <78905712+illia-prokopchuk@users.noreply.github.com> Date: Wed, 10 Jul 2024 13:48:33 +0300 Subject: [PATCH] Impl [UI] Delete single artifact data (#2595) --- src/components/Datasets/datasets.util.js | 42 ++++++++++++------- .../DeleteArtifactPopUp.js | 8 ++-- src/utils/notifications.util.js | 2 +- tests/mockServer/mock.js | 29 ++++++++++++- 4 files changed, 59 insertions(+), 22 deletions(-) diff --git a/src/components/Datasets/datasets.util.js b/src/components/Datasets/datasets.util.js index f44adad3c..5910b58d1 100644 --- a/src/components/Datasets/datasets.util.js +++ b/src/components/Datasets/datasets.util.js @@ -21,6 +21,7 @@ import React from 'react' import { isEqual } from 'lodash' import JobWizard from '../JobWizard/JobWizard' +import DeleteArtifactPopUp from '../../elements/DeleteArtifactPopUp/DeleteArtifactPopUp' import { ACTION_MENU_PARENT_ROW, @@ -257,6 +258,7 @@ export const generateActionsMenu = ( selectedDataset ) => { const isTargetPathValid = getIsTargetPathValid(datasetMin ?? {}, frontendSpec) + const datasetDataCouldBeDeleted = datasetMin?.target_path?.endsWith('.pq') || datasetMin?.target_path?.endsWith('.parquet') const getFullDataset = datasetMin => { return chooseOrFetchArtifact(dispatch, DATASETS_TAB, selectedDataset, datasetMin) @@ -311,22 +313,30 @@ export const generateActionsMenu = ( : '', className: 'danger', onClick: () => - openDeleteConfirmPopUp( - 'Delete dataset?', - `Do you want to delete the dataset "${datasetMin.db_key}"? Deleted datasets can not be restored.`, - () => { - handleDeleteArtifact( - dispatch, - projectName, - datasetMin.db_key, - datasetMin.tag, - datasetMin.tree, - handleRefresh, - datasetsFilters, - DATASET_TYPE - ) - } - ) + datasetDataCouldBeDeleted ? + openPopUp(DeleteArtifactPopUp, { + artifact: datasetMin, + artifactType: DATASET_TYPE, + category: DATASET_TYPE, + filters: datasetsFilters, + handleRefresh + }) + : openDeleteConfirmPopUp( + 'Delete dataset?', + `Do you want to delete the dataset "${datasetMin.db_key}"? Deleted datasets can not be restored.`, + () => { + handleDeleteArtifact( + dispatch, + projectName, + datasetMin.db_key, + datasetMin.tag, + datasetMin.tree, + handleRefresh, + datasetsFilters, + DATASET_TYPE + ) + } + ) }, { label: 'Delete all', diff --git a/src/elements/DeleteArtifactPopUp/DeleteArtifactPopUp.js b/src/elements/DeleteArtifactPopUp/DeleteArtifactPopUp.js index 5413810d2..95bd599c9 100644 --- a/src/elements/DeleteArtifactPopUp/DeleteArtifactPopUp.js +++ b/src/elements/DeleteArtifactPopUp/DeleteArtifactPopUp.js @@ -137,7 +137,7 @@ const DeleteArtifactPopUp = ({ artifact, artifactType, category, filters, handle return ( <>
- This action will permanently remove the data associated with the artifact + This action will permanently remove the data associated with the {artifactType}

If data deletion fails:

diff --git a/src/utils/notifications.util.js b/src/utils/notifications.util.js index 589cdee6e..0ba2acfe8 100644 --- a/src/utils/notifications.util.js +++ b/src/utils/notifications.util.js @@ -30,7 +30,7 @@ export const showErrorNotification = (dispatch, error, defaultErrorMsg, customEr error } - if (retryCallback && error.response.status !== FORBIDDEN_ERROR_STATUS_CODE) { + if (retryCallback && error?.response?.status !== FORBIDDEN_ERROR_STATUS_CODE) { notificationData.retry = retryCallback } diff --git a/tests/mockServer/mock.js b/tests/mockServer/mock.js index 469647938..78c960594 100644 --- a/tests/mockServer/mock.js +++ b/tests/mockServer/mock.js @@ -35,7 +35,8 @@ import { set, omit, forEach, - pick + pick, + isNil } from 'lodash' import frontendSpec from './data/frontendSpec.json' @@ -1784,6 +1785,31 @@ function deleteTags (req, res) { res.send() } +function getArtifact (req, res) { + let resData + let requestedArtifact = artifacts.artifacts.find( + artifact => + (artifact.metadata?.project === req.params.project || artifact.project === req.params.project) && + (artifact.spec?.db_key === req.params.key || artifact?.db_key === req.params.key) && + (isNil(req.query.iter) || +req.query.iter === artifact?.iter || +req.query.iter === artifact.metadata?.iter) && + (isNil(req.query.tag) || artifact.metadata?.tag === req.query.tag || artifact?.tag === req.query.tag) && + (isNil(req.query.tree) || artifact.metadata?.tree === req.query.tree || artifact?.tree === req.query.tree) + ) + + if (requestedArtifact) { + resData = requestedArtifact + } else { + res.statusCode = 404 + resData = { + detail: { + reason: `MLRunNotFoundError('Artifact not found ${req.params.project}/${req.params.key}')` + } + } + } + + res.send(resData) +} + function postArtifact (req, res) { const currentDate = new Date() const artifactTag = req.body.metadata.tag || 'latest' @@ -2280,6 +2306,7 @@ app.get(`${mlrunAPIIngress}/projects/:project/pipelines/:pipelineID`, getPipelin app.get(`${mlrunAPIIngress}/projects/:project/artifact-tags`, getProjectsArtifactTags) app.get(`${mlrunAPIIngressV2}/projects/:project/artifacts`, getArtifacts) +app.get(`${mlrunAPIIngressV2}/projects/:project/artifacts/:key`, getArtifact) app.post(`${mlrunAPIIngressV2}/projects/:project/artifacts`, postArtifact) app.put(`${mlrunAPIIngressV2}/projects/:project/artifacts/:key`, putArtifact) app.delete(`${mlrunAPIIngressV2}/projects/:project/artifacts/:key`, deleteArtifact)