Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ NOTE: As semantic versioning states all 0.y.z releases can contain breaking chan

- [#102](https://github.com/kobsio/kobs/pull/102): Fix GitHub Action for creating a new Helm release.
- [#109](https://github.com/kobsio/kobs/pull/109): Fix tooltip position in Prometheus charts.
- [#110](https://github.com/kobsio/kobs/pull/110): Fix Dashboard tabs showing wrong variables.

### Changed

Expand Down
77 changes: 54 additions & 23 deletions plugins/dashboards/src/components/dashboards/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { Alert, AlertActionLink, AlertVariant, Grid, GridItem, Spinner, Title } from '@patternfly/react-core';
import {
Alert,
AlertActionLink,
AlertVariant,
Grid,
GridItem,
PageSection,
PageSectionVariants,
Spinner,
Title,
} from '@patternfly/react-core';
import { QueryObserverResult, useQuery } from 'react-query';
import React, { useContext, useState } from 'react';
import React, { memo, useContext, useState } from 'react';

import {
ClustersContext,
Expand All @@ -16,6 +26,8 @@ import { interpolate, rowHeight, toGridSpans } from '../../utils/dashboard';
import DashboardToolbar from './DashboardToolbar';

interface IDashboardProps {
activeKey: string;
eventKey: string;
defaults: IPluginDefaults;
dashboard: IDashboard;
forceDefaultSpan: boolean;
Expand All @@ -27,6 +39,8 @@ interface IDashboardProps {
// The component is also used to set the initial value for the times and for fetching all defined variable values. To
// allow a user to change the time or select another variable value the component includes a toolbar component.
const Dashboard: React.FunctionComponent<IDashboardProps> = ({
activeKey,
eventKey,
defaults,
dashboard,
forceDefaultSpan,
Expand Down Expand Up @@ -64,9 +78,13 @@ const Dashboard: React.FunctionComponent<IDashboardProps> = ({
// Prometheus plugin. For the Prometheus plugin the user must specify the name of the Prometheus instance via the name
// parameter in the options. When the user changes the variables, we keep the old variable values, so that we not have
// to rerender all the panels in the dashboard.
const { isError, error, data, refetch } = useQuery<IVariableValues[], Error>(
['dashboard/variables', variables, times],
const { isError, error, data, refetch } = useQuery<IVariableValues[] | null, Error>(
['dashboard/variables', variables, times, activeKey],
async () => {
if (activeKey !== eventKey) {
return null;
}

if (!variables) {
return [];
}
Expand Down Expand Up @@ -145,32 +163,36 @@ const Dashboard: React.FunctionComponent<IDashboardProps> = ({

if (isError) {
return (
<Alert
variant={AlertVariant.danger}
title="Variables were not fetched"
actionLinks={
<React.Fragment>
<AlertActionLink onClick={(): Promise<QueryObserverResult<IVariableValues[], Error>> => refetch()}>
Retry
</AlertActionLink>
</React.Fragment>
}
>
<p>{error?.message}</p>
</Alert>
<PageSection variant={PageSectionVariants.default} isFilled={true}>
<Alert
variant={AlertVariant.danger}
title="Variables were not fetched"
actionLinks={
<React.Fragment>
<AlertActionLink onClick={(): Promise<QueryObserverResult<IVariableValues[] | null, Error>> => refetch()}>
Retry
</AlertActionLink>
</React.Fragment>
}
>
<p>{error?.message}</p>
</Alert>
</PageSection>
);
}

if (!data) {
return (
<div className="pf-u-text-align-center">
<Spinner />
</div>
<PageSection variant={PageSectionVariants.default} isFilled={true}>
<div className="pf-u-text-align-center">
<Spinner />
</div>
</PageSection>
);
}

return (
<React.Fragment>
<PageSection variant={PageSectionVariants.default} isFilled={true}>
<DashboardToolbar variables={data} setVariables={setVariables} times={times} setTimes={setTimes} />

<p>&nbsp;</p>
Expand Down Expand Up @@ -211,8 +233,17 @@ const Dashboard: React.FunctionComponent<IDashboardProps> = ({
</React.Fragment>
))}
</Grid>
</React.Fragment>
</PageSection>
);
};

export default Dashboard;
export default memo(Dashboard, (prevProps, nextProps) => {
if (
JSON.stringify(prevProps.dashboard) === JSON.stringify(nextProps.dashboard) &&
prevProps.activeKey === nextProps.activeKey
) {
return true;
}

return false;
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const DashboardWrapper: React.FunctionComponent<IDashboardWrapperProps> = ({
return (
<div ref={refWrapper}>
<Dashboard
activeKey=""
eventKey=""
defaults={defaults}
dashboard={dashboard}
forceDefaultSpan={tabsSize.width < 1200}
Expand Down
17 changes: 8 additions & 9 deletions plugins/dashboards/src/components/dashboards/Dashboards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,17 @@ const Dashboards: React.FunctionComponent<IDashboardsProps> = ({
}
className="pf-u-mt-md kobsio-dashboards-tabs-without-margin-top"
isFilled={true}
mountOnEnter={true}
>
{data.map((dashboard) => (
<Tab key={dashboard.title} eventKey={dashboard.title} title={<TabTitleText>{dashboard.title}</TabTitleText>}>
<PageSection variant={PageSectionVariants.default} isFilled={true}>
<Dashboard
defaults={defaults}
dashboard={dashboard}
forceDefaultSpan={forceDefaultSpan}
showDetails={useDrawer ? setDetails : undefined}
/>
</PageSection>
<Dashboard
activeKey={options.dashboard}
eventKey={dashboard.title}
defaults={defaults}
dashboard={dashboard}
forceDefaultSpan={forceDefaultSpan}
showDetails={useDrawer ? setDetails : undefined}
/>
</Tab>
))}
</Tabs>
Expand Down
1 change: 0 additions & 1 deletion plugins/jaeger/src/components/panel/TracesChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ const TracesChart: React.FunctionComponent<ITracesChartProps> = ({ traces }: ITr
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
tooltip={(tooltip) => {
const isFirstHalf = tooltip.node.index < series[0].data.length / 2;
console.log(tooltip.node);

return (
<TooltipWrapper anchor={isFirstHalf ? 'right' : 'left'} position={[0, 20]}>
Expand Down