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

Order projects alphabetically rather than by project id in "My Snippets" panel #34

Open
M47hieu opened this issue Jun 2, 2023 · 2 comments

Comments

@M47hieu
Copy link

M47hieu commented Jun 2, 2023

No description provided.

@M47hieu
Copy link
Author

M47hieu commented Jun 2, 2023

Hi @JennieJi

First of all, thank you for this extensions !
I first tried on my own, how to make this "little" enhancement, but I'm not sure how to do this.
That would really help when you have to manage lots of snippets thru differents projects.

Have a good day

Mathieu

@JennieJi
Copy link
Owner

JennieJi commented Jun 2, 2023

Hi @M47hieu, I’m more than happy to hear from you. And sorry that I was lazy to write a developer document for contributing.

To start development:

  1. Clone and run command: yarn
  2. Make changes and run command: yarn compile
  3. Debug with VSCode debugger, simply start from top menu bar “Run” > “Run with debugging”.

This is roughly how the “My Snippets” works now:

  1. First of all, it is a VSCode TreeView. You will need to read through the TreeView Guide to get an idea of it.
  2. The data logic of this my snippets tree is located in views/myView.ts. It is a class extends TreeDataProvider. The class loads hosts when construct.
  3. When you expand a tree item, it will call the getChildren() method for children data list, and getTreeItem() for rendering each item. Hence when a host is expanded, I loaded user snippets list in getChildren(). And if you keep the return shape of getChildren() the same, no further change required.
  4. For some reasons, when I add the listing by repository feature, I chose to keep the logic of loading user snippets (there is no project info in this GitLab API), just group the snippets according to the projectID, and then load the projects info asynchronously.

To sort projects alphabetically, I have 2 ideas. Each of them has pros and cons.

The first idea is instead of loading user snippets then project info, load the user projects list then get project snippets when user expand the repository. The pros of this is that I believe the get projects API allows sorting in different ways, and project list is paginated. The cons of this is we need to figure out how to hide the repository without snippets in a neat way.

The second idea is use the GraphQL API for this part, so you may fetch the user snippets together with their project info. The pros are getting data together and you don’t need to work with my current messy code of fetching data as I am using REST APIs. But the cons are the GraphQL API seems significantly slower than the REST, user snippets list is paginated(a quick workaround is to set a large limit to load as many as possible).

I hope this helps! I am not able to contribute code in the next several days but I would stay connected. Let me know if you have any further questions ;)

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

No branches or pull requests

2 participants