Fix CodeMirror throwing error on Code Comment editing (#449)

jobatzil/rename
Tan Nhu 2023-09-13 05:03:29 +00:00 committed by Harness
parent 42252a170e
commit 4d85926c81
7 changed files with 18 additions and 19 deletions

View File

@ -101,10 +101,6 @@ rules:
- lodash.*
paths:
- lodash
- name: yaml
importNames:
- stringify
message: 'Please use yamlStringify from @common/utils/YamlHelperMethods instead of this'
overrides:
- files:

View File

@ -36,7 +36,7 @@ const CloneCredentialDialog = (props: CloneCredentialDialogProps) => {
},
[mutate, showError]
)
const tokenData = standalone ? false : hooks?.useGenerateToken?.(hash, currentUser.uid, flag)
const tokenData = standalone ? false : hooks?.useGenerateToken?.(hash, currentUser?.uid, flag)
useEffect(() => {
if (tokenData) {

View File

@ -47,7 +47,6 @@ export const Editor = React.memo(function CodeMirrorReactEditor({
onViewUpdate,
darkTheme
}: EditorProps) {
const contentRef = useRef(content)
const view = useRef<EditorView>()
const ref = useRef<HTMLDivElement>()
const languageConfig = useMemo(() => new Compartment(), [])
@ -139,14 +138,5 @@ export const Editor = React.memo(function CodeMirrorReactEditor({
}
}, [filename, forMarkdown, view, languageConfig, markdownLanguageSupport])
useEffect(() => {
if (contentRef.current !== content) {
contentRef.current = content
viewRef?.current?.dispatch({
changes: { from: 0, to: viewRef?.current?.state.doc.length, insert: content }
})
}
}, [content, viewRef])
return <Container ref={ref} className={cx(css.editor, className)} style={style} />
})

View File

@ -193,6 +193,7 @@ export interface StringsMap {
failedToCreateSpace: string
failedToDeleteBranch: string
failedToDeleteWebhook: string
failedToFetchFileContent: string
failedToSavePipeline: string
fileDeleted: string
fileTooLarge: string

View File

@ -676,6 +676,7 @@ aiSearch: AI Search
codeSearch: Code Search
startSearching: Begin search by describing what you are looking for.
poweredByAI: Unlock the power of AI with Semantic Code search. Try phrases like "Locate the code for authentication".
failedToFetchFileContent: 'ERROR: Failed to fetch file content.'
run: Run
plugins:
title: Plugins

View File

@ -113,7 +113,7 @@ export const Conversation: React.FC<ConversationProps> = ({
const allCommentBlock = blocks.filter(_activities => !isSystemComment(_activities))
const userCommentsOnly = allCommentBlock.filter(_activities => {
const userCommentReply = _activities.filter(
authorIsUser => authorIsUser.payload?.author?.uid === currentUser.uid
authorIsUser => currentUser?.uid && authorIsUser.payload?.author?.uid === currentUser?.uid
)
return userCommentReply.length !== 0
})
@ -122,7 +122,7 @@ export const Conversation: React.FC<ConversationProps> = ({
}
return blocks
}, [activities, dateOrderSort, activityFilter, currentUser.uid])
}, [activities, dateOrderSort, activityFilter, currentUser?.uid])
const path = useMemo(
() => `/api/v1/repos/${repoMetadata.path}/+/pullreq/${pullRequestMetadata.number}/comments`,
[repoMetadata.path, pullRequestMetadata.number]

View File

@ -90,12 +90,15 @@ export default function Search() {
error: resourceError = null,
loading: resourceLoading
} = useGetResourceContent({ repoMetadata, gitRef, resourcePath, includeCommit: false, lazy: !resourcePath })
const fileContent = useMemo(
const fileContent: string = useMemo(
() =>
resourceContent?.path === resourcePath
? decodeGitContent((resourceContent?.content as RepoFileContent)?.data)
: resourceError
? getString('failedToFetchFileContent')
: '',
[resourceContent?.content, resourceContent?.path, resourcePath]
[resourceContent?.content, resourceContent?.path, resourcePath, resourceError, getString]
)
// eslint-disable-next-line react-hooks/exhaustive-deps
@ -136,6 +139,14 @@ export default function Search() {
}
}, [repoMetadata?.path]) // eslint-disable-line react-hooks/exhaustive-deps
useEffect(() => {
if (fileContent && fileContent !== viewRef?.current?.state.doc.toString()) {
viewRef?.current?.dispatch({
changes: { from: 0, to: viewRef?.current?.state.doc.length, insert: fileContent }
})
}
}, [fileContent])
useShowRequestError(resourceError)
return (