-
-
Notifications
You must be signed in to change notification settings - Fork 411
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
add fallback behavior for showOpenFilePicker
and showSaveFilePicker
#967
Conversation
showOpenFilePicker
and showSaveFilePicker
LGTM! |
className="maputnik-big-button" | ||
onClick={this.onOpenFile}><MdFileUpload/> {t("Open Style")} | ||
</InputButton> | ||
{typeof window.showOpenFilePicker === "function" ? ( |
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.
Can we use if-else here? I think it will be clearer...
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.
Is this the syntax you want to go with?
<div>
{(() => {
if (typeof window.showOpenFilePicker === "function") {
return (
<InputButton
className="maputnik-big-button"
onClick={this.onOpenFile}><MdFileUpload/> {t("Open Style")}
</InputButton>
)
} else {
return (
<FileReaderInput onChange={this.onFileChanged} tabIndex={-1} aria-label={t("Open Style")}>
<InputButton className="maputnik-upload-button"><MdFileUpload /> {t("Open Style")}</InputButton>
</FileReaderInput>
)
}
})()}
</div>
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.
Is the lambda mandatory? I recall that react has a simpler way to add if inside the render method...?
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.
Not sure how? I can't find anything about it in the react docs nor stackoverflow. Using a tenary operator appears to be the shortest way. Alternatively, we could move the html block before the return statement and use it from a variable.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #967 +/- ##
==========================================
- Coverage 59.84% 58.94% -0.91%
==========================================
Files 104 104
Lines 3011 3057 +46
Branches 680 687 +7
==========================================
Hits 1802 1802
- Misses 1209 1255 +46 ☔ View full report in Codecov by Sentry. |
Launch Checklist
CHANGELOG.md
under the## main
section.Description
showOpenFilePicker
andshowSaveFilePicker
are undefined on Firefox. With this pr, Maputnik uses the old behavior as a fallback. It keeps the naming "open" and "save" instead of "upload" and "download" to underline that the style stays within the browser and no actual upload happens.@zstadler Could you give it a try, please?
Related Issue
Visual Changes
The "Save as" button gets hidden if
showSaveFilePicker
is not available since it would have no use.