Skip to content

Commit

Permalink
Add fixes for dates depending on the locale #6712 (#6715) (#6749)
Browse files Browse the repository at this point in the history
cherry-picked commit c388007
  • Loading branch information
metas-ts committed May 28, 2020
1 parent bdf281e commit 0a6a83c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 21 deletions.
8 changes: 4 additions & 4 deletions frontend/src/components/filters/Filters.js
Expand Up @@ -476,12 +476,12 @@ export default 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 @@ -995,6 +995,7 @@ class Table extends Component {
focusOnFieldName,
modalVisible,
isGerman,
activeLocale,
} = this.props;

const {
Expand Down Expand Up @@ -1025,6 +1026,7 @@ class Table extends Component {
{...item}
{...{
entity,
activeLocale,
cols,
windowId,
mainTable,
Expand Down Expand Up @@ -1354,6 +1356,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.includes('de')
: false,
Expand Down
46 changes: 29 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 @@ -258,18 +262,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 @@ -407,6 +412,13 @@ TableCell.propTypes = {
onCellExtend: PropTypes.func,
isEdited: PropTypes.bool,
isGerman: PropTypes.bool,
entity: PropTypes.any,
getSizeClass: PropTypes.func,
mainTable: PropTypes.bool,
viewId: PropTypes.string,
modalVisible: PropTypes.bool,
docId: PropTypes.any,
activeLocale: PropTypes.object,
};

export default TableCell;
5 changes: 5 additions & 0 deletions frontend/src/components/table/TableItem.js
Expand Up @@ -363,6 +363,7 @@ class TableItem extends PureComponent {
isGerman,
isSelected,
focusOnFieldName,
activeLocale,
} = this.props;
const {
edited,
Expand Down Expand Up @@ -407,6 +408,7 @@ class TableItem extends PureComponent {
return (
<TableCell
{...{
activeLocale,
getSizeClass,
entity,
windowId,
Expand Down Expand Up @@ -676,6 +678,9 @@ TableItem.propTypes = {
modalVisible: PropTypes.bool,
isGerman: PropTypes.bool,
keyProperty: PropTypes.string,
selected: PropTypes.array,
page: PropTypes.number,
activeLocale: PropTypes.object,
};

export default TableItem;

0 comments on commit 0a6a83c

Please sign in to comment.