Skip to content

Commit

Permalink
Impl [Artifacts] Delete single artifact data
Browse files Browse the repository at this point in the history
  • Loading branch information
mariana-furyk committed May 15, 2024
1 parent 4a34362 commit 54a7d6c
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 28 deletions.
9 changes: 7 additions & 2 deletions src/api/artifacts-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,26 @@ const fetchArtifacts = (project, filters, config = {}, withLatestTag) => {
const artifactsApi = {
addTag: (project, tag, data) => mainHttpClient.put(`/projects/${project}/tags/${tag}`, data),
buildFunction: data => mainHttpClient.post('/build/function', data),
deleteArtifact: (project, key, tag, tree) => {
deleteArtifact: (project, key, tag, tree, deletion_strategy, secrets) => {
const config = {
params: {
tag,
tree
}
}

if (deletion_strategy) {
config.params.deletion_strategy = deletion_strategy
config.data = { secrets }
}

return mainHttpClientV2.delete(`/projects/${project}/artifacts/${key}`, config)
},
deleteArtifacts: (project, name, category) => {
const config = {
params: {}
}

if (name) config.params.name = name
if (category) config.params.category = category

Expand Down
30 changes: 12 additions & 18 deletions src/components/Files/files.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ such restriction.
*/
import React from 'react'

import DeleteArtifactPopUp from '../../elements/DeleteArtifactPopUp/DeleteArtifactPopUp'

import {
ACTION_MENU_PARENT_ROW,
ACTION_MENU_PARENT_ROW_EXPANDED,
Expand All @@ -44,6 +46,7 @@ import { openDeleteConfirmPopUp } from 'igz-controls/utils/common.util'
import { searchArtifactItem } from '../../utils/searchArtifactItem'
import { setDownloadItem, setShowDownloadsList } from '../../reducers/downloadReducer'
import { sortListByDate } from '../../utils'
import { openPopUp } from 'igz-controls/utils/common.util'

import { ReactComponent as TagIcon } from 'igz-controls/images/tag-icon.svg'
import { ReactComponent as YamlIcon } from 'igz-controls/images/yaml.svg'
Expand Down Expand Up @@ -218,7 +221,7 @@ export const generateActionsMenu = (
handleAddTag,
projectName,
handleRefresh,
datasetsFilters,
filters,
menuPosition
) => {
const isTargetPathValid = getIsTargetPathValid(file ?? {}, frontendSpec)
Expand Down Expand Up @@ -269,22 +272,13 @@ export const generateActionsMenu = (
: '',
className: 'danger',
onClick: () =>
openDeleteConfirmPopUp(
'Delete artifact?',
`Do you want to delete the artifact "${file.db_key}"? Deleted artifacts can not be restored.`,
() => {
handleDeleteArtifact(
dispatch,
projectName,
file.db_key,
file.tag,
file.tree,
handleRefresh,
datasetsFilters,
ARTIFACT_TYPE,
)
}
)
openPopUp(DeleteArtifactPopUp, {
artifact: file,
artifactType: ARTIFACT_TYPE,
category: ARTIFACT_OTHER_TYPE,
filters,
handleRefresh
})
},
{
label: 'Delete all',
Expand All @@ -303,7 +297,7 @@ export const generateActionsMenu = (
file.tag,
file.tree,
handleRefresh,
datasetsFilters,
filters,
ARTIFACT_TYPE,
ARTIFACT_OTHER_TYPE,
true
Expand Down
2 changes: 1 addition & 1 deletion src/components/ModelsPage/Models/Models.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ const Models = ({ fetchModelFeatureVector }) => {
}
})
},
[dispatch]
[dispatch, params.projectName]
)

const handleRefresh = useCallback(
Expand Down
159 changes: 159 additions & 0 deletions src/elements/DeleteArtifactPopUp/DeleteArtifactPopUp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
Copyright 2019 Iguazio Systems Ltd.
Licensed under the Apache License, Version 2.0 (the "License") with
an addition restriction as set forth herein. 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.
In addition, you may not use the software for any purposes that are
illegal under applicable law, and the grant of the foregoing license
under the Apache 2.0 license is conditioned upon your compliance with
such restriction.
*/
import React, { useCallback, useState } from 'react'
import { useDispatch } from 'react-redux'
import { useParams } from 'react-router-dom'
import { Form } from 'react-final-form'
import { createForm } from 'final-form'
import arrayMutators from 'final-form-arrays'
import PropTypes from 'prop-types'

import { ConfirmDialog, FormRadio, FormKeyValueTable } from 'igz-controls/components'
import { TERTIARY_BUTTON, DANGER_BUTTON } from 'igz-controls/constants'

import { handleDeleteArtifact } from '../../utils/handleDeleteArtifact'
import { getValidationRules } from 'igz-controls/utils/validation.util'
import { setFieldState } from 'igz-controls/utils/form.util'

import './deleteArtifactPopUp.scss'

const DeleteArtifactPopUp = ({ artifact, artifactType, category, filters, handleRefresh }) => {
const [isConfirmDialogOpen, setIsConfirmDialogOpen] = useState(true)
const dispatch = useDispatch()
const params = useParams()
const formRef = React.useRef(
createForm({
initialValues: {
deletion_strategy: 'metadata-only',
secrets: []
},
mutators: { ...arrayMutators, setFieldState },
onSubmit: () => {}
})
)

const handleCancel = () => {
setIsConfirmDialogOpen(false)
}

const handleDelete = useCallback(() => {
const secrets = {}

formRef.current.getState().values.secrets.forEach(secret => {
secrets[secret.data.key] = secret.data.value
})

handleDeleteArtifact(
dispatch,
params.projectName,
artifact.db_key,
artifact.tag,
artifact.tree,
handleRefresh,
filters,
artifactType,
category,
false,
formRef.current.getState().values.deletion_strategy,
secrets
).then(() => {
setIsConfirmDialogOpen(false)
})
}, [
artifact.db_key,
artifact.tag,
artifact.tree,
artifactType,
category,
dispatch,
filters,
handleRefresh,
params.projectName
])

return (
<ConfirmDialog
cancelButton={{
handler: () => handleCancel(),
label: 'Cancel',
variant: TERTIARY_BUTTON
}}
className="delete-artifact-pop-up"
confirmButton={{
handler: () => handleDelete(),
label: 'Delete',
variant: DANGER_BUTTON
}}
header={`Delete ${artifactType}?`}
isOpen={isConfirmDialogOpen}
message={`Do you want to delete the dataset "${artifact.db_key}"? Deleted datasets can not be restored.`}
>
<Form form={formRef.current} onSubmit={() => {}}>
{formState => {
return (
<>
<FormRadio
label="metadata-only"
name="deletion_strategy"
value="metadata-only"
tooltip="Delete only the artifact object. The related artifact data remains."
/>
<FormRadio
label="data-optional"
name="deletion_strategy"
value="data-optional"
tooltip="Delete the artifact object and the data. If data deletion is unsuccessful, deletes only the object."
/>
<FormRadio
label="data-force"
name="deletion_strategy"
value="data-force"
tooltip="Delete the artifact object and the data. If data deletion is unsuccessful, does not delete the object either."
/>
<div className="secrets-table">
{formState.values.deletion_strategy !== 'metadata-only' && (
<FormKeyValueTable
addNewItemLabel="Add secret"
isKeyEditable={false}
isValuePassword={true}
valueType="password"
keyValidationRules={getValidationRules('project.secrets.key')}
fieldsPath="secrets"
formState={formState}
/>
)}
</div>
</>
)
}}
</Form>
</ConfirmDialog>
)
}

DeleteArtifactPopUp.propTypes = {
artifact: PropTypes.object.isRequired,
artifactType: PropTypes.string.isRequired,
category: PropTypes.string.isRequired,
filters: PropTypes.object.isRequired,
handleRefresh: PropTypes.func.isRequired
}

export default DeleteArtifactPopUp
5 changes: 5 additions & 0 deletions src/elements/DeleteArtifactPopUp/deleteArtifactPopUp.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.delete-artifact-pop-up {
.secrets-table {
margin-top: 20px;
}
}
9 changes: 6 additions & 3 deletions src/reducers/artifactsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,12 @@ export const addTag = createAsyncThunk('addTag', ({ project, tag, data }) => {
export const buildFunction = createAsyncThunk('buildFunction', ({ funcData }) => {
return artifactsApi.buildFunction(funcData)
})
export const deleteArtifact = createAsyncThunk('deleteArtifact', ({ project, key, tag, tree }) => {
return artifactsApi.deleteArtifact(project, key, tag, tree)
})
export const deleteArtifact = createAsyncThunk(
'deleteArtifact',
({ project, key, tag, tree, deletion_strategy, secrets }) => {
return artifactsApi.deleteArtifact(project, key, tag, tree, deletion_strategy, secrets)
}
)
export const deleteArtifacts = createAsyncThunk(
'deleteArtifacts',
({ project, name, category }) => {
Expand Down
10 changes: 6 additions & 4 deletions src/utils/handleDeleteArtifact.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,19 @@ export const handleDeleteArtifact = (
filters,
artifactType,
category,
isDeleteAll
isDeleteAll,
deletion_strategy,
secrets
) => {
dispatch(
return dispatch(
isDeleteAll
? deleteArtifacts({ project, name: key, category })
: deleteArtifact({ project, key, tag, tree })
: deleteArtifact({ project, key, tag, tree, deletion_strategy, secrets })
)
.unwrap()
.then(() => {
refreshArtifacts(filters)
dispatch(
return dispatch(
setNotification({
status: 200,
id: Math.random(),
Expand Down

0 comments on commit 54a7d6c

Please sign in to comment.