-
-
Notifications
You must be signed in to change notification settings - Fork 551
[UX] Export/Import categories data #5145
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
base: main
Are you sure you want to change the base?
Conversation
flavioislima
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
CommandMC
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think having the buttons in the modal itself makes sense, since they offer functionality you don't need often. Tucking them somewhere into the settings, or at least making the buttons less prominent, would be ideal
maybe I can hide the 2 buttons inside a what I like about the buttons in the modal is that it makes it really easy to discover them, it's right next to where categories are managed I think collapsing them and show them only on demand can help clean it up and keep them easily discoverable, I'll update the PR |
CommandMC
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for another nitpick, testing things now:
- One button says "Export to file", the other "Import file". To keep them consistent, I'd either change the one to "Export file", or the other to "Import from file"
- Maybe add icons to the buttons?
| const jsonContent = JSON.parse(content) as Record<string, string[]> | ||
|
|
||
| for (const key in jsonContent) { | ||
| // some checks to ensure we don't break the categories if the | ||
| // json file is not the correct format | ||
| // only allow string keys | ||
| if (typeof key !== 'string') continue | ||
|
|
||
| // only allow an array of strings | ||
| if (!Array.isArray(jsonContent[key])) continue | ||
| const gameIds = jsonContent[key].filter((val) => typeof val === 'string') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like an obvious use case for Zod
// Somewhere at the start of the file
const ImportSchema = z.record(z.string(), z.string().array())
// Inside the function
const jsonContent = JSON.parse(content)
const validatedContent = ImportSchema.parse(jsonContent)
// validatedContent is now of type Record<string, string[]>If we truly want to accept partially-malformed category exports, we could still handle that in Zod with some transforms. IMO we should just not do that though, I don't think that's a common use case
| export const exportCategories = makeHandlerInvoker('exportCategories') | ||
| export const importCategories = makeHandlerInvoker('importCategories') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you seem to be looking to create more exporters/importers, you may want to create a "category" for those IPC functions. It makes them easier to find & lessens the load on the language server (well, it would if we had more of them)
A "category" is just an object with properties, like this example:
HeroicGamesLauncher/src/preload/api/settings.ts
Lines 20 to 23 in 23de3f9
| export const systemInfo = { | |
| get: makeHandlerInvoker('getSystemInfo'), | |
| copyToClipboard: makeListenerCaller('copySystemInfoToClipboard') | |
| } |
(whether you sort them export.categories or categories.export is up to you)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, the idea is that we could have more importers/exporters for other things in the future, like the app settings for example that users currently have to copy around internal files


This PR adds the actions to export the categories to a JSON file and also the option to import a JSON file with categories information.
For now it exports the categories inside the
Games/Heroicfolder, so we can be sure Heroic flatpak will have write access to it.The buttons are at the bottom of the Manage Categories modal:
Closes #3416
Use the following Checklist if you have changed something on the Backend or Frontend: