Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
bfa8df67
Commit
bfa8df67
authored
Aug 17, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
Aug 22, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure user input is not overridden by export suggested filename
parent
82ed0375
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
9 deletions
+17
-9
ExportAnnotations.tsx
src/sidebar/components/ShareDialog/ExportAnnotations.tsx
+12
-7
ExportAnnotations-test.js
...bar/components/ShareDialog/test/ExportAnnotations-test.js
+5
-2
No files found.
src/sidebar/components/ShareDialog/ExportAnnotations.tsx
View file @
bfa8df67
import
{
Button
,
CardActions
,
Input
}
from
'@hypothesis/frontend-shared'
;
import
{
use
Ref
}
from
'preact/hooks'
;
import
{
use
Memo
,
useState
}
from
'preact/hooks'
;
import
{
downloadJSONFile
}
from
'../../../shared/download-json-file'
;
import
{
withServices
}
from
'../../service-context'
;
...
...
@@ -15,8 +15,6 @@ export type ExportAnnotationsProps = {
toastMessenger
:
ToastMessengerService
;
};
// TODO: does the Input need a label?
/**
* Render content for "export" tab panel: allow user to export annotations
* with a specified filename.
...
...
@@ -32,7 +30,11 @@ function ExportAnnotations({
const
exportCount
=
exportableAnnotations
.
length
;
const
draftCount
=
store
.
countDrafts
();
const
inputRef
=
useRef
<
HTMLInputElement
|
null
>
(
null
);
const
defaultFilename
=
useMemo
(
()
=>
suggestedFilename
({
groupName
:
group
?.
name
}),
[
group
],
);
const
[
customFilename
,
setCustomFilename
]
=
useState
<
string
>
();
if
(
!
exportReady
)
{
return
<
LoadingSpinner
/>;
...
...
@@ -42,7 +44,7 @@ function ExportAnnotations({
e
.
preventDefault
();
try
{
const
filename
=
`
${
inputRef
.
current
!
.
valu
e
}
.json`
;
const
filename
=
`
${
customFilename
??
defaultFilenam
e
}.
json
`;
const exportData = annotationsExporter.buildExportContent(
exportableAnnotations,
);
...
...
@@ -75,8 +77,11 @@ function ExportAnnotations({
<Input
data-testid="export-filename"
id="export-filename"
defaultValue=
{
suggestedFilename
({
groupName
:
group
?.
name
})
}
elementRef=
{
inputRef
}
defaultValue={defaultFilename}
value={customFilename}
onChange={e =>
setCustomFilename((e.target as HTMLInputElement).value)
}
required
maxLength={250}
/>
...
...
src/sidebar/components/ShareDialog/test/ExportAnnotations-test.js
View file @
bfa8df67
...
...
@@ -135,9 +135,12 @@ describe('ExportAnnotations', () => {
it
(
'downloads a file using user-entered filename appended with `.json`'
,
()
=>
{
const
wrapper
=
createComponent
();
const
filenameInput
=
wrapper
.
find
(
'input[data-testid="export-filename"]'
,
);
wrapper
.
find
(
'input[data-testid="export-filename"]'
).
getDOMNode
().
value
=
'my-filename'
;
filenameInput
.
getDOMNode
().
value
=
'my-filename'
;
filenameInput
.
simulate
(
'change'
)
;
submitExportForm
(
wrapper
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment