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
3bd366f0
Commit
3bd366f0
authored
Nov 14, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
Nov 14, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add annotations export format select
parent
82830801
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
14 deletions
+83
-14
ExportAnnotations.tsx
src/sidebar/components/ShareDialog/ExportAnnotations.tsx
+61
-11
ExportAnnotations-test.js
...bar/components/ShareDialog/test/ExportAnnotations-test.js
+22
-3
No files found.
src/sidebar/components/ShareDialog/ExportAnnotations.tsx
View file @
3bd366f0
...
...
@@ -26,6 +26,30 @@ export type ExportAnnotationsProps = {
toastMessenger
:
ToastMessengerService
;
};
type
ExportFormat
=
{
value
:
'json'
|
'csv'
|
'text'
|
'html'
;
name
:
string
;
};
const
exportFormats
:
ExportFormat
[]
=
[
{
value
:
'json'
,
name
:
'JSON'
,
},
{
value
:
'csv'
,
name
:
'CSV'
,
},
{
value
:
'text'
,
name
:
'Text'
,
},
{
value
:
'html'
,
name
:
'HTML'
,
},
];
/**
* Render content for "export" tab panel: allow user to export annotations
* with a specified filename.
...
...
@@ -68,6 +92,9 @@ function ExportAnnotations({
allAnnotationsOption
,
);
const
exportFormatsEnabled
=
store
.
isFeatureEnabled
(
'export_formats'
);
const
[
exportFormat
,
setExportFormat
]
=
useState
(
exportFormats
[
0
]);
const
fileInputId
=
useId
();
const
userSelectId
=
useId
();
...
...
@@ -133,17 +160,39 @@ function ExportAnnotations({
>
Name of export file:
</label>
<Input
data-testid="export-filename"
id={fileInputId}
defaultValue={defaultFilename}
value={customFilename}
onChange={e =>
setCustomFilename((e.target as HTMLInputElement).value)
}
required
maxLength={250}
/>
<div className="flex">
<Input
classes="grow"
data-testid="export-filename"
id={fileInputId}
defaultValue={defaultFilename}
value={customFilename}
onChange={e =>
setCustomFilename((e.target as HTMLInputElement).value)
}
required
maxLength={250}
/>
{exportFormatsEnabled && (
<div className="grow-0 ml-2 min-w-[5rem]">
<SelectNext
value={exportFormat}
onChange={setExportFormat}
buttonContent={exportFormat.name}
data-testid="export-format-select"
>
{exportFormats.map(exportFormat => (
<SelectNext.Option
key={exportFormat.value}
value={exportFormat}
>
{exportFormat.name}
</SelectNext.Option>
))}
</SelectNext>
</div>
)}
</div>
<label htmlFor={userSelectId} className="block font-medium">
Select which user{"'"}s annotations to export:
</label>
...
...
@@ -154,6 +203,7 @@ function ExportAnnotations({
buttonContent={
<UserAnnotationsListItem userAnnotations={selectedUser} />
}
data-testid="user-select"
>
<SelectNext.Option value={allAnnotationsOption}>
<UserAnnotationsListItem userAnnotations={allAnnotationsOption} />
...
...
src/sidebar/components/ShareDialog/test/ExportAnnotations-test.js
View file @
3bd366f0
...
...
@@ -81,6 +81,9 @@ describe('ExportAnnotations', () => {
$imports
.
$restore
();
});
const
waitForTestId
=
async
(
wrapper
,
testId
)
=>
waitForElement
(
wrapper
,
`[data-testid="
${
testId
}
"]`
);
context
(
'export annotations not ready (loading)'
,
()
=>
{
it
(
'renders a loading spinner if there is no focused group'
,
()
=>
{
fakeStore
.
focusedGroup
.
returns
(
null
);
...
...
@@ -181,7 +184,7 @@ describe('ExportAnnotations', () => {
const
wrapper
=
createComponent
();
const
userList
=
await
waitFor
Element
(
wrapper
,
SelectNext
);
const
userList
=
await
waitFor
TestId
(
wrapper
,
'user-select'
);
const
users
=
userList
.
find
(
SelectNext
.
Option
);
assert
.
equal
(
users
.
length
,
userEntries
.
length
);
...
...
@@ -207,6 +210,22 @@ describe('ExportAnnotations', () => {
assert
.
equal
(
input
.
prop
(
'defaultValue'
),
'suggested-filename'
);
});
[
{
exportFormatsEnabled
:
true
,
expectedAmountOfSelects
:
2
},
{
exportFormatsEnabled
:
false
,
expectedAmountOfSelects
:
1
},
].
forEach
(({
exportFormatsEnabled
,
expectedAmountOfSelects
})
=>
{
it
(
'displays format selector when feature is enabled'
,
async
()
=>
{
fakeStore
.
isFeatureEnabled
.
callsFake
(
ff
=>
exportFormatsEnabled
||
ff
!==
'export_formats'
,
);
const
wrapper
=
createComponent
();
const
selects
=
await
waitForElement
(
wrapper
,
SelectNext
);
assert
.
equal
(
selects
.
length
,
expectedAmountOfSelects
);
});
});
describe
(
'export form submitted'
,
()
=>
{
const
submitExportForm
=
wrapper
=>
wrapper
.
find
(
'[data-testid="export-form"]'
).
simulate
(
'submit'
);
...
...
@@ -265,7 +284,7 @@ describe('ExportAnnotations', () => {
const
wrapper
=
createComponent
();
// Select the user whose annotations we want to export
const
userList
=
await
waitFor
Element
(
wrapper
,
SelectNext
);
const
userList
=
await
waitFor
TestId
(
wrapper
,
'user-select'
);
const
option
=
userList
.
find
(
SelectNext
.
Option
)
.
filterWhere
(
...
...
@@ -376,7 +395,7 @@ describe('ExportAnnotations', () => {
it
(
'should pass a11y checks'
,
async
()
=>
{
const
wrapper
=
createComponent
();
const
select
=
await
waitFor
Element
(
wrapper
,
SelectNext
);
const
select
=
await
waitFor
TestId
(
wrapper
,
'user-select'
);
await
checkAccessibility
({
content
:
()
=>
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