feat: [AH-1026]: support python package type in artifact and version pages (#3523)

* feat: [AH-1026]: support actions at python version level
* feat: [AH-1026]: support python package type in artifact and version pages
try-new-ui
Shivanand Sonnad 2025-03-07 11:09:00 +00:00 committed by Harness
parent 9572478b86
commit b4b6305c80
15 changed files with 483 additions and 0 deletions

View File

@ -0,0 +1,23 @@
/*
* Copyright 2024 Harness, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
.cardContainer {
width: 60% !important;
min-width: 1040px;
padding: var(--spacing-7) !important;
background-color: var(--white);
margin: var(--spacing-large);
}

View File

@ -0,0 +1,19 @@
/*
* Copyright 2023 Harness, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint-disable */
// This is an auto-generated file
export declare const cardContainer: string

View File

@ -0,0 +1,94 @@
/*
* Copyright 2024 Harness, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react'
import { Layout } from '@harnessio/uicore'
import type { ArtifactVersionSummary } from '@harnessio/react-har-service-client'
import { String } from '@ar/frameworks/strings'
import { RepositoryPackageType } from '@ar/common/types'
import { VersionListColumnEnum } from '@ar/pages/version-list/components/VersionListTable/types'
import ArtifactActions from '@ar/pages/artifact-details/components/ArtifactActions/ArtifactActions'
import VersionListTable, {
type CommonVersionListTableProps
} from '@ar/pages/version-list/components/VersionListTable/VersionListTable'
import {
type ArtifactActionProps,
type VersionActionProps,
type VersionDetailsHeaderProps,
type VersionDetailsTabProps,
type VersionListTableProps,
VersionStep
} from '@ar/frameworks/Version/Version'
import VersionActions from '../components/VersionActions/VersionActions'
import { VersionDetailsTab } from '../components/VersionDetailsTabs/constants'
import PythonVersionOverviewPage from './pages/overview/PythonVersionOverviewPage'
import PythonVersionArtifactDetailsPage from './pages/artifact-dertails/PythonVersionArtifactDetailsPage'
import VersionDetailsHeaderContent from '../components/VersionDetailsHeaderContent/VersionDetailsHeaderContent'
export class PythonVersionType extends VersionStep<ArtifactVersionSummary> {
protected packageType = RepositoryPackageType.PYTHON
protected allowedVersionDetailsTabs: VersionDetailsTab[] = [
VersionDetailsTab.OVERVIEW,
VersionDetailsTab.ARTIFACT_DETAILS,
VersionDetailsTab.CODE
]
versionListTableColumnConfig: CommonVersionListTableProps['columnConfigs'] = {
[VersionListColumnEnum.Name]: { width: '150%' },
[VersionListColumnEnum.Size]: { width: '100%' },
[VersionListColumnEnum.FileCount]: { width: '100%' },
[VersionListColumnEnum.DownloadCount]: { width: '100%' },
[VersionListColumnEnum.PullCommand]: { width: '100%' },
[VersionListColumnEnum.LastModified]: { width: '100%' },
[VersionListColumnEnum.Actions]: { width: '30%' }
}
renderVersionListTable(props: VersionListTableProps): JSX.Element {
return <VersionListTable {...props} columnConfigs={this.versionListTableColumnConfig} />
}
renderVersionDetailsHeader(props: VersionDetailsHeaderProps<ArtifactVersionSummary>): JSX.Element {
return <VersionDetailsHeaderContent {...props} />
}
renderVersionDetailsTab(props: VersionDetailsTabProps): JSX.Element {
switch (props.tab) {
case VersionDetailsTab.OVERVIEW:
return <PythonVersionOverviewPage />
case VersionDetailsTab.ARTIFACT_DETAILS:
return <PythonVersionArtifactDetailsPage />
case VersionDetailsTab.OSS:
return (
<Layout.Vertical spacing="xlarge">
<PythonVersionOverviewPage />
<PythonVersionArtifactDetailsPage />
</Layout.Vertical>
)
default:
return <String stringID="tabNotFound" />
}
}
renderArtifactActions(props: ArtifactActionProps): JSX.Element {
return <ArtifactActions {...props} />
}
renderVersionActions(props: VersionActionProps): JSX.Element {
return <VersionActions {...props} />
}
}

View File

@ -0,0 +1,66 @@
/*
* Copyright 2024 Harness, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React, { useCallback } from 'react'
import { Layout } from '@harnessio/uicore'
import { useParentHooks } from '@ar/hooks'
import { useStrings } from '@ar/frameworks/strings'
import { ButtonTab, ButtonTabs } from '@ar/components/ButtonTabs/ButtonTabs'
import VersionFilesProvider from '@ar/pages/version-details/context/VersionFilesProvider'
import PythonVersionFilesContent from './PythonVersionFilesContent'
import PythonVersionReadmeContent from './PythonVersionReadmeContent'
import { PythonArtifactDetailsTabEnum, type PythonVersionDetailsQueryParams } from '../../types'
export default function PythonVersionArtifactDetailsPage() {
const { getString } = useStrings()
const { useUpdateQueryParams, useQueryParams } = useParentHooks()
const { updateQueryParams } = useUpdateQueryParams()
const { detailsTab = PythonArtifactDetailsTabEnum.ReadMe } = useQueryParams<PythonVersionDetailsQueryParams>()
const handleTabChange = useCallback(
(nextTab: PythonArtifactDetailsTabEnum): void => {
updateQueryParams({ detailsTab: nextTab })
},
[updateQueryParams]
)
return (
<Layout.Vertical padding="large" spacing="large">
<ButtonTabs small bold selectedTabId={detailsTab} onChange={handleTabChange}>
<ButtonTab
id={PythonArtifactDetailsTabEnum.ReadMe}
icon="document"
iconProps={{ size: 12 }}
panel={<PythonVersionReadmeContent />}
title={getString('versionDetails.artifactDetails.tabs.readme')}
/>
<ButtonTab
id={PythonArtifactDetailsTabEnum.Files}
icon="document"
iconProps={{ size: 12 }}
panel={
<VersionFilesProvider>
<PythonVersionFilesContent />
</VersionFilesProvider>
}
title={getString('versionDetails.artifactDetails.tabs.files')}
/>
</ButtonTabs>
</Layout.Vertical>
)
}

View File

@ -0,0 +1,35 @@
/*
* Copyright 2024 Harness, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React, { useContext } from 'react'
import { DEFAULT_PAGE_INDEX } from '@ar/constants'
import { VersionFilesContext } from '@ar/pages/version-details/context/VersionFilesProvider'
import ArtifactFileListTable from '@ar/pages/version-details/components/ArtifactFileListTable/ArtifactFileListTable'
export default function PythonVersionFilesContent() {
const { data, updateQueryParams, sort } = useContext(VersionFilesContext)
return (
<ArtifactFileListTable
data={data}
gotoPage={pageNumber => updateQueryParams({ page: pageNumber })}
setSortBy={sortArr => {
updateQueryParams({ sort: sortArr, page: DEFAULT_PAGE_INDEX })
}}
sortBy={sort}
/>
)
}

View File

@ -0,0 +1,28 @@
/*
* Copyright 2024 Harness, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react'
import { Container } from '@harnessio/uicore'
import ReadmeFileContent from '@ar/pages/version-details/components/ReadmeFileContent/ReadmeFileContent'
import { MOCK_README_CONTENT } from './mockData'
export default function PythonVersionReadmeContent() {
return (
<Container>
<ReadmeFileContent source={MOCK_README_CONTENT} />
</Container>
)
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,97 @@
/*
* Copyright 2024 Harness, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React, { useContext } from 'react'
import { defaultTo } from 'lodash-es'
import { FontVariation } from '@harnessio/design-system'
import { Card, Container, Layout, Text } from '@harnessio/uicore'
import type { ArtifactDetail, PythonArtifactDetailConfig } from '@harnessio/react-har-service-client'
import { useStrings } from '@ar/frameworks/strings'
import { DEFAULT_DATE_TIME_FORMAT } from '@ar/constants'
import { getReadableDateTime } from '@ar/common/dateUtils'
import { LabelValueTypeEnum } from '@ar/pages/version-details/components/LabelValueContent/type'
import { VersionOverviewContext } from '@ar/pages/version-details/context/VersionOverviewProvider'
import { LabelValueContent } from '@ar/pages/version-details/components/LabelValueContent/LabelValueContent'
import css from './overview.module.scss'
interface PythonVersionGeneralInfoProps {
className?: string
}
export default function PythonVersionGeneralInfo(props: PythonVersionGeneralInfoProps) {
const { className } = props
const contextValue = useContext(VersionOverviewContext)
const data = contextValue.data as ArtifactDetail & PythonArtifactDetailConfig
const { getString } = useStrings()
return (
<Card
data-testid="general-information-card"
className={className}
title={getString('versionDetails.overview.generalInformation.title')}>
<Layout.Vertical spacing="medium">
<Text font={{ variation: FontVariation.CARD_TITLE }}>
{getString('versionDetails.overview.generalInformation.title')}
</Text>
<Container className={css.gridContainer}>
<LabelValueContent
label={getString('versionDetails.overview.generalInformation.packageType')}
value={getString('packageTypes.pythonPackage')}
type={LabelValueTypeEnum.PackageType}
icon="python"
/>
<LabelValueContent
label={getString('versionDetails.overview.generalInformation.size')}
value={data.size}
type={LabelValueTypeEnum.Text}
/>
<LabelValueContent
label={getString('versionDetails.overview.generalInformation.downloads')}
value={defaultTo(data.downloadCount?.toLocaleString(), 0)}
type={LabelValueTypeEnum.Text}
/>
<LabelValueContent
label={getString('versionDetails.overview.generalInformation.repository')}
value={data.repository}
type={LabelValueTypeEnum.Link}
/>
<LabelValueContent
label={getString('versionDetails.overview.generalInformation.homepage')}
value={data.homepage}
type={LabelValueTypeEnum.Link}
/>
<LabelValueContent
label={getString('versionDetails.overview.generalInformation.license')}
value={data.license}
type={LabelValueTypeEnum.Text}
/>
<LabelValueContent
label={getString('versionDetails.overview.generalInformation.uploadedBy')}
value={getReadableDateTime(Number(data.modifiedAt), DEFAULT_DATE_TIME_FORMAT)}
type={LabelValueTypeEnum.Text}
/>
<LabelValueContent
label={getString('versionDetails.overview.generalInformation.pullCommand')}
value={data.pullCommand}
type={LabelValueTypeEnum.CommandBlock}
/>
</Container>
</Layout.Vertical>
</Card>
)
}

View File

@ -0,0 +1,31 @@
/*
* Copyright 2024 Harness, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react'
import VersionOverviewProvider from '@ar/pages/version-details/context/VersionOverviewProvider'
import PythonVersionGeneralInfo from './PythonVersionGeneralInfo'
import genericStyles from '../../PythonVersion.module.scss'
export default function PythonVersionOverviewPage() {
return (
<VersionOverviewProvider>
<PythonVersionGeneralInfo className={genericStyles.cardContainer} />
</VersionOverviewProvider>
)
}

View File

@ -0,0 +1,23 @@
/*
* Copyright 2024 Harness, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
.gridContainer {
align-items: center;
display: grid;
grid-template-columns: max-content auto;
row-gap: var(--spacing-medium);
column-gap: 30px;
}

View File

@ -0,0 +1,19 @@
/*
* Copyright 2023 Harness, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint-disable */
// This is an auto-generated file
export declare const gridContainer: string

View File

@ -0,0 +1,26 @@
/*
* Copyright 2024 Harness, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import type { VersionDetailsQueryParams } from '../types'
export enum PythonArtifactDetailsTabEnum {
ReadMe = 'readme',
Files = 'files'
}
export interface PythonVersionDetailsQueryParams extends VersionDetailsQueryParams {
detailsTab: PythonArtifactDetailsTabEnum
digest: string
}

View File

@ -20,9 +20,11 @@ import { HelmVersionType } from './HelmVersion/HelmVersionType'
import { GenericVersionType } from './GenericVersion/GenericVersionType'
import { MavenVersionType } from './MavenVersion/MavenVersion'
import { NpmVersionType } from './NpmVersion/NpmVersionType'
import { PythonVersionType } from './PythonVersion/PythonVersionType'
versionFactory.registerStep(new DockerVersionType())
versionFactory.registerStep(new HelmVersionType())
versionFactory.registerStep(new GenericVersionType())
versionFactory.registerStep(new MavenVersionType())
versionFactory.registerStep(new NpmVersionType())
versionFactory.registerStep(new PythonVersionType())

View File

@ -77,6 +77,7 @@ packageTypes:
genericPackage: Generic
mavenPackage: Maven Package
npmPackage: npm
pythonPackage: Python Package
repositoryTypes:
docker: Docker
helm: Helm

View File

@ -354,6 +354,7 @@ export interface StringsMap {
'packageTypes.helmPackage': string
'packageTypes.mavenPackage': string
'packageTypes.npmPackage': string
'packageTypes.pythonPackage': string
plaintext: string
plusNewName: string
prod: string