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
2a7a3607
Commit
2a7a3607
authored
Feb 12, 2024
by
Alejandro Celaya
Committed by
Alejandro Celaya
Feb 12, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace local confirm helper with the one in frontend-shared
parent
1e58310e
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
11 additions
and
142 deletions
+11
-142
prompts.tsx
src/shared/prompts.tsx
+0
-77
prompts-test.js
src/shared/test/prompts-test.js
+0
-58
AnnotationActionBar.tsx
src/sidebar/components/Annotation/AnnotationActionBar.tsx
+1
-1
AnnotationActionBar-test.js
...ar/components/Annotation/test/AnnotationActionBar-test.js
+1
-1
GroupListItem.tsx
src/sidebar/components/GroupList/GroupListItem.tsx
+6
-2
GroupListItem-test.js
src/sidebar/components/GroupList/test/GroupListItem-test.js
+1
-1
HypothesisApp.tsx
src/sidebar/components/HypothesisApp.tsx
+1
-1
HypothesisApp-test.js
src/sidebar/components/test/HypothesisApp-test.js
+1
-1
No files found.
src/shared/prompts.tsx
deleted
100644 → 0
View file @
1e58310e
import
{
Button
,
ModalDialog
}
from
'@hypothesis/frontend-shared'
;
import
{
render
}
from
'preact'
;
import
{
createRef
}
from
'preact'
;
import
type
{
RefObject
}
from
'preact'
;
import
type
{
ComponentChildren
}
from
'preact'
;
export
type
ConfirmModalProps
=
{
title
?:
string
;
message
:
ComponentChildren
;
confirmAction
?:
string
;
};
/**
* Show the user a prompt asking them to confirm an action.
*
* This is like an async version of `window.confirm` except that:
*
* - It can be used inside iframes (browsers are starting to prevent this for
* the native `window.confirm` dialog)
* - The visual style of the dialog matches the Hypothesis design system
*
* @return - Promise that resolves with `true` if the user confirmed the action
* or `false` if they canceled it.
*/
export
async
function
confirm
({
title
=
'Confirm'
,
message
,
confirmAction
=
'Yes'
,
}:
ConfirmModalProps
):
Promise
<
boolean
>
{
const
cancelButton
=
createRef
<
HTMLElement
|
undefined
>
();
const
container
=
document
.
createElement
(
'div'
);
container
.
setAttribute
(
'data-testid'
,
'confirm-container'
);
// Ensure dialog appears above any existing content. The Z-index value here
// is Good Enough™ for current usage.
container
.
style
.
position
=
'relative'
;
container
.
style
.
zIndex
=
'10'
;
document
.
body
.
appendChild
(
container
);
return
new
Promise
(
resolve
=>
{
const
close
=
(
result
:
boolean
)
=>
{
render
(
null
,
container
);
container
.
remove
();
resolve
(
result
);
};
render
(
<
ModalDialog
buttons=
{
<>
<
Button
elementRef=
{
cancelButton
}
data
-
testid=
"cancel-button"
onClick=
{
()
=>
close
(
false
)
}
>
Cancel
</
Button
>
<
Button
data
-
testid=
"confirm-button"
variant=
"primary"
onClick=
{
()
=>
close
(
true
)
}
>
{
confirmAction
}
</
Button
>
</>
}
initialFocus=
{
cancelButton
as
RefObject
<
HTMLElement
>
}
title=
{
title
}
onClose=
{
()
=>
close
(
false
)
}
>
{
message
}
</
ModalDialog
>,
container
,
);
});
}
src/shared/test/prompts-test.js
deleted
100644 → 0
View file @
1e58310e
import
{
confirm
}
from
'../prompts'
;
describe
(
'shared/prompts'
,
()
=>
{
describe
(
'confirm'
,
()
=>
{
function
clickClose
()
{
const
closeButton
=
getCustomDialog
().
querySelector
(
'[aria-label="Close"]'
,
);
closeButton
.
click
();
}
function
clickCancel
()
{
const
cancelButton
=
getCustomDialog
().
querySelector
(
'[data-testid="cancel-button"]'
,
);
cancelButton
.
click
();
}
function
clickConfirm
()
{
const
confirmButton
=
getCustomDialog
().
querySelector
(
'[data-testid="confirm-button"]'
,
);
confirmButton
.
click
();
}
function
getCustomDialog
()
{
return
document
.
querySelector
(
'[data-testid="confirm-container"]'
);
}
it
(
'renders a custom dialog'
,
async
()
=>
{
const
result
=
confirm
({
title
:
'Confirm action?'
,
message
:
'Do the thing?'
,
confirmAction
:
'Yeah!'
,
});
const
dialog
=
getCustomDialog
();
assert
.
ok
(
dialog
);
clickClose
();
assert
.
notOk
(
getCustomDialog
());
assert
.
isFalse
(
await
result
);
});
it
(
'returns true if "Confirm" button is clicked'
,
async
()
=>
{
const
result
=
confirm
({
message
:
'Do the thing?'
});
clickConfirm
();
assert
.
isTrue
(
await
result
);
});
it
(
'returns false if "Cancel" button is clicked'
,
async
()
=>
{
const
result
=
confirm
({
message
:
'Do the thing?'
});
clickCancel
();
assert
.
isFalse
(
await
result
);
});
});
});
src/sidebar/components/Annotation/AnnotationActionBar.tsx
View file @
2a7a3607
import
{
import
{
confirm
,
IconButton
,
IconButton
,
EditIcon
,
EditIcon
,
FlagIcon
,
FlagIcon
,
...
@@ -7,7 +8,6 @@ import {
...
@@ -7,7 +8,6 @@ import {
TrashIcon
,
TrashIcon
,
}
from
'@hypothesis/frontend-shared'
;
}
from
'@hypothesis/frontend-shared'
;
import
{
confirm
}
from
'../../../shared/prompts'
;
import
type
{
SavedAnnotation
}
from
'../../../types/api'
;
import
type
{
SavedAnnotation
}
from
'../../../types/api'
;
import
type
{
SidebarSettings
}
from
'../../../types/config'
;
import
type
{
SidebarSettings
}
from
'../../../types/config'
;
import
{
serviceConfig
}
from
'../../config/service-config'
;
import
{
serviceConfig
}
from
'../../config/service-config'
;
...
...
src/sidebar/components/Annotation/test/AnnotationActionBar-test.js
View file @
2a7a3607
...
@@ -92,13 +92,13 @@ describe('AnnotationActionBar', () => {
...
@@ -92,13 +92,13 @@ describe('AnnotationActionBar', () => {
$imports
.
$mock
(
mockImportedComponents
());
$imports
.
$mock
(
mockImportedComponents
());
$imports
.
$mock
({
$imports
.
$mock
({
'@hypothesis/frontend-shared'
:
{
confirm
:
fakeConfirm
},
'../../helpers/annotation-sharing'
:
{
'../../helpers/annotation-sharing'
:
{
sharingEnabled
:
fakeSharingEnabled
,
sharingEnabled
:
fakeSharingEnabled
,
annotationSharingLink
:
fakeAnnotationSharingLink
,
annotationSharingLink
:
fakeAnnotationSharingLink
,
},
},
'../../helpers/permissions'
:
{
permits
:
fakePermits
},
'../../helpers/permissions'
:
{
permits
:
fakePermits
},
'../../store'
:
{
useSidebarStore
:
()
=>
fakeStore
},
'../../store'
:
{
useSidebarStore
:
()
=>
fakeStore
},
'../../../shared/prompts'
:
{
confirm
:
fakeConfirm
},
});
});
});
});
...
...
src/sidebar/components/GroupList/GroupListItem.tsx
View file @
2a7a3607
import
{
CopyIcon
,
ExternalIcon
,
LeaveIcon
}
from
'@hypothesis/frontend-shared'
;
import
{
confirm
,
CopyIcon
,
ExternalIcon
,
LeaveIcon
,
}
from
'@hypothesis/frontend-shared'
;
import
classnames
from
'classnames'
;
import
classnames
from
'classnames'
;
import
{
confirm
}
from
'../../../shared/prompts'
;
import
type
{
Group
}
from
'../../../types/api'
;
import
type
{
Group
}
from
'../../../types/api'
;
import
{
orgName
}
from
'../../helpers/group-list-item-common'
;
import
{
orgName
}
from
'../../helpers/group-list-item-common'
;
import
{
withServices
}
from
'../../service-context'
;
import
{
withServices
}
from
'../../service-context'
;
...
...
src/sidebar/components/GroupList/test/GroupListItem-test.js
View file @
2a7a3607
...
@@ -62,13 +62,13 @@ describe('GroupListItem', () => {
...
@@ -62,13 +62,13 @@ describe('GroupListItem', () => {
fakeConfirm
=
sinon
.
stub
().
resolves
(
false
);
fakeConfirm
=
sinon
.
stub
().
resolves
(
false
);
$imports
.
$mock
({
$imports
.
$mock
({
'@hypothesis/frontend-shared'
:
{
confirm
:
fakeConfirm
},
'../MenuItem'
:
FakeMenuItem
,
'../MenuItem'
:
FakeMenuItem
,
'../../util/copy-to-clipboard'
:
{
'../../util/copy-to-clipboard'
:
{
copyPlainText
:
fakeCopyPlainText
,
copyPlainText
:
fakeCopyPlainText
,
},
},
'../../helpers/group-list-item-common'
:
fakeGroupListItemCommon
,
'../../helpers/group-list-item-common'
:
fakeGroupListItemCommon
,
'../../store'
:
{
useSidebarStore
:
()
=>
fakeStore
},
'../../store'
:
{
useSidebarStore
:
()
=>
fakeStore
},
'../../../shared/prompts'
:
{
confirm
:
fakeConfirm
},
});
});
});
});
...
...
src/sidebar/components/HypothesisApp.tsx
View file @
2a7a3607
import
{
confirm
}
from
'@hypothesis/frontend-shared'
;
import
classnames
from
'classnames'
;
import
classnames
from
'classnames'
;
import
{
useEffect
,
useMemo
}
from
'preact/hooks'
;
import
{
useEffect
,
useMemo
}
from
'preact/hooks'
;
import
{
confirm
}
from
'../../shared/prompts'
;
import
type
{
SidebarSettings
}
from
'../../types/config'
;
import
type
{
SidebarSettings
}
from
'../../types/config'
;
import
{
serviceConfig
}
from
'../config/service-config'
;
import
{
serviceConfig
}
from
'../config/service-config'
;
import
{
isThirdPartyService
}
from
'../helpers/is-third-party-service'
;
import
{
isThirdPartyService
}
from
'../helpers/is-third-party-service'
;
...
...
src/sidebar/components/test/HypothesisApp-test.js
View file @
2a7a3607
...
@@ -81,13 +81,13 @@ describe('HypothesisApp', () => {
...
@@ -81,13 +81,13 @@ describe('HypothesisApp', () => {
$imports
.
$mock
(
mockImportedComponents
());
$imports
.
$mock
(
mockImportedComponents
());
$imports
.
$mock
({
$imports
.
$mock
({
'@hypothesis/frontend-shared'
:
{
confirm
:
fakeConfirm
},
'../config/service-config'
:
{
serviceConfig
:
fakeServiceConfig
},
'../config/service-config'
:
{
serviceConfig
:
fakeServiceConfig
},
'../store'
:
{
useSidebarStore
:
()
=>
fakeStore
},
'../store'
:
{
useSidebarStore
:
()
=>
fakeStore
},
'../helpers/session'
:
{
'../helpers/session'
:
{
shouldAutoDisplayTutorial
:
fakeShouldAutoDisplayTutorial
,
shouldAutoDisplayTutorial
:
fakeShouldAutoDisplayTutorial
,
},
},
'../helpers/theme'
:
{
applyTheme
:
fakeApplyTheme
},
'../helpers/theme'
:
{
applyTheme
:
fakeApplyTheme
},
'../../shared/prompts'
:
{
confirm
:
fakeConfirm
},
'../helpers/is-third-party-service'
:
{
'../helpers/is-third-party-service'
:
{
isThirdPartyService
:
fakeIsThirdPartyService
,
isThirdPartyService
:
fakeIsThirdPartyService
,
},
},
...
...
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