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

[TM-1531] add job connection #745

Open
wants to merge 25 commits into
base: staging
Choose a base branch
from

Conversation

egrojMonroy
Copy link
Collaborator

add the connection to pull the list of jobs

Copy link

vercel bot commented Dec 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
wri-terramatch-website ❌ Failed (Inspect) Dec 20, 2024 8:28pm

@egrojMonroy egrojMonroy requested a review from roguenet December 13, 2024 19:28
Copy link
Collaborator

@roguenet roguenet left a comment

Choose a reason for hiding this comment

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

A quick review pass to hopefully nudge you closer to the right direction.

src/connections/DelayedJob.ts Outdated Show resolved Hide resolved
src/connections/DelayedJob.ts Outdated Show resolved Hide resolved
src/connections/DelayedJob.ts Outdated Show resolved Hide resolved
src/connections/DelayedJob.ts Show resolved Hide resolved
src/generated/apiFetcher.ts Outdated Show resolved Hide resolved
src/connections/DelayedJob.ts Outdated Show resolved Hide resolved
src/connections/DelayedJob.ts Outdated Show resolved Hide resolved
src/connections/DelayedJob.ts Outdated Show resolved Hide resolved
src/connections/DelayedJob.ts Outdated Show resolved Hide resolved
src/connections/DelayedJob.ts Outdated Show resolved Hide resolved
hasLoadFailed: bulkUpdateJobsFetchFailed(store) != null,
response: bulkUpdateState.response
};
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should use ?? for defaults, although I think this is an overall better format for this method:

const bulkUpdateJobsSelector = (store: ApiDataStore) => ({
  isLoading: bulkUpdateJobsIsFetching(store),
  hasLoadFailed: bulkUpdateJobsFetchFailed(store) != null,
  response: store.delayedJobs?.reponse
});

However, I'm also confused as to why you would expect a response object to be on store.delayedJobs. That shouldn't be possible with the current redux setup.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the response object wasnt needed, and everything keeps working.

src/connections/DelayedJob.ts Outdated Show resolved Hide resolved
src/connections/DelayedJob.ts Outdated Show resolved Hide resolved
src/connections/DelayedJob.ts Show resolved Hide resolved
src/store/apiSlice.ts Outdated Show resolved Hide resolved
Base automatically changed from feat/TM-1531-add-job-service to release/utltimate-ulmus December 19, 2024 22:59
@egrojMonroy egrojMonroy marked this pull request as ready for review December 19, 2024 23:19
}
},

isLoaded: state => !state.isLoading,

selector: createSelector([store => bulkUpdateJobsSelector(store)], ({ isLoading, hasLoadFailed, response }) => ({
selector: createSelector(bulkUpdateJobsSelector, ({ isLoading, hasLoadFailed, response }) => ({
isLoading,
hasLoadFailed,
response
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems like it should be throwing an error in the TS compiler... Maybe I'm missing something, but this shape does not seem to match DelayedJobsConnection.

A couple of thoughts here:

  • Typically, each connection will have its own shape. That's not required, but it's normal
  • I've found in the past that properties like isLoading, hasLoadFailed and response, while seeming convenient when looking at a single connection, are actually a disaster down the road. The reason being that if we follow such generic conventions for individual connections, then when a component ends up using 2 or more connections, it gets really awkward to juggle all the isLoadings that each connection returns. Instead, I think it's better to be super specific with the properties of the connection shape. So something more like bulkUpdateJobsIsLoading and bulkUpdateJobsHasFailed.

As for response - this appears to be just returning all the delayed jobs like the other connection does. Are these used in the same component? Perhaps a better approach would be to combine them into a single connection. I think of connections as being responsible for providing a given set of data from the redux cache, and a set of functions for operating on that data. It would be totally reasonable for this bulkUpdateJobs call to be triggered from a function that's included on the other connection. Or, the bulkUpdate function could be simply exposed by this file, and then we simply rely on the original connection to provide the delayedJobs from the store. One of the primary wins of this system is that a connection returns data that got cached in the store regardless of where it came from. So if one call does the initial fetch, and another call modifies that data, as long as the data ends up back in the store under the same ID, the component that relies on it will rerender when it gets updated.

Base automatically changed from release/utltimate-ulmus to main December 20, 2024 21:27
@roguenet roguenet changed the base branch from main to staging December 20, 2024 22:22
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.

2 participants