Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Commit

Permalink
All urls to Istio details page using same component
Browse files Browse the repository at this point in the history
  • Loading branch information
xeviknal committed May 25, 2020
1 parent acaa501 commit 7213f16
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 80 deletions.
49 changes: 37 additions & 12 deletions src/components/Link/IstioObjectLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ interface Props {
namespace: string;
type: string;
subType?: string;
query?: string;
}

const IstioObjectLink = (props: Props) => {
const { name, namespace, type, subType } = props;
export const GetIstioObjectUrl = (name: string, namespace: string, type: string, subType?: string, query?: string): string => {
const istioType = IstioTypes[type];
let to = '/namespaces/' + namespace + '/' + Paths.ISTIO;

Expand All @@ -22,16 +22,41 @@ const IstioObjectLink = (props: Props) => {
to = to + '/' + istioType.url + '/' + name;
}

return (
<>
<Tooltip position={TooltipPosition.top} content={<>{istioType.name}</>}>
<Badge className={'virtualitem_badge_definition'}>{istioType.icon}</Badge>
</Tooltip>
<Link to={to}>
{namespace}/{name}
</Link>
</>
);
if (!!query) {
to = to + '?' + query;
}

return to;
};

export class ReferenceIstioObjectLink extends React.Component<Props> {
render() {
const { name, namespace, type, subType } = this.props;
const istioType = IstioTypes[type];

return (
<>
<Tooltip position={TooltipPosition.top} content={<>{istioType.name}</>}>
<Badge className={'virtualitem_badge_definition'}>{istioType.icon}</Badge>
</Tooltip>
<IstioObjectLink name={name} namespace={namespace} type={type} subType={subType}>
{namespace}/{name}
</IstioObjectLink>
</>
);
}
}

class IstioObjectLink extends React.Component<Props> {
render() {
const { name, namespace, type, subType, query } = this.props;

return (
<Link to={GetIstioObjectUrl(name, namespace, type, subType, query)}>
{this.props.children}
</Link>
)
}
}

export default IstioObjectLink;
15 changes: 5 additions & 10 deletions src/components/VirtualList/Renderers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import ValidationSummary from '../Validations/ValidationSummary';
import OverviewCardContentExpanded from '../../pages/Overview/OverviewCardContentExpanded';
import { OverviewToolbar } from '../../pages/Overview/OverviewToolbar';
import OverviewCardLinks from '../../pages/Overview/OverviewCardLinks';
import { GetIstioObjectUrl } from '../Link/IstioObjectLink';

// Links

Expand All @@ -32,21 +33,15 @@ const getLink = (item: TResource, config: Resource, query?: string) => {
};

const getIstioLink = (item: TResource) => {
let to = '/namespaces/' + item.namespace + '/istio';
const name = item.name;
const type = item['type'];
let subType;

// Adapters and Templates need to pass subtype
if (type === 'adapter' || type === 'template') {
// Build a /adapters/<adapter_type_plural>/<adapter_name> or
// /templates/<template_type_plural>/<template_name>
const istioType = type + 's';
const subtype = type === 'adapter' ? item['adapter']!.adapters : item['template']!.templates;
to = to + '/' + istioType + '/' + subtype + '/' + name;
} else {
to = to + '/' + IstioTypes[type].url + '/' + name;
subType = type === 'adapter' ? item['adapter']!.adapters : item['template']!.templates;
}
return to;

return GetIstioObjectUrl(item.name, item.namespace, type, subType);
};

// Cells
Expand Down
8 changes: 4 additions & 4 deletions src/pages/IstioConfigDetails/IstioConfigDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import 'brace/theme/eclipse';
import { ObjectReference, ObjectValidation } from '../../types/IstioObjects';
import { AceValidations, jsYaml, parseKialiValidations, parseYamlValidations } from '../../types/AceValidations';
import IstioActionDropdown from '../../components/IstioActions/IstioActionsDropdown';
import { RenderHeader, RenderComponentScroll } from '../../components/Nav/Page';
import { RenderComponentScroll, RenderHeader } from '../../components/Nav/Page';
import './IstioConfigDetailsPage.css';
import { default as IstioActionButtonsContainer } from '../../components/IstioActions/IstioActionsButtons';
import VirtualServiceDetail from './IstioObjectDetails/VirtualServiceDetail';
Expand All @@ -31,9 +31,9 @@ import {
CardBody,
CardHeader,
EmptyState,
EmptyStateBody,
EmptyStateIcon,
EmptyStateVariant,
EmptyStateBody,
Grid,
GridItem,
Stack,
Expand All @@ -47,7 +47,7 @@ import { KialiIcon } from '../../config/KialiIcon';
import { dicIstioType } from '../../types/IstioConfigList';
import { showInMessageCenter } from '../../utils/IstioValidationUtils';
import { PfColors } from '../../components/Pf/PfColors';
import IstioObjectLink from '../../components/Link/IstioObjectLink';
import { ReferenceIstioObjectLink } from '../../components/Link/IstioObjectLink';

const rightToolbarStyle = style({
position: 'absolute',
Expand Down Expand Up @@ -408,7 +408,7 @@ class IstioConfigDetailsPage extends React.Component<RouteComponentProps<IstioCo
{objectReferences.map((reference, i) => {
return (
<StackItem key={'rel-object-' + i}>
<IstioObjectLink
<ReferenceIstioObjectLink
name={reference.name}
type={reference.objectType}
namespace={reference.namespace}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { Host, ObjectValidation, VirtualService } from '../../../types/IstioObje
import LocalTime from '../../../components/Time/LocalTime';
import DetailObject from '../../../components/Details/DetailObject';
import VirtualServiceRoute from './VirtualServiceRoute';
import { Link } from 'react-router-dom';
import { Card, CardBody, Grid, GridItem, Stack, StackItem, Text, TextVariants, Title } from '@patternfly/react-core';
import GlobalValidation from '../../../components/Validations/GlobalValidation';
import IstioObjectLink from '../../../components/Link/IstioObjectLink';

interface VirtualServiceProps {
namespace: string;
Expand Down Expand Up @@ -69,7 +69,9 @@ class VirtualServiceDetail extends React.Component<VirtualServiceProps> {
{host.service === 'mesh' || !isValid ? (
host.service
) : (
<Link to={`/namespaces/${host.namespace}/istio/gateways/${host.service}`}>{gateways[key]}</Link>
<IstioObjectLink name={host.service} namespace={host.namespace} type={'gateway'}>
{gateways[key]}
</IstioObjectLink>
)}
</li>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ import {
CardBody,
EmptyState,
EmptyStateBody,
EmptyStateVariant,
EmptyStateIcon,
EmptyStateVariant,
Grid,
GridItem,
Title
} from '@patternfly/react-core';
import { ICell, IRow, Table, TableHeader, TableBody, TableVariant, cellWidth } from '@patternfly/react-table';
import { cellWidth, ICell, IRow, Table, TableBody, TableHeader, TableVariant } from '@patternfly/react-table';
import { NetworkIcon } from '@patternfly/react-icons';
import LocalTime from '../../../components/Time/LocalTime';
import DetailObject from '../../../components/Details/DetailObject';
import { Link } from 'react-router-dom';
import { ValidationObjectSummary } from '../../../components/Validations/ValidationObjectSummary';
import { DestinationRule, ObjectValidation, Subset } from '../../../types/IstioObjects';
import Labels from '../../../components/Label/Labels';
import { safeRender } from '../../../utils/SafeRender';
import { ServiceDetailsInfo } from '../../../types/ServiceInfo';
import IstioObjectLink from '../../../components/Link/IstioObjectLink';

interface ServiceInfoDestinationRulesProps {
destinationRules?: DestinationRule[];
Expand All @@ -45,17 +45,9 @@ class ServiceInfoDestinationRules extends React.Component<ServiceInfoDestination

yamlLink(destinationRule: DestinationRule) {
return (
<Link
to={
'/namespaces/' +
destinationRule.metadata.namespace +
'/istio/destinationrules/' +
destinationRule.metadata.name +
'?list=yaml'
}
>
<IstioObjectLink name={destinationRule.metadata.name} namespace={destinationRule.metadata.namespace || ''} type={'destinationrule'} query={'list=yaml'}>
View YAML
</Link>
</IstioObjectLink>
);
}

Expand All @@ -69,17 +61,9 @@ class ServiceInfoDestinationRules extends React.Component<ServiceInfoDestination

overviewLink(destinationRule: DestinationRule) {
return (
<Link
to={
'/namespaces/' +
destinationRule.metadata.namespace +
'/istio/destinationrules/' +
destinationRule.metadata.name +
'?list=overview'
}
>
<IstioObjectLink name={destinationRule.metadata.name} namespace={destinationRule.metadata.namespace || ''} type={'destinationrule'}>
{destinationRule.metadata.name}
</Link>
</IstioObjectLink>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import {
CardBody,
EmptyState,
EmptyStateBody,
EmptyStateVariant,
EmptyStateIcon,
EmptyStateVariant,
Grid,
GridItem,
Title
} from '@patternfly/react-core';
import { ICell, IRow, Table, TableHeader, TableBody, TableVariant, cellWidth } from '@patternfly/react-table';
import { cellWidth, ICell, IRow, Table, TableBody, TableHeader, TableVariant } from '@patternfly/react-table';
import { CodeBranchIcon } from '@patternfly/react-icons';
import { Link } from 'react-router-dom';
import { ObjectValidation, VirtualService } from '../../../types/IstioObjects';
import './ServiceInfoVirtualServices.css';
import LocalTime from '../../../components/Time/LocalTime';
import { ValidationObjectSummary } from '../../../components/Validations/ValidationObjectSummary';
import { ServiceDetailsInfo } from '../../../types/ServiceInfo';
import IstioObjectLink from '../../../components/Link/IstioObjectLink';

interface ServiceInfoVirtualServicesProps {
virtualServices?: VirtualService[];
Expand Down Expand Up @@ -49,33 +49,17 @@ class ServiceInfoVirtualServices extends React.Component<ServiceInfoVirtualServi

overviewLink(virtualService: VirtualService) {
return (
<Link
to={
'/namespaces/' +
virtualService.metadata.namespace +
'/istio/virtualservices/' +
virtualService.metadata.name +
'?list=overview'
}
>
<IstioObjectLink name={virtualService.metadata.name} namespace={virtualService.metadata.namespace || ''} type={'virtualservice'}>
{virtualService.metadata.name}
</Link>
</IstioObjectLink>
);
}

yamlLink(virtualService: VirtualService) {
return (
<Link
to={
'/namespaces/' +
virtualService.metadata.namespace +
'/istio/virtualservices/' +
virtualService.metadata.name +
'?list=yaml'
}
>
<IstioObjectLink name={virtualService.metadata.name} namespace={virtualService.metadata.namespace || ''} type={'virtualservice'} query={'list=yaml'}>
View YAML
</Link>
</IstioObjectLink>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const virtualServices: VirtualService[] = [
{
metadata: {
name: 'reviews-default',
namespace: 'bookinfo',
resourceVersion: '1234',
creationTimestamp: '2018-03-14T10:17:52Z'
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ exports[`#ServiceInfoVirtualServices render correctly with data should render se
/>,
},
Object {
"title": <Link
to="/namespaces/undefined/istio/virtualservices/reviews-default?list=overview"
"title": <IstioObjectLink
name="reviews-default"
namespace="bookinfo"
type="virtualservice"
>
reviews-default
</Link>,
</IstioObjectLink>,
},
Object {
"title": <LocalTime
Expand All @@ -74,11 +76,14 @@ exports[`#ServiceInfoVirtualServices render correctly with data should render se
"title": "1234",
},
Object {
"title": <Link
to="/namespaces/undefined/istio/virtualservices/reviews-default?list=yaml"
"title": <IstioObjectLink
name="reviews-default"
namespace="bookinfo"
query="list=yaml"
type="virtualservice"
>
View YAML
</Link>,
</IstioObjectLink>,
},
],
},
Expand Down

0 comments on commit 7213f16

Please sign in to comment.