-
Notifications
You must be signed in to change notification settings - Fork 669
Add details card #1696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add details card #1696
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import * as React from 'react'; | ||
| import * as _ from 'lodash-es'; | ||
| import { OverlayTrigger, Tooltip } from 'patternfly-react'; | ||
|
|
||
| import { LoadingInline } from '../../utils'; | ||
|
|
||
| export const DetailItem: React.FC<DetailItemProps> = React.memo(({ title, value, isLoading }) => { | ||
| const description = value ? ( | ||
| <OverlayTrigger | ||
| overlay={<Tooltip id={_.uniqueId('tooltip-for-')}>{value}</Tooltip>} | ||
| placement="top" | ||
| trigger={['hover', 'focus']} | ||
| rootClose={false} | ||
| > | ||
| <span>{value}</span> | ||
|
||
| </OverlayTrigger> | ||
| ) : ( | ||
| '-' | ||
| ); | ||
| return ( | ||
| <React.Fragment> | ||
| <dt className="co-details-card__item-title">{title}</dt> | ||
| <dd className="co-details-card__item-value">{isLoading ? <LoadingInline /> : description}</dd> | ||
|
||
| </React.Fragment> | ||
| ); | ||
| }); | ||
|
|
||
| type DetailItemProps = { | ||
| title: string; | ||
| value?: string; | ||
| isLoading: boolean; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import * as React from 'react'; | ||
|
|
||
| export const DetailsBody: React.FC<DetailsBodyProps> = ({ children }) => ( | ||
| <dl className="co-details-card__body">{children}</dl> | ||
| ); | ||
|
|
||
| type DetailsBodyProps = { | ||
| children: React.ReactNode; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| .co-details-card { | ||
| margin-bottom: 1rem; | ||
| } | ||
|
|
||
| .co-details-card__body { | ||
| display: flex; | ||
| flex-wrap: wrap; | ||
| } | ||
|
|
||
| .co-details-card__item-title { | ||
| flex-basis: 100%; | ||
| font-size: 0.875rem; | ||
| text-transform: capitalize; | ||
| } | ||
|
|
||
| .co-details-card__item-value { | ||
| flex-basis: 100%; | ||
| font-size: 0.875rem; | ||
| margin-bottom: 8px; | ||
| overflow: hidden; | ||
| text-overflow: ellipsis; | ||
| white-space: nowrap; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export * from './detail-item'; | ||
| export * from './details-body'; |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,121 @@ | ||||||||||
| import * as React from 'react'; | ||||||||||
| import * as _ from 'lodash-es'; | ||||||||||
|
|
||||||||||
| import { | ||||||||||
| DashboardCard, | ||||||||||
| DashboardCardBody, | ||||||||||
| DashboardCardHeader, | ||||||||||
| DashboardCardTitle, | ||||||||||
| } from '../../dashboard/dashboard-card'; | ||||||||||
| import { DetailsBody, DetailItem } from '../../dashboard/details-card'; | ||||||||||
| import { withDashboardResources, DashboardItemProps } from '../with-dashboard-resources'; | ||||||||||
| import { InfrastructureModel, ClusterVersionModel } from '../../../models'; | ||||||||||
| import { referenceForModel, K8sResourceKind, getOpenShiftVersion, getK8sGitVersion, getClusterName, ClusterVersionKind } from '../../../module/k8s'; | ||||||||||
| import { FLAGS } from '../../../const'; | ||||||||||
| import { flagPending, connectToFlags } from '../../../reducers/features'; | ||||||||||
| import { FirehoseResource } from '../../utils'; | ||||||||||
|
|
||||||||||
| const getInfrastructurePlatform = (infrastructure: K8sResourceKind): string => _.get(infrastructure, 'status.platform'); | ||||||||||
|
|
||||||||||
| const clusterVersionResource: FirehoseResource = { | ||||||||||
| kind: referenceForModel(ClusterVersionModel), | ||||||||||
| namespaced: false, | ||||||||||
| name: 'version', | ||||||||||
| isList: false, | ||||||||||
| prop: 'cv', | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| const infrastructureResource: FirehoseResource = { | ||||||||||
| kind: referenceForModel(InfrastructureModel), | ||||||||||
| namespaced: false, | ||||||||||
| name: 'cluster', | ||||||||||
| isList: false, | ||||||||||
| prop: 'infrastructure', | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| export const DetailsCard_: React.FC<DetailsCardProps> = ({ | ||||||||||
| watchURL, | ||||||||||
| stopWatchURL, | ||||||||||
| watchK8sResource, | ||||||||||
| stopWatchK8sResource, | ||||||||||
| resources, | ||||||||||
| urlResults, | ||||||||||
| flags, | ||||||||||
| }) => { | ||||||||||
| const openshiftFlag = flags[FLAGS.OPENSHIFT]; | ||||||||||
| React.useEffect(() => { | ||||||||||
| if (flagPending(openshiftFlag)) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
| if (openshiftFlag) { | ||||||||||
| watchK8sResource(clusterVersionResource); | ||||||||||
| watchK8sResource(infrastructureResource); | ||||||||||
| return () => { | ||||||||||
| stopWatchK8sResource(clusterVersionResource); | ||||||||||
| stopWatchK8sResource(infrastructureResource); | ||||||||||
| }; | ||||||||||
| } | ||||||||||
| watchURL('version'); | ||||||||||
| return () => { | ||||||||||
| stopWatchURL('version'); | ||||||||||
| }; | ||||||||||
| }, [openshiftFlag, watchK8sResource, stopWatchK8sResource, watchURL, stopWatchURL]); | ||||||||||
|
|
||||||||||
| const clusterVersion = _.get(resources, 'cv'); | ||||||||||
|
||||||||||
| const clusterVersion = _.get(resources, 'cv'); | |
| const clusterVersion = _.get(resources, 'cv.data') as ClusterVersionKind; | |
| // ... | |
| const openshiftVersion = getOpenShiftVersion(clusterVersion); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typescript complains Conversion of type 'FirehoseResult' to type 'ClusterVersionKind' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. . It thinks that cv.data is FirehoseResult but in reality it is K8sResourceKind | K8sResourceKind[] :/ Splitting the expression in a way I do does not result in error. Seems like a bug in TS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems weird. Is this a bug in the lodash typings? How does TypeScript know the type returned by _.get?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say that is an issue of @types/lodash-es but Im not very familiar with it. I tried updating to latest version (4.17.3, console is using 4.17.0) but it didnt help :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is
idused forTooltip? I don't see where it's referenced. If it's not required, we should leave it out.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is required https://github.com/react-bootstrap/react-bootstrap/blob/master/src/Tooltip.js#L14