Skip to content

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

Merged
merged 3 commits into from
Oct 26, 2017

Conversation

rihadavid
Copy link
Contributor

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.

datearray

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:

"build": "SET NODE_ENV=production && webpack --config webpack/production.config.js && webpack --config webpack/PIG.config.js",
    "test": "SET NODE_PATH=./node_modules && jest",

..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 on

Using Jest CLI v12.1.1, jasmine2
No tests found for "".

and I was not able to solve this issue. So the PR is not tested, can someone please do it?

@@ -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));
Copy link
Contributor

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?

Copy link
Contributor Author

@rihadavid rihadavid Sep 7, 2017

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?

Copy link
Contributor

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;
});

@rihadavid
Copy link
Contributor Author

@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.

@flovilmart flovilmart merged commit 161a06a into parse-community:master Oct 26, 2017
@flovilmart
Copy link
Contributor

Thanks @rihadavid looking great! Releasing a new version soon!

flovilmart pushed a commit that referenced this pull request Oct 27, 2017
* Added explicit Date __Type field to Dates in Arrays

* Update CHANGELOG.md

* Reformatted to avoid nested ternary operators
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants