forked from openshift/console
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: topology data transformer should use values from plugin
- Loading branch information
Showing
4 changed files
with
154 additions
and
38 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
frontend/packages/rhoas-plugin/src/topology/components/TopologyKafkaPanel.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,93 @@ | ||
import * as React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { | ||
navFactory, | ||
SimpleTabNav, | ||
ResourceIcon | ||
} from '@console/internal/components/utils'; | ||
import * as UIActions from '@console/internal/actions/ui'; | ||
import { Alert, AlertActionCloseButton } from '@patternfly/react-core'; | ||
import { Node } from '@patternfly/react-topology'; | ||
import { ResourceSummary } from '@console/internal/components/utils'; | ||
|
||
type PropsFromState = { | ||
selectedDetailsTab?: any; | ||
}; | ||
|
||
type PropsFromDispatch = { | ||
onClickTab?: (name: string) => void; | ||
}; | ||
|
||
const stateToProps = ({ UI }): PropsFromState => ({ | ||
selectedDetailsTab: UI.getIn(['overview', 'selectedDetailsTab']), | ||
}); | ||
|
||
const dispatchToProps = (dispatch): PropsFromDispatch => ({ | ||
onClickTab: (name) => dispatch(UIActions.selectOverviewDetailsTab(name)), | ||
}); | ||
|
||
type OwnProps = { | ||
item: Node; | ||
}; | ||
|
||
type TopologyHelmReleasePanelProps = PropsFromState & PropsFromDispatch & OwnProps; | ||
|
||
const DetailsComponent: React.FC<any> = ({ obj }) => { | ||
return (<> | ||
<div style={{ "padding": 20 }}> | ||
<ResourceSummary resource={obj} /> | ||
</div> | ||
</>) | ||
} | ||
|
||
export const ConnectedTopologyHelmReleasePanel: React.FC<TopologyHelmReleasePanelProps> = ({ | ||
item, | ||
selectedDetailsTab, | ||
onClickTab, | ||
}: TopologyHelmReleasePanelProps) => { | ||
// Resource | ||
const mkc = item?.getData().resource; | ||
if (!mkc) { | ||
return <>No data</> | ||
} | ||
|
||
return ( | ||
<div className="overview__sidebar-pane resource-overview"> | ||
<div className="overview__sidebar-pane-head resource-overview__heading"> | ||
<h1 className="co-m-pane__heading"> | ||
<div className="co-m-pane__name co-resource-item"> | ||
<ResourceIcon className="co-m-resource-icon--lg" kind="MKC" /> | ||
<h3>Managed Kafka Connection</h3> | ||
</div> | ||
</h1> | ||
</div> | ||
|
||
<Alert | ||
variant="default" | ||
title="ManagedService" | ||
actionClose={<AlertActionCloseButton />} | ||
isInline | ||
> | ||
This resource represents service that exist outside your cluster. | ||
To view details about resource please go to <br/> | ||
<a href="https://cloud.redhat.com/beta/application-services/openshift-streams/">OpenShift Streams Apache Kafka </a> console. | ||
|
||
</Alert> | ||
|
||
<SimpleTabNav | ||
selectedTab={selectedDetailsTab} | ||
onClickTab={onClickTab} | ||
tabs={[ | ||
{ name: "Details", component: navFactory.details(DetailsComponent).component }, | ||
]} | ||
tabProps={{ obj: mkc }} | ||
additionalClassNames="co-m-horizontal-nav__menu--within-sidebar co-m-horizontal-nav__menu--within-overview-sidebar" | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default connect<PropsFromState, PropsFromDispatch, TopologyHelmReleasePanelProps>( | ||
stateToProps, | ||
dispatchToProps, | ||
)(ConnectedTopologyHelmReleasePanel); |
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
90 changes: 55 additions & 35 deletions
90
frontend/packages/rhoas-plugin/src/topology/rhoas-data-transformer.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 |
---|---|---|
@@ -1,45 +1,65 @@ | ||
import { Model, NodeModel } from '@patternfly/react-topology'; | ||
import { K8sResourceKind } from '@console/internal/module/k8s'; | ||
import { OdcNodeModel, TopologyDataResources } from '@console/topology/src/topology-types'; | ||
|
||
import { apiVersionForModel, K8sResourceKind } from '@console/internal/module/k8s'; | ||
import { | ||
TopologyDataObject, | ||
TopologyDataResources | ||
} from '@console/topology/src/topology-types'; | ||
| ||
import { KAFKA_WIDTH, KAFKA_HEIGHT, KAFKA_PADDING } from "./components/const" | ||
import { ManagedKafkaConnectionModel } from '../models' | ||
import { | ||
getTopologyNodeItem, | ||
} from '@console/topology/src/data-transforms/transform-utils'; | ||
import { OverviewItem } from '@console/shared/src'; | ||
import {MANAGED_KAFKA_TOPOLOGY_TYPE} from "./rhoas-topology-plugin" | ||
|
||
export const getTopologyRhoasItem = ( | ||
objArray: K8sResourceKind[] | ||
const KAFKA_PROPS = { | ||
width: KAFKA_WIDTH, | ||
height: KAFKA_HEIGHT, | ||
group: false, | ||
visible: true, | ||
style: { | ||
padding: KAFKA_PADDING, | ||
}, | ||
}; | ||
| ||
export const createOverviewItem = (obj: K8sResourceKind): OverviewItem<K8sResourceKind> => { | ||
if (!obj.apiVersion) { | ||
obj.apiVersion = apiVersionForModel(ManagedKafkaConnectionModel); | ||
} | ||
if (!obj.kind) { | ||
obj.kind = ManagedKafkaConnectionModel.kind; | ||
} | ||
| ||
return { | ||
obj, | ||
} | ||
}; | ||
| ||
export const getTopologyRhoasNodes = ( | ||
kafkaConnections: K8sResourceKind[] | ||
): NodeModel[] => { | ||
const returnData = []; | ||
for (const obj of objArray) { | ||
const managedKafka: OdcNodeModel = { | ||
id: "ManagedKafkaConnection" + obj.metadata.uid, | ||
type: ManagedKafkaConnectionModel.kind, | ||
resourceKind: ManagedKafkaConnectionModel.kind, | ||
group: false, | ||
label: obj.metadata.name, | ||
children: [], | ||
width: KAFKA_WIDTH, | ||
height: KAFKA_HEIGHT, | ||
visible: true, | ||
style: { | ||
padding: KAFKA_PADDING, | ||
}, | ||
const nodes = []; | ||
for (const obj of kafkaConnections) { | ||
const data: TopologyDataObject = { | ||
id: obj.metadata.uid, | ||
name: obj.metadata.name, | ||
type: MANAGED_KAFKA_TOPOLOGY_TYPE, | ||
resource: obj, | ||
// resources is poorly named, should be overviewItem, eventually going away. | ||
resources: createOverviewItem(obj), | ||
data: { | ||
resource: obj | ||
resource: obj, | ||
} | ||
}; | ||
returnData.push(managedKafka); | ||
nodes.push(getTopologyNodeItem(obj, ManagedKafkaConnectionModel.kind, data, KAFKA_PROPS)); | ||
} | ||
|
||
return returnData; | ||
}; | ||
|
||
export const getRhoasTopologyDataModel = () => { | ||
|
||
return (namespace: string, resources: TopologyDataResources): Promise<Model> => { | ||
const items = getTopologyRhoasItem(resources.kafkaConnections.data); | ||
|
||
return Promise.resolve({ | ||
nodes: items | ||
}); | ||
}; | ||
| ||
return nodes; | ||
}; | ||
| ||
export const getRhoasTopologyDataModel = () => | ||
(namespace: string, resources: TopologyDataResources): Promise<Model> => | ||
Promise.resolve({ | ||
nodes: getTopologyRhoasNodes(resources.kafkaConnections.data) | ||
}); |
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