Skip to content

Commit

Permalink
Merge pull request #181 from BESTSELLER/#174-dynamic-backend-url
Browse files Browse the repository at this point in the history
Now pulls the baseUrl from the app-config.yml
  • Loading branch information
wrighbr authored Apr 27, 2022
2 parents 61e023c + d639cca commit 47e47fc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { ConfigReader } from '@backstage/core-app-api'
import { configApiRef } from '@backstage/core-plugin-api'
import { TestApiProvider } from '@backstage/test-utils'
import { act, render, screen } from '@testing-library/react'
import React from 'react'
import { HarborRepository } from './HarborRepository'

const configApi = new ConfigReader({
backend: { baseUrl: 'http://localhost:7000' },
})

global.fetch = jest.fn(() =>
Promise.resolve({
json: () =>
Expand Down Expand Up @@ -40,11 +47,13 @@ describe('Harbor Repository', () => {
it('loads repo info', async () => {
await act(async () =>
render(
<HarborRepository
project="project"
repository="component"
widget={false}
/>
<TestApiProvider apis={[[configApiRef, configApi]]}>
<HarborRepository
project="project"
repository="component"
widget={false}
/>
</TestApiProvider>
)
)

Expand Down
12 changes: 5 additions & 7 deletions src/components/HarborRepository/HarborRepository.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Progress, Table } from '@backstage/core-components'
import { configApiRef, useApi } from '@backstage/core-plugin-api'
import React, { useState } from 'react'
import ReactSpeedometer from 'react-d3-speedometer'
import { useAsync } from 'react-use'
import { columns } from './tableHeadings'

function HarborRepository(props: RepositoryProps) {
export function HarborRepository(props: RepositoryProps) {
const [error, setError] = useState(false)
const [errorMsg, setErrorMsg] = useState('')
const [repository, setRepository] = useState<Repository[]>([])

const config = useApi(configApiRef)
const backendUrl = config.getString('backend.baseUrl')

const { loading } = useAsync(async () => {
let backendUrl = window.location.origin
if (backendUrl.includes('3000')) {
backendUrl = backendUrl.replace('3000', '7000')
}
const response = await fetch(
`${backendUrl}/api/harbor/artifacts?project=${props.project}&repository=${props.repository}`
)
Expand Down Expand Up @@ -139,5 +139,3 @@ interface Vulnerabilities {
count: number
severity: string
}

export { HarborRepository }

0 comments on commit 47e47fc

Please sign in to comment.