Skip to content
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

Feat/scout 28 competition groups #33

Merged
merged 9 commits into from
Sep 5, 2022
Merged

Conversation

dejwi
Copy link
Collaborator

@dejwi dejwi commented Aug 26, 2022

SCOUT-28

Task Description

competition groups module

  • modules / pages (ADMIN)

Additional Notes (optional)

removed updatedDiff from edit form as it converted array into object and broke updating

Copy link
Collaborator

@jakubfiglak jakubfiglak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try and debug this issue with updatedDiff? Perhaps there's a way to make it work properly. I'd rather be consistent and use this on every edit form, in fact, we should probably extract this to a helper function.

@@ -0,0 +1,88 @@
import { TextField } from '@mui/material'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a typo in file path -> froms instead of forms

@dejwi
Copy link
Collaborator Author

dejwi commented Aug 29, 2022

I was unable to find solution that satisfied me within deep-object-diff repo and other packages, maybe I wasn't looking hard enough but nonetheless problem is solved. I copied source file from deep-object-diff and made it to keep any array that it finds, also included filtering so it's all in one helper

@dejwi dejwi requested a review from jakubfiglak August 29, 2022 11:40
@jakubfiglak
Copy link
Collaborator

I was unable to find solution that satisfied me within deep-object-diff repo and other packages, maybe I wasn't looking hard enough but nonetheless problem is solved. I copied source file from deep-object-diff and made it to keep any array that it finds, also included filtering so it's all in one helper

I don't have time to dive deep into this right now but I'm not a huge fan of copying and tweaking code from external libraries. Especially that it looks like there's a good reason why it works like this. Have you seen

mattphillips/deep-object-diff#79
mattphillips/deep-object-diff#23
mattphillips/deep-object-diff#14 ?

You caught a significant issue in our app, good work! We need to rethink what we actually want here if the field of our edit form is an array, I think we can simplify this to 2 cases:

  • if array hasn't been touched (no items added, no items removed) - we don't want to send this field to the backend
  • if array has been touched (item added, item removed or both) - we want to send ENTIRE new array to the backend

Is this something we can do using functions provided by the deep-object-diff lib?

BTW, another issue is that we probably should use diff function instead of updatedDiff, WDYT?

@dejwi
Copy link
Collaborator Author

dejwi commented Aug 29, 2022

We can't do that using deep-object-diff as it only returns specific changes in array in form of a object. Their issues are mostly suggestions and as we surely can do work-arounds through multiple loops I think it's the best to fix problem at its core when this function is pretty short. If we want to keep it as library a fork is always a option.

I've made changes and now array isn't returned not touched (order doesn't matter)

@dejwi
Copy link
Collaborator Author

dejwi commented Aug 29, 2022

Here's a last message in one of the linked issues. Suggestion of function that we desire as well but it's not implemented

+1

Would be useful to have a diff that works like this regarding to arrays:

  1. If both arrays are equal, there is no diff
  2. If updatedObj is different, just keep updatedObj as a result in the diff (so we kind of treat arrays as scalar values)

An example:

const lhs = {
    bar: {
        a1: ['a', 'b'],
        a2: ['j', 'i'],
        a3: ['x', 'y'],

    },
};
 
const rhs = {
    bar: {
        a1: ['a', 'b'],
        a2: ['j'], // <-- 'i' is removed
        a3: ['x', 'y', 'z'], // 'z' is added
    },
    foo: 'bar', // <-- added new prop
};
 
console.log(diff(lhs, rhs)); // =>
/*
{
    bar: {
        a2: ['j'],
        a3: ['x', 'y', 'z']
    },
    foo: 'bar',
};
*/

@jakubfiglak
Copy link
Collaborator

I think we can do what we need using this library, I'd just need to sit down and write some code for it to show you what I have in mind. It's not worth our time right now, I'll create separate ticket for this. For now, please remove this copied functionality and go back to the state where we don't use deep-object-diff at all. Then I'll approve this PR. Sorry for all the confusion

Copy link
Collaborator

@jakubfiglak jakubfiglak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see my latest comment

@dejwi
Copy link
Collaborator Author

dejwi commented Sep 5, 2022

There's a issue when regionIds array is passed to endpoind as empty ( [] ) it doesnt update regionIds, I'll create a ticket

@dejwi dejwi merged commit 9d7fcab into develop Sep 5, 2022
@dejwi dejwi deleted the feat/SCOUT-28-competition-groups branch September 5, 2022 16:07
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.

None yet

2 participants