-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Refactor client API packages #16847
Refactor client API packages #16847
Conversation
cd17116
to
c11907a
Compare
I definitely agree a best practice and greater consistency in the code around these packages would be good. Thank you for working on this.
I would argue that building reusable components in part means targeting specific, clean parts of the API that can likewise be decomposed. Centralizing the modules feels like a step backwards in terms of isolation which I think is a key aspect of reusabilty. A component that targets our license API or the TRS APIs would be great and could be used outside the context of Galaxy readily I would think given that these APIs are isolated well and highly structured. Shipping the component together with its API interaction layer would seem to be the right way to handle that - but maybe there are frontend idiosyncrasies that make it substantially different than the backend. I'm not opposed to these changes at all - this comment doesn't need a response and shouldn't block the PR anyway. Just wanted to say my peace on isolation and convey my lessons learned on working on the backend components with a similar eye toward reusability. |
@jmchilton I appreciate the comment! That is a good point, I sometimes struggle with how to organize big code bases, I really want to come up with a solution that can be considered best practice and feels consistent across the entire project and I'm totally willing to adapt to alternatives. My line of thought was... I would like to query the API for some particular object in a component, what do I do?
The whole idea of this was to actually come up with something that we are all happy with and we can all agree on, so I'm glad you commented and I'm more than happy to rewrite it :) |
c56ce84
to
cbf20e9
Compare
I understood
to be just that ? The schema portion is pure interfaces, my understanding is that once you push bundles (which are JS so don't contain the interfaces) those would be gone. And when you publish individual components those get pulled apart as well (so you don't get the things you're not using). |
That is also a good point @mvdbeek, I'm no expert on that, but when the final bundle is done is supposed to have only what you actually imported as you mentioned, that is why we try to import individual functions instead of whole modules (I learned the lesson by doing the importing wrongly often but was catch in reviews 😆) |
I should qualify this is my belief on how things should magically work (TM) with no foundation in the real world. |
cbf20e9
to
fded7e1
Compare
Talking about magic... let's ask chatGPT for fun... 😆 Question:
Response:When working on a large Vue project using TypeScript and Webpack and you need to create a new component that requires calling API endpoints, there are a few different approaches you can take, and the best practice may depend on the specific needs and structure of your project. Here are two common approaches: Separate Modules for API Calls (Recommended):Create a dedicated directory, such as api, at the top level of your project structure. /src
/components
/YourComponent
YourComponent.vue
/api
userApi.ts
productApi.ts
orderApi.ts Inline API Calls in Component:Alternatively, you can create API calls directly within the component that needs them. In this case, you can define functions or methods within the component that handle API requests. /src
/components
/YourComponent
YourComponent.vue In general, the first approach of separating API calls into dedicated modules is recommended for large projects. It promotes code organization, reusability, and maintainability. It also makes it easier to manage authentication, error handling, and other common concerns related to API interactions. However, there may be situations where you need to make one-off API calls in a component, and it's acceptable to define them directly within the component. The key is to strike a balance between organization and efficiency based on the specific needs of your project and components. |
a856ae9
to
cebebca
Compare
- Make modal confirmation on tests optional - Fix some stubbing warnings
cebebca
to
9913b71
Compare
I've included a draft for a best practices guide in I'm happy to drop or rewrite as many changes as needed until we get something we want to maintain. |
Look like test failures are unrelated. Taking it out of draft for the first wave of reviews :) |
Thank you! |
Closes #16841
src/schema
package intosrc/api/schema
src/api/{module}
for easier discoverability and reusability.api/storage
: lives underclient/src/components/User/DiskUsage/Management/services.ts
fetch
to explicitly convey that it will trigger a server request as opposed to simplyget
that may or may not trigger a request (for example when getting the cached values from a store). Examples:GET api/whatever
we can name the fetcher aswhateverFetcher
:fetchWhatever
:client/docs/querying-the-api.md
How to test the changes?
License