Skip to content

Commit

Permalink
re-enable snapshots tab
Browse files Browse the repository at this point in the history
  • Loading branch information
glekner authored and Gilad Lekner committed Oct 21, 2020
1 parent b67adcc commit cde5803
Show file tree
Hide file tree
Showing 25 changed files with 520 additions and 205 deletions.
Expand Up @@ -8,28 +8,26 @@ import {
ModalSubmitFooter,
ModalComponentProps,
} from '@console/internal/components/factory';
import { k8sPatch } from '@console/internal/module/k8s';
import { K8sKind, k8sPatch, K8sResourceKind } from '@console/internal/module/k8s';
import { getDescription } from '../../../selectors/selectors';
import { VMGenericLikeEntityKind } from '../../../types/vmLike';
import { getVMLikeModel } from '../../../selectors/vm';
import { getUpdateDescriptionPatches } from '../../../k8s/patches/vm/vm-patches';

// TODO: should be moved under kubevirt-plugin/src/style.scss
import './_vm-description-modal.scss';
import './_description-modal.scss';

export const VMDescriptionModal = withHandlePromise((props: VMDescriptionModalProps) => {
const { vmLikeEntity, inProgress, errorMessage, handlePromise, close, cancel } = props;
const DescriptionModal = withHandlePromise((props: DescriptionModalProps) => {
const { resource, kind, inProgress, errorMessage, handlePromise, close, cancel } = props;

const [description, setDescription] = React.useState(getDescription(vmLikeEntity));
const [description, setDescription] = React.useState(getDescription(resource));

const submit = (e) => {
e.preventDefault();

const patches = getUpdateDescriptionPatches(vmLikeEntity, description);
const patches = getUpdateDescriptionPatches(resource, description);
if (patches.length === 0) {
close();
} else {
const promise = k8sPatch(getVMLikeModel(vmLikeEntity), vmLikeEntity, patches);
const promise = k8sPatch(kind, resource, patches);
handlePromise(promise, close);
}
};
Expand All @@ -55,9 +53,10 @@ export const VMDescriptionModal = withHandlePromise((props: VMDescriptionModalPr
);
});

export type VMDescriptionModalProps = HandlePromiseProps &
export type DescriptionModalProps = HandlePromiseProps &
ModalComponentProps & {
vmLikeEntity: VMGenericLikeEntityKind;
resource: K8sResourceKind;
kind: K8sKind;
};

export const vmDescriptionModal = createModalLauncher(VMDescriptionModal);
export const descriptionModal = createModalLauncher(DescriptionModal);
@@ -0,0 +1 @@
export * from './description-modal';
@@ -1,3 +1,3 @@
export * from './modal-resource-launcher';
export * from './vm-description-modal';
export * from './description-modal';
export * from './vm-flavor-modal';
@@ -1,5 +1,5 @@
import * as React from 'react';
import { Alert, AlertVariant, Form, TextInput } from '@patternfly/react-core';
import { Alert, AlertVariant, Form, TextArea, TextInput } from '@patternfly/react-core';
import { prefixedID } from '../../../utils';
import { HandlePromiseProps, withHandlePromise } from '@console/internal/components/utils';
import { getName, getNamespace } from '@console/shared';
Expand All @@ -24,13 +24,15 @@ const getSnapshotName = (vmName: string) => {
const SnapshotsModal = withHandlePromise((props: SnapshotsModalProps) => {
const { vmLikeEntity, inProgress, errorMessage, handlePromise, close, cancel } = props;
const vmName = getName(vmLikeEntity);
const [name, setName] = React.useState<string>(getSnapshotName(vmName));
const [name, setName] = React.useState(getSnapshotName(vmName));
const [description, setDescription] = React.useState('');
const asId = prefixedID.bind(null, 'snapshot');

const submit = async (e) => {
e.preventDefault();
const snapshotWrapper = new VMSnapshotWrapper().init({
name,
description,
namespace: getNamespace(vmLikeEntity),
vmName,
});
Expand Down Expand Up @@ -58,6 +60,13 @@ const SnapshotsModal = withHandlePromise((props: SnapshotsModalProps) => {
onChange={(v) => setName(v)}
/>
</FormRow>
<FormRow title="Description" fieldId={asId('desc')}>
<TextArea
value={description}
onChange={(d) => setDescription(d)}
aria-label="description text area"
/>
</FormRow>
</Form>
</ModalBody>
<ModalFooter
Expand Down
@@ -1,10 +1,5 @@
import * as React from 'react';
import {
HandlePromiseProps,
withHandlePromise,
history,
resourcePath,
} from '@console/internal/components/utils';
import { HandlePromiseProps, withHandlePromise } from '@console/internal/components/utils';
import { getName, getNamespace, getRandomChars } from '@console/shared';
import {
createModalLauncher,
Expand Down Expand Up @@ -38,7 +33,6 @@ const SnapshotRestoreModal = withHandlePromise((props: SnapshotRestoreModalProps
k8sCreate(snapshotRestoreWrapper.getModel(), snapshotRestoreWrapper.asResource()),
() => {
close();
history.push(resourcePath(snapshotRestoreWrapper.getModel().kind, restoreName, namespace));
},
);
};
Expand Down

This file was deleted.

This file was deleted.

@@ -1,9 +1,15 @@
import { VMRestore } from '../../types';
import { VMLikeEntityKind } from '../../types/vmLike';

export type VMSnapshotRowActionOpts = { withProgress: (promise: Promise<any>) => void };
export type VMSnapshotRowActionOpts = {
withProgress: (promise: Promise<any>) => void;
restores: { [key: string]: VMRestore };
};

export type VMSnapshotRowCustomData = {
vmLikeEntity: VMLikeEntityKind;
columnClasses: string[];
isDisabled: boolean;
restores: { [key: string]: VMRestore };
withProgress: (promise: Promise<any>) => void;
} & VMSnapshotRowActionOpts;
@@ -0,0 +1,41 @@
import * as React from 'react';
import { VMRestore } from '../../types';
import {
WatchK8sResource,
useK8sWatchResource,
} from '@console/internal/components/utils/k8s-watch-hook';
import { VirtualMachineRestoreModel } from '../../models';
import { getVmRestoreSnapshotName, getVmRestoreTime } from '../../selectors/snapshot/snapshot';

export const useMappedVMRestores = (
namespace: string,
): [{ [key: string]: VMRestore }, boolean, any] => {
const restoreResource: WatchK8sResource = {
isList: true,
kind: VirtualMachineRestoreModel.kind,
namespaced: true,
namespace,
};

const [restores, restoresLoaded, restoresError] = useK8sWatchResource<VMRestore[]>(
restoreResource,
);

const mappedRelevantRestores = React.useMemo(
() =>
restores.reduce((restoreMap, currentRestore) => {
const relevantRestore = restoreMap[getVmRestoreSnapshotName(currentRestore)];
if (
!relevantRestore ||
new Date(getVmRestoreTime(relevantRestore)).getTime() <
new Date(getVmRestoreTime(currentRestore)).getTime()
) {
restoreMap[getVmRestoreSnapshotName(currentRestore)] = currentRestore;
}
return restoreMap;
}, {}),
[restores],
);

return [mappedRelevantRestores, restoresLoaded, restoresError];
};
Expand Up @@ -2,6 +2,8 @@ import * as classNames from 'classnames';
import { Kebab } from '@console/internal/components/utils';

export const snapshotsTableColumnClasses = [
classNames('col-lg-2'),
classNames('col-lg-2'),
classNames('col-lg-2'),
classNames('col-lg-2'),
classNames('col-lg-2'),
Expand Down

0 comments on commit cde5803

Please sign in to comment.