forked from KaotoIO/kaoto
-
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.
fix: Toggle on/off Catalog "component", "proceeosr" and "kamelet" ind…
…ependently. Enable all of them by default Fixes: KaotoIO#1040 Fixes: KaotoIO#1039
- Loading branch information
1 parent
c85ec20
commit 6826941
Showing
4 changed files
with
103 additions
and
47 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
62 changes: 62 additions & 0 deletions
62
packages/ui/src/components/Catalog/BaseCatalogItemGroup.tsx
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,62 @@ | ||
import { Card, CardExpandableContent, CardHeader, CardTitle, DataList, Gallery } from '@patternfly/react-core'; | ||
import { CatalogDataListItem } from './DataListItem'; | ||
import { Tile } from './Tile'; | ||
import { FunctionComponent, useCallback, useState } from 'react'; | ||
import { CatalogLayout, ITile } from './Catalog.models'; | ||
|
||
interface BaseCatalogItemGroupProps { | ||
group: string; | ||
tiles: ITile[]; | ||
catalogLayout: CatalogLayout; | ||
onTagClick: (_event: unknown, value: string) => void; | ||
onTileClick: (tile: ITile) => void; | ||
} | ||
|
||
export const BaseCatalogItemGroup: FunctionComponent<BaseCatalogItemGroupProps> = ({ | ||
group, | ||
tiles, | ||
catalogLayout, | ||
onTagClick, | ||
onTileClick, | ||
}) => { | ||
const [isExpanded, setIsExpanded] = useState<boolean>(true); | ||
|
||
const toggleExpand = useCallback( | ||
(_event: React.MouseEvent, _id: string) => { | ||
setIsExpanded(!isExpanded); | ||
}, | ||
[isExpanded], | ||
); | ||
|
||
const onSelectDataListItem = useCallback( | ||
(_event: React.MouseEvent | React.KeyboardEvent, id: string) => { | ||
const tile = tiles.find((tile) => tile.name === id); | ||
onTileClick(tile!); | ||
}, | ||
[onTileClick, tiles], | ||
); | ||
|
||
return ( | ||
<Card key={`catalog-card-${group}`} data-testid={`catalog-card-${group}`} isLarge isExpanded={isExpanded}> | ||
<CardHeader onExpand={toggleExpand}> | ||
<CardTitle>{`${group.charAt(0).toUpperCase() + group.slice(1)}s (${tiles.length})`}</CardTitle> | ||
</CardHeader> | ||
<CardExpandableContent> | ||
{catalogLayout == CatalogLayout.List && ( | ||
<DataList aria-label="Catalog list" onSelectDataListItem={onSelectDataListItem} isCompact> | ||
{tiles.map((tile) => ( | ||
<CatalogDataListItem key={`${tile.name}-${tile.type}`} tile={tile} onTagClick={onTagClick} /> | ||
))} | ||
</DataList> | ||
)} | ||
{catalogLayout == CatalogLayout.Gallery && ( | ||
<Gallery hasGutter> | ||
{tiles.map((tile) => ( | ||
<Tile key={`${tile.name}-${tile.type}`} tile={tile} onClick={onTileClick} onTagClick={onTagClick} /> | ||
))} | ||
</Gallery> | ||
)} | ||
</CardExpandableContent> | ||
</Card> | ||
); | ||
}; |
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