Skip to content

Commit 80bcbc8

Browse files
authored
ref(dashboards): remove name field from TabularColumn (#95277)
### Changes Remove `name` field from `TabularColumn` for `TableWidgetVisualization`. This field is not used anymore for rendering. No UI change.
1 parent e83922b commit 80bcbc8

File tree

8 files changed

+12
-23
lines changed

8 files changed

+12
-23
lines changed

static/app/views/dashboards/widgetCard/chart.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ class WidgetCardChart extends Component<WidgetCardChartProps> {
186186
tableResults[i]?.meta
187187
).map((column, index) => ({
188188
key: column.key,
189-
name: column.name,
190189
width: widget.tableWidths?.[index] ?? minTableColumnWidth ?? column.width,
191190
type: column.type === 'never' ? null : column.type,
192191
sortable:

static/app/views/dashboards/widgetCard/issueWidgetCard.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ export function IssueWidgetCard({
7171
const columns = decodeColumnOrder(queryFields.map(field => ({field}))).map(
7272
(column, index) => ({
7373
key: column.key,
74-
name: column.name,
7574
width: widget.tableWidths?.[index] ?? column.width,
7675
type: column.type === 'never' ? null : column.type,
7776
})

static/app/views/dashboards/widgets/common/types.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ export type TabularData<TFields extends string = string> = {
8181

8282
export type TabularColumn<TFields extends string = string> = {
8383
key: TFields;
84-
name: TFields;
8584
sortable?: boolean;
8685
type?: AttributeValueType;
8786
width?: number;

static/app/views/dashboards/widgets/tableWidget/tableWidgetVisualization.spec.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ describe('TableWidgetVisualization', function () {
2626
const columns: Array<Partial<TabularColumn>> = [
2727
{
2828
key: 'count(span.duration)',
29-
name: 'Count of Span Duration',
3029
},
3130
{
3231
key: 'http.request_method',
33-
name: 'HTTP Request Method',
3432
},
3533
];
3634
const sortableColumns = columns.map(column => ({...column, sortable: true}));
@@ -54,8 +52,8 @@ describe('TableWidgetVisualization', function () {
5452
);
5553

5654
const $headers = screen.getAllByRole('columnheader');
57-
expect($headers[0]).toHaveTextContent(columns[0]!.name!);
58-
expect($headers[1]).toHaveTextContent(columns[1]!.name!);
55+
expect($headers[0]).toHaveTextContent(columns[0]!.key!);
56+
expect($headers[1]).toHaveTextContent(columns[1]!.key!);
5957
});
6058

6159
it('Renders unique number fields correctly', async function () {
@@ -250,13 +248,11 @@ describe('TableWidgetVisualization', function () {
250248
expect(onResizeColumnMock).toHaveBeenCalledWith([
251249
{
252250
key: 'http.request_method',
253-
name: 'http.request_method',
254251
type: 'string',
255252
width: 100,
256253
},
257254
{
258255
key: 'count(span.duration)',
259-
name: 'count(span.duration)',
260256
type: 'integer',
261257
width: -1,
262258
},

static/app/views/dashboards/widgets/tableWidget/tableWidgetVisualization.stories.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ export default Storybook.story('TableWidgetVisualization', story => {
2121
const customColumns: TabularColumn[] = [
2222
{
2323
key: 'count(span.duration)',
24-
name: 'count(span.duration)',
2524
type: 'number',
2625
},
2726
{
2827
key: 'http.request_method',
29-
name: 'http.request_method',
3028
type: 'string',
3129
},
3230
];

static/app/views/dashboards/widgets/tableWidget/tableWidgetVisualization.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,24 +177,27 @@ export function TableWidgetVisualization(props: TableWidgetVisualizationProps) {
177177

178178
// Fallback to extracting fields from the tableData if no columns are provided
179179
const columnOrder: TabularColumn[] =
180-
columns?.map((column, index) => ({...column, width: widths[index]})) ??
180+
columns?.map((column, index) => ({
181+
...column,
182+
width: widths[index],
183+
})) ??
181184
Object.keys(meta.fields).map((key, index) => ({
182185
key,
183-
name: key,
184186
width: widths[index],
185187
type: meta.fields[key],
186188
}));
187189

188190
return (
189191
<GridEditable
190192
data={data}
191-
columnOrder={columnOrder}
193+
// GridEditable needs name, but this functionality is replaced by aliases
194+
columnOrder={columnOrder.map(column => ({...column, name: column.key}))}
192195
columnSortBy={[]}
193196
grid={{
194197
renderHeadCell: (_tableColumn, columnIndex) => {
195198
const column = columnOrder[columnIndex]!;
196-
const align = fieldAlignment(column.name, column.type as ColumnValueType);
197-
const name = aliases?.[column.key] || column.name;
199+
const align = fieldAlignment(column.key, column.type as ColumnValueType);
200+
const name = aliases?.[column.key] || column.key;
198201
const sortColumn = getSortField(column.key) ?? column.key;
199202

200203
let direction = undefined;
@@ -246,10 +249,8 @@ export function TableWidgetVisualization(props: TableWidgetVisualizationProps) {
246249
widths[columnIndex] = defined(nextColumn.width)
247250
? nextColumn.width
248251
: COL_WIDTH_UNDEFINED;
249-
columnOrder[columnIndex] = {
250-
...nextColumn,
251-
width: widths[columnIndex],
252-
};
252+
253+
columnOrder[columnIndex]!.width = widths[columnIndex];
253254

254255
if (onResizeColumn) {
255256
onResizeColumn(columnOrder);

static/app/views/dashboards/widgets/tableWidget/utils.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ describe('Table Widget Visualization Utils', function () {
77
const columns = TabularColumnsFixture([
88
{
99
key: 'columnOne',
10-
name: 'columnOne',
1110
},
1211
{
1312
key: 'columnTwo',
14-
name: 'columnTwo',
1513
},
1614
]);
1715
const fieldAliases = ['Column One', ''];

tests/js/fixtures/tabularColumn.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type {TabularColumn} from 'sentry/views/dashboards/widgets/common/types';
33
export function TabularColumnFixture(params: Partial<TabularColumn>): TabularColumn {
44
return {
55
key: 'column_key',
6-
name: 'column_name',
76
type: 'string',
87
width: -1,
98
...params,

0 commit comments

Comments
 (0)