Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] ACM-15320 Remove hard coded local-cluster from App UI #4078

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions frontend/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,6 @@
"cluster.create.ocp.fips": "FIPS",
"cluster.create.ocp.image": "Release image",
"cluster.create.ocp.singleNode": "Single Node OpenShift",
"cluster.status.offline": "Offline",
"clusterClaim.cluster.name": "Cluster name",
"clusterClaim.create.message": "Claiming a cluster from <bold>{{clusterPoolName}}</bold> will remove one of the available clusters from the pool and a new cluster will be created to replace it.",
"clusterClaim.create.message.pending": "A cluster claim was created for <bold>{{clusterPoolName}}</bold> but no clusters were available. A Hibernating cluster will be resumed or a new cluster will be provisioned to fulfill the claim. This will take several minutes. Expand the cluster pool in the table to view or delete pending claims.",
Expand Down Expand Up @@ -2193,8 +2192,6 @@
"Project ID": "Project ID",
"prop.details.section": "Details",
"Propagation policy": "Propagation policy",
"props.show.yaml.argoset": "Applications set",
"props.show.yaml.argoset.yaml": "View application set YAML",
"Provide a kubeconfig that grants access to an external infrastructure cluster running OpenShift Virtualization.": "Provide a kubeconfig that grants access to an external infrastructure cluster running OpenShift Virtualization.",
"Provide customized control plane cluster configuration.": "Provide customized control plane cluster configuration.",
"Provides a link to the resource repository that is represented by the channel.": "Provides a link to the resource repository that is represented by the channel.",
Expand Down Expand Up @@ -2818,7 +2815,7 @@
"Tenant ID": "Tenant ID",
"Terminating": "Terminating",
"The <bold>{{clusterName}}</bold> cluster can only be destroyed through the CLI": "The <bold>{{clusterName}}</bold> cluster can only be destroyed through the CLI",
"The ArgoCD pull model does not support local-cluster as a destination cluster. Filter out local-cluster from the placement resource.": "The ArgoCD pull model does not support local-cluster as a destination cluster. Filter out local-cluster from the placement resource.",
"The ArgoCD pull model does not support the hub cluster as a destination cluster. Filter out the hub cluster from the placement resource.": "The ArgoCD pull model does not support the hub cluster as a destination cluster. Filter out the hub cluster from the placement resource.",
"The authentication method to use to connect to OpenShift Cluster Manager.": "The authentication method to use to connect to OpenShift Cluster Manager.",
"The automation template cannot be updated for any of the selected clusters.": "The automation template cannot be updated for any of the selected clusters.",
"The channel cannot be changed for any of the selected clusters.": "The channel cannot be changed for any of the selected clusters.",
Expand Down
192 changes: 0 additions & 192 deletions frontend/src/hooks/application-queries.ts

This file was deleted.

103 changes: 1 addition & 102 deletions frontend/src/lib/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { useMemo } from 'react'
import { useLocation } from 'react-router-dom-v5-compat'
import { ArgoApplication, OCPAppResource } from '../resources'
import { OCPAppResource } from '../resources'
import { getBackendUrl, IRequestResult, postRequest } from '../resources/utils'
import { flatten, uniqBy } from 'lodash'

Expand Down Expand Up @@ -65,107 +65,6 @@ export function queryStatusCount(cluster: string): IRequestResult<ISearchResult>
})
}

function getRemoteArgoFilters({
cluster,
clusters = [],
name,
namespace,
}: Pick<DiscoveredAppsParams, 'clusters'> & {
cluster?: DiscoveredAppsParams['search']
name?: DiscoveredAppsParams['search']
namespace?: DiscoveredAppsParams['search']
}) {
const clustersFilter = { property: 'cluster', values: [] as string[] }
const filtersArr = [
{ property: 'kind', values: ['Application'] },
{ property: 'apigroup', values: ['argoproj.io'] },
clustersFilter,
...(name ? [{ property: 'name', values: [`*${name}*`] }] : []),
...(namespace ? [{ property: 'destinationNamespace', values: [`*${namespace}*`] }] : []),
]

if (clusters.length) {
clustersFilter.values = clustersFilter.values.concat(clusters)
} else if (cluster) {
clustersFilter.values.push(`*${cluster}*`)
} else {
clustersFilter.values.push('!local-cluster')
}

return filtersArr
}

export async function queryRemoteArgoApps(params: DiscoveredAppsParams): Promise<ArgoApplication[]>
export async function queryRemoteArgoApps(params: DiscoveredAppsParams & { countOnly: true }): Promise<number>
export async function queryRemoteArgoApps(
params: DiscoveredAppsParams & { countOnly?: true }
): Promise<ArgoApplication[] | number> {
const { clusters = [], search, searchLimit, countOnly = false } = params

let variables: SearchQuery['variables']
let query: string

const limitObject = countOnly ? {} : { limit: searchLimit }

if (search) {
variables = {
byNameInput: [
{
filters: getRemoteArgoFilters({ clusters, name: search }),
...limitObject,
},
],
byNamespaceInput: [
{
filters: getRemoteArgoFilters({ clusters, namespace: search }),
...limitObject,
},
],
...(clusters.length
? {}
: {
byClusterInput: [
{
filters: getRemoteArgoFilters({ cluster: search }),
...limitObject,
},
],
}),
}
if (clusters.length) {
query = countOnly ? searchMatchAndFilterQueryCount : searchMatchAndFilterQuery
} else {
query = countOnly ? searchMatchWithClusterAndFilterQueryCount : searchMatchWithClusterAndFilterQuery
}
} else {
variables = {
input: [
{
filters: getRemoteArgoFilters({ clusters }),
...limitObject,
},
],
}
query = countOnly ? searchFilterQueryCount : searchFilterQuery
}

const { promise } = postRequest<SearchQuery, ISearchResult>(getBackendUrl() + apiSearchUrl, {
operationName: 'searchResult',
variables,
query,
})
return promise.then((result) => {
if (countOnly) {
return Math.max(...Object.values(result.data).map((value) => value?.[0]?.count || 0))
} else {
return uniqBy(
flatten(Object.values(result.data).map((value) => value?.[0]?.items || [])),
(item) => item._uid
) as ArgoApplication[]
}
})
}

export type DiscoveredAppsParams = {
clusters?: string[]
types?: string[]
Expand Down
Loading