Skip to content

Commit

Permalink
When 'show time' is false, current time should not be sent on the pay…
Browse files Browse the repository at this point in the history
…load bug #1543

Dyanamic dateField filtering sends the incorrect format expected by the endpoint bug #1542
Date not selectable during inline editing when show time property is enabled bug urgent #1541
The payload sends the exact format received from the component which differs to what the backend is expecting bug urgent #1468
Datefield formatting (DD-MM-YYYY) data doesn't match endpoint data/what has been selected bug #1166
  • Loading branch information
AlexStepantsov committed May 20, 2024
1 parent 22b110e commit 0af91ef
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 57 deletions.
19 changes: 7 additions & 12 deletions shesha-reactjs/src/components/reactTable/tableRow.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MoreOutlined } from '@ant-design/icons';
import classNames from 'classnames';
import React, { FC, useEffect, useRef, useState } from 'react';
import React, { FC, useRef } from 'react';
import { Row } from 'react-table';
import { RowCell } from './rowCell';
import { CrudProvider } from '@/providers/crudContext';
Expand Down Expand Up @@ -69,15 +69,9 @@ export const TableRow: FC<ISortableRowProps> = (props) => {
const { styles } = useStyles();
const { hoverRowId, setHoverRowId, dragState: draggingRowId, setDragState } = useDataTableStore();
const tableRef = useRef(null);
const [selected, setSelected] = useState<Number>(selectedRowIndex);

const handleRowClick = () => {
if (selected === row?.index) {
setSelected(-1);
} else {
onClick(row);
setSelected(row?.index);
}
onClick(row);
};

const handleRowDoubleClick = () => {
Expand All @@ -86,14 +80,15 @@ export const TableRow: FC<ISortableRowProps> = (props) => {

prepareRow(row);

useEffect(() => {
// Review if deselecting is required for click outside
/*useEffect(() => {
const onClickOutside = (event) => {
if (tableRef.current && !tableRef.current.contains(event.target)) {
setSelected(-1);
onClick(null);
}
};
document.addEventListener('click', onClickOutside);
}, []);
}, []);*/

const rowId = row.original.id ?? row.id;

Expand Down Expand Up @@ -133,7 +128,7 @@ export const TableRow: FC<ISortableRowProps> = (props) => {
styles.tr,
styles.trBody,
{ [styles.trOdd]: index % 2 === 0 },
{ [styles.trSelected]: selected === row?.index },
{ [styles.trSelected]: selectedRowIndex === row?.index },
{ [styles.shaHover]: hoverRowId === rowId },
)}
key={rowId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ export const DatePickerWrapper: FC<IDateFieldProps> = (props) => {
? newValue.startOf('quarter')
: picker === 'year'
? newValue.startOf('year')
: newValue;
: !showTime
? newValue.startOf('day')
: newValue;
return !resolveToUTC ? val.utc(true) : val.local(true);
};

Expand Down
99 changes: 56 additions & 43 deletions shesha-reactjs/src/providers/form/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,55 +550,68 @@ class StaticMustacheTag {
* @returns {string} evaluated string
*/
export const evaluateString = (template: string = '', data: any, skipUnknownTags: boolean = false) => {
if (!template || typeof template !== 'string')
return template;

const localData: IAnyObject = data ? { ...data } : undefined;
// The function throws an exception if the expression passed doesn't have a corresponding curly braces
// store moment toString function to get ISO format of datetime
var toString = moment.prototype.toString;
moment.prototype.toString = function () {
return this.toISOString();
};

try {
if (localData) {
//adding a function to the data object that will format datetime

localData.dateFormat = function () {
return function (timestamp, render) {
return new Date(render(timestamp).trim()).toLocaleDateString('en-us', {
year: 'numeric',
month: 'short',
day: 'numeric',
});

if (!template || typeof template !== 'string')
return template;

const localData: IAnyObject = data ? { ...data } : undefined;
// The function throws an exception if the expression passed doesn't have a corresponding curly braces
try {
if (localData) {
//adding a function to the data object that will format datetime

localData.dateFormat = function () {
return function (timestamp, render) {
return new Date(render(timestamp).trim()).toLocaleDateString('en-us', {
year: 'numeric',
month: 'short',
day: 'numeric',
});
};
};
};
}
}

const view = localData ?? {};

if (skipUnknownTags) {
template.match(/{{\s*[\w\.]+\s*}}/g).forEach((x) => {
const mathes = x.match(/[\w\.]+/);
const tag = mathes.length ? mathes[0] : undefined;

const parts = tag.split('.');
const field = parts.pop();
const container = parts.reduce((level, key) => {
return level.hasOwnProperty(key) ? level[key] : (level[key] = {});
}, view);
if (!container.hasOwnProperty(field)){
container[field] = new StaticMustacheTag(tag);
}
});
const view = localData ?? {};

if (skipUnknownTags) {
template.match(/{{\s*[\w\.]+\s*}}/g).forEach((x) => {
const mathes = x.match(/[\w\.]+/);
const tag = mathes.length ? mathes[0] : undefined;

const parts = tag.split('.');
const field = parts.pop();
const container = parts.reduce((level, key) => {
return level.hasOwnProperty(key) ? level[key] : (level[key] = {});
}, view);
if (!container.hasOwnProperty(field)){
container[field] = new StaticMustacheTag(tag);
}
});

const escape = (value: any): string => {
return value instanceof StaticMustacheTag
? value.toEscapedString()
: value;
};
const escape = (value: any): string => {
return value instanceof StaticMustacheTag
? value.toEscapedString()
: value;
};

return Mustache.render(template, view, undefined, { escape });
} else
return Mustache.render(template, view);
} catch (error) {
console.warn('evaluateString ', error);
return template;
return Mustache.render(template, view, undefined, { escape });
} else
return Mustache.render(template, view);
} catch (error) {
console.warn('evaluateString ', error);
return template;
}
} finally {
// restore moment toString function
moment.prototype.toString = toString;
}
};

Expand Down
2 changes: 1 addition & 1 deletion shesha-reactjs/src/utils/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const tolocalIsoDate = (dateIsoString: string) => {
export const getMoment = (value: any, dateFormat: string): Moment => {
if (value === null || value === undefined) return undefined;

const values = [isMoment(value) ? value : null, moment(value as string, dateFormat), moment(value as string)];
const values = [isMoment(value) ? value : null, moment(value as string), moment(value as string, dateFormat)];

const parsed = values.find((i) => isMoment(i) && i.isValid());

Expand Down

0 comments on commit 0af91ef

Please sign in to comment.