Skip to content

Commit

Permalink
prettier fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nir2002 committed Jul 26, 2023
1 parent a25e05b commit 190a9ee
Show file tree
Hide file tree
Showing 92 changed files with 5,834 additions and 6,040 deletions.
4 changes: 2 additions & 2 deletions dashboard/.prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
trailingComma: "es5"
tabWidth: 4
tabWidth: 2
semi: false
singleQuote: true
singleQuote: false
268 changes: 132 additions & 136 deletions dashboard/src/API/apiService.ts
Original file line number Diff line number Diff line change
@@ -1,144 +1,140 @@
import {
Chart,
ChartVersion,
Release,
ReleaseHealthStatus,
ReleaseRevision,
Repository,
} from '../data/types'
import { QueryFunctionContext } from '@tanstack/react-query'
Chart,
ChartVersion,
Release,
ReleaseHealthStatus,
ReleaseRevision,
Repository,
} from "../data/types"
import { QueryFunctionContext } from "@tanstack/react-query"
interface ClustersResponse {
AuthInfo: string
Cluster: string
IsCurrent: boolean
Name: string
Namespace: string
AuthInfo: string
Cluster: string
IsCurrent: boolean
Name: string
Namespace: string
}
class ApiService {
currentCluster = ''
constructor(protected readonly isMockMode: boolean = false) {}

setCluster = (cluster: string) => {
this.currentCluster = cluster
}

public fetchWithDefaults = async (url: string, options?: RequestInit) => {
if (this.currentCluster) {
const headers = new Headers(options?.headers)
if (!headers.has('X-Kubecontext')) {
headers.set('X-Kubecontext', this.currentCluster)
}
return fetch(url, { ...options, headers })
}
return fetch(url, options)
}
getToolVersion = async () => {
const response = await fetch(`/status`)
const data = await response.json()
return data
}

getRepositoryLatestVersion = async (repositoryName: string) => {
const response = await this.fetchWithDefaults(
`/api/helm/repositories/latestver?name=${repositoryName}`
)
const data = await response.json()
return data
}

getInstalledReleases = async () => {
const response = await this.fetchWithDefaults(`/api/helm/releases`)
const data = await response.json()
return data
}

getClusters = async () => {
const response = await fetch(`/api/k8s/contexts`)
const data = (await response.json()) as ClustersResponse[]
return data
}

getNamespaces = async () => {
const response = await this.fetchWithDefaults(
`/api/k8s/namespaces/list`
)
const data = await response.json()
return data
}

getRepositories = async () => {
const response = await this.fetchWithDefaults(`/api/helm/repositories`)
const data = await response.json()
return data
}

getRepositoryCharts = async ({
queryKey,
}: QueryFunctionContext<Chart[], Repository>) => {
const [_, repository] = queryKey
const response = await this.fetchWithDefaults(
`/api/helm/repositories/${repository}`
)
const data = await response.json()
return data
}

getChartVersions = async ({
queryKey,
}: QueryFunctionContext<ChartVersion[], Chart>) => {
const [_, chart] = queryKey

const response = await this.fetchWithDefaults(
`/api/helm/repositories/versions?name=${chart.name}`
)
const data = await response.json()
return data
}

getResourceStatus = async ({
release,
}: {
release: Release
}): Promise<ReleaseHealthStatus[] | null> => {
if (!release) return null

const response = await this.fetchWithDefaults(
`/api/helm/releases/${release.namespace}/${release.name}/resources?health=true`
)
const data = await response.json()
return data
}

getReleasesHistory = async ({
queryKey,
}: QueryFunctionContext<Release[], Release>): Promise<
ReleaseRevision[]
> => {
const [_, params] = queryKey

if (!params.namespace || !params.chart) return []

const response = await this.fetchWithDefaults(
`/api/helm/releases/${params.namespace}/${params.chart}/history`
)
const data = await response.json()

return data
}

getValues = async ({ queryKey }: any) => {
const [_, params] = queryKey
const { namespace, chart, version } = params

if (!namespace || !chart || !chart.name || version === undefined)
return Promise.reject(new Error('missing parameters'))

const url = `/api/helm/repositories/values?chart=${namespace}/${chart.name}&version=${version}`
const response = await this.fetchWithDefaults(url)
const data = await response.text()

return data
currentCluster = ""
constructor(protected readonly isMockMode: boolean = false) {}

setCluster = (cluster: string) => {
this.currentCluster = cluster
}

public fetchWithDefaults = async (url: string, options?: RequestInit) => {
if (this.currentCluster) {
const headers = new Headers(options?.headers)
if (!headers.has("X-Kubecontext")) {
headers.set("X-Kubecontext", this.currentCluster)
}
return fetch(url, { ...options, headers })
}
return fetch(url, options)
}
getToolVersion = async () => {
const response = await fetch(`/status`)
const data = await response.json()
return data
}

getRepositoryLatestVersion = async (repositoryName: string) => {
const response = await this.fetchWithDefaults(
`/api/helm/repositories/latestver?name=${repositoryName}`
)
const data = await response.json()
return data
}

getInstalledReleases = async () => {
const response = await this.fetchWithDefaults(`/api/helm/releases`)
const data = await response.json()
return data
}

getClusters = async () => {
const response = await fetch(`/api/k8s/contexts`)
const data = (await response.json()) as ClustersResponse[]
return data
}

getNamespaces = async () => {
const response = await this.fetchWithDefaults(`/api/k8s/namespaces/list`)
const data = await response.json()
return data
}

getRepositories = async () => {
const response = await this.fetchWithDefaults(`/api/helm/repositories`)
const data = await response.json()
return data
}

getRepositoryCharts = async ({
queryKey,
}: QueryFunctionContext<Chart[], Repository>) => {
const [_, repository] = queryKey

Check warning on line 76 in dashboard/src/API/apiService.ts

View workflow job for this annotation

GitHub Actions / static_and_lint

'_' is assigned a value but never used

Check warning on line 76 in dashboard/src/API/apiService.ts

View workflow job for this annotation

GitHub Actions / static_and_lint

'_' is assigned a value but never used
const response = await this.fetchWithDefaults(
`/api/helm/repositories/${repository}`
)
const data = await response.json()
return data
}

getChartVersions = async ({
queryKey,
}: QueryFunctionContext<ChartVersion[], Chart>) => {
const [_, chart] = queryKey

Check warning on line 87 in dashboard/src/API/apiService.ts

View workflow job for this annotation

GitHub Actions / static_and_lint

'_' is assigned a value but never used

Check warning on line 87 in dashboard/src/API/apiService.ts

View workflow job for this annotation

GitHub Actions / static_and_lint

'_' is assigned a value but never used

const response = await this.fetchWithDefaults(
`/api/helm/repositories/versions?name=${chart.name}`
)
const data = await response.json()
return data
}

getResourceStatus = async ({
release,
}: {
release: Release
}): Promise<ReleaseHealthStatus[] | null> => {
if (!release) return null

const response = await this.fetchWithDefaults(
`/api/helm/releases/${release.namespace}/${release.name}/resources?health=true`
)
const data = await response.json()
return data
}

getReleasesHistory = async ({
queryKey,
}: QueryFunctionContext<Release[], Release>): Promise<ReleaseRevision[]> => {
const [_, params] = queryKey

Check warning on line 113 in dashboard/src/API/apiService.ts

View workflow job for this annotation

GitHub Actions / static_and_lint

'_' is assigned a value but never used

Check warning on line 113 in dashboard/src/API/apiService.ts

View workflow job for this annotation

GitHub Actions / static_and_lint

'_' is assigned a value but never used

if (!params.namespace || !params.chart) return []

const response = await this.fetchWithDefaults(
`/api/helm/releases/${params.namespace}/${params.chart}/history`
)
const data = await response.json()

return data
}

getValues = async ({ queryKey }: any) => {

Check warning on line 125 in dashboard/src/API/apiService.ts

View workflow job for this annotation

GitHub Actions / static_and_lint

Unexpected any. Specify a different type

Check warning on line 125 in dashboard/src/API/apiService.ts

View workflow job for this annotation

GitHub Actions / static_and_lint

Unexpected any. Specify a different type
const [_, params] = queryKey

Check warning on line 126 in dashboard/src/API/apiService.ts

View workflow job for this annotation

GitHub Actions / static_and_lint

'_' is assigned a value but never used

Check warning on line 126 in dashboard/src/API/apiService.ts

View workflow job for this annotation

GitHub Actions / static_and_lint

'_' is assigned a value but never used
const { namespace, chart, version } = params

if (!namespace || !chart || !chart.name || version === undefined)
return Promise.reject(new Error("missing parameters"))

const url = `/api/helm/repositories/values?chart=${namespace}/${chart.name}&version=${version}`
const response = await this.fetchWithDefaults(url)
const data = await response.text()

return data
}
}

const apiService = new ApiService()
Expand Down
Loading

0 comments on commit 190a9ee

Please sign in to comment.