-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Currently, when looking for a `saga` component, we see a `Saga` component, but there's also a `Saga` pattern and there's no visual feedback that it exists, until we click on the `Pattern` toggle. This commit adds counters to each toggle, so we can monitor the occurrences in other groups as well. In addition to that, the lookup is debounced until the user stop writing, in a 500ms window. This helps when writing the first letters of the search term, it doesn't get stuck until the UI renders. The e2e tests for the catalog were updated to include a check after resetting the search field. fix: #745
- Loading branch information
Showing
7 changed files
with
192 additions
and
45 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
107 changes: 107 additions & 0 deletions
107
packages/ui/src/components/Catalog/filter-tiles.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,107 @@ | ||
import { CatalogKind } from '../../models/catalog-kind'; | ||
import { ITile } from './Catalog.models'; | ||
import { filterTiles } from './filter-tiles'; | ||
|
||
describe('filterTiles', () => { | ||
const tilesMap: Record<string, ITile> = { | ||
activemq: { | ||
name: 'activemq', | ||
title: 'ActiveMQ', | ||
description: 'Send messages to (or consume from) Apache ActiveMQ.', | ||
tags: ['messaging'], | ||
type: CatalogKind.Component, | ||
}, | ||
cometd: { | ||
name: 'cometd', | ||
title: 'CometD', | ||
description: | ||
'Offers publish/subscribe, peer-to-peer (via a server), and RPC style messaging using the CometD/Bayeux protocol.', | ||
tags: ['networking', 'messaging'], | ||
type: CatalogKind.Component, | ||
}, | ||
cron: { | ||
name: 'cron', | ||
title: 'Cron', | ||
description: 'Schedule a task to run at a specific time.', | ||
tags: ['scheduling'], | ||
type: CatalogKind.Component, | ||
}, | ||
hazelcast: { | ||
name: 'hazelcast', | ||
title: 'Hazelcast', | ||
description: 'Perform operations on Hazelcast distributed queue.', | ||
tags: ['cache', 'clustering', 'messaging'], | ||
type: CatalogKind.Component, | ||
}, | ||
setBody: { | ||
name: 'setBody', | ||
title: 'Set Body', | ||
description: 'Set the message body.', | ||
tags: ['eip', 'transformation'], | ||
type: CatalogKind.Pattern, | ||
}, | ||
split: { | ||
name: 'split', | ||
title: 'Split', | ||
description: 'Split a message into parts.', | ||
tags: ['eip', 'routing'], | ||
type: CatalogKind.Pattern, | ||
}, | ||
beerSource: { | ||
name: 'beerSource', | ||
title: 'Beer Source', | ||
description: 'A source that emits beer.', | ||
tags: ['beer', 'source'], | ||
type: CatalogKind.Kamelet, | ||
}, | ||
slackSource: { | ||
name: 'slackSource', | ||
title: 'Slack Source', | ||
description: 'A source that emits messages from Slack.', | ||
tags: ['slack', 'source'], | ||
type: CatalogKind.Kamelet, | ||
}, | ||
}; | ||
const tiles = Object.values(tilesMap); | ||
|
||
it('should filter tiles by search term', () => { | ||
const options = { searchTerm: 'message' }; | ||
const result = filterTiles(tiles, options); | ||
|
||
expect(result).toEqual({ | ||
[CatalogKind.Component]: [tilesMap.activemq], | ||
[CatalogKind.Pattern]: [tilesMap.setBody, tilesMap.split], | ||
[CatalogKind.Kamelet]: [tilesMap.slackSource], | ||
}); | ||
}); | ||
|
||
it('should filter tiles by a single tag', () => { | ||
const options = { searchTags: ['messaging'] }; | ||
const result = filterTiles(tiles, options); | ||
expect(result).toEqual({ | ||
[CatalogKind.Component]: [tilesMap.activemq, tilesMap.cometd, tilesMap.hazelcast], | ||
[CatalogKind.Pattern]: [], | ||
[CatalogKind.Kamelet]: [], | ||
}); | ||
}); | ||
|
||
it('should filter tiles by multiple tags', () => { | ||
const options = { searchTags: ['messaging', 'clustering'] }; | ||
const result = filterTiles(tiles, options); | ||
expect(result).toEqual({ | ||
[CatalogKind.Component]: [tilesMap.hazelcast], | ||
[CatalogKind.Pattern]: [], | ||
[CatalogKind.Kamelet]: [], | ||
}); | ||
}); | ||
|
||
it('should filter tiles by search term and tags', () => { | ||
const options = { searchTerm: 'cr', searchTags: ['scheduling'] }; | ||
const result = filterTiles(tiles, options); | ||
expect(result).toEqual({ | ||
[CatalogKind.Component]: [tilesMap.cron], | ||
[CatalogKind.Pattern]: [], | ||
[CatalogKind.Kamelet]: [], | ||
}); | ||
}); | ||
}); |
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,36 @@ | ||
import { ITile } from './Catalog.models'; | ||
|
||
const checkThatArrayContainsAllTags = (tileTags: string[], searchTags: string[]) => | ||
searchTags.every((v) => tileTags.includes(v)); | ||
|
||
export const filterTiles = ( | ||
tiles: ITile[], | ||
options?: { searchTerm?: string; searchTags?: string[] }, | ||
): Record<string, ITile[]> => { | ||
const { searchTerm = '', searchTags = [] } = options ?? {}; | ||
const searchTermLowercase = searchTerm.toLowerCase(); | ||
|
||
return tiles.reduce( | ||
(acc, tile) => { | ||
/** Filter by selected tags */ | ||
const doesTagsMatches = searchTags.length ? checkThatArrayContainsAllTags(tile.tags, searchTags) : true; | ||
|
||
/** Determine whether the tile should be included in the filtered list */ | ||
const shouldInclude = | ||
doesTagsMatches && | ||
(!searchTermLowercase || | ||
tile.name.toLowerCase().includes(searchTermLowercase) || | ||
tile.title.toLowerCase().includes(searchTermLowercase) || | ||
tile.description?.toLowerCase().includes(searchTermLowercase) || | ||
tile.tags.some((tag) => tag.toLowerCase().includes(searchTermLowercase))); | ||
|
||
acc[tile.type] = acc[tile.type] ?? []; | ||
if (shouldInclude) { | ||
acc[tile.type].push(tile); | ||
} | ||
|
||
return acc; | ||
}, | ||
{} as Record<ITile['type'], ITile[]>, | ||
); | ||
}; |
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