-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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(web): upload json config #8953
Conversation
From what I see here, you are just reading the JSON file and have not uploaded the configuration to the server yet, correct? |
Correct, currently it only automates setting the values on the web UI from the JSON file. |
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.
To me the code actually looks good, not sure why you were worried :D. I'd prefer if it'll automatically make a request to the server and update the config though.
Thanks!
I agree. I can either copy the code from |
FWIW I don't think there's much you need to do. You should be able to just call the API function and wrap it in a try catch, there isn't much else to it since what you get is already in JSON. So I'd be fine with just having that API call here as well |
It seemed to me like |
that probably won't work. the config file might be a partial but the update method requires the entire thing |
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.
When you need to use bind that usually shows bad data modelling, which is on us. I think for this PR it's fine, everything else would be out of scope.
Thank you! :)
I believe that's what this code in
|
that's not a nested deep merge, that only overrides entire config sections |
I'm fine if we just want to post the whole config for now though. At least export full config and import full config would work correctly. It is quite a bit more complicated to do anything else at the moment. |
Ah yes, that's a good point. Handling that requires changing that code in the |
Right, I'm not familiar with Svelte best practices but it did seem like this functionality would be better outside of the child component. On the other hand a bind for the config variable is also how the copy to clipboard and the download JSON are implemented and I wasn't going for large changes. |
fileSelector.type = 'file'; | ||
fileSelector.accept = '.json'; | ||
fileSelector.addEventListener('change', (e) => { | ||
const file = (e.target as HTMLInputElement).files?.[0]; | ||
if (!file) { | ||
return; | ||
} |
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 think this should just be a normal input element in the html stuff below. It can be hidden if you want though. But button click just needs to trigger clicking the input. It doesn't need to be dynamically created. You can use something like this:
let inputElement: HTMLInputElement;
const handleUpload = () => inputElement?.click();
..
<input bind:this={inputElement} ... />
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 based myself on this but I'm happy to make that change if you wish.
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.
Ah but that is a pure TypeScript file without HTML, right? Unlike this page. Sorry, learning as I go!
Is there anything else you'd like me to change on this PR? |
No, I will do some functional testing and will get it merged |
Adds "Import from JSON" button as discussed here.
My background is in embedded software, not web programming, so a review is very appreciated.
An open question is how to handle saving of the configuration. Currently the data imported from the JSON file is just put on the UI, but not saved. I believe this is counterintuitive and we should directly save after importing. In that case, it seems what we should do is call
handleSave
inadmin-settings.svelte
, but at that point my lack of knowledge about how Svelte works shows up and I'd appreciate some guidance.