mirror of
https://github.com/harness/drone.git
synced 2025-05-31 11:43:15 +00:00
fix: [code-1099]: fix count being shown in codeowner text (#796)
This commit is contained in:
parent
65f0505417
commit
9cac7996f9
@ -107,6 +107,7 @@ interface CommentBoxProps<T> {
|
||||
autoFocusAndPosition?: boolean
|
||||
enableReplyPlaceHolder?: boolean
|
||||
repoMetadata: TypesRepository | undefined
|
||||
standalone: boolean
|
||||
}
|
||||
|
||||
export const CommentBox = <T = unknown,>({
|
||||
@ -128,7 +129,8 @@ export const CommentBox = <T = unknown,>({
|
||||
outlets = {},
|
||||
autoFocusAndPosition,
|
||||
enableReplyPlaceHolder,
|
||||
repoMetadata
|
||||
repoMetadata,
|
||||
standalone
|
||||
}: CommentBoxProps<T>) => {
|
||||
const { getString } = useStrings()
|
||||
const [comments, setComments] = useState<CommentItem<T>[]>(commentItems)
|
||||
@ -244,6 +246,7 @@ export const CommentBox = <T = unknown,>({
|
||||
<Falsy>
|
||||
<Container className={cx(css.newCommentContainer, { [css.hasThread]: !!comments.length })}>
|
||||
<MarkdownEditorWithPreview
|
||||
standalone={standalone}
|
||||
repoMetadata={repoMetadata}
|
||||
className={editorClassName}
|
||||
viewRef={viewRef}
|
||||
@ -426,6 +429,7 @@ const CommentsThread = <T = unknown,>({
|
||||
<Truthy>
|
||||
<Container className={css.editCommentContainer}>
|
||||
<MarkdownEditorWithPreview
|
||||
standalone={standalone}
|
||||
repoMetadata={repoMetadata}
|
||||
value={commentItem?.content}
|
||||
onSave={async value => {
|
||||
|
@ -228,6 +228,7 @@ export const DiffViewer: React.FC<DiffViewerProps> = ({
|
||||
ReactDOM.render(
|
||||
<AppWrapper>
|
||||
<CommentBox
|
||||
standalone={standalone}
|
||||
repoMetadata={repoMetadata}
|
||||
commentItems={comment.commentItems}
|
||||
eventStream={comment.eventStream}
|
||||
|
@ -51,6 +51,7 @@ export interface EditorProps {
|
||||
darkTheme?: boolean
|
||||
repoMetadata: TypesRepository | undefined
|
||||
inGitBlame?: boolean
|
||||
standalone: boolean
|
||||
}
|
||||
|
||||
export const Editor = React.memo(function CodeMirrorReactEditor({
|
||||
@ -69,13 +70,13 @@ export const Editor = React.memo(function CodeMirrorReactEditor({
|
||||
onViewUpdate,
|
||||
darkTheme,
|
||||
repoMetadata,
|
||||
inGitBlame = false
|
||||
inGitBlame = false,
|
||||
standalone
|
||||
}: EditorProps) {
|
||||
const { showError } = useToaster()
|
||||
const { getString } = useStrings()
|
||||
const view = useRef<EditorView>()
|
||||
const ref = useRef<HTMLDivElement>()
|
||||
// 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) => {
|
||||
|
@ -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<HTMLInputElement>(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({
|
||||
</Container>
|
||||
<Container className={css.tabContent}>
|
||||
<Editor
|
||||
standalone={standalone}
|
||||
repoMetadata={repoMetadata}
|
||||
forMarkdown
|
||||
content={value || ''}
|
||||
|
@ -80,7 +80,7 @@
|
||||
flex-direction: column;
|
||||
|
||||
> p + div {
|
||||
flex-grow: 1;
|
||||
// flex-grow: 1;
|
||||
|
||||
ul + div + div {
|
||||
height: calc(100% - 47px);
|
||||
|
@ -243,6 +243,7 @@ export default function Compare() {
|
||||
<Layout.Vertical spacing="small">
|
||||
<Text font={{ variation: FontVariation.SMALL_BOLD }}>{getString('description')}</Text>
|
||||
<MarkdownEditorWithPreview
|
||||
standalone={standalone}
|
||||
repoMetadata={repoMetadata}
|
||||
value={description}
|
||||
onChange={setDescription}
|
||||
|
@ -91,7 +91,7 @@ export function CodeOwnersOverview({
|
||||
return {
|
||||
borderColor: 'green800',
|
||||
message: stringSubstitute(getString('codeOwner.approvalCompleted'), {
|
||||
count: approvalEntriesArr.length,
|
||||
count: approvalEntriesArr.length || 0,
|
||||
total: codeOwners?.evaluation_entries?.length
|
||||
}) as string,
|
||||
overallStatus: ExecutionState.SUCCESS
|
||||
|
@ -50,6 +50,7 @@ export interface ConversationProps extends Pick<GitInfoProps, 'repoMetadata' | '
|
||||
showEditDescription?: boolean
|
||||
onCancelEditDescription: () => void
|
||||
prChecksDecisionResult?: PRChecksDecisionResult
|
||||
standalone: boolean
|
||||
}
|
||||
|
||||
export const Conversation: React.FC<ConversationProps> = ({
|
||||
@ -59,7 +60,8 @@ export const Conversation: React.FC<ConversationProps> = ({
|
||||
prStats,
|
||||
showEditDescription,
|
||||
onCancelEditDescription,
|
||||
prChecksDecisionResult
|
||||
prChecksDecisionResult,
|
||||
standalone
|
||||
}) => {
|
||||
const { getString } = useStrings()
|
||||
const { currentUser } = useAppContext()
|
||||
@ -185,6 +187,7 @@ export const Conversation: React.FC<ConversationProps> = ({
|
||||
const newCommentBox = useMemo(() => {
|
||||
return (
|
||||
<CommentBox
|
||||
standalone={standalone}
|
||||
repoMetadata={repoMetadata}
|
||||
fluid
|
||||
boxClassName={css.commentBox}
|
||||
@ -251,6 +254,7 @@ export const Conversation: React.FC<ConversationProps> = ({
|
||||
}
|
||||
title={
|
||||
<CommentBox
|
||||
standalone={standalone}
|
||||
repoMetadata={repoMetadata}
|
||||
key={threadId}
|
||||
fluid
|
||||
@ -388,6 +392,7 @@ export const Conversation: React.FC<ConversationProps> = ({
|
||||
|
||||
{(hasDescription || showEditDescription) && (
|
||||
<DescriptionBox
|
||||
standalone={standalone}
|
||||
repoMetadata={repoMetadata}
|
||||
pullRequestMetadata={pullRequestMetadata}
|
||||
onCommentUpdate={onCommentUpdate}
|
||||
|
@ -36,7 +36,8 @@ export const DescriptionBox: React.FC<DescriptionBoxProps> = ({
|
||||
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<DescriptionBoxProps> = ({
|
||||
<Container padding={!edit ? { left: 'small', bottom: 'small' } : undefined}>
|
||||
{(edit && (
|
||||
<MarkdownEditorWithPreview
|
||||
standalone={standalone}
|
||||
repoMetadata={repoMetadata}
|
||||
value={content}
|
||||
onSave={value => {
|
||||
|
@ -240,6 +240,7 @@ export default function PullRequest() {
|
||||
),
|
||||
panel: (
|
||||
<Conversation
|
||||
standalone={standalone}
|
||||
repoMetadata={repoMetadata as TypesRepository}
|
||||
pullRequestMetadata={prData as TypesPullReq}
|
||||
prChecksDecisionResult={prChecksDecisionResult}
|
||||
|
@ -446,7 +446,13 @@ export function FileContent({
|
||||
panel: (
|
||||
<Container className={css.gitBlame}>
|
||||
{[resourcePath + gitRef].map(key => (
|
||||
<GitBlame repoMetadata={repoMetadata} resourcePath={resourcePath} gitRef={gitRef} key={key} />
|
||||
<GitBlame
|
||||
standalone={standalone}
|
||||
repoMetadata={repoMetadata}
|
||||
resourcePath={resourcePath}
|
||||
gitRef={gitRef}
|
||||
key={key}
|
||||
/>
|
||||
))}
|
||||
</Container>
|
||||
)
|
||||
|
@ -52,11 +52,9 @@ type BlameBlockRecord = Record<number, BlameBlock>
|
||||
|
||||
const INITIAL_TOP_POSITION = -1
|
||||
|
||||
export const GitBlame: React.FC<Pick<GitInfoProps, 'repoMetadata' | 'resourcePath' | 'gitRef'>> = ({
|
||||
repoMetadata,
|
||||
resourcePath,
|
||||
gitRef
|
||||
}) => {
|
||||
export const GitBlame: React.FC<
|
||||
Pick<GitInfoProps & { standalone: boolean }, 'repoMetadata' | 'resourcePath' | 'gitRef' | 'standalone'>
|
||||
> = ({ repoMetadata, resourcePath, gitRef, standalone }) => {
|
||||
const { getString } = useStrings()
|
||||
const [blameBlocks, setBlameBlocks] = useState<BlameBlockRecord>({})
|
||||
const path = useMemo(
|
||||
@ -191,6 +189,7 @@ export const GitBlame: React.FC<Pick<GitInfoProps, 'repoMetadata' | 'resourcePat
|
||||
|
||||
<Render when={Object.values(blameBlocks).length}>
|
||||
<GitBlameRenderer
|
||||
standalone={standalone}
|
||||
repoMetadata={repoMetadata}
|
||||
source={data?.map(({ lines }) => (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<EditorView>()
|
||||
@ -279,6 +280,7 @@ const GitBlameRenderer = React.memo(function GitBlameSourceViewer({
|
||||
|
||||
return (
|
||||
<Editor
|
||||
standalone={standalone}
|
||||
inGitBlame={true}
|
||||
repoMetadata={repoMetadata}
|
||||
viewRef={viewRef}
|
||||
|
@ -71,7 +71,7 @@ export default function Search() {
|
||||
}, [highlightlLineNumbersExtension])
|
||||
const viewRef = useRef<EditorView>()
|
||||
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() {
|
||||
<Match expr={q}>
|
||||
<Truthy>
|
||||
<Split split="vertical" className={css.split} size={450} minSize={300} maxSize={700} primary="first">
|
||||
<SearchResults repoMetadata={repoMetadata} onSelect={onSelectResult} data={searchResult} />
|
||||
<SearchResults
|
||||
standalone={standalone}
|
||||
repoMetadata={repoMetadata}
|
||||
onSelect={onSelectResult}
|
||||
data={searchResult}
|
||||
/>
|
||||
|
||||
<Layout.Vertical className={cx(css.preview, { [css.noResult]: !searchResult?.length })}>
|
||||
<Container className={css.filePath}>
|
||||
@ -253,6 +258,7 @@ export default function Search() {
|
||||
</Container>
|
||||
<Container className={css.fileContent}>
|
||||
<Editor
|
||||
standalone={standalone}
|
||||
repoMetadata={repoMetadata}
|
||||
viewRef={viewRef}
|
||||
filename={filename}
|
||||
@ -286,9 +292,10 @@ interface SearchResultsProps {
|
||||
data: SearchResultType[]
|
||||
onSelect: (fileName: string, filePath: string, content: string, highlightedLines: number[]) => void
|
||||
repoMetadata: TypesRepository | undefined
|
||||
standalone: boolean
|
||||
}
|
||||
|
||||
const SearchResults: React.FC<SearchResultsProps> = ({ data, onSelect, repoMetadata }) => {
|
||||
const SearchResults: React.FC<SearchResultsProps> = ({ 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<SearchResultsProps> = ({ data, onSelect, repoMetad
|
||||
</Layout.Horizontal>
|
||||
</Container>
|
||||
<Editor
|
||||
standalone={standalone}
|
||||
repoMetadata={repoMetadata}
|
||||
filename={item.file_name}
|
||||
content={(item.lines || []).join('\n').replace(/^\n/g, '').trim()}
|
||||
|
@ -250,12 +250,13 @@ export const handleUpload = (
|
||||
blob: File,
|
||||
setMarkdownContent: (data: string) => 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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user