-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fluent: sendbox transcript navigation (#5191)
* Fluent: allow transcript scroll when sendbox focused * Rework empty check * Fix failing tests * Changelog --------- Co-authored-by: William Wong <compulim@users.noreply.github.com>
- Loading branch information
Showing
20 changed files
with
168 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+48.3 KB
...-page-up-down-js-fluent-theme-applied-performs-transcript-navigation-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+51 KB
...-page-up-down-js-fluent-theme-applied-performs-transcript-navigation-2-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+48.3 KB
...-page-up-down-js-fluent-theme-applied-performs-transcript-navigation-3-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+48 KB
...-page-up-down-js-fluent-theme-applied-performs-transcript-navigation-4-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+63.9 KB
...-page-up-down-js-fluent-theme-applied-performs-transcript-navigation-5-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+62.2 KB
...-page-up-down-js-fluent-theme-applied-performs-transcript-navigation-6-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+62.2 KB
...-page-up-down-js-fluent-theme-applied-performs-transcript-navigation-7-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 79 additions & 0 deletions
79
__tests__/html/fluentTheme/transcript.navigation.pageUpDown.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<!doctype html> | ||
<html lang="en-US"> | ||
<head> | ||
<link href="/assets/index.css" rel="stylesheet" type="text/css" /> | ||
<script crossorigin="anonymous" src="https://unpkg.com/@babel/standalone/babel.min.js"></script> | ||
<script crossorigin="anonymous" src="https://unpkg.com/react@16.8.6/umd/react.production.min.js"></script> | ||
<script crossorigin="anonymous" src="https://unpkg.com/react-dom@16.8.6/umd/react-dom.production.min.js"></script> | ||
<script crossorigin="anonymous" src="/test-harness.js"></script> | ||
<script crossorigin="anonymous" src="/test-page-object.js"></script> | ||
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script> | ||
<script crossorigin="anonymous" src="/__dist__/botframework-webchat-fluent-theme.production.min.js"></script> | ||
</head> | ||
<body> | ||
<main id="webchat"></main> | ||
<script type="text/babel"> | ||
run(async function () { | ||
const { | ||
React, | ||
ReactDOM: { render }, | ||
WebChat: { FluentThemeProvider, ReactWebChat } | ||
} = window; // Imports in UMD fashion. | ||
|
||
const directLine = testHelpers.createDirectLineWithTranscript( | ||
testHelpers.transcriptNavigation.generateTranscript() | ||
); | ||
const store = testHelpers.createStore(); | ||
|
||
const App = () => <ReactWebChat directLine={directLine} store={store} />; | ||
|
||
render( | ||
<FluentThemeProvider> | ||
<App /> | ||
</FluentThemeProvider>, | ||
document.getElementById('webchat') | ||
); | ||
await pageConditions.uiConnected(); | ||
await pageConditions.numActivitiesShown(32); | ||
await pageConditions.scrollToBottomCompleted(); | ||
|
||
document.querySelector(`[data-testid="${WebChat.testIds.sendBoxTextBox}"]`).focus(); | ||
|
||
// Should scroll a page up | ||
await host.sendKeys('PAGE_UP'); | ||
await pageConditions.scrollStabilized(); | ||
await host.snapshot(); | ||
|
||
// Should scroll another page up | ||
await host.sendKeys('PAGE_UP'); | ||
await pageConditions.scrollStabilized(); | ||
await host.snapshot(); | ||
|
||
// Should scroll back down | ||
await host.sendKeys('PAGE_DOWN'); | ||
await pageConditions.scrollStabilized(); | ||
await host.snapshot(); | ||
|
||
// Should scroll to the top | ||
await host.sendKeys('HOME'); | ||
await pageConditions.scrollStabilized(); | ||
await host.snapshot(); | ||
|
||
// Should scroll to the bottom | ||
await host.sendKeys('END'); | ||
await pageConditions.scrollStabilized(); | ||
await host.snapshot(); | ||
|
||
// Should not scroll because the send box is not empty | ||
await host.sendKeys('A', 'PAGE_UP'); | ||
await pageConditions.scrollStabilized(); | ||
await host.snapshot(); | ||
|
||
// Should page up because the send box is no longer empty | ||
await host.sendKeys('BACK_SPACE', 'PAGE_UP'); | ||
await pageConditions.scrollStabilized(); | ||
await host.snapshot(); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
5 changes: 5 additions & 0 deletions
5
__tests__/html/fluentTheme/transcript.navigation.pageUpDown.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ | ||
|
||
describe('Fluent theme applied', () => { | ||
test('performs transcript navigation', () => runHTML('fluentTheme/transcript.navigation.pageUpDown')); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
packages/component/src/hooks/internal/useRegisterScrollRelative.js
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
packages/component/src/hooks/internal/useScrollRelative.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { createPropagation } from 'use-propagate'; | ||
|
||
export type TranscriptScrollRelativeOptions = { direction: 'down' | 'up'; displacement?: number }; | ||
|
||
const { useListen: useRegisterScrollRelativeTranscript, usePropagate: useScrollRelativeTranscript } = | ||
createPropagation<TranscriptScrollRelativeOptions>(); | ||
|
||
export { useRegisterScrollRelativeTranscript, useScrollRelativeTranscript }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
import { useCallback } from 'react'; | ||
|
||
import useScrollRelative from './internal/useScrollRelative'; | ||
import { useScrollRelativeTranscript } from './transcriptScrollRelative'; | ||
|
||
export default function useScrollDown(): (options?: { displacement: number }) => void { | ||
const scrollRelative = useScrollRelative(); | ||
const scrollRelative = useScrollRelativeTranscript(); | ||
|
||
return useCallback((...args) => scrollRelative('down', ...args), [scrollRelative]); | ||
return useCallback(options => scrollRelative({ direction: 'down', ...options }), [scrollRelative]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
import { useCallback } from 'react'; | ||
|
||
import useScrollRelative from './internal/useScrollRelative'; | ||
import { useScrollRelativeTranscript } from './transcriptScrollRelative'; | ||
|
||
export default function useScrollUp(): (options?: { displacement: number }) => void { | ||
const scrollRelative = useScrollRelative(); | ||
const scrollRelative = useScrollRelativeTranscript(); | ||
|
||
return useCallback((...args) => scrollRelative('up', ...args), [scrollRelative]); | ||
return useCallback(options => scrollRelative({ direction: 'up', ...options }), [scrollRelative]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
packages/fluent-theme/src/components/sendBox/private/useTranscriptNavigation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { useCallback, type KeyboardEvent } from 'react'; | ||
import { hooks } from 'botframework-webchat-component'; | ||
|
||
const { useScrollDown, useScrollUp } = hooks; | ||
|
||
export default function useTranscriptNavigation() { | ||
const scrollDown = useScrollDown(); | ||
const scrollUp = useScrollUp(); | ||
|
||
return useCallback( | ||
(event: KeyboardEvent<unknown>) => { | ||
if (event.target instanceof HTMLTextAreaElement && event.target.value) { | ||
return; | ||
} | ||
|
||
const { ctrlKey, metaKey, shiftKey } = event; | ||
|
||
if (ctrlKey || metaKey || shiftKey) { | ||
return; | ||
} | ||
|
||
let handled = true; | ||
|
||
switch (event.key) { | ||
case 'End': | ||
scrollDown({ displacement: Infinity }); | ||
break; | ||
|
||
case 'Home': | ||
scrollUp({ displacement: Infinity }); | ||
break; | ||
|
||
case 'PageDown': | ||
scrollDown(); | ||
break; | ||
|
||
case 'PageUp': | ||
scrollUp(); | ||
break; | ||
|
||
default: | ||
handled = false; | ||
break; | ||
} | ||
|
||
if (handled) { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
} | ||
}, | ||
[scrollDown, scrollUp] | ||
); | ||
} |