Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add column config for actions #231

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { css } from '@emotion/css';
import { GrafanaTheme2 } from '@grafana/data';

/**
* Get Styles
*/
export const getStyles = () => {
export const getStyles = (theme: GrafanaTheme2) => {
return {
labelSortable: css`
cursor: pointer;
`,
actionHeader: css`
margin: ${theme.spacing(0)};
margin-left: ${theme.spacing(1)};
`,
actions: css`
display: flex;
`,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,33 @@ describe('TableHeaderCell', () => {

expect(onAddRow).toHaveBeenCalled();
});

it('Should display text in action header', () => {
const onAddRow = jest.fn();

render(
getComponent({
header: {
getContext: () =>
({
label: 'action header',
}) as any,
column: {
id: ACTIONS_COLUMN_ID,
getIsSorted: jest.fn(),
getCanSort: jest.fn(),
getToggleSortingHandler: jest.fn(),
columnDef: {
header: ({ label }: any) => label,
},
} as any,
} as any,
isAddRowEnabled: true,
onAddRow,
})
);

expect(selectors.actionHeaderText()).toBeInTheDocument();
expect(selectors.actionHeaderText()).toHaveTextContent('action header');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,22 @@ export const TableHeaderCell = <TData,>({ header, size, isAddRowEnabled, onAddRo
* Actions Header
*/
if (header.column.id === ACTIONS_COLUMN_ID) {
if (isAddRowEnabled) {
return <IconButton name="plus" aria-label="Add Row" onClick={onAddRow} {...testIds.buttonAddRow.apply()} />;
}

return null;
return (
<div className={styles.actions}>
{isAddRowEnabled && (
<IconButton
name="plus"
size={size}
aria-label="Add Row"
onClick={onAddRow}
{...testIds.buttonAddRow.apply()}
/>
)}
<p {...testIds.actionHeaderText.apply()} className={styles.actionHeader}>
{flexRender(header.column.columnDef.header, header.getContext())}
</p>
</div>
);
}

return (
Expand Down
8 changes: 7 additions & 1 deletion src/components/Table/components/TableRow/TableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,12 @@ export const TableRow = <TData,>({
/**
* Set background color
*/
if (field.display && config.type === CellType.COLORED_BACKGROUND && !row.getIsGrouped()) {
if (
!cell.id.includes(ACTIONS_COLUMN_ID) &&
field.display &&
config.type === CellType.COLORED_BACKGROUND &&
!row.getIsGrouped()
) {
const displayValue = field.display(value);

if (displayValue.color) {
Expand All @@ -192,6 +197,7 @@ export const TableRow = <TData,>({
* Apply Display Processor to Aggregated Row
*/
if (
!cell.id.includes(ACTIONS_COLUMN_ID) &&
field.display &&
config.type === CellType.COLORED_BACKGROUND &&
cell.getIsAggregated() &&
Expand Down
1 change: 1 addition & 0 deletions src/components/TablePanel/TablePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export const TablePanel: React.FC<Props> = ({
const { tableData, columns } = useTable({
data,
columns: currentTable?.items,
actionsColumnConfig: currentTable?.actionsColumnConfig,
isAddRowEnabled,
isDeleteRowEnabled,
replaceVariables,
Expand Down
Loading
Loading