Skip to content

Commit

Permalink
Merge pull request #416 from rszwajko/migrationNeton_2_4
Browse files Browse the repository at this point in the history
Revert dropping 'Select migration network' action
  • Loading branch information
yaacov authored Apr 27, 2023
2 parents fa0033e + 8b8fb45 commit 42d5937
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
"Running - preparing for cutover": "Running - preparing for cutover",
"Running - preparing for incremental data copies": "Running - preparing for incremental data copies",
"Running - preparing for migration": "Running - preparing for migration",
"Select a default migration network for the provider. This network will be used for migrating data to all namespaces to which it is attached.": "Select a default migration network for the provider. This network will be used for migrating data to all namespaces to which it is attached.",
"Select migration network": "Select migration network",
"Show archived": "Show archived",
"Show managed": "Show managed",
"source": "source",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import React, { useCallback, useMemo, useState } from 'react';
import { Trans } from 'react-i18next';
import { DEFAULT_TRANSFER_NETWORK_ANNOTATION } from 'src/utils/constants';
import { useTranslation } from 'src/utils/i18n';

import { withActionServiceContext } from '@kubev2v/common/components/ActionServiceDropdown';
import withQueryClient from '@kubev2v/common/components/QueryClientHoc';
import { useModal } from '@kubev2v/common/polyfills/sdk-shim';
import { ConfirmModal } from '@kubev2v/legacy/common/components/ConfirmModal';
import { SelectOpenShiftNetworkModal } from '@kubev2v/legacy/common/components/SelectOpenShiftNetworkModal';
import { ProviderType } from '@kubev2v/legacy/common/constants';
import { AddEditProviderModal } from '@kubev2v/legacy/Providers/components/AddEditProviderModal';
import { hasRunningMigration } from '@kubev2v/legacy/Providers/components/ProvidersTable';
import { useDeleteProviderMutation, usePlansQuery } from '@kubev2v/legacy/queries';
import { IProviderObject } from '@kubev2v/legacy/queries/types';
import {
useDeleteProviderMutation,
useOCPMigrationNetworkMutation,
usePlansQuery,
} from '@kubev2v/legacy/queries';
import { IOpenShiftProvider, IProviderObject } from '@kubev2v/legacy/queries/types';

import { type MergedProvider, isManaged } from './data';

Expand All @@ -37,23 +43,29 @@ export const useMergedProviderActions = ({ resourceData }: { resourceData: Merge
: t('This provider cannot be deleted because it has running migrations');

const actions = useMemo(
() => [
{
id: 'edit',
cta: () => launchModal(withQueryClient(EditModal), { resourceData }),
label: t('Edit Provider'),
disabled: editingDisabled,
disabledTooltip: editingDisabled ? editDisabledTooltip : '',
},
{
id: 'delete',
cta: () => launchModal(withQueryClient(DeleteModal), { resourceData }),
label: t('Delete Provider'),
disabled: editingDisabled,
disabledTooltip: editingDisabled ? deleteDisabledTooltip : '',
},
],
[t, editingDisabled, resourceData],
() =>
[
{
id: 'edit',
cta: () => launchModal(withQueryClient(EditModal), { resourceData }),
label: t('Edit Provider'),
disabled: editingDisabled,
disabledTooltip: editingDisabled ? editDisabledTooltip : '',
},
{
id: 'delete',
cta: () => launchModal(withQueryClient(DeleteModal), { resourceData }),
label: t('Delete Provider'),
disabled: editingDisabled,
disabledTooltip: editingDisabled ? deleteDisabledTooltip : '',
},
resourceData.spec?.type === 'openshift' && {
id: 'selectNetwork',
cta: () => launchModal(withQueryClient(SelectNetworkForOpenshift), { resourceData }),
label: t('Select migration network'),
},
].filter(Boolean),
[t, editingDisabled, editDisabledTooltip, deleteDisabledTooltip, resourceData],
);

return [actions, true, undefined];
Expand All @@ -76,6 +88,44 @@ const EditModal = ({
};
EditModal.displayName = 'EditModal';

const SelectNetworkForOpenshift = ({
resourceData,
closeModal,
}: {
closeModal: () => void;
resourceData: MergedProvider;
}) => {
const { t } = useTranslation();
const migrationNetworkMutation = useOCPMigrationNetworkMutation(
resourceData.metadata?.namespace,
closeModal,
);
return (
<SelectOpenShiftNetworkModal
targetProvider={resourceData.inventory as IOpenShiftProvider}
targetNamespace={null}
initialSelectedNetwork={
resourceData.metadata?.annotations?.[DEFAULT_TRANSFER_NETWORK_ANNOTATION]
}
instructions={t(
'Select a default migration network for the provider. This network will be used for migrating data to all namespaces to which it is attached.',
)}
onClose={() => {
migrationNetworkMutation.reset();
closeModal();
}}
onSubmit={(network) =>
migrationNetworkMutation.mutate({
provider: resourceData.inventory as IOpenShiftProvider,
network,
})
}
mutationResult={migrationNetworkMutation}
/>
);
};
SelectNetworkForOpenshift.displayName = 'SelectNetworkForOpenshift';

const DeleteModal = ({
resourceData,
closeModal,
Expand Down

0 comments on commit 42d5937

Please sign in to comment.