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/normalizing state #882

Merged
merged 39 commits into from
Nov 3, 2023
Merged

Feat/normalizing state #882

merged 39 commits into from
Nov 3, 2023

Conversation

Guilherme-NL
Copy link
Contributor

@Guilherme-NL Guilherme-NL commented Oct 17, 2023

Normalized state

In this PR, we normalized the stories and pastIteration in the Redux state.

Stories

The data was in the format below:

    {
        "id": 4,
        "title": "A user should be able to estimate features",
        "description": null,
        "estimate": 3,
        "storyType": "feature",
        "state": "started",
        "acceptedAt": null,
        "requestedById": 1,
        "ownedById": 1,
        "projectId": 1,
        "createdAt": "2023/10/02 16:54:44 -0300",
        "updatedAt": "2023/10/11 10:32:07 -0300",
        "position": "5.5",
        "labels": [
            {
                "id": 0,
                "name": "estimates"
            },
            {
                "id": 1,
                "name": "features"
            }
        ],
        "requestedByName": "Foo Bar",
        "ownedByName": "Foo Bar",
        "ownedByInitials": "FB",
        "releaseDate": null,
        "deliveredAt": "2023/10/04 16:49:42 -0300",
        "newPosition": null,
        "errors": {},
        "notes": [],
        "tasks": [],
        "collapsed": true
    }

Considering this, for now, we implemented a simpler normalization:

{
    stories: {
    byId: {
      1: {id: 1, ...},
      2: {id: 2, ...}
      },
    allIds: [1, 2]
    }
}

PastIterations

The data was in the format below:

    {
      startDate: '2023/08/02',
      endDate: '2023/08/06',
      iterationNumber: 1,
      stories: [],
      points: 0,
      hasStories: false
    }

Normalized data example:

{
    pastIterations: {
        byId: {
        1: {iterationNumber: 1, ...},
        2: {iterationNumber: 2, ...}
        },
        allIds: [1, 2]
    }
}

normalize and denormalize

I created functions to handle normalization and denormalization. I believe this was the biggest challenge of this task. After calling normalization and denormalization in the correct places, it is easy to make changes to the structure of the normalized object, since the function is isolated and no longer interferes with the functioning of the application

To ensure that everything was working as before, I applied normalization only in the reducer. And I denormalized for functions that used the state as input.

Addition multiple new stories:

We changed the default id of new stories to a Symbol (new-${Date.now()}, this way we can uniquely identify each new story, and add multiple new stories at the same time.

app/assets/javascripts/models/beta/story.js Outdated Show resolved Hide resolved
app/assets/javascripts/models/beta/story.js Outdated Show resolved Hide resolved
app/assets/javascripts/models/beta/story.js Outdated Show resolved Hide resolved
spec/javascripts/selectors/columns_spec.js Outdated Show resolved Hide resolved
app/assets/javascripts/models/beta/story.js Outdated Show resolved Hide resolved
@Guilherme-NL Guilherme-NL marked this pull request as ready for review October 23, 2023 13:28
@Guilherme-NL Guilherme-NL force-pushed the feat/normalizing-state branch from d118957 to a28e5fc Compare October 25, 2023 16:06
Copy link
Member

@talyssonoc talyssonoc left a comment

Choose a reason for hiding this comment

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

I added some comments about using selectors

@Guilherme-NL Guilherme-NL force-pushed the feat/normalizing-state branch from 49f21c1 to cf02560 Compare November 1, 2023 17:53
@talyssonoc talyssonoc merged commit dc9af32 into master Nov 3, 2023
3 checks passed
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.

4 participants