-
Notifications
You must be signed in to change notification settings - Fork 33
fix: Formatting Rule Doesn't use default set by user #1547
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
Changes from 5 commits
789a7df
5a23de3
175f777
b65a4c4
93c32fb
c039d56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,9 +71,6 @@ interface ColumnSpecificSectionContentState { | |
| showTimeZone: boolean; | ||
| showTSeparator: boolean; | ||
| timeZone: string; | ||
| defaultDateTimeFormat: string; | ||
| defaultDecimalFormatOptions: FormatOption; | ||
| defaultIntegerFormatOptions: FormatOption; | ||
| truncateNumbersWithPound: boolean; | ||
| timestampAtMenuOpen: Date; | ||
| } | ||
|
|
@@ -116,9 +113,6 @@ export class ColumnSpecificSectionContent extends PureComponent< | |
|
|
||
| const { | ||
| formatter, | ||
| defaultDateTimeFormat, | ||
| defaultDecimalFormatOptions, | ||
| defaultIntegerFormatOptions, | ||
| showTimeZone, | ||
| showTSeparator, | ||
| timeZone, | ||
|
|
@@ -141,9 +135,6 @@ export class ColumnSpecificSectionContent extends PureComponent< | |
| showTimeZone, | ||
| showTSeparator, | ||
| timeZone, | ||
| defaultDateTimeFormat, | ||
| defaultDecimalFormatOptions, | ||
| defaultIntegerFormatOptions, | ||
| truncateNumbersWithPound, | ||
| timestampAtMenuOpen: new Date(), | ||
| }; | ||
|
|
@@ -221,7 +212,7 @@ export class ColumnSpecificSectionContent extends PureComponent< | |
| let resetKeys = {}; | ||
| if (key === 'columnType') { | ||
| resetKeys = { | ||
| format: '', | ||
| format: this.makeDefaultFormatterItemByType(value as string), | ||
| }; | ||
| } | ||
| const newEntry = { | ||
|
|
@@ -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 = | ||
|
|
@@ -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`; | ||
|
|
@@ -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); | ||
| }; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why you added these here - |
||
| const ruleError = this.getRuleError(rule); | ||
|
|
||
| return ( | ||
|
|
@@ -511,6 +542,7 @@ export class ColumnSpecificSectionContent extends PureComponent< | |
| isInvalid: boolean | ||
| ): ReactElement { | ||
| const { showTimeZone, showTSeparator, timeZone } = this.state; | ||
|
|
||
| const value = format.formatString ?? ''; | ||
| return ( | ||
| <select | ||
|
|
@@ -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 | ||
|
|
@@ -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 => { | ||
|
|
@@ -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 | ||
|
|
@@ -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 => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -617,7 +617,7 @@ export class FormattingSectionContent extends PureComponent< | |
| checked={truncateNumbersWithPound ?? null} | ||
| onChange={this.handleTruncateNumbersWithPoundChange} | ||
| > | ||
| Truncate numbers with # | ||
| Show truncated numbers as ### | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It only applies to numbers though |
||
| </Checkbox> | ||
| </div> | ||
| </div> | ||
|
|
||
There was a problem hiding this comment.
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.