Skip to content
Merged
15 changes: 1 addition & 14 deletions src/components/Catalog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { useTranslation } from 'react-i18next'
import { useHistory, useLocation } from 'react-router-dom'
import { useSession } from 'providers/Session'
import { applyAclToUiSchema, getSpec } from 'common/api-spec'
import { useAppDispatch, useAppSelector } from 'redux/hooks'
import { useAppDispatch } from 'redux/hooks'
import { setError } from 'redux/reducers'
import { makeStyles } from 'tss-react/mui'
import { cleanLink } from 'utils/data'
Expand Down Expand Up @@ -135,7 +135,6 @@ export default function ({
const { classes } = useStyles()
const dispatch = useAppDispatch()
const { user } = useSession()
const globalError = useAppSelector(({ global: { error } }) => error)
const hash = location.hash.substring(1)
const hashMap = {
info: 0,
Expand All @@ -150,20 +149,8 @@ export default function ({
}
const [data, setData] = useState<any>(workload)
const [workloadValues, setWorkloadValues] = useState<any>(values)
const [scrollPosition, setScrollPosition] = useState(0)
const icon = data?.icon || '/logos/akamai_logo.svg'

const handleScroll = () => {
const position = window.scrollY
setScrollPosition(position)
}
useEffect(() => {
window.addEventListener('scroll', handleScroll, { passive: true })
return () => {
window.removeEventListener('scroll', handleScroll)
}
}, [])

useEffect(() => {
if (!workload) return
setWorkloadValues(values)
Expand Down
34 changes: 6 additions & 28 deletions src/components/Catalogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,12 @@ interface Props {

// TODO: this needs to be fetched from APL Api
interface NewChartValues {
url: string
chartName: string
gitRepositoryUrl: string
chartTargetDirName: string
chartIcon?: string
chartPath: string
revision: string
allowTeams: boolean
}

interface NewChartPayload extends NewChartValues {
teamId: string
userSub: string
}

export default function ({ teamId, catalogs, fetchCatalog }: Props): React.ReactElement {
const { classes, cx } = useStyles()
const [filterName, setFilterName] = useState('')
Expand All @@ -88,25 +81,9 @@ export default function ({ teamId, catalogs, fetchCatalog }: Props): React.React
setFilteredCatalog(filtered)
}

const addChart = async (values: NewChartValues) => {
let finalUrl = ''

try {
const parsedUrl = new URL(values.url)
// Split the pathname into segments and filter out empty values.
const segments = parsedUrl.pathname.split('/').filter(Boolean)
if (segments.length < 2) throw new Error('Invalid repository URL: not enough segments.')

// Construct the base URL using only the first two segments.
// This gives you: https://github.com/{company}/{project}.git
finalUrl = `${parsedUrl.protocol}//${parsedUrl.hostname}/${segments[0]}/${segments[1]}.git`
} catch (error) {
return
}

const payload: NewChartPayload = { ...values, teamId, userSub: user.sub, url: finalUrl }
const addChart = async (data: NewChartValues) => {
try {
const result = await createWorkloadCatalog({ body: payload }).unwrap()
const result = await createWorkloadCatalog({ body: data }).unwrap()
fetchCatalog()
if (result) enqueueSnackbar('Chart successfully added', { variant: 'success' })
else enqueueSnackbar('Error adding chart', { variant: 'error' })
Expand Down Expand Up @@ -160,11 +137,12 @@ export default function ({ teamId, catalogs, fetchCatalog }: Props): React.React
</Box>
<NewChartModal
actionButtonColor='primary'
actionButtonText='Add Chart'
actionButtonText='Submit'
title='Add Helm Chart'
open={openNewChartModal}
handleAction={(handleActionValues) => addChart(handleActionValues)}
handleClose={() => setOpenNewChartModal(false)}
chartDirectories={filteredCatalog.map((item) => item.name) || []}
/>
</>
)
Expand Down
Loading