Skip to content

Commit

Permalink
Convert Providers screen to Console page
Browse files Browse the repository at this point in the history
Code changes:
1. use StandardPage list component
2. entity list is produced by merging results from k8s API and
   exsting Forklift inventory REST API.
3. actions in the table (kebab actions) are provided via extension
   point 'console.action/provider'
4. use existing actions for Add/Edit/Delete/Select Network

Functional changes:
1. display all providers in one table
2. use only 'Ready' condition to describe the state of the provider
3. disable rich content in Network/Storage columns until the design for
   the details page is known

Signed-off-by: Radoslaw Szwajkowski <[email protected]>
  • Loading branch information
rszwajko committed Nov 9, 2022
1 parent bbf20b8 commit e4d5a14
Show file tree
Hide file tree
Showing 19 changed files with 886 additions and 23 deletions.
46 changes: 41 additions & 5 deletions console-extensions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import type { EncodedExtension } from '@openshift/dynamic-plugin-sdk';
import type {
ActionProvider,
HorizontalNavTab,
HrefNavItem,
NavSection,
ResourceActionProvider,
ResourceDetailsPage,
ResourceListPage,
ResourceNSNavItem,
RoutePage,
Separator,
} from '@openshift-console/dynamic-plugin-sdk';
Expand Down Expand Up @@ -38,16 +44,46 @@ const extensions: EncodedExtension[] = [
} as EncodedExtension<Separator>,

{
type: 'console.navigation/href',
type: 'console.navigation/resource-ns',
properties: {
id: 'providers',
insertAfter: 'importSeparator',
perspective: 'admin',
section: 'virtualization',
name: '%plugin__forklift-console-plugin~Providers for VM Import%',
href: '/mtv/providers',
model: {
group: 'forklift.konveyor.io',
kind: 'Provider',
version: 'v1beta1',
},
dataAttributes: {
'data-quickstart-id': 'qs-nav-providers',
'data-test-id': 'providers-nav-item',
},
},
} as EncodedExtension<HrefNavItem>,
} as EncodedExtension<ResourceNSNavItem>,

{
type: 'console.page/resource/list',
properties: {
component: {
$codeRef: 'ProvidersPage',
},
model: {
group: 'forklift.konveyor.io',
kind: 'Provider',
version: 'v1beta1',
},
},
} as EncodedExtension<ResourceListPage>,

{
type: 'console.action/provider',
properties: {
contextId: 'mergedProvider',
provider: {
$codeRef: 'useMergedProviders',
},
},
} as EncodedExtension<ActionProvider>,

{
type: 'console.navigation/href',
Expand Down
32 changes: 31 additions & 1 deletion locales/en/plugin__forklift-console-plugin.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,53 @@
{
"{{type}} provider {{name}} will no longer be selectable as a migration source.": "{{type}} provider {{name}} will no longer be selectable as a migration source.",
"{{type}} provider {{name}} will no longer be selectable as a migration target.": "{{type}} provider {{name}} will no longer be selectable as a migration target.",
"Actions": "Actions",
"Add Provider": "Add Provider",
"Cancel": "Cancel",
"Cannot remove provider": "Cannot remove provider",
"Clear all filters": "Clear all filters",
"Clusters": "Clusters",
"Delete": "Delete",
"Delete Provider": "Delete Provider",
"Edit Provider": "Edit Provider",
"Endpoint": "Endpoint",
"False": "False",
"Filter by endpoint": "Filter by endpoint",
"Filter by name": "Filter by name",
"Filter by namespace": "Filter by namespace",
"Hosts": "Hosts",
"KubeVirt": "KubeVirt",
"Loading": "Loading",
"Manage Columns": "Manage Columns",
"Mappings for VM Import": "Mappings for VM Import",
"Name": "Name",
"Namespace": "Namespace",
"Networks": "Networks",
"No information": "No information",
"No results found": "No results found",
"No results match the filter criteria. Clear all filters and try again.": "No results match the filter criteria. Clear all filters and try again.",
"oVirt": "oVirt",
"Permanently delete provider?": "Permanently delete provider?",
"Plans for VM Import": "Plans for VM Import",
"Providers": "Providers",
"Providers for VM Import": "Providers for VM Import",
"Ready": "Ready",
"Reorder": "Reorder",
"Restore default colums": "Restore default colums",
"Save": "Save",
"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 Filter": "Select Filter",
"Select migration network": "Select migration network",
"Selected columns will be displayed in the table.": "Selected columns will be displayed in the table.",
"Storage": "Storage",
"Table column management": "Table column management",
"The host provider cannot be edited": "The host provider cannot be edited",
"This provider cannot be edited because it has running migrations": "This provider cannot be edited because it has running migrations",
"True": "True",
"Type": "Type",
"Unable to retrieve data": "Unable to retrieve data",
"Virtualization": "Virtualization"
"Unknown": "Unknown",
"Virtualization": "Virtualization",
"VMs": "VMs",
"VMware": "VMware"
}
2 changes: 1 addition & 1 deletion pkg/web/src/app/Providers/HostsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface IHostsMatchParams {

export const HostsPage: React.FunctionComponent = () => {
const match = useRouteMatch<IHostsMatchParams>({
path: '/providers/vsphere/:providerName',
path: `${PATH_PREFIX}/providers/vsphere/:providerName`,
strict: true,
sensitive: true,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import * as React from 'react';
import { Dropdown, KebabToggle, DropdownItem, DropdownPosition } from '@patternfly/react-core';
import { useDeleteProviderMutation } from '@app/queries';
import { ICorrelatedProvider, InventoryProvider } from '@app/queries/types';
import {
ICorrelatedProvider,
INameNamespaceRef,
InventoryProvider,
IPlan,
} from '@app/queries/types';
import { PATH_PREFIX, ProviderType, PROVIDER_TYPE_NAMES } from '@app/common/constants';
import { ConfirmModal } from '@app/common/components/ConfirmModal';
import { EditProviderContext } from '@app/Providers/ProvidersPage';
Expand All @@ -11,6 +16,21 @@ import { isSameResource } from '@app/queries/helpers';
import { useHistory } from 'react-router-dom';
import { useClusterProvidersQuery } from '@app/queries';

export const hasRunningMigration = ({
plans = [],
providerMetadata,
}: {
plans: IPlan[];
providerMetadata: INameNamespaceRef;
}) =>
!!plans
.filter((plan) => hasCondition(plan.status?.conditions || [], 'Executing'))
.find((runningPlan) => {
const { source, destination } = runningPlan.spec.provider;
return (
isSameResource(providerMetadata, source) || isSameResource(providerMetadata, destination)
);
});
interface IProviderActionsDropdownProps {
provider: ICorrelatedProvider<InventoryProvider>;
providerType: ProviderType;
Expand All @@ -37,15 +57,8 @@ export const ProviderActionsDropdown: React.FunctionComponent<IProviderActionsDr
}
});

const hasRunningMigration = !!plans
.filter((plan) => hasCondition(plan.status?.conditions || [], 'Executing'))
.find((runningPlan) => {
const { source, destination } = runningPlan.spec.provider;
return (
isSameResource(provider.metadata, source) || isSameResource(provider.metadata, destination)
);
});
const isEditDeleteDisabled = !provider.spec.url || hasRunningMigration;
const isEditDeleteDisabled =
!provider.spec.url || hasRunningMigration({ plans, providerMetadata: provider.metadata });

return (
<>
Expand All @@ -61,7 +74,7 @@ export const ProviderActionsDropdown: React.FunctionComponent<IProviderActionsDr
content={
!provider.spec.url
? 'The host provider cannot be edited'
: hasRunningMigration
: hasRunningMigration({ plans, providerMetadata: provider.metadata })
? 'This provider cannot be edited because it has running migrations'
: ''
}
Expand All @@ -83,7 +96,7 @@ export const ProviderActionsDropdown: React.FunctionComponent<IProviderActionsDr
content={
!provider.spec.url
? 'The host provider cannot be removed'
: hasRunningMigration
: hasRunningMigration({ plans, providerMetadata: provider.metadata })
? 'This provider cannot be removed because it has running migrations'
: ''
}
Expand Down
5 changes: 3 additions & 2 deletions plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
"MappingsPage": "./extensions/MappingsWrapper",
"HostsPage": "./extensions/HostsPageWrapper",
"PlanWizard": "./extensions/PlanWizardWrapper",
"VMMigrationDetails": "./extensions/VMMigrationDetailsWrapper"
"VMMigrationDetails": "./extensions/VMMigrationDetailsWrapper",
"useMergedProviders": "./extensions/UseMergedProviders"
},
"dependencies": {
"@console/pluginAPI": "*"
}
}
}
122 changes: 122 additions & 0 deletions src/Providers/ProviderRow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import React, { JSXElementConstructor } from 'react';
import { Link } from 'react-router-dom';
import { RowProps } from 'src/components/TableView';
import { CONDITIONS, PROVIDERS, useTranslation } from 'src/internal/i18n';
import {
ACTIONS,
HOST_COUNT,
NAME,
NAMESPACE,
NETWORK_COUNT,
READY,
STORAGE_COUNT,
TYPE,
URL,
} from 'src/utils/constants';

import { PATH_PREFIX } from '@app/common/constants';
import { StatusIcon } from '@migtools/lib-ui';
import { ResourceLink } from '@openshift-console/dynamic-plugin-sdk';
import { Button, Popover } from '@patternfly/react-core';
import { DatabaseIcon, NetworkIcon, OutlinedHddIcon } from '@patternfly/react-icons';
import { Td, Tr } from '@patternfly/react-table';

import { MergedProvider } from './data';
import { ProviderActions } from './providerActions';

interface CellProps {
value: string;
entity: MergedProvider;
t?: (k: string) => string;
}
const StatusCell = ({ value, entity: { conditions }, t }: CellProps) => {
const existingConditions = Object.values(conditions).filter(Boolean);
const toState = (value) => {
switch (value) {
case 'True':
return 'Ok';
case 'False':
return 'Error';
default:
return 'Unknown';
}
};
const label = CONDITIONS?.[value]?.(t);
return (
<Popover
hasAutoWidth
bodyContent={
<div>
{existingConditions.length > 0
? existingConditions.map(({ message, status }) => {
return <StatusIcon key={message} status={toState(status)} label={message} />;
})
: t('No information')}
</div>
}
>
<Button variant="link" isInline aria-label={label}>
<StatusIcon status={toState(value)} label={label} />
</Button>
</Popover>
);
};

const TextCell = ({ value }: { value: string }) => <>{value ?? ''}</>;

const TextWithIcon = ({ value, Icon }: { value: string; Icon: JSXElementConstructor<unknown> }) => (
<>
{value && (
<>
<Icon /> <TextCell value={value} />
</>
)}
</>
);

const ProviderLink = ({ value, entity }: CellProps) => (
<ResourceLink kind={entity.kind} name={value} namespace={entity?.namespace} />
);

const HostCell = ({ value, entity: { ready, name, type } }: CellProps) => (
<>
{ready === 'True' && value && type === 'vsphere' ? (
<Link to={`${PATH_PREFIX}/providers/vsphere/${name}`}>
<TextWithIcon Icon={OutlinedHddIcon} value={value} />
</Link>
) : (
<TextWithIcon Icon={OutlinedHddIcon} value={value} />
)}
</>
);

const cellCreator = {
[NAME]: ProviderLink,
[READY]: StatusCell,
[URL]: TextCell,
[TYPE]: ({ value, t }: CellProps) => <TextCell value={PROVIDERS?.[value]?.(t)} />,
[NAMESPACE]: ({ value }: CellProps) => <ResourceLink kind="Namespace" name={value} />,
[ACTIONS]: ProviderActions,
[NETWORK_COUNT]: ({ value }: CellProps) => <TextWithIcon Icon={NetworkIcon} value={value} />,
[STORAGE_COUNT]: ({ value }: CellProps) => <TextWithIcon Icon={DatabaseIcon} value={value} />,
[HOST_COUNT]: HostCell,
};

const ProviderRow = ({ columns, entity }: RowProps<MergedProvider>) => {
const { t } = useTranslation();
return (
<Tr>
{columns.map(({ id, toLabel }) => (
<Td key={id} dataLabel={toLabel(t)}>
{cellCreator?.[id]?.({
value: entity[id],
entity,
t,
}) ?? <TextCell value={String(entity[id] ?? '')} />}
</Td>
))}
</Tr>
);
};

export default ProviderRow;
Loading

0 comments on commit e4d5a14

Please sign in to comment.