Skip to content

Commit

Permalink
fix(weave): align tables column header cell text based on panel type
Browse files Browse the repository at this point in the history
  • Loading branch information
domphan-wandb committed Sep 25, 2024
1 parent a4ee3ae commit 4b98cf5
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 26 deletions.
1 change: 0 additions & 1 deletion weave-js/src/components/Panel2/PanelTable.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export const ColumnName = styled.div`
color: ${globals.primary};
}
overflow: hidden;
text-align: left;
`;
ColumnName.displayName = 'S.ColumnName';

Expand Down
9 changes: 6 additions & 3 deletions weave-js/src/components/Panel2/PanelTable/ColumnHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import {
voidNode,
} from '@wandb/weave/core';
import {TableState} from '@wandb/weave/index';
import React, {useCallback, useMemo, useState} from 'react';
import React, {useCallback, useMemo, useState, useContext} from 'react';
import {Popup} from 'semantic-ui-react';

import {WeaveFormatContext} from '../WeaveFormatContext';
import {useWeaveContext} from '../../../context';
import {focusEditor, WeaveExpression} from '../../../panel/WeaveExpression';
import {SUGGESTION_OPTION_CLASS} from '../../../panel/WeaveExpression/styles';
Expand Down Expand Up @@ -152,6 +152,7 @@ export const ColumnHeader: React.FC<{
}) => {
const weave = useWeaveContext();
const {stack} = usePanelContext();
const {columnFormat} = useContext(WeaveFormatContext);

const [columnSettingsOpen, setColumnSettingsOpen] = useState(false);

Expand Down Expand Up @@ -495,7 +496,9 @@ export const ColumnHeader: React.FC<{
}, [cellFrame, weave, propsSelectFunction, inputArrayNode]);

return (
<S.ColumnHeader data-test="column-header">
<S.ColumnHeader
data-test="column-header"
style={{textAlign: columnFormat?.textAlign ?? 'center'}}>
{simpleTable ? (
workingColumnName !== '' ? (
<S.ColumnNameText>{workingColumnName}</S.ColumnNameText>
Expand Down
47 changes: 26 additions & 21 deletions weave-js/src/components/Panel2/PanelTable/PanelTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -542,28 +542,33 @@ const PanelTableInner: React.FC<

const headerRendererForColumn = useCallback(
(colId: string, {headerIndex}: any) => {
const columnDef = columnDefinitions[colId];
const colType = columnDef.selectFn.type;

return (
<ColumnHeader
isGroupCol={columnDefinitions[colId].isGrouped}
tableState={tableState}
inputArrayNode={input}
rowsNode={rowsNode}
columnName={tableState.columnNames[colId]}
selectFunction={tableState.columnSelectFunctions[colId]}
colId={colId}
panelId={tableState.columns[colId].panelId}
config={tableState.columns[colId].panelConfig}
panelContext={props.context}
updatePanelContext={updateContext}
updateTableState={updateTableState}
isPinned={config.pinnedColumns?.includes(colId)}
setColumnPinState={(pinned: boolean) => {
setColumnPinState(colId, pinned);
}}
simpleTable={props.config.simpleTable}
countColumnId={countColumnId}
setCountColumnId={setCountColumnId}
/>
<WeaveFormatContext.Provider value={getColumnCellFormats(colType)}>
<ColumnHeader
isGroupCol={columnDefinitions[colId].isGrouped}
tableState={tableState}
inputArrayNode={input}
rowsNode={rowsNode}
columnName={tableState.columnNames[colId]}
selectFunction={tableState.columnSelectFunctions[colId]}
colId={colId}
panelId={tableState.columns[colId].panelId}
config={tableState.columns[colId].panelConfig}
panelContext={props.context}
updatePanelContext={updateContext}
updateTableState={updateTableState}
isPinned={config.pinnedColumns?.includes(colId)}
setColumnPinState={(pinned: boolean) => {
setColumnPinState(colId, pinned);
}}
simpleTable={props.config.simpleTable}
countColumnId={countColumnId}
setCountColumnId={setCountColumnId}
/>
</WeaveFormatContext.Provider>
);
},
[
Expand Down
7 changes: 6 additions & 1 deletion weave-js/src/components/Panel2/PanelTable/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {WeaveFormatContextType} from '../WeaveFormatContext';
import * as Table from './tableState';
import {useTableStateWithRefinedExpressions} from './tableStateReact';

// Formatting for PanelNumbers and PanelStrings inside Tables
// Formatting for PanelNumber and PanelString headers and values inside Tables
export const getColumnCellFormats = (colType: Type): WeaveFormatContextType => {
const t = nullableTaggableStrip(colType);
const numberFormat =
Expand All @@ -42,9 +42,14 @@ export const getColumnCellFormats = (colType: Type): WeaveFormatContextType => {
}
: {};
const stringFormat = {spacing: t === 'string'};
const columnFormat = {
textAlign: t === 'number' ? 'right' as const : 'center' as const,
};

return {
numberFormat,
stringFormat,
columnFormat,
};
};

Expand Down
8 changes: 8 additions & 0 deletions weave-js/src/components/Panel2/WeaveFormatContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ type PanelStringFormat = {
spacing?: boolean;
};

type PanelColumnFormat = {
textAlign?: React.CSSProperties['textAlign'];
};

export type WeaveFormatContextType = {
numberFormat: PanelNumberFormat;
stringFormat: PanelStringFormat;
columnFormat: PanelColumnFormat;
};

export const WeaveFormatContext = React.createContext<WeaveFormatContextType>({
Expand All @@ -26,4 +31,7 @@ export const WeaveFormatContext = React.createContext<WeaveFormatContextType>({
stringFormat: {
spacing: false,
},
columnFormat: {
textAlign: 'center',
},
});

0 comments on commit 4b98cf5

Please sign in to comment.