Skip to content

Commit 53bd90b

Browse files
committed
Impl [Artifact/Models/Datasets] Add option to delete artifacts , models, dataset in the UI
1 parent 61a4d6a commit 53bd90b

File tree

9 files changed

+407
-206
lines changed

9 files changed

+407
-206
lines changed

src/api/artifacts-api.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,19 @@ const fetchArtifacts = (project, filters, config = {}) => {
4949

5050
const artifactsApi = {
5151
addTag: (project, tag, data) => mainHttpClient.put(`/projects/${project}/tags/${tag}`, data),
52-
replaceTag: (project, tag, data) => mainHttpClient.post(`/projects/${project}/tags/${tag}`, data),
52+
buildFunction: data => mainHttpClient.post('/build/function', data),
53+
deleteArtifact: (project, key, tag) => {
54+
const config = {
55+
params: {
56+
key,
57+
tag
58+
}
59+
}
60+
61+
return mainHttpClient.delete(`/projects/${project}/artifacts`, config)
62+
},
5363
deleteTag: (project, tag, data) =>
5464
mainHttpClient.delete(`/projects/${project}/tags/${tag}`, { data }),
55-
buildFunction: data => mainHttpClient.post('/build/function', data),
5665
getArtifactPreview: (project, path, user, fileFormat, cancelToken) => {
5766
const config = {
5867
params: { path }
@@ -153,6 +162,7 @@ const artifactsApi = {
153162
}`,
154163
data
155164
),
165+
replaceTag: (project, tag, data) => mainHttpClient.post(`/projects/${project}/tags/${tag}`, data),
156166
updateArtifact: (project, data) =>
157167
mainHttpClient.post(
158168
`/projects/${project}/artifacts/${data.uid || data.metadata?.tree}/${

src/components/Datasets/Datasets.js

Lines changed: 23 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,17 @@ import {
3737
fetchDataSet,
3838
fetchDataSets,
3939
removeDataSet,
40-
removeDataSets,
41-
showArtifactsPreview
40+
removeDataSets
4241
} from '../../reducers/artifactsReducer'
4342
import {
4443
checkForSelectedDataset,
4544
fetchDataSetRowData,
4645
filters,
46+
generateActionsMenu,
4747
generatePageData,
4848
handleApplyDetailsChanges
4949
} from './datasets.util'
5050
import { cancelRequest } from '../../utils/cancelRequest'
51-
import { createDatasetsRowData, getIsTargetPathValid } from '../../utils/createArtifactsContent'
5251
import { getArtifactIdentifier } from '../../utils/getUniqueIdentifier'
5352
import { isDetailsTabExists } from '../../utils/isDetailsTabExists'
5453
import { openPopUp } from 'igz-controls/utils/common.util'
@@ -59,13 +58,7 @@ import { useGetTagOptions } from '../../hooks/useGetTagOptions.hook'
5958
import { useGroupContent } from '../../hooks/groupContent.hook'
6059
import { useYaml } from '../../hooks/yaml.hook'
6160
import { getViewMode } from '../../utils/helper'
62-
import { copyToClipboard } from '../../utils/copyToClipboard'
63-
import { generateUri } from '../../utils/resources'
64-
65-
import { ReactComponent as TagIcon } from 'igz-controls/images/tag-icon.svg'
66-
import { ReactComponent as YamlIcon } from 'igz-controls/images/yaml.svg'
67-
import { ReactComponent as ArtifactView } from 'igz-controls/images/eye-icon.svg'
68-
import { ReactComponent as Copy } from 'igz-controls/images/copy-to-clipboard-icon.svg'
61+
import { createDatasetsRowData } from '../../utils/createArtifactsContent'
6962

7063
const Datasets = () => {
7164
const [datasets, setDatasets] = useState([])
@@ -149,45 +142,26 @@ const Datasets = () => {
149142
)
150143

151144
const actionsMenu = useMemo(
152-
() => dataset => {
153-
const isTargetPathValid = getIsTargetPathValid(dataset ?? {}, frontendSpec)
154-
155-
return [
156-
[
157-
{
158-
disabled: !isTargetPathValid,
159-
label: 'Preview',
160-
icon: <ArtifactView />,
161-
onClick: dataset => {
162-
dispatch(
163-
showArtifactsPreview({
164-
isPreview: true,
165-
selectedItem: dataset
166-
})
167-
)
168-
}
169-
}
170-
],
171-
[
172-
{
173-
label: 'Copy URI',
174-
icon: <Copy />,
175-
onClick: dataset => copyToClipboard(generateUri(dataset, DATASETS_PAGE), dispatch)
176-
},
177-
{
178-
label: 'View YAML',
179-
icon: <YamlIcon />,
180-
onClick: toggleConvertedYaml
181-
},
182-
{
183-
label: 'Add a tag',
184-
icon: <TagIcon />,
185-
onClick: handleAddTag
186-
}
187-
]
188-
]
189-
},
190-
[dispatch, frontendSpec, handleAddTag, toggleConvertedYaml]
145+
() => dataset =>
146+
generateActionsMenu(
147+
dataset,
148+
frontendSpec,
149+
dispatch,
150+
toggleConvertedYaml,
151+
handleAddTag,
152+
params.projectName,
153+
handleRefresh,
154+
datasetsFilters
155+
),
156+
[
157+
datasetsFilters,
158+
dispatch,
159+
frontendSpec,
160+
handleAddTag,
161+
handleRefresh,
162+
params.projectName,
163+
toggleConvertedYaml
164+
]
191165
)
192166

193167
const applyDetailsChanges = useCallback(

src/components/Datasets/datasets.util.js

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ illegal under applicable law, and the grant of the foregoing license
1717
under the Apache 2.0 license is conditioned upon your compliance with
1818
such restriction.
1919
*/
20+
import React from 'react'
2021

2122
import { applyTagChanges } from '../../utils/artifacts.util'
2223
import { getArtifactIdentifier } from '../../utils/getUniqueIdentifier'
2324
import { generateProducerDetailsInfo } from '../../utils/generateProducerDetailsInfo'
2425
import {
26+
DATASET_TYPE,
2527
DATASETS,
2628
DATASETS_PAGE,
2729
FULL_VIEW_MODE,
@@ -30,10 +32,19 @@ import {
3032
NAME_FILTER,
3133
TAG_FILTER
3234
} from '../../constants'
33-
import { createDatasetsRowData } from '../../utils/createArtifactsContent'
35+
import { createDatasetsRowData, getIsTargetPathValid } from '../../utils/createArtifactsContent'
3436
import { searchArtifactItem } from '../../utils/searchArtifactItem'
3537
import { sortListByDate } from '../../utils'
36-
import { fetchDataSet } from '../../reducers/artifactsReducer'
38+
import { fetchDataSet, showArtifactsPreview } from '../../reducers/artifactsReducer'
39+
import { copyToClipboard } from '../../utils/copyToClipboard'
40+
import { generateUri } from '../../utils/resources'
41+
import { handleDeleteArtifact } from '../../utils/handleDeleteArtifact'
42+
43+
import { ReactComponent as TagIcon } from 'igz-controls/images/tag-icon.svg'
44+
import { ReactComponent as YamlIcon } from 'igz-controls/images/yaml.svg'
45+
import { ReactComponent as ArtifactView } from 'igz-controls/images/eye-icon.svg'
46+
import { ReactComponent as Copy } from 'igz-controls/images/copy-to-clipboard-icon.svg'
47+
import { ReactComponent as Delete } from 'igz-controls/images/delete.svg'
3748

3849
export const infoHeaders = [
3950
{
@@ -194,3 +205,66 @@ export const checkForSelectedDataset = (
194205
}
195206
})
196207
}
208+
209+
export const generateActionsMenu = (
210+
dataset,
211+
frontendSpec,
212+
dispatch,
213+
toggleConvertedYaml,
214+
handleAddTag,
215+
projectName,
216+
handleRefresh,
217+
datasetsFilters
218+
) => {
219+
const isTargetPathValid = getIsTargetPathValid(dataset ?? {}, frontendSpec)
220+
221+
return [
222+
[
223+
{
224+
disabled: !isTargetPathValid,
225+
label: 'Preview',
226+
icon: <ArtifactView />,
227+
onClick: dataset => {
228+
dispatch(
229+
showArtifactsPreview({
230+
isPreview: true,
231+
selectedItem: dataset
232+
})
233+
)
234+
}
235+
}
236+
],
237+
[
238+
{
239+
label: 'Copy URI',
240+
icon: <Copy />,
241+
onClick: dataset => copyToClipboard(generateUri(dataset, DATASETS_PAGE), dispatch)
242+
},
243+
{
244+
label: 'View YAML',
245+
icon: <YamlIcon />,
246+
onClick: toggleConvertedYaml
247+
},
248+
{
249+
label: 'Add a tag',
250+
icon: <TagIcon />,
251+
onClick: handleAddTag
252+
},
253+
{
254+
label: 'Delete',
255+
icon: <Delete />,
256+
className: 'danger',
257+
onClick: () =>
258+
handleDeleteArtifact(
259+
dispatch,
260+
projectName,
261+
dataset.db_key,
262+
dataset.tag,
263+
handleRefresh,
264+
datasetsFilters,
265+
DATASET_TYPE
266+
)
267+
}
268+
]
269+
]
270+
}

src/components/Files/Files.js

Lines changed: 23 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,13 @@ import {
3737
checkForSelectedFile,
3838
fetchFilesRowData,
3939
filters,
40+
generateActionsMenu,
4041
generatePageData,
4142
handleApplyDetailsChanges
4243
} from './files.util'
4344
import { cancelRequest } from '../../utils/cancelRequest'
44-
import { createFilesRowData, getIsTargetPathValid } from '../../utils/createArtifactsContent'
45-
import {
46-
fetchFile,
47-
fetchFiles,
48-
removeFile,
49-
removeFiles,
50-
showArtifactsPreview
51-
} from '../../reducers/artifactsReducer'
45+
import { createFilesRowData } from '../../utils/createArtifactsContent'
46+
import { fetchFile, fetchFiles, removeFile, removeFiles } from '../../reducers/artifactsReducer'
5247
import { getArtifactIdentifier } from '../../utils/getUniqueIdentifier'
5348
import { isDetailsTabExists } from '../../utils/isDetailsTabExists'
5449
import { openPopUp } from 'igz-controls/utils/common.util'
@@ -59,13 +54,6 @@ import { useGetTagOptions } from '../../hooks/useGetTagOptions.hook'
5954
import { useGroupContent } from '../../hooks/groupContent.hook'
6055
import { useYaml } from '../../hooks/yaml.hook'
6156
import { getViewMode } from '../../utils/helper'
62-
import { copyToClipboard } from '../../utils/copyToClipboard'
63-
import { generateUri } from '../../utils/resources'
64-
65-
import { ReactComponent as TagIcon } from 'igz-controls/images/tag-icon.svg'
66-
import { ReactComponent as YamlIcon } from 'igz-controls/images/yaml.svg'
67-
import { ReactComponent as ArtifactView } from 'igz-controls/images/eye-icon.svg'
68-
import { ReactComponent as Copy } from 'igz-controls/images/copy-to-clipboard-icon.svg'
6957

7058
const Files = () => {
7159
const [files, setFiles] = useState([])
@@ -139,45 +127,26 @@ const Files = () => {
139127
)
140128

141129
const actionsMenu = useMemo(
142-
() => file => {
143-
const isTargetPathValid = getIsTargetPathValid(file ?? {}, frontendSpec)
144-
145-
return [
146-
[
147-
{
148-
disabled: !isTargetPathValid,
149-
label: 'Preview',
150-
icon: <ArtifactView />,
151-
onClick: file => {
152-
dispatch(
153-
showArtifactsPreview({
154-
isPreview: true,
155-
selectedItem: file
156-
})
157-
)
158-
}
159-
}
160-
],
161-
[
162-
{
163-
label: 'Copy URI',
164-
icon: <Copy />,
165-
onClick: file => copyToClipboard(generateUri(file, FILES_PAGE), dispatch)
166-
},
167-
{
168-
label: 'View YAML',
169-
icon: <YamlIcon />,
170-
onClick: toggleConvertedYaml
171-
},
172-
{
173-
label: 'Add a tag',
174-
icon: <TagIcon />,
175-
onClick: handleAddTag
176-
}
177-
]
178-
]
179-
},
180-
[dispatch, frontendSpec, handleAddTag, toggleConvertedYaml]
130+
() => file =>
131+
generateActionsMenu(
132+
file,
133+
frontendSpec,
134+
dispatch,
135+
toggleConvertedYaml,
136+
handleAddTag,
137+
params.projectName,
138+
handleRefresh,
139+
filesFilters
140+
),
141+
[
142+
dispatch,
143+
filesFilters,
144+
frontendSpec,
145+
handleAddTag,
146+
handleRefresh,
147+
params.projectName,
148+
toggleConvertedYaml
149+
]
181150
)
182151

183152
const handleRemoveRowData = useCallback(

0 commit comments

Comments
 (0)