Add buttons to delete image upload

These buttons don't do anything yet, and they are also currently
unrestricted (ie, they will appear regardless of whether the user
is authorized to delete images).  Both of those will change in
later changes, but for now, this change adds the dropdown menus
and confirmation dialogs needed to delete images and uploads
through the web ui.

Change-Id: I7e31cfe1c248d3d3e1eac71494941fc176688f46
This commit is contained in:
James E. Blair committed 2025-01-08 09:55:58 -08:00
1 parent 49ec288811
commit 7c5df255ab
3 files changed
+118 -21

No files matched your search

+61 -10
View File
@@ -13,14 +13,17 @@
// License for the specific language governing permissions and limitations
// under the License.
import React from 'react'
import React, { useState } from 'react'
import { useSelector } from 'react-redux'
import PropTypes from 'prop-types'
import {
Button,
EmptyState,
EmptyStateBody,
Spinner,
Title,
Modal,
ModalVariant,
} from '@patternfly/react-core'
import {
Table,
@@ -34,7 +37,8 @@ import ImageUploadTable from './ImageUploadTable'
function ImageBuildTable(props) {
const { buildArtifacts, fetching } = props
const [collapsedRows, setCollapsedRows] = React.useState([])
const [collapsedRows, setCollapsedRows] = useState([])
const [showDeleteImageModal, setShowDeleteImageModal] = useState(false)
const setRowCollapsed = (idx, isCollapsing = true) =>
setCollapsedRows(prevCollapsed => {
const otherCollapsedRows = prevCollapsed.filter(r => r !== idx)
@@ -65,9 +69,18 @@ function ImageBuildTable(props) {
]
function createImageBuildRow(rows, build) {
// Only link to the build if it is in this tenant
const buildUUID = build.build_tenant?
<Link to={`${tenant.linkPrefix}/build/${build.build_uuid}`}>
{build.build_uuid}
</Link>
:
build.build_uuid
return {
uuid: build.uuid,
id: rows.length,
isOpen: !isRowCollapsed(rows.length),
canDelete: build.build_tenant,
cells: [
{
title: build.uuid
@@ -79,23 +92,22 @@ function ImageBuildTable(props) {
title: build.validated.toString()
},
{
// TODO: This may not be a valid link if it's outside this tenant;
// consider hiding it in that case.
title: <Link to={`${tenant.linkPrefix}/build/${build.build_uuid}`}>
{build.build_uuid}
</Link>
title: buildUUID
},
]
}
}
function createImageUploadRow(rows, parent, build) {
return {
id: rows.length,
parent: parent.id,
cells: [
{
title: <ImageUploadTable uploads={build.uploads}
fetching={fetching}/>
title: <ImageUploadTable
build={build}
uploads={build.uploads}
fetching={fetching}/>
},
]
}
@@ -137,6 +149,44 @@ function ImageBuildTable(props) {
}
}
const actionResolver = (rowData) => {
if (rowData.parent !== undefined || !rowData.canDelete) {
return []
}
return [
{
title: 'Delete build',
onClick: () => {setShowDeleteImageModal(true)}
},
]
}
function renderDeleteImageModal() {
const title = 'Delete image build'
return (
<Modal
variant={ModalVariant.small}
isOpen={showDeleteImageModal}
title={title}
onClose={() => { setShowDeleteImageModal(false) }}
actions={[
<Button key="confirm" variant="primary"
onClick={() => {setShowDeleteImageModal(false) }}>
Confirm
</Button>,
<Button key="cancel" variant="link"
onClick={() => {setShowDeleteImageModal(false) }}>
Cancel
</Button>,
]}>
<p>
Please confirm that you want to delete this image
and all of its uploads.
</p>
</Modal>
)
}
return (
<>
<Title headingLevel="h3">
@@ -147,10 +197,10 @@ function ImageBuildTable(props) {
variant={TableVariant.compact}
cells={columns}
rows={rows}
actionResolver={actionResolver}
onCollapse={(_event, rowIndex, isOpen) => {
setRowCollapsed(rowIndex, !isOpen)
}}
className="zuul-table"
>
<TableHeader />
<TableBody />
@@ -166,6 +216,7 @@ function ImageBuildTable(props) {
</EmptyStateBody>
</EmptyState>
)}
{renderDeleteImageModal()}
</>
)
}
@@ -13,13 +13,16 @@
// License for the specific language governing permissions and limitations
// under the License.
import React from 'react'
import React, { useState } from 'react'
import PropTypes from 'prop-types'
import {
Button,
EmptyState,
EmptyStateBody,
Spinner,
Title,
Modal,
ModalVariant,
} from '@patternfly/react-core'
import {
Table,
@@ -29,7 +32,8 @@ import {
} from '@patternfly/react-table'
function ImageUploadTable(props) {
const { uploads, fetching } = props
const { build, uploads, fetching } = props
const [showDeleteUploadModal, setShowDeleteUploadModal] = useState(false)
const columns = [
{
@@ -56,6 +60,7 @@ function ImageUploadTable(props) {
function createImageUploadRow(upload) {
return {
canDelete: build.build_tenant,
cells: [
{
title: upload.uuid
@@ -95,6 +100,43 @@ function ImageUploadTable(props) {
return rows
}
const actionResolver = (rowData) => {
if (!rowData.canDelete) {
return []
}
return [
{
title: 'Delete upload',
onClick: () => {setShowDeleteUploadModal(true)}
},
]
}
function renderDeleteUploadModal() {
const title = 'Delete image upload'
return (
<Modal
variant={ModalVariant.small}
isOpen={showDeleteUploadModal}
title={title}
onClose={() => { setShowDeleteUploadModal(false) }}
actions={[
<Button key="confirm" variant="primary"
onClick={() => {setShowDeleteUploadModal(false) }}>
Confirm
</Button>,
<Button key="cancel" variant="link"
onClick={() => {setShowDeleteUploadModal(false) }}>
Cancel
</Button>,
]}>
<p>
Please confirm that you want to delete this image upload.
</p>
</Modal>
)
}
const haveUploads = uploads && uploads.length > 0
let rows = []
@@ -117,7 +159,7 @@ function ImageUploadTable(props) {
variant={TableVariant.compact}
cells={columns}
rows={rows}
className="zuul-table"
actionResolver={actionResolver}
>
<TableHeader />
<TableBody />
@@ -133,11 +175,13 @@ function ImageUploadTable(props) {
</EmptyStateBody>
</EmptyState>
)}
{renderDeleteUploadModal()}
</>
)
}
ImageUploadTable.propTypes = {
build: PropTypes.object,
uploads: PropTypes.array,
fetching: PropTypes.bool.isRequired,
}
+10 -8
View File
@@ -377,7 +377,7 @@ class ProviderConverter:
# A class to encapsulate the conversion of Provider objects to
# API output.
@staticmethod
def toDict(provider, build_artifacts, uploads):
def toDict(tenant, provider, build_artifacts, uploads):
# These are the flattened versions of these objects for this
# provider.
images = []
@@ -395,7 +395,7 @@ class ProviderConverter:
if image_build_artifacts:
ret_image['build_artifacts'] = [
ImageBuildArtifactConverter.toDict(
b,
tenant, b,
[u for u in uploads if u.artifact_uuid == b.uuid]
)
for b in image_build_artifacts
@@ -480,12 +480,13 @@ class ImageBuildArtifactConverter:
# A class to encapsulate the conversion of image build objects to
# API output.
@staticmethod
def toDict(build, uploads):
def toDict(tenant, build, uploads):
timestamp = _datetimeToString(
datetime.utcfromtimestamp(build.timestamp))
ret = {
'uuid': build.uuid,
'canonical_name': build.canonical_name,
'build_tenant': tenant.name == build.build_tenant_name,
'build_uuid': build.build_uuid,
'format': build.format,
'md5sum': build.md5sum,
@@ -504,6 +505,7 @@ class ImageBuildArtifactConverter:
return Prop('The image build artifact', {
'uuid': str,
'canonical_name': str,
'build_tenant': bool,
'build_uuid': str,
'format': str,
'md5sum': str,
@@ -519,7 +521,7 @@ class ImageConverter:
# A class to encapsulate the conversion of Image objects to
# API output.
@staticmethod
def toDict(image, build_artifacts, uploads):
def toDict(tenant, image, build_artifacts, uploads):
ret = {
'name': image.name,
'canonical_name': image.canonical_name,
@@ -530,7 +532,7 @@ class ImageConverter:
if build_artifacts:
ret['build_artifacts'] = [
ImageBuildArtifactConverter.toDict(
b,
tenant, b,
[u for u in uploads if u.artifact_uuid == b.uuid]
)
for b in build_artifacts
@@ -1882,7 +1884,7 @@ class ZuulWebAPI(object):
build_artifacts = []
uploads = []
ret.append(ProviderConverter.toDict(
provider, build_artifacts, uploads))
tenant, provider, build_artifacts, uploads))
return ret
@cherrypy.expose
@@ -1941,11 +1943,11 @@ class ZuulWebAPI(object):
b for b in ibr.getArtifactsForImage(image.canonical_name)
if b.uuid in artifact_uuids
]
else:
build_artifacts = []
uploads = []
ret.append(ImageConverter.toDict(image, build_artifacts, uploads))
ret.append(ImageConverter.toDict(tenant, image,
build_artifacts, uploads))
return ret
@cherrypy.expose