Skip to content

Commit

Permalink
Impl [UI] Delete single artifact data (#2595)
Browse files Browse the repository at this point in the history
  • Loading branch information
illia-prokopchuk committed Jul 10, 2024
1 parent 191d1f3 commit 7689b14
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 22 deletions.
42 changes: 26 additions & 16 deletions src/components/Datasets/datasets.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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',
Expand Down
8 changes: 4 additions & 4 deletions src/elements/DeleteArtifactPopUp/DeleteArtifactPopUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const DeleteArtifactPopUp = ({ artifact, artifactType, category, filters, handle
return (
<>
<FormCheckBox
label="Delete artifact data, not only the artifact metadata."
label={`Delete ${artifactType} data, not only the ${artifactType} metadata.`}
name="extended_deletion_strategy"
/>
<FormOnChange
Expand All @@ -148,18 +148,18 @@ const DeleteArtifactPopUp = ({ artifact, artifactType, category, filters, handle
<>
<div className="warning">
<AlertIcon className="warning__icon" />
This action will permanently remove the data associated with the artifact
This action will permanently remove the data associated with the {artifactType}
</div>
<div className="delete-artifact-pop-up__extended-data">
<h4>If data deletion fails:</h4>
<FormRadio
label="Do not delete the artifact metadata."
label={`Do not delete the ${artifactType} metadata.`}
name="deletion_strategy"
value="data-force"
/>
<FormOnChange handler={onDeletionStrategyChange} name="deletion_strategy" />
<FormRadio
label="Delete the artifact metadata, even if the data deletion fails."
label={`Delete the ${artifactType} metadata, even if the data deletion fails.`}
name="deletion_strategy"
value="data-optional"
/>
Expand Down
2 changes: 1 addition & 1 deletion src/utils/notifications.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
29 changes: 28 additions & 1 deletion tests/mockServer/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import {
set,
omit,
forEach,
pick
pick,
isNil
} from 'lodash'

import frontendSpec from './data/frontendSpec.json'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7689b14

Please sign in to comment.