Skip to content

Commit

Permalink
fix(upstream-list): use exact match search on upstream list [KHCP-11054]
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewhchen committed Mar 12, 2024
1 parent 6718c8d commit d89b248
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 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 @@ -13,9 +13,7 @@ export default function useFetchUrlBuilder(
const _config = ref(unref(config))
const _baseUrl = ref(unref(baseUrl))

const isExactMatch = computed(
(): boolean => !!(_config.value.app === 'konnect' || _config.value.isExactMatch),
)
const isExactMatch = computed((): boolean => !!_config.value.isExactMatch)

// Construct a URL object, adding the current `window.location.origin` if the path begins with a slash
const baseRequestUrl = computed((): URL =>
Expand All @@ -35,9 +33,11 @@ export default function useFetchUrlBuilder(
if (isExactMatch.value && query) {
// Using exact match
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 = new URL(`${urlWithParams.href}/${query}/`)
} else if (_config.value.app === 'konnect') {
// Konnect support filter param structure
urlWithParams.search = '' // trim any query params
urlWithParams = new URL(`${urlWithParams.href}?filter[name][contains]=${query}`)
} else {
if (!isExactMatch.value) {
// Using fuzzy match
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 d89b248

Please sign in to comment.