-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Updating array of Dates no longer converts it to array of strings #770
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
Conversation
@@ -201,7 +201,7 @@ export default class BrowserTable extends React.Component { | |||
value = ''; | |||
} else if (type === 'Array') { | |||
if (value) { | |||
value = value.map(val => val instanceof Parse.Object ? val.toPointer() : val); | |||
value = value.map(val => val instanceof Parse.Object ? val.toPointer() : (typeof val.getMonth === 'function' ? { __type: "Date", iso: val.toISOString() } : val)); |
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 would prefer not having nested ternary operators here. What do you think?
And when the user edits the date in the array, is it saved back correctly?
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.
@natanrolnik Yes, it is saved correctly. Even the previous version was able to save provided {"__type":"Date","iso":"2017-09-05T18:06:06.943Z" }
correctly as a valid Date, but it was then again displayed (after refresh) as "2017-09-05T18:06:06.943Z"
. Now it is still displayed as the iso string, but when you open the cell, it adds this {"__type":"Date","iso": .... }
so that it is saved correctly when update is confirmed :-)
How would you recommend to avoid nested ternary operators?
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 would do something like this:
value = value.map(val => {
if (val instanceof Parse.Object) {
return val.toPointer;
} else if (typeof val.getMonth === 'function') {
return { __type: "Date", iso: val.toISOString() };
}
return val;
});
@natanrolnik Ok, I updated the code with the suggested formatting and tested there are no typos, is it OK now, can it be a part of the next parse dashboard release? :-) Thanks. |
Thanks @rihadavid looking great! Releasing a new version soon! |
* Added explicit Date __Type field to Dates in Arrays * Update CHANGELOG.md * Reformatted to avoid nested ternary operators
This PR fixes issue #590 (but does not fix issue #756 )
It might not be the best solution (the problem might be deeper in the system), but it is a
one-line workaround that just does what is needed and prevents dashboard users from creating fatal damage to their Date arrays just by opening the field and losing focus thus saving changes.
BTW: I had troubles running the jest tests on windows, spend a few hours figuring out how to do it but I was not able to. It really drives me crazy. Could someone please try it on windows and update CONTRIBUTING.md with info how to do it? First I was getting
'NODE_PATH' is not recognized as an internal or external command
, then I found out I need to do some changes in package.json:..and maybe also setting windows NODE_PATH environment variable and running
npm install jest
was needed, I don't know what exactly was needed, tried a lot of things. But then I ended up onand I was not able to solve this issue. So the PR is not tested, can someone please do it?