forked from open-metadata/OpenMetadata
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor: add base class for tags (open-metadata#14218)
* Minor: exclude knowledge center classification tags from tag suggestion * add base class for tags * add unit test * clean up constants
- Loading branch information
1 parent
bc81ff5
commit 0d2e883
Showing
7 changed files
with
151 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
openmetadata-ui/src/main/resources/ui/src/utils/TagClassBase.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright 2023 Collate. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { SearchIndex } from '../enums/search.enum'; | ||
import { searchQuery } from '../rest/searchAPI'; | ||
import tagClassBase, { TagClassBase } from './TagClassBase'; | ||
|
||
jest.mock('../rest/searchAPI'); | ||
|
||
describe('TagClassBase', () => { | ||
beforeEach(() => { | ||
(searchQuery as jest.Mock).mockClear(); | ||
}); | ||
|
||
it('should create an instance of TagClassBase', () => { | ||
expect(tagClassBase).toBeInstanceOf(TagClassBase); | ||
}); | ||
|
||
it('should call searchQuery with correct parameters', async () => { | ||
const searchText = 'test'; | ||
const page = 1; | ||
|
||
const mockResponse = { | ||
hits: { | ||
hits: [ | ||
{ | ||
_source: { | ||
fullyQualifiedName: 'test', | ||
}, | ||
}, | ||
], | ||
total: { | ||
value: 1, | ||
}, | ||
}, | ||
}; | ||
|
||
(searchQuery as jest.Mock).mockResolvedValue(mockResponse); | ||
await tagClassBase.getTags(searchText, page); | ||
|
||
expect(searchQuery).toHaveBeenCalledWith({ | ||
query: `*${searchText}*`, | ||
filters: 'disabled:false', | ||
pageNumber: page, | ||
pageSize: 10, // Assuming PAGE_SIZE is 10 | ||
queryFilter: {}, | ||
searchIndex: SearchIndex.TAG, | ||
}); | ||
}); | ||
|
||
it('should return correct data structure', async () => { | ||
const searchText = 'test'; | ||
const page = 1; | ||
const mockResponse = { | ||
hits: { | ||
hits: [ | ||
{ | ||
_source: { | ||
fullyQualifiedName: 'test', | ||
}, | ||
}, | ||
], | ||
total: { | ||
value: 1, | ||
}, | ||
}, | ||
}; | ||
|
||
(searchQuery as jest.Mock).mockResolvedValue(mockResponse); | ||
|
||
const result = await tagClassBase.getTags(searchText, page); | ||
|
||
expect(result).toEqual({ | ||
data: [ | ||
{ | ||
label: 'test', | ||
value: 'test', | ||
data: { | ||
fullyQualifiedName: 'test', | ||
}, | ||
}, | ||
], | ||
paging: { | ||
total: 1, | ||
}, | ||
}); | ||
}); | ||
}); |
44 changes: 44 additions & 0 deletions
44
openmetadata-ui/src/main/resources/ui/src/utils/TagClassBase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2023 Collate. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { PAGE_SIZE } from '../constants/constants'; | ||
import { SearchIndex } from '../enums/search.enum'; | ||
import { searchQuery } from '../rest/searchAPI'; | ||
|
||
class TagClassBase { | ||
public async getTags(searchText: string, page: number) { | ||
const res = await searchQuery({ | ||
query: `*${searchText}*`, | ||
filters: 'disabled:false', | ||
pageNumber: page, | ||
pageSize: PAGE_SIZE, | ||
queryFilter: {}, | ||
searchIndex: SearchIndex.TAG, | ||
}); | ||
|
||
return { | ||
data: res.hits.hits.map(({ _source }) => ({ | ||
label: _source.fullyQualifiedName ?? '', | ||
value: _source.fullyQualifiedName ?? '', | ||
data: _source, | ||
})), | ||
paging: { | ||
total: res.hits.total.value, | ||
}, | ||
}; | ||
} | ||
} | ||
|
||
const tagClassBase = new TagClassBase(); | ||
|
||
export default tagClassBase; | ||
export { TagClassBase }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters