Skip to content

Commit

Permalink
fix(upstream-list): use exact match search on upstream list [KHCP-110…
Browse files Browse the repository at this point in the history
…54] (#1230)
  • Loading branch information
lukewhchen authored Mar 13, 2024
1 parent eecffb2 commit d7266c3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('useFetchUrlBuilder()', () => {
expect(builder(query)).toBe('http://foo.bar/entity/testQuery/')
})

it('should apply correct query schema for konnect', () => {
it('should apply correct query schema for konnect when isExactMatch is not activated', () => {
const config = {
apiBaseUrl: '/',
app: 'konnect',
Expand All @@ -68,4 +68,26 @@ describe('useFetchUrlBuilder()', () => {

expect(builder(query)).toBe('http://foo.bar/entity?filter[name][contains]=testQuery')
})

it('should apply correct query schema for konnect when isExactMatch activated', () => {
const config = {
apiBaseUrl: '/',
app: 'konnect',
controlPlaneId: 'default',
isExactMatch: true,
} as KonnectConfig

const builder = useFetchUrlBuilder(config, 'http://foo.bar/entity')

const query: FetcherParams = {
page: 1,
pageSize: 10,
offset: 0,
sortColumnKey: 'name',
sortColumnOrder: 'asc',
query: 'testQuery',
}

expect(builder(query)).toBe('http://foo.bar/entity/testQuery/')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ export default function useFetchUrlBuilder(
try {
let urlWithParams: URL = new URL(baseRequestUrl.value.href)
if (isExactMatch.value && query) {
// Using exact match
// handle
// 1) all konnect usage or
// 2) kongManager usage with _config.value.isExactMatch === true
urlWithParams.search = '' // trim any query params
urlWithParams = _config.value.app === 'konnect'
? new URL(`${urlWithParams.href}?filter[name][contains]=${query}`)
: new URL(`${urlWithParams.href}/${query}/`)
urlWithParams = _config.value.isExactMatch
? new URL(`${urlWithParams.href}/${query}/`)
: new URL(`${urlWithParams.href}?filter[name][contains]=${query}`)
} else {
// handle kongManager usage with _config.value.isExactMatch === false
if (!isExactMatch.value) {
// Using fuzzy match
new URLSearchParams(query).forEach((value, key) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/entities/entities-shared/src/types/app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export interface KonnectConfig extends BaseAppConfig {
app: 'konnect'
/** The control plane id */
controlPlaneId: string
/** Should use exact match */
isExactMatch?: boolean
}

/** Base config properties for Kong Manager. All entity configs should extend this interface for the app. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ A table component for upstreams.
- type: `boolean`
- required: `false`
- default: `undefined`
- *Specific to Kong Manager*. Whether to use exact match.
- Whether to use exact match.

- `disableSorting`:
- type: `boolean`
Expand Down

0 comments on commit d7266c3

Please sign in to comment.