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

fix(entities-shared): update useFetchUrlBuilder to allow exact match search from host app. [KHCP-11054] #1230

Merged
merged 1 commit into from
Mar 13, 2024
Merged
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
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
Loading