Skip to content

Commit

Permalink
Add fixes for dates depending on the locale #6712
Browse files Browse the repository at this point in the history
  • Loading branch information
Petrica Nanca committed May 22, 2020
1 parent bae8b38 commit f59f29d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
8 changes: 4 additions & 4 deletions frontend/src/components/filters/Filters.js
Expand Up @@ -558,12 +558,12 @@ class Filters extends PureComponent {
: parameter && parameter.widgetType;

const captionValue = activeParameter
? TableCell.fieldValueToString(
activeParameter.valueTo
? TableCell.fieldValueToString({
fieldValue: activeParameter.valueTo
? [activeParameter.value, activeParameter.valueTo]
: activeParameter.value,
filterType
)
fieldType: filterType,
})
: '';

return {
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/components/table/Table.js
Expand Up @@ -1036,6 +1036,7 @@ class Table extends Component {
focusOnFieldName,
modalVisible,
isGerman,
activeLocale,
} = this.props;

const {
Expand Down Expand Up @@ -1069,6 +1070,7 @@ class Table extends Component {
{...{
page: this.props.page,
entity,
activeLocale,
cols,
windowId,
mainTable,
Expand Down Expand Up @@ -1393,6 +1395,7 @@ const mapStateToProps = (state) => ({
allowShortcut: state.windowHandler.allowShortcut,
allowOutsideClick: state.windowHandler.allowOutsideClick,
modalVisible: state.windowHandler.modal.visible,
activeLocale: state.appHandler.me.language,
isGerman:
state.appHandler.me.language && state.appHandler.me.language.key
? state.appHandler.me.language.key.includes('de')
Expand Down
40 changes: 23 additions & 17 deletions frontend/src/components/table/TableCell.js
Expand Up @@ -27,13 +27,16 @@ class TableCell extends PureComponent {

static getDateFormat = (fieldType) => DATE_FIELD_FORMATS[fieldType];

static createDate = (fieldValue, fieldType) => {
static createDate = ({ fieldValue, fieldType, activeLocale }) => {
const languageKey = activeLocale ? activeLocale.key : null;
if (fieldValue) {
return !Moment.isMoment(fieldValue) && fieldValue.match(TIME_REGEX_TEST)
? Moment.utc(Moment.duration(fieldValue).asMilliseconds()).format(
TIME_FORMAT
)
: Moment(fieldValue).format(TableCell.getDateFormat(fieldType));
? Moment.utc(Moment.duration(fieldValue).asMilliseconds())
.locale(languageKey)
.format(TIME_FORMAT)
: Moment(fieldValue)
.locale(languageKey)
.format(TableCell.getDateFormat(fieldType));
}

return '';
Expand Down Expand Up @@ -82,12 +85,13 @@ class TableCell extends PureComponent {

// @TODO: THIS NEEDS URGENT REFACTORING, WHY THE HECK ARE WE RETURNING
// SIX DIFFERENT TYPES OF VALUES HERE ? UBER-BAD DESIGN !
static fieldValueToString = (
static fieldValueToString = ({
fieldValue,
fieldType = 'Text',
precision = null,
isGerman
) => {
isGerman,
activeLocale,
}) => {
if (fieldValue === null) {
return '';
}
Expand All @@ -102,7 +106,7 @@ class TableCell extends PureComponent {

return DATE_FIELD_TYPES.includes(fieldType) ||
TIME_FIELD_TYPES.includes(fieldType)
? TableCell.createDate(fieldValue, fieldType)
? TableCell.createDate({ fieldValue, fieldType, activeLocale })
: fieldValue.caption;
}
case 'boolean': {
Expand All @@ -117,7 +121,7 @@ class TableCell extends PureComponent {
DATE_FIELD_TYPES.includes(fieldType) ||
TIME_FIELD_TYPES.includes(fieldType)
) {
return TableCell.createDate(fieldValue, fieldType);
return TableCell.createDate({ fieldValue, fieldType, activeLocale });
} else if (AMOUNT_FIELD_TYPES.includes(fieldType)) {
return TableCell.createAmount(fieldValue, precision, isGerman);
} else if (SPECIAL_FIELD_TYPES.includes(fieldType)) {
Expand Down Expand Up @@ -260,18 +264,19 @@ class TableCell extends PureComponent {
modalVisible,
onClickOutside,
isGerman,
activeLocale,
} = this.props;
const widgetData = getWidgetData(item, isEditable, supportFieldEdit);

const docId = `${this.props.docId}`;
const { tooltipToggled } = this.state;
const tdValue = !isEdited
? TableCell.fieldValueToString(
widgetData[0].value,
item.widgetType,
widgetData[0].precision,
isGerman
)
? TableCell.fieldValueToString({
fieldValue: widgetData[0].value,
fieldType: item.widgetType,
precision: widgetData[0].precision,
isGerman,
activeLocale,
})
: null;
const description =
widgetData[0].value && widgetData[0].value.description
Expand Down Expand Up @@ -431,6 +436,7 @@ TableCell.propTypes = {
viewId: PropTypes.string,
modalVisible: PropTypes.bool,
docId: PropTypes.any,
activeLocale: PropTypes.object,
};

export default TableCell;
3 changes: 3 additions & 0 deletions frontend/src/components/table/TableItem.js
Expand Up @@ -406,6 +406,7 @@ class TableItem extends Component {
isGerman,
isSelected,
focusOnFieldName,
activeLocale,
} = this.props;
const {
edited,
Expand Down Expand Up @@ -450,6 +451,7 @@ class TableItem extends Component {
return (
<TableCell
{...{
activeLocale,
getSizeClass,
entity,
windowId,
Expand Down Expand Up @@ -723,6 +725,7 @@ TableItem.propTypes = {
keyProperty: PropTypes.string,
selected: PropTypes.array,
page: PropTypes.number,
activeLocale: PropTypes.object,
};

export default TableItem;

0 comments on commit f59f29d

Please sign in to comment.