From 04fcbf71838f36a862e6ac934e72de65afccd5d6 Mon Sep 17 00:00:00 2001 From: Tomas Matus Date: Wed, 19 Jul 2023 16:28:05 +0200 Subject: [PATCH] Use card view for remote management --- src/changeRemoteModal.jsx | 265 ------------------ src/client.js | 3 + src/deploymentModals.jsx | 198 +++++++++++++ src/ostree.jsx | 565 +++++++++++++++++++++++++++----------- src/ostree.scss | 10 +- src/repositoryModals.jsx | 436 +++++++++++++++++++++++++++++ test/check-ostree | 563 ++++++++++++++++++++++++------------- 7 files changed, 1416 insertions(+), 624 deletions(-) delete mode 100644 src/changeRemoteModal.jsx create mode 100644 src/deploymentModals.jsx create mode 100644 src/repositoryModals.jsx diff --git a/src/changeRemoteModal.jsx b/src/changeRemoteModal.jsx deleted file mode 100644 index 0e5a37b9..00000000 --- a/src/changeRemoteModal.jsx +++ /dev/null @@ -1,265 +0,0 @@ -/* - * This file is part of Cockpit. - * - * Copyright (C) 2020 Red Hat, Inc. - * - * Cockpit is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * Cockpit is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Cockpit; If not, see . - */ - -import React, { useState } from 'react'; -import PropTypes from "prop-types"; - -import { Alert, AlertActionCloseButton } from "@patternfly/react-core/dist/esm/components/Alert"; -import { Button } from "@patternfly/react-core/dist/esm/components/Button"; -import { ActionGroup, Form, FormGroup } from "@patternfly/react-core/dist/esm/components/Form"; -import { Checkbox } from "@patternfly/react-core/dist/esm/components/Checkbox"; -import { Modal } from "@patternfly/react-core/dist/esm/components/Modal"; -import { SimpleList, SimpleListItem } from "@patternfly/react-core/dist/esm/components/SimpleList"; -import { TextArea } from "@patternfly/react-core/dist/esm/components/TextArea"; -import { TextInput } from "@patternfly/react-core/dist/esm/components/TextInput"; -import { Title } from "@patternfly/react-core/dist/esm/components/Title"; - -import { PencilAltIcon, AddCircleOIcon } from '@patternfly/react-icons'; - -import { FormHelper } from 'cockpit-components-form-helper.jsx'; -import cockpit from 'cockpit'; - -import * as remotes from './remotes'; - -const _ = cockpit.gettext; - -export const ChangeRemoteModal = ({ setIsModalOpen, isModalOpen, remotesList, currentRemote, refreshRemotes, onChangeRemoteOrigin }) => { - const [addNewRepoDialogOpen, setAddNewRepoDialogOpen] = useState(false); - const [editRepoDialogOpen, setEditRepoDialogOpen] = useState(false); - const [selectedRemote, setSelectedRemote] = useState(currentRemote); - const [error, setError] = useState(""); - - // Disable 'Change Repository' button when the 'Edit' form is open or when the previously selected remote does not exit any more (got deleted) - const footer = ( - <> - - - - ); - - return ( - setIsModalOpen(false)} - footer={footer}> - <> - {error && } - setSelectedRemote(currentItemProps.id)}> - {(remotesList || []).map(remote => { - return ( - (!editRepoDialogOpen || editRepoDialogOpen.name !== remote) - ? { - ev.stopPropagation(); - ev.preventDefault(); - }} - isActive={remote === selectedRemote}> - {remote} - - - :
- -
- ); - }).concat([ - !addNewRepoDialogOpen - ? { - ev.stopPropagation(); - ev.preventDefault(); - }} - key="add-new"> - - - :
- -
- ])} -
- -
- ); -}; - -ChangeRemoteModal.propTypes = { - remotesList: PropTypes.array.isRequired, - currentRemote: PropTypes.string, - isModalOpen: PropTypes.bool.isRequired, - setIsModalOpen: PropTypes.func.isRequired, - refreshRemotes: PropTypes.func.isRequired, - onChangeRemoteOrigin: PropTypes.func.isRequired, -}; - -const AddNewRepoForm = ({ setAddNewRepoDialogOpen, refreshRemotes }) => { - const [newRepoName, setNewRepoName] = useState(""); - const [newRepoURL, setNewRepoURL] = useState(""); - const [newRepoTrusted, setNewRepoTrusted] = useState(false); - - const [hasValidation, setHasValidation] = useState(false); - const [addNewRepoError, setAddNewRepoError] = useState(undefined); - - const onAddRemote = () => { - if (!(newRepoURL.trim().length && newRepoName.trim().length)) { - setHasValidation(true); - return; - } - return remotes.addRemote(newRepoName, newRepoURL, newRepoTrusted) - .then(() => refreshRemotes()) - .then(() => setAddNewRepoDialogOpen(false), - ex => setAddNewRepoError(ex.message)); - }; - - return ( -
- - {_("Add new repository")} - - {addNewRepoError && } - - setNewRepoName(name)} /> - - - - setNewRepoURL(url)} /> - - - - setNewRepoTrusted(checked)} /> - - - - - - - ); -}; -AddNewRepoForm.propTypes = { - refreshRemotes: PropTypes.func.isRequired, - setAddNewRepoDialogOpen: PropTypes.func.isRequired, -}; - -const EditRemoteForm = ({ remoteSettings, setEditRepoDialogOpen, refreshRemotes }) => { - const [addAnotherKey, setAddAnotherKey] = useState(false); - const [key, setKey] = useState(''); - const [isTrusted, setIsTrusted] = useState(remoteSettings['gpg-verify'] !== 'false'); - const [error, setError] = useState(''); - - const onUpdate = () => { - const promises = []; - if (key) - promises.push(remotes.importGPGKey(remoteSettings.name, key)); - promises.push(remotes.updateRemoteSettings(remoteSettings.name, { "gpg-verify": isTrusted })); - - Promise.all(promises).then(() => setEditRepoDialogOpen(false), ex => setError(ex.message)); - }; - const onDelete = () => { - remotes.deleteRemote(remoteSettings.name) - .then(() => refreshRemotes()) - .then(setEditRepoDialogOpen(false), ex => setError(ex.message)); - }; - - return ( -
- {error && this.setState({ error: undefined })} />} - title={error} />} - - {remoteSettings.name} - - - - - - { - setIsTrusted(!isTrusted); - }} /> - - - {!addAnotherKey - ? - :