Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -138,7 +138,10 @@ it('displays an error when the formatting rule is empty', async () => {
expect(screen.getByDisplayValue('test')).toBeInTheDocument();

await user.selectOptions(screen.getByLabelText('Column Type'), 'Decimal');
await user.type(screen.getByLabelText('Formatting Rule'), ' {backspace}');
await user.type(
screen.getByLabelText('Formatting Rule'),
' {Control>}A{/Control}{backspace}'
);
expect(screen.queryByText(/Empty formatting rule\./)).toBeInTheDocument();
});

Expand Down Expand Up @@ -215,7 +218,7 @@ it('should change the input value when column type is Integer', async () => {
await user.selectOptions(screen.getByLabelText('Column Type'), 'Integer');
await user.type(
screen.getByLabelText('Formatting Rule'),
`{selectall}${newFormat}`
`{Control>}A{/Control}${newFormat}`
);

expect(screen.getByDisplayValue(newFormat)).toBeInTheDocument();
Expand Down
73 changes: 57 additions & 16 deletions packages/code-studio/src/settings/ColumnSpecificSectionContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ interface ColumnSpecificSectionContentState {
showTimeZone: boolean;
showTSeparator: boolean;
timeZone: string;
defaultDateTimeFormat: string;
defaultDecimalFormatOptions: FormatOption;
defaultIntegerFormatOptions: FormatOption;
truncateNumbersWithPound: boolean;
timestampAtMenuOpen: Date;
}
Expand Down Expand Up @@ -116,9 +113,6 @@ export class ColumnSpecificSectionContent extends PureComponent<

const {
formatter,
defaultDateTimeFormat,
defaultDecimalFormatOptions,
defaultIntegerFormatOptions,
showTimeZone,
showTSeparator,
timeZone,
Expand All @@ -141,9 +135,6 @@ export class ColumnSpecificSectionContent extends PureComponent<
showTimeZone,
showTSeparator,
timeZone,
defaultDateTimeFormat,
defaultDecimalFormatOptions,
defaultIntegerFormatOptions,
truncateNumbersWithPound,
timestampAtMenuOpen: new Date(),
};
Expand Down Expand Up @@ -221,7 +212,7 @@ export class ColumnSpecificSectionContent extends PureComponent<
let resetKeys = {};
if (key === 'columnType') {
resetKeys = {
format: '',
format: this.makeDefaultFormatterItemByType(value as string),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there's a way using function overloading and/or generics to correct this so you don't need to cast it: https://www.typescriptlang.org/docs/handbook/2/functions.html#function-overloads

Figuring that out isn't really necessary for this though.

};
}
const newEntry = {
Expand Down Expand Up @@ -284,14 +275,18 @@ export class ColumnSpecificSectionContent extends PureComponent<
commitChanges(): void {
const {
formatSettings,
defaultDateTimeFormat,
showTimeZone,
showTSeparator,
timeZone,
defaultDecimalFormatOptions,
defaultIntegerFormatOptions,
truncateNumbersWithPound,
} = this.state;

const {
defaultDateTimeFormat,
defaultDecimalFormatOptions,
defaultIntegerFormatOptions,
} = this.props;

const { dh } = this.props;

const formatter =
Expand Down Expand Up @@ -390,6 +385,41 @@ export class ColumnSpecificSectionContent extends PureComponent<
return error;
}

makeDefaultFormatterItemByType(
columnType: string
): TableColumnFormat | string {
switch (TableUtils.getNormalizedType(columnType)) {
case TableUtils.dataType.INT: {
const { defaultIntegerFormatOptions } = this.props;
const { defaultFormatString: defaultIntegerFormatString } =
defaultIntegerFormatOptions;
return IntegerColumnFormatter.makeFormat(
'',
defaultIntegerFormatString ??
IntegerColumnFormatter.DEFAULT_FORMAT_STRING,
IntegerColumnFormatter.TYPE_GLOBAL,
undefined
);
}

case TableUtils.dataType.DECIMAL: {
const { defaultDecimalFormatOptions } = this.props;
const { defaultFormatString: defaultDecimalFormatString } =
defaultDecimalFormatOptions;
return DecimalColumnFormatter.makeFormat(
'',
defaultDecimalFormatString ??
DecimalColumnFormatter.DEFAULT_FORMAT_STRING,
DecimalColumnFormatter.TYPE_GLOBAL,
undefined
);
}
default: {
return '';
}
}
}

renderFormatRule(i: number, rule: FormatterItem): ReactElement {
const columnNameId = `input-${i}-columnName`;
const columnTypeId = `input-${i}-columnType`;
Expand All @@ -399,8 +429,9 @@ export class ColumnSpecificSectionContent extends PureComponent<
this.handleFormatRuleChange(i, 'columnName', e.target.value);
const onNameBlur = (): void =>
this.handleFormatRuleChange(i, 'isNewRule', false);
const onTypeChange = (e: ChangeEvent<HTMLSelectElement>): void =>
const onTypeChange = (e: ChangeEvent<HTMLSelectElement>): void => {
this.handleFormatRuleChange(i, 'columnType', e.target.value);
};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why you added these here - handleFormatRuleChange doesn't return anything, so you can keep the shorthand. Or update the onNameChange and onNameBlur declarations to match for consistency.

const ruleError = this.getRuleError(rule);

return (
Expand Down Expand Up @@ -511,6 +542,7 @@ export class ColumnSpecificSectionContent extends PureComponent<
isInvalid: boolean
): ReactElement {
const { showTimeZone, showTSeparator, timeZone } = this.state;

const value = format.formatString ?? '';
return (
<select
Expand Down Expand Up @@ -544,6 +576,8 @@ export class ColumnSpecificSectionContent extends PureComponent<
format: Partial<TableColumnFormat>,
isInvalid: boolean
): ReactElement {
const { defaultIntegerFormatOptions } = this.props;
const { defaultFormatString } = defaultIntegerFormatOptions;
const value = format.formatString ?? '';
return (
<input
Expand All @@ -552,7 +586,9 @@ export class ColumnSpecificSectionContent extends PureComponent<
})}
data-lpignore
id={formatId}
placeholder={IntegerColumnFormatter.DEFAULT_FORMAT_STRING}
placeholder={
defaultFormatString ?? IntegerColumnFormatter.DEFAULT_FORMAT_STRING
}
type="text"
value={value}
onChange={e => {
Expand All @@ -574,6 +610,9 @@ export class ColumnSpecificSectionContent extends PureComponent<
format: Partial<TableColumnFormat>,
isInvalid: boolean
): ReactElement {
const { defaultDecimalFormatOptions } = this.props;
const { defaultFormatString } = defaultDecimalFormatOptions;

const value = format.formatString ?? '';
return (
<input
Expand All @@ -582,7 +621,9 @@ export class ColumnSpecificSectionContent extends PureComponent<
})}
data-lpignore
id={formatId}
placeholder={DecimalColumnFormatter.DEFAULT_FORMAT_STRING}
placeholder={
defaultFormatString ?? DecimalColumnFormatter.DEFAULT_FORMAT_STRING
}
type="text"
value={value}
onChange={e => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ export class FormattingSectionContent extends PureComponent<
checked={truncateNumbersWithPound ?? null}
onChange={this.handleTruncateNumbersWithPoundChange}
>
Truncate numbers with #
Show truncated numbers as ###
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A contextual help bubble could be useful here... I think the phrase "Mask truncated numbers with ###" may be better as well, @dsmmcken any opinion?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with this suggestion. Using the word show is more consistent wit the other labels, like "Show T seperator", and I like the multiple hashtags in the label. It's a bit long now is my only complaint.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about Show truncation as ###

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It only applies to numbers though

</Checkbox>
</div>
</div>
Expand Down