-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #950 from yaacov/migrations-tabls-to-plans-details
🐾 Add a migrations section to plans details tab
- Loading branch information
Showing
9 changed files
with
179 additions
and
14 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
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
31 changes: 31 additions & 0 deletions
31
...plugin/src/modules/Plans/views/details/components/MigrationsSection/MigrationsSection.tsx
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,31 @@ | ||
import React from 'react'; | ||
|
||
import { MigrationModelGroupVersionKind, V1beta1Migration, V1beta1Plan } from '@kubev2v/types'; | ||
import { useK8sWatchResource } from '@openshift-console/dynamic-plugin-sdk'; | ||
|
||
import { Suspend } from '../Suspend'; | ||
|
||
import { MigrationsTable } from './components'; | ||
|
||
export const MigrationsSection: React.FC<MigrationsSectionProps> = ({ obj }) => { | ||
const [migrations, loaded, loadError] = useK8sWatchResource<V1beta1Migration[]>({ | ||
groupVersionKind: MigrationModelGroupVersionKind, | ||
namespaced: true, | ||
isList: true, | ||
namespace: obj?.metadata?.namespace, | ||
}); | ||
|
||
const ownedMigrations = migrations.filter( | ||
(m) => m?.metadata?.ownerReferences?.[0]?.uid === obj.metadata.uid, | ||
); | ||
|
||
return ( | ||
<Suspend obj={ownedMigrations} loaded={loaded} loadError={loadError}> | ||
<MigrationsTable migrations={ownedMigrations} /> | ||
</Suspend> | ||
); | ||
}; | ||
|
||
export type MigrationsSectionProps = { | ||
obj: V1beta1Plan; | ||
}; |
102 changes: 102 additions & 0 deletions
102
...c/modules/Plans/views/details/components/MigrationsSection/components/MigrationsTable.tsx
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,102 @@ | ||
import React from 'react'; | ||
import StatusIcon from 'src/components/status/StatusIcon'; | ||
import { useForkliftTranslation } from 'src/utils/i18n'; | ||
|
||
import { | ||
MigrationModelGroupVersionKind, | ||
PlanModelGroupVersionKind, | ||
V1beta1Migration, | ||
V1beta1MigrationStatusConditions, | ||
} from '@kubev2v/types'; | ||
import { ResourceLink, Timestamp } from '@openshift-console/dynamic-plugin-sdk'; | ||
import { HelperText, HelperTextItem, Split, SplitItem } from '@patternfly/react-core'; | ||
import { TableComposable, Tbody, Td, Th, Thead, Tr } from '@patternfly/react-table'; | ||
|
||
export const MigrationsTable: React.FC<MigrationTableProps> = ({ migrations, showOwner }) => { | ||
const { t } = useForkliftTranslation(); | ||
|
||
if (!migrations || migrations.length < 1) { | ||
return ( | ||
<HelperText> | ||
<HelperTextItem>{t('Migrations not found')}</HelperTextItem> | ||
</HelperText> | ||
); | ||
} | ||
|
||
return ( | ||
<TableComposable aria-label="Expandable table" variant="compact"> | ||
<Thead> | ||
<Tr> | ||
<Th width={20}>{t('Migration')}</Th> | ||
{showOwner && <Th width={20}>{t('Owner')}</Th>} | ||
<Th width={10}>{t('Status')}</Th> | ||
<Th width={10}>{t('VMs')}</Th> | ||
<Th width={15}>{t('Started at')}</Th> | ||
<Th width={15}>{t('Completed at')}</Th> | ||
</Tr> | ||
</Thead> | ||
<Tbody> | ||
{migrations.map((migration) => ( | ||
<Tr key={migration?.metadata?.uid}> | ||
<Td> | ||
<ResourceLink | ||
groupVersionKind={MigrationModelGroupVersionKind} | ||
name={migration?.metadata?.name} | ||
namespace={migration?.metadata?.namespace} | ||
/> | ||
</Td> | ||
{showOwner && ( | ||
<Td> | ||
{migration?.metadata?.ownerReferences?.[0] ? ( | ||
<ResourceLink | ||
groupVersionKind={PlanModelGroupVersionKind} | ||
name={migration?.metadata?.ownerReferences?.[0]?.name} | ||
namespace={migration?.metadata?.namespace} | ||
/> | ||
) : ( | ||
'' | ||
)} | ||
</Td> | ||
)} | ||
<Td>{getStatusLabel(migration?.status?.conditions)}</Td> | ||
<Td>{migration?.status?.vms?.length || '-'}</Td> | ||
<Td> | ||
<Timestamp timestamp={migration?.status?.started} /> | ||
</Td> | ||
<Td> | ||
<Timestamp timestamp={migration?.status?.completed} /> | ||
</Td> | ||
</Tr> | ||
))} | ||
</Tbody> | ||
</TableComposable> | ||
); | ||
}; | ||
|
||
const getStatusLabel = (conditions: V1beta1MigrationStatusConditions[]) => { | ||
let phase: string; | ||
|
||
const phases = ['Ready', 'Running', 'Succeeded', 'Failed']; | ||
|
||
// Look for a condition indicating a migration phase | ||
phases.forEach((p) => { | ||
const condition = conditions.find((c) => c.type === p && c.status === 'True'); | ||
if (condition) { | ||
phase = p; | ||
} | ||
}); | ||
|
||
return ( | ||
<Split> | ||
<SplitItem className="forklift-overview__controller-card__status-icon"> | ||
<StatusIcon phase={phase} /> | ||
</SplitItem> | ||
<SplitItem>{phase}</SplitItem> | ||
</Split> | ||
); | ||
}; | ||
|
||
export type MigrationTableProps = { | ||
migrations: V1beta1Migration[]; | ||
showOwner?: boolean; | ||
}; |
3 changes: 3 additions & 0 deletions
3
...e-plugin/src/modules/Plans/views/details/components/MigrationsSection/components/index.ts
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,3 @@ | ||
// @index(['./*', /style/g], f => `export * from '${f.path}';`) | ||
export * from './MigrationsTable'; | ||
// @endindex |
4 changes: 4 additions & 0 deletions
4
...lift-console-plugin/src/modules/Plans/views/details/components/MigrationsSection/index.ts
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,4 @@ | ||
// @index(['./*', /style/g], f => `export * from '${f.path}';`) | ||
export * from './components'; | ||
export * from './MigrationsSection'; | ||
// @endindex |
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