Skip to content

Commit

Permalink
Merge branch 'main' of github.com:percona-platform/grafana into PMM-1…
Browse files Browse the repository at this point in the history
…2382-custom-labels-validation
  • Loading branch information
matejkubinec committed Aug 16, 2023
2 parents 2460d11 + 5614654 commit 31ad279
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 11 deletions.
3 changes: 3 additions & 0 deletions public/app/percona/inventory/Inventory.messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ export const Messages = {
services: {
add: 'Add Service',
columns: {
nodeId: 'Node ID',
status: 'Status',
serviceId: 'Service ID',
serviceName: 'Service Name',
nodeName: 'Node Name',
monitoring: 'Monitoring',
Expand Down Expand Up @@ -51,6 +53,7 @@ export const Messages = {
forceConfirmation: 'Force mode is going to delete all agents and services associated with the nodes',
emptyTable: 'No nodes available',
noServices: 'No services',
servicesCount: (count: number) => `${count} services`,
columns: {
nodeName: 'Node Name',
nodeId: 'Node ID',
Expand Down
32 changes: 26 additions & 6 deletions public/app/percona/inventory/Tabs/Nodes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Form } from 'react-final-form';
import { Row } from 'react-table';

import { AppEvents } from '@grafana/data';
import { Badge, Button, HorizontalGroup, Icon, Modal, TagList, useStyles2 } from '@grafana/ui';
import { Badge, Button, HorizontalGroup, Icon, Link, Modal, TagList, useStyles2 } from '@grafana/ui';
import { OldPage } from 'app/core/components/Page/Page';
import { Action } from 'app/percona/dbaas/components/MultipleActions';
import { CheckboxField } from 'app/percona/shared/components/Elements/Checkbox';
Expand Down Expand Up @@ -33,7 +33,7 @@ import { FlattenNode, MonitoringStatus, Node } from '../Inventory.types';
import { StatusBadge } from '../components/StatusBadge/StatusBadge';
import { StatusLink } from '../components/StatusLink/StatusLink';

import { stripNodeId } from './Nodes.utils';
import { getServiceLink, stripNodeId } from './Nodes.utils';
import { getBadgeColorForServiceStatus, getBadgeIconForServiceStatus } from './Services.utils';
import { getStyles } from './Tabs.styles';

Expand Down Expand Up @@ -67,6 +67,13 @@ export const NodesTab = () => {

const columns = useMemo(
(): Array<ExtendedColumn<Node>> => [
{
Header: Messages.services.columns.nodeId,
id: 'nodeId',
accessor: 'nodeId',
hidden: true,
type: FilterFieldTypes.TEXT,
},
{
Header: Messages.services.columns.status,
accessor: 'status',
Expand Down Expand Up @@ -145,12 +152,21 @@ export const NodesTab = () => {
if (!value || value.length < 1) {
return <div>{Messages.nodes.noServices}</div>;
}
return <div>{value.length > 1 ? `${value.length} services` : value[0].serviceName}</div>;

if (value.length === 1) {
return (
<Link className={styles.link} href={getServiceLink(value[0].serviceId)}>
{value[0].serviceName}
</Link>
);
}

return <div>{Messages.nodes.servicesCount(value.length)}</div>;
},
},
getExpandAndActionsCol(getActions),
],
[getActions]
[styles, getActions]
);

const loadData = useCallback(async () => {
Expand Down Expand Up @@ -189,7 +205,11 @@ export const NodesTab = () => {
{row.original.services && row.original.services.length && (
<DetailsRow.Contents title={Messages.nodes.details.serviceNames}>
{row.original.services.map((service) => (
<div key={service.serviceId}>{service.serviceName}</div>
<div key={service.serviceId}>
<Link className={styles.link} href={getServiceLink(service.serviceId)}>
{service.serviceName}
</Link>
</div>
))}
</DetailsRow.Contents>
)}
Expand All @@ -214,7 +234,7 @@ export const NodesTab = () => {
</DetailsRow>
);
},
[styles.tagList]
[styles.tagList, styles.link]
);

const deletionMsg = useMemo(() => {
Expand Down
7 changes: 7 additions & 0 deletions public/app/percona/inventory/Tabs/Nodes.utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { stripServiceId } from './Services.utils';

export const stripNodeId = (nodeId: string) => {
const regex = /\/node_id\/(.*)/gm;
const match = regex.exec(nodeId);
Expand All @@ -10,3 +12,8 @@ export const stripNodeId = (nodeId: string) => {
};

export const formatNodeId = (nodeId: string) => `/node_id/${nodeId}`;

export const getServiceLink = (serviceId: string) => {
const strippedId = stripServiceId(serviceId);
return `/inventory/services?search-text-input=${strippedId}&search-select=serviceId`;
};
17 changes: 15 additions & 2 deletions public/app/percona/inventory/Tabs/Services.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Row } from 'react-table';

import { AppEvents } from '@grafana/data';
import { locationService } from '@grafana/runtime';
import { Badge, Button, HorizontalGroup, Icon, Modal, TagList, useStyles2 } from '@grafana/ui';
import { Badge, Button, HorizontalGroup, Icon, Link, Modal, TagList, useStyles2 } from '@grafana/ui';
import { OldPage } from 'app/core/components/Page/Page';
import { stripServiceId } from 'app/percona/check/components/FailedChecksTab/FailedChecksTab.utils';
import { Action } from 'app/percona/dbaas/components/MultipleActions';
Expand Down Expand Up @@ -44,6 +44,7 @@ import {
getBadgeIconForServiceStatus,
getBadgeTextForServiceStatus,
getAgentsMonitoringStatus,
getNodeLink,
} from './Services.utils';
import { getStyles } from './Tabs.styles';

Expand Down Expand Up @@ -100,6 +101,13 @@ export const Services = () => {

const columns = useMemo(
(): Array<ExtendedColumn<FlattenService>> => [
{
Header: Messages.services.columns.serviceId,
id: 'serviceId',
accessor: 'serviceId',
hidden: true,
type: FilterFieldTypes.TEXT,
},
{
Header: Messages.services.columns.status,
accessor: 'status',
Expand Down Expand Up @@ -142,6 +150,11 @@ export const Services = () => {
{
Header: Messages.services.columns.nodeName,
accessor: 'nodeName',
Cell: ({ value, row }: { row: Row<FlattenService>; value: string }) => (
<Link className={styles.link} href={getNodeLink(row.original)}>
{value}
</Link>
),
type: FilterFieldTypes.TEXT,
},
{
Expand Down Expand Up @@ -176,7 +189,7 @@ export const Services = () => {
},
getExpandAndActionsCol(getActions),
],
[getActions]
[styles, getActions]
);

const deletionMsg = useMemo(() => {
Expand Down
20 changes: 19 additions & 1 deletion public/app/percona/inventory/Tabs/Services.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { BadgeColor, IconName } from '@grafana/ui';
import { capitalizeText } from 'app/percona/shared/helpers/capitalizeText';
import { DbAgent, ServiceStatus } from 'app/percona/shared/services/services/Services.types';

import { MonitoringStatus, ServiceAgentStatus } from '../Inventory.types';
import { FlattenService, MonitoringStatus, ServiceAgentStatus } from '../Inventory.types';

import { stripNodeId } from './Nodes.utils';

const SERVICE_STATUS_TO_BADGE_COLOR: Record<ServiceStatus, BadgeColor> = {
[ServiceStatus.UP]: 'green',
Expand Down Expand Up @@ -47,3 +49,19 @@ export const getAgentsMonitoringStatus = (agents: DbAgent[]) => {
);
return allAgentsOk ? MonitoringStatus.OK : MonitoringStatus.FAILED;
};

export const stripServiceId = (serviceId: string) => {
const regex = /\/service_id\/(.*)/gm;
const match = regex.exec(serviceId);

if (match && match.length > 0) {
return match[1] || '';
}

return '';
};

export const getNodeLink = (service: FlattenService) => {
const nodeId = service.nodeId === 'pmm-server' ? 'pmm-server' : stripNodeId(service.nodeId);
return `/inventory/nodes?search-text-input=${nodeId}&search-select=nodeId`;
};
5 changes: 4 additions & 1 deletion public/app/percona/inventory/Tabs/Tabs.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { css } from '@emotion/css';

import { GrafanaTheme2 } from '@grafana/data';

export const getStyles = ({ spacing }: GrafanaTheme2) => ({
export const getStyles = ({ colors, spacing }: GrafanaTheme2) => ({
detailsWrapper: css`
display: flex;
flex-direction: column;
Expand Down Expand Up @@ -53,4 +53,7 @@ export const getStyles = ({ spacing }: GrafanaTheme2) => ({
goBack: css`
vertical-align: middle;
`,
link: css`
color: ${colors.text.link};
`,
});
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,14 @@ export const Filter = ({ columns, rawData, setFilteredData, hasBackendFiltering
)}
</div>
)}
{!hasBackendFiltering && <FormSpy onChange={(state) => onFormChange(state.values)}></FormSpy>}
{!hasBackendFiltering && (
<FormSpy
subscription={{
values: true,
}}
onChange={(state) => onFormChange(state.values)}
></FormSpy>
)}
</form>
)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const Table: FC<TableProps> = ({
const manualPagination = !!(totalPages && totalPages >= 0);
const initialState: Partial<PaginatedTableState> = {
pageIndex: propPageIndex,
hiddenColumns: columns.filter((c) => c.hidden && c.id).map((c) => c.id!),
};
const tableOptions: PaginatedTableOptions = {
columns,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export type ExtendedColumn<D extends object = {}> = Column<D> & {
label?: string;
noHiddenOverflow?: boolean;
tooltipInfo?: PopoverContent;
hidden?: boolean;
};

export enum FilterFieldTypes {
Expand Down

0 comments on commit 31ad279

Please sign in to comment.