/** * Copyright (c) 2021 OpenLens Authors * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of * the Software, and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import "./release-rollback-dialog.scss"; import React from "react"; import { observable } from "mobx"; import { observer } from "mobx-react"; import { Dialog, DialogProps } from "../dialog"; import { Wizard, WizardStep } from "../wizard"; import { getReleaseHistory, HelmRelease, IReleaseRevision } from "../../api/endpoints/helm-releases.api"; import { releaseStore } from "./release.store"; import { Select, SelectOption } from "../select"; import { Notifications } from "../notifications"; import orderBy from "lodash/orderBy"; interface Props extends DialogProps { } @observer export class ReleaseRollbackDialog extends React.Component { @observable static isOpen = false; @observable.ref static release: HelmRelease = null; @observable isLoading = false; @observable revision: IReleaseRevision; @observable revisions = observable.array(); static open(release: HelmRelease) { ReleaseRollbackDialog.isOpen = true; ReleaseRollbackDialog.release = release; } static close() { ReleaseRollbackDialog.isOpen = false; } get release(): HelmRelease { return ReleaseRollbackDialog.release; } onOpen = async () => { this.isLoading = true; const currentRevision = this.release.getRevision(); let releases = await getReleaseHistory(this.release.getName(), this.release.getNs()); releases = releases.filter(item => item.revision !== currentRevision); // remove current releases = orderBy(releases, "revision", "desc"); // sort this.revisions.replace(releases); this.revision = this.revisions[0]; this.isLoading = false; }; rollback = async () => { const revisionNumber = this.revision.revision; try { await releaseStore.rollback(this.release.getName(), this.release.getNs(), revisionNumber); this.close(); } catch (err) { Notifications.error(err); } }; close = () => { ReleaseRollbackDialog.close(); }; renderContent() { const { revision, revisions } = this; if (!revision) { return

No revisions to rollback.

; } return (
Revision