mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Search: clean up styling (#47221)
This commit is contained in:
parent
916749897c
commit
015a31644c
@ -1,11 +1,11 @@
|
|||||||
import React, { useMemo } from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import { useTable, useBlockLayout, Column, TableOptions, Cell } from 'react-table';
|
import { useTable, Column, TableOptions, Cell, useAbsoluteLayout } from 'react-table';
|
||||||
import { DataFrame, DataFrameType, DataFrameView, DataSourceRef, Field, GrafanaTheme2 } from '@grafana/data';
|
import { DataFrame, DataFrameType, DataFrameView, DataSourceRef, Field, GrafanaTheme2 } from '@grafana/data';
|
||||||
import { css } from '@emotion/css';
|
import { css } from '@emotion/css';
|
||||||
import { useStyles2 } from '@grafana/ui';
|
|
||||||
import { FixedSizeList } from 'react-window';
|
import { FixedSizeList } from 'react-window';
|
||||||
import { TableCell } from '@grafana/ui/src/components/Table/TableCell';
|
import { TableCell } from '@grafana/ui/src/components/Table/TableCell';
|
||||||
import { getTableStyles } from '@grafana/ui/src/components/Table/styles';
|
import { getTableStyles } from '@grafana/ui/src/components/Table/styles';
|
||||||
|
import { useStyles2 } from '@grafana/ui';
|
||||||
|
|
||||||
import { LocationInfo } from '../../service';
|
import { LocationInfo } from '../../service';
|
||||||
import { generateColumns } from './columns';
|
import { generateColumns } from './columns';
|
||||||
@ -66,7 +66,7 @@ export const Table = ({ data, width, tags, onTagFilterChange, onDatasourceChange
|
|||||||
[memoizedColumns, memoizedData]
|
[memoizedColumns, memoizedData]
|
||||||
);
|
);
|
||||||
|
|
||||||
const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow } = useTable(options, useBlockLayout);
|
const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow } = useTable(options, useAbsoluteLayout);
|
||||||
|
|
||||||
const RenderRow = React.useCallback(
|
const RenderRow = React.useCallback(
|
||||||
({ index: rowIndex, style }) => {
|
({ index: rowIndex, style }) => {
|
||||||
@ -78,35 +78,15 @@ export const Table = ({ data, width, tags, onTagFilterChange, onDatasourceChange
|
|||||||
return (
|
return (
|
||||||
<div {...row.getRowProps({ style })} className={styles.rowContainer}>
|
<div {...row.getRowProps({ style })} className={styles.rowContainer}>
|
||||||
{row.cells.map((cell: Cell, index: number) => {
|
{row.cells.map((cell: Cell, index: number) => {
|
||||||
if (
|
|
||||||
cell.column.id === 'column-checkbox' ||
|
|
||||||
cell.column.id === 'column-tags' ||
|
|
||||||
cell.column.id === 'column-datasource'
|
|
||||||
) {
|
|
||||||
return (
|
|
||||||
<div key={index} className={styles.cellWrapper}>
|
|
||||||
<TableCell
|
|
||||||
key={index}
|
|
||||||
tableStyles={tableStyles}
|
|
||||||
cell={cell}
|
|
||||||
columnIndex={index}
|
|
||||||
columnCount={row.cells.length}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<a href={url} key={index}>
|
<a href={url} key={index} className={styles.cellWrapper}>
|
||||||
<div className={styles.cellWrapper}>
|
<TableCell
|
||||||
<TableCell
|
key={index}
|
||||||
key={index}
|
tableStyles={tableStyles}
|
||||||
tableStyles={tableStyles}
|
cell={cell}
|
||||||
cell={cell}
|
columnIndex={index}
|
||||||
columnIndex={index}
|
columnCount={row.cells.length}
|
||||||
columnCount={row.cells.length}
|
/>
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</a>
|
</a>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
@ -178,7 +158,12 @@ const getStyles = (theme: GrafanaTheme2) => {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
`,
|
`,
|
||||||
cellWrapper: css`
|
cellWrapper: css`
|
||||||
display: flex;
|
div {
|
||||||
|
border-right: none;
|
||||||
|
&:hover {
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
headerCell: css`
|
headerCell: css`
|
||||||
padding-top: 2px;
|
padding-top: 2px;
|
||||||
@ -190,17 +175,30 @@ const getStyles = (theme: GrafanaTheme2) => {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
`,
|
`,
|
||||||
rowContainer: css`
|
rowContainer: css`
|
||||||
|
label: row;
|
||||||
&:hover {
|
&:hover {
|
||||||
background-color: ${rowHoverBg};
|
background-color: ${rowHoverBg};
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
typeIcon: css`
|
typeIcon: css`
|
||||||
|
margin-left: 5px;
|
||||||
margin-right: 9.5px;
|
margin-right: 9.5px;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
margin-bottom: ${theme.v1.spacing.xxs};
|
margin-bottom: ${theme.v1.spacing.xxs};
|
||||||
fill: ${theme.colors.text.secondary};
|
fill: ${theme.colors.text.secondary};
|
||||||
`,
|
`,
|
||||||
|
datasourceItem: css`
|
||||||
|
span {
|
||||||
|
&:hover {
|
||||||
|
color: ${theme.colors.text.link};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
invalidDatasourceItem: css`
|
||||||
|
color: ${theme.colors.error.main};
|
||||||
|
text-decoration: line-through;
|
||||||
|
`,
|
||||||
typeText: css`
|
typeText: css`
|
||||||
color: ${theme.colors.text.secondary};
|
color: ${theme.colors.text.secondary};
|
||||||
`,
|
`,
|
||||||
@ -218,13 +216,14 @@ const getStyles = (theme: GrafanaTheme2) => {
|
|||||||
margin-top: 5px;
|
margin-top: 5px;
|
||||||
`,
|
`,
|
||||||
infoWrap: css`
|
infoWrap: css`
|
||||||
|
color: ${theme.colors.text.secondary};
|
||||||
span {
|
span {
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
tagList: css`
|
tagList: css`
|
||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
pointer-events: auto;
|
flex-wrap: nowrap;
|
||||||
`,
|
`,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -65,6 +65,7 @@ export const generateColumns = (
|
|||||||
const DATASOURCE_COLUMN_WIDTH = 200;
|
const DATASOURCE_COLUMN_WIDTH = 200;
|
||||||
const INFO_COLUMN_WIDTH = 100;
|
const INFO_COLUMN_WIDTH = 100;
|
||||||
const LOCATION_COLUMN_WIDTH = 200;
|
const LOCATION_COLUMN_WIDTH = 200;
|
||||||
|
const TAGS_COLUMN_WIDTH = 200;
|
||||||
|
|
||||||
width = TYPE_COLUMN_WIDTH;
|
width = TYPE_COLUMN_WIDTH;
|
||||||
if (isDashboardList) {
|
if (isDashboardList) {
|
||||||
@ -92,12 +93,28 @@ export const generateColumns = (
|
|||||||
// Show datasources if we have any
|
// Show datasources if we have any
|
||||||
if (access.datasource && hasFieldValue(access.datasource)) {
|
if (access.datasource && hasFieldValue(access.datasource)) {
|
||||||
width = DATASOURCE_COLUMN_WIDTH;
|
width = DATASOURCE_COLUMN_WIDTH;
|
||||||
columns.push(makeDataSourceColumn(access.datasource, width, styles.typeIcon, onDatasourceChange));
|
columns.push(
|
||||||
|
makeDataSourceColumn(
|
||||||
|
access.datasource,
|
||||||
|
width,
|
||||||
|
styles.typeIcon,
|
||||||
|
styles.datasourceItem,
|
||||||
|
styles.invalidDatasourceItem,
|
||||||
|
onDatasourceChange
|
||||||
|
)
|
||||||
|
);
|
||||||
|
availableWidth -= width;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show tags if we have any
|
||||||
|
if (access.tags && hasFieldValue(access.tags)) {
|
||||||
|
width = TAGS_COLUMN_WIDTH;
|
||||||
|
columns.push(makeTagsColumn(access.tags, width, styles.tagList, tags, onTagFilterChange));
|
||||||
availableWidth -= width;
|
availableWidth -= width;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDashboardList) {
|
if (isDashboardList) {
|
||||||
width = INFO_COLUMN_WIDTH;
|
width = Math.max(availableWidth, INFO_COLUMN_WIDTH);
|
||||||
columns.push({
|
columns.push({
|
||||||
Cell: DefaultCell,
|
Cell: DefaultCell,
|
||||||
id: `column-info`,
|
id: `column-info`,
|
||||||
@ -109,8 +126,8 @@ export const generateColumns = (
|
|||||||
},
|
},
|
||||||
width: width,
|
width: width,
|
||||||
});
|
});
|
||||||
availableWidth -= width;
|
|
||||||
} else {
|
} else {
|
||||||
|
width = Math.max(availableWidth, LOCATION_COLUMN_WIDTH);
|
||||||
columns.push({
|
columns.push({
|
||||||
Cell: DefaultCell,
|
Cell: DefaultCell,
|
||||||
id: `column-location`,
|
id: `column-location`,
|
||||||
@ -138,15 +155,8 @@ export const generateColumns = (
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
width: LOCATION_COLUMN_WIDTH,
|
width: width,
|
||||||
});
|
});
|
||||||
availableWidth -= width;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show tags if we have any
|
|
||||||
if (access.tags && hasFieldValue(access.tags)) {
|
|
||||||
width = Math.max(availableWidth, 250);
|
|
||||||
columns.push(makeTagsColumn(access.tags, width, styles.tagList, tags, onTagFilterChange));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return columns;
|
return columns;
|
||||||
@ -176,6 +186,8 @@ function makeDataSourceColumn(
|
|||||||
field: Field<DataSourceRef[]>,
|
field: Field<DataSourceRef[]>,
|
||||||
width: number,
|
width: number,
|
||||||
iconClass: string,
|
iconClass: string,
|
||||||
|
datasourceItemClass: string,
|
||||||
|
invalidDatasourceItemClass: string,
|
||||||
onDatasourceChange: (datasource?: string) => void
|
onDatasourceChange: (datasource?: string) => void
|
||||||
): TableColumn {
|
): TableColumn {
|
||||||
return {
|
return {
|
||||||
@ -188,27 +200,30 @@ function makeDataSourceColumn(
|
|||||||
if (dslist?.length) {
|
if (dslist?.length) {
|
||||||
const srv = getDataSourceSrv();
|
const srv = getDataSourceSrv();
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className={datasourceItemClass}>
|
||||||
{dslist.map((v, i) => {
|
{dslist.map((v, i) => {
|
||||||
const settings = srv.getInstanceSettings(v);
|
const settings = srv.getInstanceSettings(v);
|
||||||
const icon = settings?.meta?.info?.logos?.small;
|
const icon = settings?.meta?.info?.logos?.small;
|
||||||
if (icon) {
|
if (icon) {
|
||||||
return (
|
return (
|
||||||
<a
|
<span
|
||||||
key={i}
|
key={i}
|
||||||
href={`datasources/edit/${settings.uid}`}
|
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
onDatasourceChange(settings.uid);
|
onDatasourceChange(settings.uid);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<SVG src={icon} width={14} height={14} title={settings.type} className={iconClass} />
|
<img src={icon} width={14} height={14} title={settings.type} className={iconClass} />
|
||||||
{settings.name}
|
{settings.name}
|
||||||
</a>
|
</span>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return <span key={i}>{v.type}</span>;
|
return (
|
||||||
|
<span className={invalidDatasourceItemClass} key={i}>
|
||||||
|
{v.type}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user