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

KIALI-2129 UXD: Move the grafana link to the topbar #876

Merged
merged 4 commits into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/actions/LoginThunkActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ const performLogin = (
API.login(loginUser, loginPass).then(
token => {
dispatch(LoginActions.loginSuccess(token['data'], loginUser));
const auth = `Bearer ${token['data']['token']}`;
dispatch(HelpDropdownThunkActions.refresh());
dispatch(GrafanaThunkActions.getInfo(auth));
},
error => {
if (anonymous) {
Expand Down
15 changes: 2 additions & 13 deletions src/components/GraphFilter/GraphRefresh.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,6 @@ export class GraphRefresh extends React.PureComponent<GraphRefreshProps> {
HistoryManager.setParam(URLParams.POLL_INTERVAL, String(this.props.refreshInterval));
}

formatRefreshText = (key, isTitle: boolean = false): string => {
// Ensure that we have an integer (for comparisons).
key = Number(key);

if (isTitle) {
return key !== 0 ? `Every ${GraphRefresh.POLL_INTERVAL_LIST[key]}` : 'Paused';
} else {
return key !== 0 ? `Every ${GraphRefresh.POLL_INTERVAL_LIST[key]}` : GraphRefresh.POLL_INTERVAL_LIST[key];
}
};

render() {
return (
<>
Expand All @@ -95,7 +84,7 @@ export class GraphRefresh extends React.PureComponent<GraphRefreshProps> {
/>
<DropdownButton
id="graph_refresh_dropdown"
title={this.formatRefreshText(this.props.refreshInterval, true)}
title={GraphRefresh.POLL_INTERVAL_LIST[this.props.refreshInterval]}
disabled={this.props.disabled}
>
{Object.keys(GraphRefresh.POLL_INTERVAL_LIST).map((key: any) => {
Expand All @@ -106,7 +95,7 @@ export class GraphRefresh extends React.PureComponent<GraphRefreshProps> {
active={Number(key) === this.props.refreshInterval}
onSelect={value => this.props.setRefreshInterval(Number(value))}
>
{this.formatRefreshText(key)}
{GraphRefresh.POLL_INTERVAL_LIST[key]}
</MenuItem>
);
})}
Expand Down
8 changes: 1 addition & 7 deletions src/components/Metrics/Metrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ class Metrics extends React.Component<MetricsProps, MetricsState> {
onLabelsFiltersChanged={this.onLabelsFiltersChanged}
direction={this.props.direction}
labelValues={this.state.labelValues}
grafanaLink={this.getGrafanaLink()}
/>
{expandedChart ? this.renderExpandedChart(expandedChart) : this.renderMetrics()}
</div>
Expand All @@ -254,13 +255,6 @@ class Metrics extends React.Component<MetricsProps, MetricsState> {
<div className="card-pf-body">{Object.keys(charts).map(key => this.renderChart(key, charts[key]))}</div>
</div>
</div>
{this.props.grafanaInfo && (
<span id="grafana-link">
<a href={this.getGrafanaLink()} target="_blank">
View in Grafana
</a>
</span>
)}
</div>
</div>
);
Expand Down
30 changes: 19 additions & 11 deletions src/components/MetricsOptions/MetricsOptionsBar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { Toolbar, ToolbarRightContent, FormGroup } from 'patternfly-react';
import { Toolbar, ToolbarRightContent, FormGroup, Icon } from 'patternfly-react';
import isEqual from 'lodash/fp/isEqual';

import RefreshContainer from '../../containers/RefreshContainer';
Expand All @@ -18,6 +18,7 @@ export interface MetricsOptionsBarProps {
onLabelsFiltersChanged: (label: L.LabelName, value: string, checked: boolean) => void;
direction: Direction;
labelValues: Map<L.LabelName, L.LabelValues>;
grafanaLink: string;
}

export class MetricsOptionsBar extends React.Component<MetricsOptionsBarProps> {
Expand Down Expand Up @@ -161,17 +162,24 @@ export class MetricsOptionsBar extends React.Component<MetricsOptionsBarProps> {
options={MetricsOptionsBar.ReporterOptions}
/>
</FormGroup>
<ToolbarDropdown
id={'metrics_filter_interval_duration'}
disabled={false}
handleSelect={this.onDurationChanged}
nameDropdown={'Displaying'}
initialValue={this.duration}
initialLabel={String(MetricsOptionsBar.Durations[this.duration])}
options={MetricsOptionsBar.Durations}
/>
{this.props.grafanaLink && (
<FormGroup style={{ borderRight: 'none' }}>
<a id={'grafana_link'} href={this.props.grafanaLink} target="_blank">
View in Grafana <Icon type={'fa'} name={'external-link'} />
</a>
</FormGroup>
)}
<ToolbarRightContent>
<RefreshContainer id="metrics-refresh" handleRefresh={this.props.onRefresh} />
<ToolbarDropdown
id={'metrics_filter_interval_duration'}
disabled={false}
handleSelect={this.onDurationChanged}
nameDropdown={'Fetching'}
initialValue={this.duration}
initialLabel={String(MetricsOptionsBar.Durations[this.duration])}
options={MetricsOptionsBar.Durations}
/>
<RefreshContainer id="metrics-refresh" handleRefresh={this.props.onRefresh} hideLabel={true} />
</ToolbarRightContent>
</Toolbar>
);
Expand Down
18 changes: 18 additions & 0 deletions src/components/MetricsOptions/__tests__/MetricsOptionsBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('MetricsOptionsBar', () => {
onLabelsFiltersChanged={jest.fn()}
direction={'inbound'}
labelValues={new Map()}
grafanaLink={'http://grafana-istio-system.127.0.0.1.nip.io/d/UbsSZTDik/istio-workload-dashboard'}
/>
</Provider>
);
Expand All @@ -31,6 +32,7 @@ describe('MetricsOptionsBar', () => {
onLabelsFiltersChanged={jest.fn()}
direction={'inbound'}
labelValues={new Map()}
grafanaLink={''}
/>
</Provider>
);
Expand All @@ -44,4 +46,20 @@ describe('MetricsOptionsBar', () => {
wrapper.setProps({}); // Force re-render
expect(optionsChanged).toHaveBeenCalledTimes(2);
});

it('Has a Grafana link', () => {
let wrapper = mount(
<Provider store={store}>
<MetricsOptionsBar
onOptionsChanged={jest.fn()}
onRefresh={jest.fn()}
onLabelsFiltersChanged={jest.fn()}
direction={'inbound'}
labelValues={new Map()}
grafanaLink={'http://grafana-istio-system.127.0.0.1.nip.io/d/UbsSZTDik/istio-workload-dashboard'}
/>
</Provider>
);
expect(wrapper.find('#grafana_link')).toHaveLength(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ ShallowWrapper {
>
<MetricsOptionsBar
direction="inbound"
grafanaLink="http://grafana-istio-system.127.0.0.1.nip.io/d/UbsSZTDik/istio-workload-dashboard"
labelValues={Map {}}
onLabelsFiltersChanged={[MockFunction]}
onOptionsChanged={[MockFunction]}
Expand All @@ -37,6 +38,7 @@ ShallowWrapper {
"nodeType": "class",
"props": Object {
"direction": "inbound",
"grafanaLink": "http://grafana-istio-system.127.0.0.1.nip.io/d/UbsSZTDik/istio-workload-dashboard",
"labelValues": Map {},
"onLabelsFiltersChanged": [MockFunction],
"onOptionsChanged": [MockFunction],
Expand All @@ -53,6 +55,7 @@ ShallowWrapper {
"nodeType": "class",
"props": Object {
"direction": "inbound",
"grafanaLink": "http://grafana-istio-system.127.0.0.1.nip.io/d/UbsSZTDik/istio-workload-dashboard",
"labelValues": Map {},
"onLabelsFiltersChanged": [MockFunction],
"onOptionsChanged": [MockFunction],
Expand Down
4 changes: 3 additions & 1 deletion src/components/Refresh/Refresh.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { PollIntervalInMs } from '../../types/Common';
type ComponentProps = {
id: string;
handleRefresh: () => void;
hideLabel?: boolean;
};

type ReduxProps = {
Expand Down Expand Up @@ -54,9 +55,10 @@ class Refresh extends React.Component<Props, State> {

render() {
if (this.props.refreshInterval !== undefined) {
const { hideLabel } = this.props;
return (
<>
<label style={{ paddingRight: '0.5em', marginLeft: '1.5em' }}>Refreshing</label>
{!hideLabel && <label style={{ paddingRight: '0.5em', marginLeft: '1.5em' }}>Refreshing</label>}
<DropdownButton id={this.props.id} title={POLL_INTERVALS[this.props.refreshInterval]}>
{Object.keys(POLL_INTERVALS).map(strKey => {
const key = Number(strKey);
Expand Down
Loading