From 9cac7996f931ba46e6099ed0f580dc21a751f930 Mon Sep 17 00:00:00 2001 From: Calvin Lee Date: Mon, 13 Nov 2023 23:20:58 +0000 Subject: [PATCH] fix: [code-1099]: fix count being shown in codeowner text (#796) --- web/src/components/CommentBox/CommentBox.tsx | 6 +++- web/src/components/DiffViewer/DiffViewer.tsx | 1 + web/src/components/Editor/Editor.tsx | 7 +++-- .../MarkdownEditorWithPreview.tsx | 7 +++-- web/src/pages/Compare/Compare.module.scss | 2 +- web/src/pages/Compare/Compare.tsx | 1 + .../CodeOwners/CodeOwnersOverview.tsx | 2 +- .../PullRequest/Conversation/Conversation.tsx | 7 ++++- .../Conversation/DescriptionBox.tsx | 4 ++- web/src/pages/PullRequest/PullRequest.tsx | 1 + .../FileContent/FileContent.tsx | 8 ++++- .../FileContent/GitBlame.tsx | 14 +++++---- web/src/pages/Search/Search.tsx | 14 +++++++-- web/src/utils/GitUtils.ts | 29 +++++++++++-------- 14 files changed, 71 insertions(+), 32 deletions(-) diff --git a/web/src/components/CommentBox/CommentBox.tsx b/web/src/components/CommentBox/CommentBox.tsx index 9e5d6ba49..6ca4e7e85 100644 --- a/web/src/components/CommentBox/CommentBox.tsx +++ b/web/src/components/CommentBox/CommentBox.tsx @@ -107,6 +107,7 @@ interface CommentBoxProps { autoFocusAndPosition?: boolean enableReplyPlaceHolder?: boolean repoMetadata: TypesRepository | undefined + standalone: boolean } export const CommentBox = ({ @@ -128,7 +129,8 @@ export const CommentBox = ({ outlets = {}, autoFocusAndPosition, enableReplyPlaceHolder, - repoMetadata + repoMetadata, + standalone }: CommentBoxProps) => { const { getString } = useStrings() const [comments, setComments] = useState[]>(commentItems) @@ -244,6 +246,7 @@ export const CommentBox = ({ ({ { diff --git a/web/src/components/DiffViewer/DiffViewer.tsx b/web/src/components/DiffViewer/DiffViewer.tsx index 061ba9bd8..1a7b7d391 100644 --- a/web/src/components/DiffViewer/DiffViewer.tsx +++ b/web/src/components/DiffViewer/DiffViewer.tsx @@ -228,6 +228,7 @@ export const DiffViewer: React.FC = ({ ReactDOM.render( () const ref = useRef() - // const { repoMetadata } = useGetRepositoryMetadata() const languageConfig = useMemo(() => new Compartment(), []) const [markdownContent, setMarkdownContent] = useState('') @@ -199,7 +200,7 @@ export const Editor = React.memo(function CodeMirrorReactEditor({ } }, [filename, forMarkdown, view, languageConfig, markdownLanguageSupport]) const handleUploadCallback = (file: File) => { - handleUpload(file, setMarkdownContent, repoMetadata, showError) + handleUpload(file, setMarkdownContent, repoMetadata, showError, standalone) } // eslint-disable-next-line @typescript-eslint/no-explicit-any const handleDropForUpload = async (event: any) => { diff --git a/web/src/components/MarkdownEditorWithPreview/MarkdownEditorWithPreview.tsx b/web/src/components/MarkdownEditorWithPreview/MarkdownEditorWithPreview.tsx index 00424a5c5..c027f0191 100644 --- a/web/src/components/MarkdownEditorWithPreview/MarkdownEditorWithPreview.tsx +++ b/web/src/components/MarkdownEditorWithPreview/MarkdownEditorWithPreview.tsx @@ -95,6 +95,7 @@ interface MarkdownEditorWithPreviewProps { // and cursor is set to the end of the document autoFocusAndPosition?: boolean repoMetadata: TypesRepository | undefined + standalone: boolean } export function MarkdownEditorWithPreview({ @@ -112,7 +113,8 @@ export function MarkdownEditorWithPreview({ viewRef: viewRefProp, autoFocusAndPosition, secondarySaveButton: SecondarySaveButton, - repoMetadata + repoMetadata, + standalone }: MarkdownEditorWithPreviewProps) { const { getString } = useStrings() const fileInputRef = useRef(null) @@ -364,7 +366,7 @@ export function MarkdownEditorWithPreview({ variation={ButtonVariation.PRIMARY} disabled={false} onClick={() => { - handleUpload(file as File, setMarkdownContent, repoMetadata, showError) + handleUpload(file as File, setMarkdownContent, repoMetadata, showError, standalone) setOpen(false) setFile(undefined) }} @@ -418,6 +420,7 @@ export function MarkdownEditorWithPreview({ p + div { - flex-grow: 1; + // flex-grow: 1; ul + div + div { height: calc(100% - 47px); diff --git a/web/src/pages/Compare/Compare.tsx b/web/src/pages/Compare/Compare.tsx index 742d991ac..c735c2a57 100644 --- a/web/src/pages/Compare/Compare.tsx +++ b/web/src/pages/Compare/Compare.tsx @@ -243,6 +243,7 @@ export default function Compare() { {getString('description')} void prChecksDecisionResult?: PRChecksDecisionResult + standalone: boolean } export const Conversation: React.FC = ({ @@ -59,7 +60,8 @@ export const Conversation: React.FC = ({ prStats, showEditDescription, onCancelEditDescription, - prChecksDecisionResult + prChecksDecisionResult, + standalone }) => { const { getString } = useStrings() const { currentUser } = useAppContext() @@ -185,6 +187,7 @@ export const Conversation: React.FC = ({ const newCommentBox = useMemo(() => { return ( = ({ } title={ = ({ {(hasDescription || showEditDescription) && ( = ({ repoMetadata, pullRequestMetadata, onCommentUpdate: refreshPullRequestMetadata, - onCancelEditDescription + onCancelEditDescription, + standalone }) => { const [edit, setEdit] = useState(false) const [dirty, setDirty] = useState(false) @@ -63,6 +64,7 @@ export const DescriptionBox: React.FC = ({ {(edit && ( { diff --git a/web/src/pages/PullRequest/PullRequest.tsx b/web/src/pages/PullRequest/PullRequest.tsx index bef05951e..c177ba7e7 100644 --- a/web/src/pages/PullRequest/PullRequest.tsx +++ b/web/src/pages/PullRequest/PullRequest.tsx @@ -240,6 +240,7 @@ export default function PullRequest() { ), panel: ( {[resourcePath + gitRef].map(key => ( - + ))} ) diff --git a/web/src/pages/Repository/RepositoryContent/FileContent/GitBlame.tsx b/web/src/pages/Repository/RepositoryContent/FileContent/GitBlame.tsx index 8ed0735b2..e1be0c446 100644 --- a/web/src/pages/Repository/RepositoryContent/FileContent/GitBlame.tsx +++ b/web/src/pages/Repository/RepositoryContent/FileContent/GitBlame.tsx @@ -52,11 +52,9 @@ type BlameBlockRecord = Record const INITIAL_TOP_POSITION = -1 -export const GitBlame: React.FC> = ({ - repoMetadata, - resourcePath, - gitRef -}) => { +export const GitBlame: React.FC< + Pick +> = ({ repoMetadata, resourcePath, gitRef, standalone }) => { const { getString } = useStrings() const [blameBlocks, setBlameBlocks] = useState({}) const path = useMemo( @@ -191,6 +189,7 @@ export const GitBlame: React.FC (lines as string[]).join('\n')).join('\n') || ''} filename={resourcePath} @@ -225,6 +224,7 @@ interface GitBlameRendererProps { onViewUpdate?: (update: ViewUpdate) => void blameBlocks: BlameBlockRecord repoMetadata: TypesRepository | undefined + standalone: boolean } interface EditorLinePaddingWidgetSpec extends LineWidgetSpec { @@ -236,7 +236,8 @@ const GitBlameRenderer = React.memo(function GitBlameSourceViewer({ filename, onViewUpdate = noop, blameBlocks, - repoMetadata + repoMetadata, + standalone }: GitBlameRendererProps) { const extensions = useMemo(() => new Compartment(), []) const viewRef = useRef() @@ -279,6 +280,7 @@ const GitBlameRenderer = React.memo(function GitBlameSourceViewer({ return ( () const { getString } = useStrings() - const { routes } = useAppContext() + const { routes, standalone } = useAppContext() const { q } = useQueryParams<{ q: string }>() const [searchTerm, setSearchTerm] = useState(q || '') const { repoMetadata, error, loading, refetch } = useGetRepositoryMetadata() @@ -204,7 +204,12 @@ export default function Search() { - + @@ -253,6 +258,7 @@ export default function Search() { void repoMetadata: TypesRepository | undefined + standalone: boolean } -const SearchResults: React.FC = ({ data, onSelect, repoMetadata }) => { +const SearchResults: React.FC = ({ data, onSelect, repoMetadata, standalone }) => { const { getString } = useStrings() const [selected, setSelected] = useState(data?.[0]?.file_path || '') const count = useMemo(() => data?.length || 0, [data]) @@ -344,6 +351,7 @@ const SearchResults: React.FC = ({ data, onSelect, repoMetad void, repoMetadata: TypesRepository | undefined, - showError: (message: React.ReactNode, timeout?: number | undefined, key?: string | undefined) => void + showError: (message: React.ReactNode, timeout?: number | undefined, key?: string | undefined) => void, + standalone: boolean ) => { const reader = new FileReader() // Set up a function to be called when the load event is triggered reader.onload = async function () { - const markdown = await uploadImage(reader.result, showError, repoMetadata) + const markdown = await uploadImage(reader.result, showError, repoMetadata, standalone) setMarkdownContent(markdown) // Set the markdown content } reader.readAsArrayBuffer(blob) // This will trigger the onload function when the reading is complete @@ -265,18 +266,22 @@ export const uploadImage = async ( // eslint-disable-next-line @typescript-eslint/no-explicit-any fileBlob: any, showError: (message: React.ReactNode, timeout?: number | undefined, key?: string | undefined) => void, - repoMetadata: TypesRepository | undefined + repoMetadata: TypesRepository | undefined, + standalone: boolean ) => { try { - const response = await fetch(`${window.location.origin}/api/v1/repos/${repoMetadata?.path}/+/uploads/`, { - method: 'POST', - headers: { - Accept: 'application/json', - 'content-type': 'application/octet-stream' - }, - body: fileBlob, - redirect: 'follow' - }) + const response = await fetch( + `${window.location.origin}/${standalone ? '' : 'code/'}api/v1/repos/${repoMetadata?.path}/+/uploads/`, + { + method: 'POST', + headers: { + Accept: 'application/json', + 'content-type': 'application/octet-stream' + }, + body: fileBlob, + redirect: 'follow' + } + ) const result = await response.json() if (!response.ok && result) { showError(getErrorMessage(result))