Disable branch creation when committing first new file into an empty repo (#217)

This commit is contained in:
Tan Nhu 2023-01-16 12:20:09 -08:00 committed by GitHub
parent 797e339e02
commit 92c82f5c44
4 changed files with 9 additions and 3 deletions

View File

@ -50,6 +50,7 @@ interface CommitModalButtonProps extends Omit<ButtonProps, 'onClick' | 'onSubmit
gitRef: string
resourcePath: string
commitTitlePlaceHolder: string
disableBranchCreation?: boolean
oldResourcePath?: string
payload?: string
sha?: string
@ -63,6 +64,7 @@ export const CommitModalButton: React.FC<CommitModalButtonProps> = ({
resourcePath,
commitTitlePlaceHolder,
oldResourcePath,
disableBranchCreation = false,
payload = '',
sha,
onSuccess,
@ -172,6 +174,7 @@ export const CommitModalButton: React.FC<CommitModalButtonProps> = ({
)}>
<FormInput.RadioGroup
name="branch"
disabled={disableBranchCreation}
label=""
onChange={e => {
setTargetBranchOption(get(e.target, 'defaultValue'))

View File

@ -25,8 +25,8 @@ export function useGetResourceContent({
lazy: !repoMetadata || lazy
})
const isRepositoryEmpty = useMemo(
() => repoMetadata && error && !data && response?.status === 404,
[repoMetadata, error, data, response]
() => (repoMetadata && resourcePath === '' && error && response?.status === 404) || false,
[repoMetadata, resourcePath, error, response]
)
return { data, error: isRepositoryEmpty ? undefined : error, loading, refetch, response, isRepositoryEmpty }

View File

@ -15,9 +15,10 @@ import css from './FileEditor.module.scss'
interface EditorProps extends Pick<GitInfoProps, 'repoMetadata' | 'gitRef' | 'resourcePath'> {
resourceContent: GitInfoProps['resourceContent'] | null
isRepositoryEmpty: boolean
}
function Editor({ resourceContent, repoMetadata, gitRef, resourcePath }: EditorProps) {
function Editor({ resourceContent, repoMetadata, gitRef, resourcePath, isRepositoryEmpty }: EditorProps) {
const history = useHistory()
const inputRef = useRef<HTMLInputElement | null>()
const isNew = useMemo(() => !resourceContent || isDir(resourceContent), [resourceContent])
@ -200,6 +201,7 @@ function Editor({ resourceContent, repoMetadata, gitRef, resourcePath }: EditorP
}
setOriginalContent(content)
}}
disableBranchCreation={isRepositoryEmpty}
/>
<Button
text={getString('cancel')}

View File

@ -35,6 +35,7 @@ export default function RepositoryFileEdit() {
gitRef={gitRef}
resourcePath={resourcePath}
resourceContent={resourceContent}
isRepositoryEmpty={isRepositoryEmpty}
/>
)}
</Container>