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

Data Explorer: Visually distinguish column names with leading/trailing whitespace or empty string #5653

Open
wants to merge 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@
font-weight: var(--positron-data-grid-column-header-title-font-weight);
}

.data-grid-column-header
.content
.title-description
.title
.whitespace {
opacity: 50%;
}

.data-grid-column-header
.content
.title-description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { selectionType } from '../utilities/mouseUtilities.js';
import { VerticalSplitter } from '../../../../base/browser/ui/positronComponents/splitters/verticalSplitter.js';
import { ColumnSelectionState } from '../classes/dataGridInstance.js';
import { usePositronDataGridContext } from '../positronDataGridContext.js';
import { renderLeadingTrailingWhitespace } from '../../../services/positronDataExplorer/browser/components/tableDataCell.js';

/**
* Constants.
Expand Down Expand Up @@ -103,6 +104,8 @@ export const DataGridColumnHeader = (props: DataGridColumnHeaderProps) => {
// Determine whether the column is selected.
const selected = (columnSelectionState & ColumnSelectionState.Selected) !== 0;

const renderedColumn = renderLeadingTrailingWhitespace(props.column?.name);

// Render.
return (
<div
Expand Down Expand Up @@ -137,7 +140,7 @@ export const DataGridColumnHeader = (props: DataGridColumnHeaderProps) => {
}}
>
<div className='title-description'>
<div className='title'>{props.column?.name}</div>
<div className='title'>{renderedColumn}</div>
{props.column?.description &&
<div className='description'>{props.column.description}</div>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@
grid-column: title / sparkline;
}

.data-grid-row-cell .content .column-summary .basic-info .column-name .whitespace {
opacity: 50%;
}

/* column-sparkline */

.data-grid-row-cell .content .column-summary .basic-info .column-sparkline {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { ColumnProfileDatetime } from './columnProfileDatetime.js';
import { TableSummaryDataGridInstance } from '../tableSummaryDataGridInstance.js';
import { ColumnDisplayType, ColumnProfileType, ColumnSchema } from '../../../languageRuntime/common/positronDataExplorerComm.js';
import { dataExplorerExperimentalFeatureEnabled } from '../../common/positronDataExplorerExperimentalConfig.js';
import { renderLeadingTrailingWhitespace } from './tableDataCell.js';

/**
* Constants.
Expand Down Expand Up @@ -354,6 +355,8 @@ export const ColumnSummaryCell = (props: ColumnSummaryCellProps) => {
break;
}

const renderedColumn = renderLeadingTrailingWhitespace(props.columnSchema.column_name);

// Determine whether this is the cursor.
const cursor = props.columnIndex === props.instance.cursorRowIndex;

Expand Down Expand Up @@ -413,7 +416,7 @@ export const ColumnSummaryCell = (props: ColumnSummaryCellProps) => {
onMouseLeave={() => props.hoverService.hideHover()}
/>
<div className='column-name'>
{props.columnSchema.column_name}
{renderedColumn}
</div>
{!expanded && <ColumnSparkline />}
<ColumnNullPercent />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,28 @@ interface TableDataCellProps {
dataCell: DataCell;
}

/**
* TableDataCell component.
* @param props A TableDataCellProps that contains the component properties.
* @returns The rendered component.
*/
export const TableDataCell = (props: TableDataCellProps) => {
const EMPTY_SPACE_SYMBOL = '\u00B7';
export function renderLeadingTrailingWhitespace(text: string | undefined) {
const parts: (string | JSX.Element)[] = [];

let isSpecialValue = props.dataCell.kind !== DataCellKind.NON_NULL;
text = text ?? '';

// Render empty strings as special value
// Initialize rendered output parts
const parts: (string | JSX.Element)[] = [];
const formattedText = props.dataCell.formatted
.replace(/\r/g, '\\r')
.replace(/\n/g, '\\n');
if (text === '') {
// TODO: is this what we want?
return [<span className='whitespace'>{'<empty>'}</span>];
}

const EMPTY_SPACE_SYMBOL = '\u00B7';

// Handle text that is only whitespace
if (formattedText.trim() === '') {
if (text.trim() === '') {
parts.push(
<span className='whitespace'>
{EMPTY_SPACE_SYMBOL.repeat(formattedText.length)}
{EMPTY_SPACE_SYMBOL.repeat(text.length)}
</span>
);
} else {
// Handle leading whitespace
const leadingMatch = formattedText.match(/^\s+/);
const leadingMatch = text.match(/^\s+/);
if (leadingMatch) {
parts.push(
<span className='whitespace'>
Expand All @@ -59,11 +54,11 @@ export const TableDataCell = (props: TableDataCellProps) => {
}

// Add the main content
const mainContent = formattedText.trim();
const mainContent = text.trim();
parts.push(mainContent);

// Handle trailing whitespace
const trailingMatch = formattedText.match(/\s+$/);
const trailingMatch = text.match(/\s+$/);
if (trailingMatch) {
parts.push(
<span className='whitespace'>
Expand All @@ -72,6 +67,26 @@ export const TableDataCell = (props: TableDataCellProps) => {
);
}
}

return parts;
}

/**
* TableDataCell component.
* @param props A TableDataCellProps that contains the component properties.
* @returns The rendered component.
*/
export const TableDataCell = (props: TableDataCellProps) => {
// Render empty strings as special value
// Initialize rendered output parts
const formattedText = props.dataCell.formatted
.replace(/\r/g, '\\r')
.replace(/\n/g, '\\n');

const parts = renderLeadingTrailingWhitespace(formattedText);

let isSpecialValue = props.dataCell.kind !== DataCellKind.NON_NULL;

let renderedOutput = parts;
if (props.dataCell.kind === DataCellKind.NON_NULL && formattedText === '') {
isSpecialValue = true;
Expand Down
Loading