Skip to content

Commit

Permalink
feat: Adds the repo empty view (harness#836)
Browse files Browse the repository at this point in the history
* feat: add repo empty view

* feat: add preview

* fix: minor design fixes

* fix: spacing
  • Loading branch information
sans-harness authored Jan 27, 2025
1 parent 61a148e commit 68c6db2
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 6 deletions.
6 changes: 6 additions & 0 deletions apps/design-system/src/pages/view-preview/view-preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { RepoBranchesView } from '@subjects/views/repo-branches'
import { RepoCommitsView } from '@subjects/views/repo-commits'
import { CreateRepoView } from '@subjects/views/repo-create'
import { RepoCreateRule } from '@subjects/views/repo-create-rule'
import { RepoEmpty } from '@subjects/views/repo-empty/repo-empty-view'
import { RepoFilesEditView } from '@subjects/views/repo-files/repo-files-edit-view'
import { RepoFilesJsonView } from '@subjects/views/repo-files/repo-files-json-view'
import { RepoFilesList } from '@subjects/views/repo-files/repo-files-list'
Expand Down Expand Up @@ -62,6 +63,11 @@ export const viewPreviews: Record<string, ReactNode> = {
<RepoSummaryViewWrapper />
</RepoViewWrapper>
),
'repo-empty': (
<RepoViewWrapper>
<RepoEmpty />
</RepoViewWrapper>
),
'repo-list': (
<RootViewWrapper>
<RepoListWrapper />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { RepoEmptyView } from '@harnessio/ui/views'

export const RepoEmpty = () => {
return (
<RepoEmptyView
httpUrl="https://github.com/mock-repo"
repoName="mock-repo"
projName="mock-project"
sshUrl="[email protected]:mock-repo.git"
/>
)
}
1 change: 1 addition & 0 deletions packages/ui/src/views/repo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export * from '@views/repo/repo-create'

// repo summary
export * from '@views/repo/repo-summary/repo-summary'
export * from '@views/repo/repo-summary/repo-empty-view'

// repo types
export * from '@views/repo/repo.types'
Expand Down
105 changes: 105 additions & 0 deletions packages/ui/src/views/repo/repo-summary/repo-empty-view.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import {
Button,
ButtonGroup,
ControlGroup,
CopyButton,
Fieldset,
FormSeparator,
Input,
MarkdownViewer,
NoData,
Spacer,
StyledLink,
Text
} from '@/components'
import { SandboxLayout } from '@/views'

interface RepoEmptyViewProps {
repoName: string
projName: string
httpUrl: string
sshUrl: string
}

export const RepoEmptyView: React.FC<RepoEmptyViewProps> = ({ repoName, projName, httpUrl, sshUrl }) => {
const getInitialCommitMarkdown = () => {
return `
\`\`\`shell
cd ${repoName}
git branch -M main
echo '# Hello World' >> README.md
git add README.md
git commit -m 'Initial commit'
git push -u origin main
\`\`\`
`
}

const getExistingRepoMarkdown = () => {
return `
\`\`\`shell
git remote add origin http://localhost:3000/git/${projName}/${repoName}.git
git branch -M main
git push -u origin main
\`\`\`
`
}
return (
<SandboxLayout.Main>
<SandboxLayout.Content className="max-w-[850px] mx-auto">
<Text size={5} weight={'medium'}>
Repository
</Text>
<Spacer size={6} />
<NoData
withBorder
iconName="no-repository"
title="This repository is empty"
description={['We recommend every repository include a', 'README, LICENSE, and .gitignore.']}
primaryButton={{ label: 'New file' }}
className="py-0 pb-0 min-h-[40vh]"
/>
<Spacer size={6} />

<Fieldset>
<Text size={4} weight="medium">
Please Generate Git Cradentials if it’s your first time cloning the repository
</Text>
<Text size={3}>Git clone URL</Text>
<Input label="HTTP" value={httpUrl} readOnly rightElement={<CopyButton name={httpUrl} />} />
<Input label="SSH" value={sshUrl} readOnly rightElement={<CopyButton name={sshUrl} />} />
<ControlGroup>
<ButtonGroup>
<Button>Generate Clone Credentials</Button>
</ButtonGroup>
<p className="mt-2">
You can also manage your git credential{' '}
<StyledLink to="/" relative="path">
here
</StyledLink>
</p>
</ControlGroup>

<FormSeparator />
<Text size={4} weight="medium">
Then push some content into it
</Text>
<MarkdownViewer source={getInitialCommitMarkdown()} />
<Text size={4} weight="medium">
Or you can push an existing repository
</Text>
<ControlGroup>
<MarkdownViewer source={getExistingRepoMarkdown()} />
<p>
You might need to{' '}
<StyledLink to="/" relative="path">
create an API token
</StyledLink>{' '}
In order to pull from or push into this repository.
</p>
</ControlGroup>
</Fieldset>
</SandboxLayout.Content>
</SandboxLayout.Main>
)
}
12 changes: 6 additions & 6 deletions packages/ui/src/views/repo/repo-summary/repo-summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { formatDate } from '@utils/utils'

import { CloneRepoDialog } from './components/clone-repo-dialog'
import SummaryPanel from './components/summary-panel'
import { RepoEmptyView } from './repo-empty-view'

interface RoutingProps {
toRepoFiles: () => string
Expand Down Expand Up @@ -119,12 +120,11 @@ export function RepoSummaryView({

if (!repoEntryPathToFileTypeMap.size) {
return (
<NoData
iconName="no-data-folder"
title="No files yet"
description={['There are no files in this repository yet.', 'Create new or import an existing file.']}
primaryButton={{ label: 'Create file' }}
secondaryButton={{ label: 'Import file' }}
<RepoEmptyView
sshUrl={repository?.git_ssh_url ?? 'could not fetch url'}
httpUrl={repository?.git_url ?? 'could not fetch url'}
repoName={repoId}
projName={spaceId}
/>
)
}
Expand Down

0 comments on commit 68c6db2

Please sign in to comment.