Enable View Raw file + optimize fetching current user (#413)

This commit is contained in:
Tan Nhu 2023-09-08 15:51:54 +00:00 committed by Harness
parent f3d05107ac
commit 1a477a23a0
3 changed files with 22 additions and 11 deletions

View File

@ -1,4 +1,5 @@
import React, { useState, useContext, useEffect } from 'react'
import React, { useState, useContext, useEffect, useMemo } from 'react'
import { matchPath } from 'react-router-dom'
import { noop } from 'lodash-es'
import { useGet } from 'restful-react'
import type { AppProps } from 'AppProps'
@ -33,8 +34,13 @@ export const AppContextProvider: React.FC<{ value: AppProps }> = React.memo(func
value: initialValue,
children
}) {
const lazy = useMemo(
() => initialValue.standalone && !!matchPath(location.pathname, { path: '/(signin|register)' }),
[initialValue.standalone]
)
const { data: currentUser = defaultCurrentUser } = useGet({
path: '/api/v1/user'
path: '/api/v1/user',
lazy
})
const [appStates, setAppStates] = useState<AppProps>(initialValue)

View File

@ -36,7 +36,6 @@ import NewPipeline from 'pages/NewPipeline/NewPipeline'
export const RouteDestinations: React.FC = React.memo(function RouteDestinations() {
const { getString } = useStrings()
const repoPath = `${pathProps.space}/${pathProps.repoName}`
const { OPEN_SOURCE_PIPELINES, OPEN_SOURCE_SECRETS } = useFeatureFlag()
return (

View File

@ -31,6 +31,7 @@ import { useAppContext } from 'AppContext'
import { LatestCommitForFile } from 'components/LatestCommit/LatestCommit'
import { useCommitModal } from 'components/CommitModalButton/CommitModalButton'
import { useStrings } from 'framework/strings'
import { getConfig } from 'services/config'
import { OptionsMenuButton } from 'components/OptionsMenuButton/OptionsMenuButton'
import { PlainButton } from 'components/PlainButton/PlainButton'
import { CommitsView } from 'components/CommitsView/CommitsView'
@ -57,7 +58,6 @@ export function FileContent({
useFileContentViewerDecision({ repoMetadata, gitRef, resourcePath, resourceContent })
const history = useHistory()
const [activeTab, setActiveTab] = React.useState<string>(FileSection.CONTENT)
const content = useMemo(
() => decodeGitContent((resourceContent?.content as RepoFileContent)?.data),
[resourceContent?.content]
@ -199,13 +199,18 @@ export function FileContent({
style={{ padding: '5px' }}
width="145px"
items={[
// {
// hasIcon: true,
// iconName: 'arrow-right',
// text: getString('viewRaw'),
// onClick: () => window.open(rawURL, '_blank') // TODO: This is still not working due to token is not stored in cookies
// },
// '-',
{
hasIcon: true,
iconName: 'arrow-right',
text: getString('viewRaw'),
onClick: () => {
const url = standalone
? rawURL.replace(/^\/code/, '')
: getConfig(rawURL).replace('//', '/')
window.open(url, '_blank')
}
},
'-',
{
hasIcon: true,
iconName: 'cloud-download',
@ -243,6 +248,7 @@ export function FileContent({
<Match expr={isViewable}>
<Falsy>
<Center>
rawURL: {rawURL}
<Link
to={rawURL} // TODO: Link component generates wrong copy link
onClick={e => {