Skip to content

Commit

Permalink
Merge branch 'main' into account-settings
Browse files Browse the repository at this point in the history
  • Loading branch information
yasell committed Jan 29, 2025
2 parents 3b62ed9 + 0397383 commit c5d464d
Show file tree
Hide file tree
Showing 106 changed files with 3,855 additions and 868 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 @@ -21,6 +21,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 @@ -65,6 +66,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
Expand Up @@ -25,6 +25,8 @@ const PullRequestCompareWrapper: FC<Partial<PullRequestComparePageProps>> = prop

return (
<PullRequestComparePage
desc=""
setDesc={noop}
handleDeleteReviewer={noop}
handleAddReviewer={noop}
onFormSubmit={noop}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ const PullRequestConversation: FC<PullRequestConversationProps> = ({ state }) =>
handleSaveComment={noop}
currentUser={{ display_name: currentUserData?.display_name, uid: currentUserData?.uid }}
onCopyClick={noop}
onCommentSaveAndStatusChange={noop}
toggleConversationStatus={noop}
onCommitSuggestion={noop}
addSuggestionToBatch={noop}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,144 @@ export const mockPullRequestActions = [
]

export const mockActivities = [
{
id: 795,
created: 1737660580605,
updated: 1737660580605,
edited: 1737660580605,
parent_id: null,
repo_id: 22,
pullreq_id: 174,
order: 2,
sub_order: 0,
type: 'code-comment',
kind: 'change-comment',
text: 'We should add type checking for this function to improve type safety',
payload: {
title: '@@ -0,0 +1,4 @@',
lines: [
"+import tailwindcssAnimate from 'tailwindcss-animate'",
"+import { PluginAPI } from 'tailwindcss/types/config'",
'+',
'+export default {'
],
line_start_new: true,
line_end_new: true
},
author: {
id: 3,
uid: 'admin',
display_name: 'Administrator',
email: '[email protected]',
type: 'user',
created: 1699863416002,
updated: 1699863416002
},
resolved: 1737660580605,
resolver: {
id: 3,
uid: 'admin',
display_name: 'Administrator',
email: '[email protected]',
type: 'user',
created: 1699863416002,
updated: 1699863416002
},
code_comment: {
outdated: false,
merge_base_sha: '12421f51a7cca90376cba8de0fe9b3289eb6e218',
source_sha: '34f4d7bbfeda153e4965395ac6a20e80dec63e57',
path: 'packages/canary/configs/tailwind.ts',
line_new: 2,
span_new: 1,
line_old: 0,
span_old: 0
}
},
{
id: 796,
created: 1737660580605,
updated: 1737660580605,
edited: 1737660580605,
parent_id: null,
repo_id: 22,
pullreq_id: 174,
order: 2,
sub_order: 0,
type: 'comment',
kind: 'comment',
text: 'Should we consider adding unit tests for the new animation components?',
payload: {},
author: {
id: 3,
uid: 'admin',
display_name: 'Administrator',
email: '[email protected]',
type: 'user',
created: 1699863416002,
updated: 1699863416002
},
resolved: 1737660580607,
resolver: {
id: 3,
uid: 'admin',
display_name: 'Administrator',
email: '[email protected]',
type: 'user',
created: 1699863416002,
updated: 1699863416002
}
},

{
id: 797,
created: 1737660580606,
updated: 1737660580606,
edited: 1737660580606,
parent_id: 796,
repo_id: 22,
pullreq_id: 174,
order: 2,
sub_order: 1,
type: 'comment',
kind: 'comment',
text: 'Yes, I agree. I will add tests for basic animations first.',
payload: {},
author: {
id: 3,
uid: 'admin',
display_name: 'Administrator',
email: '[email protected]',
type: 'user',
created: 1699863416002,
updated: 1699863416002
}
},

{
id: 798,
created: 1737660580607,
updated: 1737660580607,
edited: 1737660580607,
parent_id: 796,
repo_id: 22,
pullreq_id: 174,
order: 2,
sub_order: 2,
type: 'comment',
kind: 'comment',
text: 'Tests have been added in PR #123. We can close this discussion.',
payload: {},
author: {
id: 3,
uid: 'admin',
display_name: 'Administrator',
email: '[email protected]',
type: 'user',
created: 1699863416002,
updated: 1699863416002
}
},
{
id: 792,
created: 1737660563002,
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"
/>
)
}
19 changes: 9 additions & 10 deletions apps/gitness/src/AppMFE.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,27 @@ import { MFEContext } from './framework/context/MFEContext'
import { NavigationProvider } from './framework/context/NavigationContext'
import { ThemeProvider, useThemeStore } from './framework/context/ThemeContext'
import { queryClient } from './framework/queryClient'
import { extractRedirectRouteObjects } from './framework/routing/utils'
import { useLoadMFEStyles } from './hooks/useLoadMFEStyles'
import i18n from './i18n/i18n'
import { extractRedirectRouteObjects, mfeRoutes, repoRoutes } from './routes'
import { mfeRoutes, repoRoutes } from './routes'

export interface MFERouteRendererProps {
renderUrl: string
parentLocationPath: string
onRouteChange: (updatedLocationPathname: string) => void
}

const filteredRoutes = extractRedirectRouteObjects(repoRoutes)
const isRouteMatchingRedirectRoutes = (pathToValidate: string) => {
return filteredRoutes.every(route => !matchPath(`/${route.path}` as string, pathToValidate))
const filteredRedirectRoutes = extractRedirectRouteObjects(repoRoutes)
const isRouteNotMatchingRedirectRoutes = (pathToValidate: string) => {
return filteredRedirectRoutes.every(route => !matchPath(`/${route.path}` as string, pathToValidate))
}

function MFERouteRenderer({ renderUrl, parentLocationPath, onRouteChange }: MFERouteRendererProps) {
const navigate = useNavigate()
const location = useLocation()
const parentPath = parentLocationPath.replace(renderUrl, '')
const isNotRedirectPath = isRouteMatchingRedirectRoutes(location.pathname)
const isNotRedirectPath = isRouteNotMatchingRedirectRoutes(location.pathname)

/**
* renderUrl ==> base URL of parent application
Expand All @@ -50,20 +51,18 @@ function MFERouteRenderer({ renderUrl, parentLocationPath, onRouteChange }: MFER
)

// Handle location change detected from parent route

useEffect(() => {
if (canNavigate) {
const pathToNavigate = parentLocationPath.replace(renderUrl, '')
navigate(pathToNavigate, { replace: true })
navigate(parentPath, { replace: true })
}
}, [parentLocationPath])
}, [parentPath])

// Notify parent about route change
useEffect(() => {
if (canNavigate) {
onRouteChange?.(`${renderUrl}${location.pathname}`)
}
}, [location])
}, [location.pathname])

return null
}
Expand Down
2 changes: 1 addition & 1 deletion apps/gitness/src/components-v2/app-shell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export const AppShellMFE = () => {
function BreadcrumbsAndOutlet({ className }: { className?: string }) {
return (
<div className={cn('flex flex-col', className)}>
<div className="layer-high bg-background-1 sticky top-0">
<div className="layer-high sticky top-0 bg-background-1">
<Breadcrumbs />
</div>
<Outlet />
Expand Down
12 changes: 9 additions & 3 deletions apps/gitness/src/framework/context/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { ProfileSettingsErrorType } from '@harnessio/ui/views'

import useLocalStorage from '../hooks/useLocalStorage'
import usePageTitle from '../hooks/usePageTitle'

interface AppContextType {
spaces: TypesSpace[]
Expand Down Expand Up @@ -45,6 +46,7 @@ const AppContext = createContext<AppContextType>({
})

export const AppProvider: FC<{ children: ReactNode }> = ({ children }) => {
usePageTitle()
const [spaces, setSpaces] = useState<TypesSpace[]>([])
const [currentUser, setCurrentUser] = useLocalStorage<TypesUser>('currentUser', {})
const [isLoadingUser, setIsLoadingUser] = useState(false)
Expand Down Expand Up @@ -89,14 +91,18 @@ export const AppProvider: FC<{ children: ReactNode }> = ({ children }) => {
}

useEffect(() => {
Promise.all([
Promise.allSettled([
membershipSpaces({
queryParams: { page: 1, limit: 100, sort: 'identifier', order: 'asc' }
}),
fetchUser()
])
.then(([membershipResponse]) => {
setSpaces(membershipResponse.body.filter(item => item?.space).map(item => item.space as TypesSpace))
.then(results => {
const [membershipResult] = results

if (membershipResult.status === 'fulfilled') {
setSpaces(membershipResult.value.body.filter(item => item?.space).map(item => item.space as TypesSpace))
}
})
.catch(() => {
// Optionally handle error or show toast
Expand Down
28 changes: 28 additions & 0 deletions apps/gitness/src/framework/hooks/usePageTitle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { useEffect } from 'react'
import { useMatches } from 'react-router-dom'

import { useTranslationStore } from '../../i18n/stores/i18n-store'
import { CustomHandle } from '../routing/types'

const usePageTitle = () => {
const { t } = useTranslationStore()
const matches = useMatches()

useEffect(() => {
const fullPageTitle = matches
.reduce<string[]>((titles, match) => {
const { pageTitle } = (match.handle || {}) as CustomHandle
if (typeof pageTitle === 'string') {
titles.push(pageTitle)
} else if (typeof pageTitle === 'function') {
titles.push(pageTitle(match.params))
}
return titles
}, [])
.join(' | ')

document.title = fullPageTitle || t('views:app.harnessOpenSource', 'Harness Open Source')
}, [matches, t])
}

export default usePageTitle
8 changes: 7 additions & 1 deletion apps/gitness/src/framework/routing/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum RouteConstants {
toSignIn = 'toSignIn',
toCreateRepo = 'toCreateRepo',
toImportRepo = 'toImportRepo',
toImportMultipleRepos = 'toImportMultipleRepos',
toRepositories = 'toRepositories',
toRepoSummary = 'toRepoSummary',
toRepoCommits = 'toRepoCommits',
Expand Down Expand Up @@ -88,7 +89,7 @@ export interface CustomHandle {
/**
* Defines the breadcrumb text or label using route parameters.
*/
breadcrumb?: (params: Params<string>) => string
breadcrumb?: (params: Params<string>) => string | JSX.Element

/**
* Renders the breadcrumb as a custom React component instead of a link.
Expand All @@ -99,6 +100,11 @@ export interface CustomHandle {
* Associated route name for the breadcrumb.
*/
routeName?: string

/**
* Updates the document title based on route parameters.
*/
pageTitle?: string | ((params: Params<string>) => string)
}

// Intersection of RouteObject with the custom handle
Expand Down
19 changes: 18 additions & 1 deletion apps/gitness/src/framework/routing/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Params } from 'react-router-dom'
import { Navigate, Params } from 'react-router-dom'

import '../context/NavigationContext'

Expand Down Expand Up @@ -77,3 +77,20 @@ export const getRouteMapping = ({
const routeEntries = generateRouteEntries({ routes, parentPath, parentName })
return generateRouteNameToPathFunctions(routeEntries)
}

export const extractRedirectRouteObjects = (routes: CustomRouteObject[]): CustomRouteObject[] => {
const navigateObjects: CustomRouteObject[] = []
const traverseRoutes = (routes: CustomRouteObject[], currentPath: string = '') => {
for (const route of routes) {
const newPath = currentPath ? `${currentPath}${route.path ? `/${route.path}` : ''}` : (route.path ?? '')
if ((route.element as JSX.Element)?.type === Navigate) {
navigateObjects.push({ ...route, path: newPath })
}
if (route.children) {
traverseRoutes(route.children, newPath)
}
}
}
traverseRoutes(routes)
return navigateObjects
}
Loading

0 comments on commit c5d464d

Please sign in to comment.