-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c19099
commit 27537be
Showing
4 changed files
with
211 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
/* | ||
* This file is part of Cockpit. | ||
* | ||
* Copyright (C) 2023 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import React, { useState } from 'react'; | ||
|
||
import cockpit from 'cockpit'; | ||
|
||
import { Alert, AlertActionCloseButton } from "@patternfly/react-core/dist/esm/components/Alert"; | ||
import { Button } from "@patternfly/react-core/dist/esm/components/Button"; | ||
import { Checkbox } from '@patternfly/react-core/dist/esm/components/Checkbox'; | ||
import { Modal } from "@patternfly/react-core/dist/esm/components/Modal"; | ||
import { Stack } from "@patternfly/react-core/dist/esm/layouts/Stack"; | ||
import { Text } from "@patternfly/react-core/dist/esm/components/Text"; | ||
|
||
const _ = cockpit.gettext; | ||
|
||
export const CleanUpModal = ({ closeModal }) => { | ||
const [deleteTemporaryFiles, setDeleteTemporaryFiles] = useState(true); | ||
const [deleteRPMmetadata, setDeleteRPMmetadata] = useState(true); | ||
const [deletePendingDeployments, setDeletePendingDeployments] = useState(false); | ||
const [deleteRollbackDeployments, setDeleteRollbackDeployments] = useState(false); | ||
const [error, setError] = useState(""); | ||
|
||
const doCleanup = () => { | ||
const cleanupFlags = []; | ||
if (deleteTemporaryFiles) { | ||
cleanupFlags.push("--base"); | ||
} | ||
if (deleteRPMmetadata) { | ||
cleanupFlags.push("--repomd"); | ||
} | ||
if (deletePendingDeployments) { | ||
cleanupFlags.push("--pending"); | ||
} | ||
if (deleteRollbackDeployments) { | ||
cleanupFlags.push("--rollback"); | ||
} | ||
|
||
cockpit.spawn(["rpm-ostree", "cleanup", ...cleanupFlags], { superuser: "try" }) | ||
.then(closeModal) | ||
.catch(ex => setError(ex.message)); | ||
}; | ||
|
||
const actions = [ | ||
<Button key="cleanup-accept" | ||
variant="primary" | ||
isDisabled={!deleteTemporaryFiles && !deleteRPMmetadata && !deletePendingDeployments && !deleteRollbackDeployments} | ||
onClick={() => doCleanup()}> | ||
{_("Delete temporary files")} | ||
</Button>, | ||
<Button key="cleanup-cancel" variant="link" onClick={closeModal}> | ||
{_("Cancel")} | ||
</Button> | ||
]; | ||
|
||
return ( | ||
<Modal isOpen | ||
id="cleanup-deployment-modal" | ||
title={_("Clean up")} | ||
position="top" | ||
variant="small" | ||
onClose={closeModal} | ||
actions={actions} | ||
> | ||
{error && | ||
<Alert variant="danger" | ||
isInline | ||
title={error} | ||
actionClose={<AlertActionCloseButton onClose={() => setError("")} />} | ||
/> | ||
} | ||
<Text>{_("Remove cache and other temporary files")}</Text> | ||
<Stack className="pf-v5-u-pt-md"> | ||
<Checkbox label={_("Temporary files")} | ||
key="temporary-files" | ||
id="temporary-files-checkbox" | ||
onChange={(_, isChecked) => setDeleteTemporaryFiles(isChecked)} | ||
isChecked={deleteTemporaryFiles} | ||
/> | ||
<Checkbox label={_("RPM repo metadata")} | ||
key="rpm-repo-metadata" | ||
id="rpm-repo-metadata-checkbox" | ||
onChange={(_, isChecked) => setDeleteRPMmetadata(isChecked)} | ||
isChecked={deleteRPMmetadata} | ||
/> | ||
<Checkbox label={_("Pending deployment")} | ||
key="pending-deployment" | ||
id="pending-deployment-checkbox" | ||
onChange={(_, isChecked) => setDeletePendingDeployments(isChecked)} | ||
isChecked={deletePendingDeployments} | ||
/> | ||
<Checkbox label={_("Rollback deployment")} | ||
key="rollback-deployment" | ||
id="rollback-deployment-checkbox" | ||
onChange={(_, isChecked) => setDeleteRollbackDeployments(isChecked)} | ||
isChecked={deleteRollbackDeployments} | ||
/> | ||
</Stack> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export const ResetModal = ({ closeModal }) => { | ||
const [removeOverlays, setRemoveOverlays] = useState(false); | ||
const [removeOverrides, setRemoveOverrides] = useState(false); | ||
const [error, setError] = useState(false); | ||
const [buttonLoading, setButtonLoading] = useState(false); | ||
|
||
const doReset = () => { | ||
setButtonLoading(true); | ||
|
||
const resetFlags = []; | ||
if (removeOverlays) { | ||
resetFlags.push("--overlays"); | ||
} | ||
if (removeOverrides) { | ||
resetFlags.push("--overrides"); | ||
} | ||
|
||
cockpit.spawn(["rpm-ostree", "reset", ...resetFlags], { superuser: "try" }) | ||
.then(closeModal) | ||
.catch(ex => setError(ex.message)); | ||
}; | ||
|
||
const actions = [ | ||
<Button key="reset-accept" | ||
variant="warning" | ||
isLoading={buttonLoading} | ||
isDisabled={buttonLoading} | ||
onClick={() => doReset()}> | ||
{_("Reset to original state")} | ||
</Button>, | ||
<Button key="reset-cancel" variant="link" onClick={closeModal}> | ||
{_("Cancel")} | ||
</Button> | ||
]; | ||
|
||
return ( | ||
<Modal isOpen | ||
id="reset-modal" | ||
title={_("Reset")} | ||
position="top" | ||
variant="small" | ||
onClose={closeModal} | ||
actions={actions} | ||
> | ||
{error && | ||
<Alert variant="danger" | ||
isInline | ||
title={error} | ||
actionClose={<AlertActionCloseButton onClose={() => setError("")} />} | ||
/> | ||
} | ||
<Text> | ||
{_("Remove package additions or substitutions to return the current deployment to its original state.")} | ||
</Text> | ||
<Stack className="pf-v5-u-pt-md"> | ||
<Checkbox label={_("Remove overlays")} | ||
key="remove-overlays" | ||
id="remove-overlays-checkbox" | ||
onChange={(_, isChecked) => setRemoveOverlays(isChecked)} | ||
isChecked={removeOverlays} | ||
description={_("Packages which have been added to the system")} | ||
/> | ||
<Checkbox label={_("Remove overrides")} | ||
key="remove-overrides" | ||
id="remove-overrides-checkbox" | ||
onChange={(_, isChecked) => setRemoveOverrides(isChecked)} | ||
isChecked={removeOverrides} | ||
description={_("Substitutions of packages normally included in an OS build")} | ||
/> | ||
</Stack> | ||
</Modal> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters