Skip to content

Commit

Permalink
fix newFile commit bug and PR comments bug (#450)
Browse files Browse the repository at this point in the history
* fix newFile commit bug and PR comments bug

* fix newFile commit bug and PR comments bug

* fix newFile commit bug and PR comments bug

* fix viveks comments

Signed-off-by: Calvin Lee <[email protected]>

---------

Signed-off-by: Calvin Lee <[email protected]>
Co-authored-by: Calvin Lee <[email protected]>
  • Loading branch information
shaurya-harness and cjlee1 authored Nov 16, 2024
1 parent 7dfa0b5 commit b65d16d
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 57 deletions.
46 changes: 22 additions & 24 deletions apps/gitness/src/components/FileEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,30 +210,28 @@ export const FileEditor: React.FC = () => {
</>
)
})}
{!isNew && (
<BreadcrumbItem>
<Input
id="fileName"
value={fileName}
size={20}
onInput={(event: ChangeEvent<HTMLInputElement>) => {
setFileName(event.currentTarget.value)
}}
ref={_ref => (inputRef.current = _ref)}
onBlur={rebuildPaths}
onFocus={({ target }) => {
const value = (parentPath ? parentPath + FILE_SEPERATOR : '') + fileName
setFileName(value)
setParentPath('')
setTimeout(() => {
target.setSelectionRange(value.length, value.length)
target.scrollLeft = Number.MAX_SAFE_INTEGER
}, 0)
}}
placeholder="Name your file..."
/>
</BreadcrumbItem>
)}
<BreadcrumbItem>
<Input
id="fileName"
value={fileName}
size={20}
onInput={(event: ChangeEvent<HTMLInputElement>) => {
setFileName(event.currentTarget.value)
}}
ref={_ref => (inputRef.current = _ref)}
onBlur={rebuildPaths}
onFocus={({ target }) => {
const value = (parentPath ? parentPath + FILE_SEPERATOR : '') + fileName
setFileName(value)
setParentPath('')
setTimeout(() => {
target.setSelectionRange(value.length, value.length)
target.scrollLeft = Number.MAX_SAFE_INTEGER
}, 0)
}}
placeholder="Name your file..."
/>
</BreadcrumbItem>
</ButtonGroup.Root>
</ListActions.Left>
<ListActions.Right>
Expand Down
6 changes: 3 additions & 3 deletions apps/gitness/src/components/GitCommitDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default function GitCommitDialog({

const onSubmit = async (formValues: GitCommitFormType) => {
const { message, description, commitToGitRef, newBranchName, fileName } = formValues
const path = oldResourcePath ?? (isNew ? resourcePath + '/' + fileName : resourcePath)
const path = oldResourcePath ?? (isNew && resourcePath.length < 1 ? '/' + fileName : resourcePath)
const data: OpenapiCommitFilesRequest = {
actions: [
{
Expand Down Expand Up @@ -112,7 +112,7 @@ export default function GitCommitDialog({
const dryRun = async (commitToGitRef: CommitToGitRefOption, fileName?: string) => {
resetViolation()
setDisableCTA(false)
const path = oldResourcePath ?? (isNew ? resourcePath + '/' + fileName : resourcePath)
const path = oldResourcePath ?? (isNew && resourcePath.length < 1 ? '/' + fileName : resourcePath)
if (commitToGitRef === CommitToGitRefOption.DIRECTLY) {
try {
const data: OpenapiCommitFilesRequest = {
Expand Down Expand Up @@ -173,7 +173,7 @@ export default function GitCommitDialog({
violation={violation}
bypassable={bypassable}
defaultBranch={defaultBranch || 'Master'}
isNew={isNew}
isFileNameRequired={isNew && resourcePath?.length < 1}
/>
</DialogDescription>
</DialogContent>
Expand Down
38 changes: 20 additions & 18 deletions apps/gitness/src/components/GitCommitForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface GitCommitFormProps {
violation: boolean
bypassable: boolean
defaultBranch?: string
isNew: boolean
isFileNameRequired: boolean
}

export enum CommitToGitRefOption {
Expand Down Expand Up @@ -77,7 +77,7 @@ export function GitCommitForm({
violation,
bypassable,
defaultBranch,
isNew
isFileNameRequired
}: GitCommitFormProps) {
const { setAllStates } = useRuleViolationCheck()
const form = useZodForm({
Expand All @@ -87,12 +87,29 @@ export function GitCommitForm({
message: '',
description: '',
newBranchName: '',
fileName: isNew ? '' : undefined
fileName: isFileNameRequired ? '' : undefined
}
}) as UseFormReturn<GitCommitFormType>

return (
<Form className="space-y-6" form={form} onSubmit={onSubmit}>
<div className="grid gap-2">
{isFileNameRequired && (
<FormField
control={form.control}
name="fileName"
render={({ field }) => (
<FormItem>
<FormLabel className="text-primary">File Name</FormLabel>
<FormControl>
<Input className="text-primary" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
)}
</div>
<div className="grid gap-2">
<FormField
control={form.control}
Expand Down Expand Up @@ -122,21 +139,6 @@ export function GitCommitForm({
)}
/>

{isNew && (
<FormField
control={form.control}
name="fileName"
render={({ field }) => (
<FormItem>
<FormControl>
<Textarea className="text-primary" {...field} placeholder="Name your file" />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
)}

<FormField
control={form.control}
name="commitToGitRef"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export const CreatePullRequest = () => {
}
useEffect(() => {
// useMergeCheckMutation
setApiError(null)
mergeCheck({ queryParams: {}, repo_ref: repoRef, range: diffApiPath })
.then(({ body: value }) => {
setMergeabilty(value?.mergeable)
Expand Down
23 changes: 22 additions & 1 deletion apps/gitness/src/pages/repo/repo-summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {
ListActions,
Spacer,
StackedList,
Text
Text,
ToggleGroup,
ToggleGroupItem
} from '@harnessio/canary'
import {
RepoSummaryPanel,
Expand Down Expand Up @@ -275,6 +277,24 @@ export const RepoSummaryList: React.FC = () => {
<StackedList.Root>
<StackedList.Item isHeader disableHover>
<StackedList.Field title={<Text color="tertiaryBackground">README.md</Text>} />
<StackedList.Field
right
title={
<ToggleGroup type="single" variant="compact" size="sm">
<ToggleGroupItem
value="edit"
onClick={() =>
navigate(
`/spaces/${spaceId}/repos/${repoId}/code/edit/${gitRef || selectedBranch}/~/README.md`
)
}
title="Edit"
size="sm">
<Icon name="edit-pen" className="text-foreground size-5" />
</ToggleGroupItem>
</ToggleGroup>
}
/>
</StackedList.Item>
<StackedList.Item disableHover>
<MarkdownViewer source={decodedReadmeContent || ''} />
Expand Down Expand Up @@ -312,6 +332,7 @@ export const RepoSummaryList: React.FC = () => {
iconName: 'open-pr'
}
]}
description={repository?.description}
/>
</SandboxLayout.Content>
</SandboxLayout.Column>
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ module.exports = {
}
},
plugins: [require('@tailwindcss/typography')],
safelist: ['prose', 'prose-invert ', 'prose-headings', 'prose-p', 'prose-a', 'prose-img', 'prose-code']
safelist: ['prose', 'prose-invert', 'prose-headings', 'prose-p', 'prose-a', 'prose-img', 'prose-code']
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { memo, useEffect, useState } from 'react'
import { memo, useState } from 'react'
import { Button, Card, Input, NodeGroup, Text } from '@harnessio/canary'
import cx from 'classnames'
interface TimelineItemProps {
Expand Down Expand Up @@ -68,9 +68,7 @@ const PullRequestTimelineItem: React.FC<TimelineItemProps> = ({
// currentUser
}) => {
const [comment, setComment] = useState<string>('')
useEffect(() => {
setComment('')
}, [handleSaveComment])

return (
<NodeGroup.Root>
<NodeGroup.Icon className={cx({ 'border-transparent': hideIconBorder })}>{icon}</NodeGroup.Icon>
Expand All @@ -85,7 +83,7 @@ const PullRequestTimelineItem: React.FC<TimelineItemProps> = ({
{content}
{/* TODO: will have to eventually implement a commenting and reply system similiar to gitness */}
{!hideReply && (
<div className="flex items-center gap-3 border-t px-4 py-4">
<div className="flex items-center gap-3 border-t p-4">
{header.length > 0 && header[0].avatar}
<Input
value={comment}
Expand Down
9 changes: 6 additions & 3 deletions packages/views/src/components/repo-summary-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ interface PageProps {
title: string
details: DetailsProps[]
timestamp?: string
onAddDescription?: () => void
description?: string
}

export const RepoSummaryPanel = ({ ...props }: PageProps) => {
const { title, details, timestamp } = props
const { title, details, timestamp, onAddDescription, description } = props

return (
<div className="flex flex-col">
Expand All @@ -40,14 +42,15 @@ export const RepoSummaryPanel = ({ ...props }: PageProps) => {
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem className="flex items-center gap-1.5">
<DropdownMenuItem className="flex items-center gap-1.5" onClick={onAddDescription}>
<Icon name="plus" size={12} className="text-tertiary-background" />
<Text>Add description</Text>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>

<Spacer size={2} />
{description?.length && <Text>{description}</Text>}
<Spacer size={2} />
{timestamp && (
<Text size={1} color={'tertiaryBackground'}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ const SandboxPullRequestCompare: React.FC<SandboxPullRequestCompareProps> = ({
</Layout.Vertical>
) : (
<NoData
title={'Compare and review about anything'}
title={'Compare and review just about anything'}
description={['Branches, tags, commit ranges, and time ranges. In the same repository and across forks.']}
/>
)}
Expand Down
2 changes: 1 addition & 1 deletion packages/views/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ module.exports = {
}
},
plugins: [require('@tailwindcss/typography')],
safelist: ['prose', 'prose-invert ', 'prose-headings', 'prose-p', 'prose-a', 'prose-img', 'prose-code']
safelist: ['prose', 'prose-invert', 'prose-headings', 'prose-p', 'prose-a', 'prose-img', 'prose-code']
}

0 comments on commit b65d16d

Please sign in to comment.