-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Implement suggestion for edit composer #35226
Merged
Merged
Changes from 15 commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
99c7092
test
dukenv0307 dee95c9
implement suggestion for edit composer
dukenv0307 d40e5cc
Merge branch 'main' into fix/34442
dukenv0307 0de2686
implement suggestion for edit composer
dukenv0307 a1ef1bf
Merge branch 'main' into fix/34442
dukenv0307 0273240
display suggestion below when composer at the top of the screen
dukenv0307 31bf412
fix edge case
dukenv0307 e5eb167
Merge branch 'main' into fix/34442
dukenv0307 ee43388
create global ref
dukenv0307 4858707
Merge branch 'main' into fix/34442
dukenv0307 bd0ccb7
merge main
dukenv0307 5f4c43a
merge main
dukenv0307 f11b8ed
fix lint
dukenv0307 a7bcde6
update suggestion
dukenv0307 be5faa2
rename variable
dukenv0307 c4094f3
merge main
dukenv0307 eb09849
move portal of suggestion to the correct place
dukenv0307 a663612
merge main
dukenv0307 0b5ea25
Merge branch 'main' into fix/34442
dukenv0307 930eb47
remove global ref and create suggestion context
dukenv0307 ec83df8
Merge branch 'main' into fix/34442
dukenv0307 5e5cd88
merge main
dukenv0307 01c63b8
merge main
dukenv0307 cc1810a
Merge branch 'main' into fix/34442
dukenv0307 8dcd362
fix the suggestion padding for edit composer
dukenv0307 05f316f
Merge branch 'main' into fix/34442
dukenv0307 07db2ab
update variable name
dukenv0307 d511cb8
merge main
dukenv0307 c093a99
fix portal on native
dukenv0307 616c3c7
rename
dukenv0307 8caeee3
resolve conflict
dukenv0307 8c961f3
resolve conflict
dukenv0307 a2065fd
resolve conflict
dukenv0307 be61ac7
merge main
dukenv0307 4ad4341
Merge branch 'main' into fix/34442
dukenv0307 265ced8
resolve conflict
dukenv0307 c7defeb
merge main
dukenv0307 d5d7f24
re-open suggestion menu after scrolling
dukenv0307 10cedd0
Merge branch 'main' into fix/34442
dukenv0307 3ff18ff
fix suggestion open after scrolling
dukenv0307 d923e85
Merge branch 'main' into fix/34442
dukenv0307 0e7eb4f
create new const for suggestion portal host name
dukenv0307 f57ca56
Merge branch 'main' into fix/34442
dukenv0307 d734b75
Merge branch 'main' into fix/34442
dukenv0307 b153d07
Merge branch 'main' into fix/34442
dukenv0307 c95b4aa
add explain comment
dukenv0307 cd0f980
add isGroupPolicyReport prop
dukenv0307 b820982
fix ts
dukenv0307 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 | ||||
---|---|---|---|---|---|---|
|
@@ -4,6 +4,7 @@ import {View} from 'react-native'; | |||||
import useStyleUtils from '@hooks/useStyleUtils'; | ||||||
import useWindowDimensions from '@hooks/useWindowDimensions'; | ||||||
import * as DeviceCapabilities from '@libs/DeviceCapabilities'; | ||||||
import {measureHeightOfSuggestionsContainer} from '@libs/SuggestionUtils'; | ||||||
import BaseAutoCompleteSuggestions from './BaseAutoCompleteSuggestions'; | ||||||
import type {AutoCompleteSuggestionsProps} from './types'; | ||||||
|
||||||
|
@@ -18,11 +19,13 @@ function AutoCompleteSuggestions<TSuggestion>({measureParentContainer = () => {} | |||||
const StyleUtils = useStyleUtils(); | ||||||
const containerRef = React.useRef<HTMLDivElement>(null); | ||||||
const {windowHeight, windowWidth} = useWindowDimensions(); | ||||||
const suggestionContainerHeight = measureHeightOfSuggestionsContainer(props.suggestions.length, props.isSuggestionPickerLarge); | ||||||
const [{width, left, bottom}, setContainerState] = React.useState({ | ||||||
width: 0, | ||||||
left: 0, | ||||||
bottom: 0, | ||||||
}); | ||||||
const [shouldBelowContainer, setShouldBelowContainer] = React.useState(false); | ||||||
React.useEffect(() => { | ||||||
const container = containerRef.current; | ||||||
if (!container) { | ||||||
|
@@ -41,13 +44,19 @@ function AutoCompleteSuggestions<TSuggestion>({measureParentContainer = () => {} | |||||
if (!measureParentContainer) { | ||||||
return; | ||||||
} | ||||||
measureParentContainer((x, y, w) => setContainerState({left: x, bottom: windowHeight - y, width: w})); | ||||||
}, [measureParentContainer, windowHeight, windowWidth]); | ||||||
|
||||||
measureParentContainer((x, y, w, h) => { | ||||||
const currenBottom = y < suggestionContainerHeight ? windowHeight - y - suggestionContainerHeight - h : windowHeight - y; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
setShouldBelowContainer(y < suggestionContainerHeight); | ||||||
setContainerState({left: x, bottom: currenBottom, width: w}); | ||||||
}); | ||||||
}, [measureParentContainer, windowHeight, windowWidth, suggestionContainerHeight]); | ||||||
|
||||||
const componentToRender = ( | ||||||
<BaseAutoCompleteSuggestions<TSuggestion> | ||||||
// eslint-disable-next-line react/jsx-props-no-spreading | ||||||
{...props} | ||||||
shouldBeDisplayedBelowParentContainer={shouldBelowContainer} | ||||||
ref={containerRef} | ||||||
/> | ||||||
); | ||||||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React from 'react'; | ||
import type {NativeSyntheticEvent, TextInputKeyPressEventData, TextInputSelectionChangeEventData} from 'react-native'; | ||
|
||
type SuggestionsRef = { | ||
getSuggestions: () => void; | ||
resetSuggestions: () => void; | ||
triggerHotkeyActions: (event: NativeSyntheticEvent<TextInputKeyPressEventData> | KeyboardEvent) => boolean; | ||
onSelectionChange: (event: NativeSyntheticEvent<TextInputSelectionChangeEventData>) => void; | ||
updateShouldShowSuggestionMenuToFalse: () => void; | ||
setShouldBlockSuggestionCalc: () => void; | ||
}; | ||
|
||
const suggestionsRef = React.createRef<SuggestionsRef>(); | ||
|
||
function resetSuggestions() { | ||
if (!suggestionsRef.current) { | ||
return; | ||
} | ||
|
||
suggestionsRef.current.resetSuggestions(); | ||
} | ||
|
||
function triggerHotkeyActions(event: NativeSyntheticEvent<TextInputKeyPressEventData> | KeyboardEvent): boolean { | ||
if (!suggestionsRef.current) { | ||
return false; | ||
} | ||
|
||
return suggestionsRef.current.triggerHotkeyActions(event); | ||
} | ||
|
||
function updateShouldShowSuggestionMenuToFalse() { | ||
if (!suggestionsRef.current) { | ||
return; | ||
} | ||
|
||
suggestionsRef.current.updateShouldShowSuggestionMenuToFalse(); | ||
} | ||
|
||
function onSelectionChange(event: NativeSyntheticEvent<TextInputSelectionChangeEventData>) { | ||
if (!suggestionsRef.current) { | ||
return; | ||
} | ||
|
||
suggestionsRef.current.onSelectionChange(event); | ||
} | ||
|
||
export {suggestionsRef, resetSuggestions, triggerHotkeyActions, onSelectionChange, updateShouldShowSuggestionMenuToFalse}; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export type {SuggestionsRef}; |
94 changes: 94 additions & 0 deletions
94
...me/report/ReportActionCompose/ComposerWithSuggestionsEdit/ComposerWithSuggestionsEdit.tsx
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,94 @@ | ||
import type {Dispatch, ForwardedRef, RefObject, SetStateAction} from 'react'; | ||
import React, {useState} from 'react'; | ||
import type {TextInput} from 'react-native'; | ||
import Composer from '@components/Composer'; | ||
import type {ComposerProps} from '@components/Composer/types'; | ||
import type {SuggestionsRef} from '@libs/actions/SuggestionsActions'; | ||
import Suggestions from '@pages/home/report/ReportActionCompose/Suggestions'; | ||
|
||
type ComposerWithSuggestionsEditProps = { | ||
setValue: Dispatch<SetStateAction<string>>; | ||
setSelection: Dispatch< | ||
SetStateAction<{ | ||
start: number; | ||
end: number; | ||
}> | ||
>; | ||
resetKeyboardInput: () => void; | ||
isComposerFocused: boolean; | ||
suggestionsRef: RefObject<SuggestionsRef>; | ||
updateDraft: (newValue: string) => void; | ||
measureParentContainer: (callback: () => void) => void; | ||
}; | ||
|
||
function ComposerWithSuggestionsEdit( | ||
{ | ||
value, | ||
maxLines = -1, | ||
onKeyPress = () => {}, | ||
style, | ||
onSelectionChange = () => {}, | ||
selection = { | ||
start: 0, | ||
end: 0, | ||
}, | ||
onBlur = () => {}, | ||
onFocus = () => {}, | ||
onChangeText = () => {}, | ||
setValue = () => {}, | ||
setSelection = () => {}, | ||
resetKeyboardInput = () => {}, | ||
isComposerFocused, | ||
suggestionsRef, | ||
updateDraft, | ||
measureParentContainer, | ||
id = undefined, | ||
}: ComposerWithSuggestionsEditProps & ComposerProps, | ||
ref: ForwardedRef<TextInput>, | ||
) { | ||
const [composerHeight, setComposerHeight] = useState(0); | ||
|
||
return ( | ||
<> | ||
<Composer | ||
multiline | ||
ref={ref} | ||
id={id} | ||
onChangeText={onChangeText} // Debounced saveDraftComment | ||
onKeyPress={onKeyPress} | ||
value={value} | ||
maxLines={maxLines} // This is the same that slack has | ||
style={style} | ||
onFocus={onFocus} | ||
onBlur={onBlur} | ||
selection={selection} | ||
onSelectionChange={onSelectionChange} | ||
onLayout={(e) => { | ||
const composerLayoutHeight = e.nativeEvent.layout.height; | ||
if (composerHeight === composerLayoutHeight) { | ||
return; | ||
} | ||
setComposerHeight(composerLayoutHeight); | ||
}} | ||
/> | ||
|
||
<Suggestions | ||
ref={suggestionsRef} | ||
// @ts-expect-error TODO: Remove this once Suggestions is migrated to TypeScript. | ||
isComposerFullSize={false} | ||
isComposerFocused={isComposerFocused} | ||
updateComment={updateDraft} | ||
composerHeight={composerHeight} | ||
measureParentContainer={measureParentContainer} | ||
isAutoSuggestionPickerLarge | ||
value={value} | ||
setValue={setValue} | ||
selection={selection} | ||
setSelection={setSelection} | ||
resetKeyboardInput={resetKeyboardInput} | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
export default React.forwardRef(ComposerWithSuggestionsEdit); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.