mirror of
https://github.com/harness/drone.git
synced 2025-05-21 11:29:52 +08:00
Enable View Raw file + optimize fetching current user (#413)
This commit is contained in:
parent
742769bba1
commit
e61be1ec2d
@ -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 { noop } from 'lodash-es'
|
||||||
import { useGet } from 'restful-react'
|
import { useGet } from 'restful-react'
|
||||||
import type { AppProps } from 'AppProps'
|
import type { AppProps } from 'AppProps'
|
||||||
@ -33,8 +34,13 @@ export const AppContextProvider: React.FC<{ value: AppProps }> = React.memo(func
|
|||||||
value: initialValue,
|
value: initialValue,
|
||||||
children
|
children
|
||||||
}) {
|
}) {
|
||||||
|
const lazy = useMemo(
|
||||||
|
() => initialValue.standalone && !!matchPath(location.pathname, { path: '/(signin|register)' }),
|
||||||
|
[initialValue.standalone]
|
||||||
|
)
|
||||||
const { data: currentUser = defaultCurrentUser } = useGet({
|
const { data: currentUser = defaultCurrentUser } = useGet({
|
||||||
path: '/api/v1/user'
|
path: '/api/v1/user',
|
||||||
|
lazy
|
||||||
})
|
})
|
||||||
const [appStates, setAppStates] = useState<AppProps>(initialValue)
|
const [appStates, setAppStates] = useState<AppProps>(initialValue)
|
||||||
|
|
||||||
|
@ -36,7 +36,6 @@ import NewPipeline from 'pages/NewPipeline/NewPipeline'
|
|||||||
export const RouteDestinations: React.FC = React.memo(function RouteDestinations() {
|
export const RouteDestinations: React.FC = React.memo(function RouteDestinations() {
|
||||||
const { getString } = useStrings()
|
const { getString } = useStrings()
|
||||||
const repoPath = `${pathProps.space}/${pathProps.repoName}`
|
const repoPath = `${pathProps.space}/${pathProps.repoName}`
|
||||||
|
|
||||||
const { OPEN_SOURCE_PIPELINES, OPEN_SOURCE_SECRETS } = useFeatureFlag()
|
const { OPEN_SOURCE_PIPELINES, OPEN_SOURCE_SECRETS } = useFeatureFlag()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -31,6 +31,7 @@ import { useAppContext } from 'AppContext'
|
|||||||
import { LatestCommitForFile } from 'components/LatestCommit/LatestCommit'
|
import { LatestCommitForFile } from 'components/LatestCommit/LatestCommit'
|
||||||
import { useCommitModal } from 'components/CommitModalButton/CommitModalButton'
|
import { useCommitModal } from 'components/CommitModalButton/CommitModalButton'
|
||||||
import { useStrings } from 'framework/strings'
|
import { useStrings } from 'framework/strings'
|
||||||
|
import { getConfig } from 'services/config'
|
||||||
import { OptionsMenuButton } from 'components/OptionsMenuButton/OptionsMenuButton'
|
import { OptionsMenuButton } from 'components/OptionsMenuButton/OptionsMenuButton'
|
||||||
import { PlainButton } from 'components/PlainButton/PlainButton'
|
import { PlainButton } from 'components/PlainButton/PlainButton'
|
||||||
import { CommitsView } from 'components/CommitsView/CommitsView'
|
import { CommitsView } from 'components/CommitsView/CommitsView'
|
||||||
@ -57,7 +58,6 @@ export function FileContent({
|
|||||||
useFileContentViewerDecision({ repoMetadata, gitRef, resourcePath, resourceContent })
|
useFileContentViewerDecision({ repoMetadata, gitRef, resourcePath, resourceContent })
|
||||||
const history = useHistory()
|
const history = useHistory()
|
||||||
const [activeTab, setActiveTab] = React.useState<string>(FileSection.CONTENT)
|
const [activeTab, setActiveTab] = React.useState<string>(FileSection.CONTENT)
|
||||||
|
|
||||||
const content = useMemo(
|
const content = useMemo(
|
||||||
() => decodeGitContent((resourceContent?.content as RepoFileContent)?.data),
|
() => decodeGitContent((resourceContent?.content as RepoFileContent)?.data),
|
||||||
[resourceContent?.content]
|
[resourceContent?.content]
|
||||||
@ -199,13 +199,18 @@ export function FileContent({
|
|||||||
style={{ padding: '5px' }}
|
style={{ padding: '5px' }}
|
||||||
width="145px"
|
width="145px"
|
||||||
items={[
|
items={[
|
||||||
// {
|
{
|
||||||
// hasIcon: true,
|
hasIcon: true,
|
||||||
// iconName: 'arrow-right',
|
iconName: 'arrow-right',
|
||||||
// text: getString('viewRaw'),
|
text: getString('viewRaw'),
|
||||||
// onClick: () => window.open(rawURL, '_blank') // TODO: This is still not working due to token is not stored in cookies
|
onClick: () => {
|
||||||
// },
|
const url = standalone
|
||||||
// '-',
|
? rawURL.replace(/^\/code/, '')
|
||||||
|
: getConfig(rawURL).replace('//', '/')
|
||||||
|
window.open(url, '_blank')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'-',
|
||||||
{
|
{
|
||||||
hasIcon: true,
|
hasIcon: true,
|
||||||
iconName: 'cloud-download',
|
iconName: 'cloud-download',
|
||||||
@ -243,6 +248,7 @@ export function FileContent({
|
|||||||
<Match expr={isViewable}>
|
<Match expr={isViewable}>
|
||||||
<Falsy>
|
<Falsy>
|
||||||
<Center>
|
<Center>
|
||||||
|
rawURL: {rawURL}
|
||||||
<Link
|
<Link
|
||||||
to={rawURL} // TODO: Link component generates wrong copy link
|
to={rawURL} // TODO: Link component generates wrong copy link
|
||||||
onClick={e => {
|
onClick={e => {
|
||||||
|
Loading…
Reference in New Issue
Block a user