Skip to content

Commit

Permalink
feat(core): added ability to filter by badges (#1004)
Browse files Browse the repository at this point in the history
* feat(core): added ability to filter by badges

* Create sharp-timers-agree.md
  • Loading branch information
boyney123 authored Dec 6, 2024
1 parent a907d96 commit ff449d7
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 28 deletions.
5 changes: 5 additions & 0 deletions .changeset/sharp-timers-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@eventcatalog/core": patch
---

feat(core): added ability to filter by badges
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ import { getIconForCollection as getIconForCollectionOriginal } from '@utils/col

const STORAGE_KEY = 'EventCatalog:catalogSidebarCollapsedGroups';

const CatalogResourcesSideBar = ({ resources, currentPath }: any) => {
interface CatalogResourcesSideBarProps {
resources: any;
currentPath: string;
}

const CatalogResourcesSideBar: React.FC<CatalogResourcesSideBarProps> = ({ resources, currentPath }) => {
if (typeof window === 'undefined') {
return null;
}

const [data, setData] = useState(resources);
const [searchQuery, setSearchQuery] = useState('');
const [isInitialized, setIsInitialized] = useState(false);
Expand Down
12 changes: 11 additions & 1 deletion eventcatalog/src/components/Tables/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type { CollectionTypes } from '@types';
declare module '@tanstack/react-table' {
// @ts-ignore
interface ColumnMeta<TData extends RowData, TValue> {
filterVariant?: 'collection' | 'name';
filterVariant?: 'collection' | 'name' | 'badges';
collectionFilterKey?: string;
showFilter?: boolean;
className?: string;
Expand Down Expand Up @@ -211,6 +211,16 @@ function Filter({ column }: { column: Column<any, unknown> }) {

return uniqueItemsInList.sort().slice(0, 2000);
}
if (filterVariant === 'badges') {
const allBadges = column.getFacetedUniqueValues().keys();
// join all badges into a single array
const allBadgesArray = Array.from(allBadges)
.flat()
.filter((b) => !!b);
const allBadgesString = allBadgesArray.map((badge) => badge.content);
const uniqueBadges = Array.from(new Set(allBadgesString));
return uniqueBadges.sort().slice(0, 2000);
}
return Array.from(column.getFacetedUniqueValues().keys()).sort().slice(0, 2000);
}, [column.getFacetedUniqueValues(), filterVariant]);

Expand Down
14 changes: 4 additions & 10 deletions eventcatalog/src/components/Tables/columns/DomainTableColumns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { ServerIcon } from '@heroicons/react/20/solid';
import { RectangleGroupIcon } from '@heroicons/react/20/solid';
import { createColumnHelper } from '@tanstack/react-table';
import type { CollectionEntry } from 'astro:content';
import { filterByName, filterCollectionByName } from '../filters/custom-filters';
import { filterByBadge, filterByName, filterCollectionByName } from '../filters/custom-filters';
import { buildUrl } from '@utils/url-builder';
import { Tag } from 'lucide-react';
import { createBadgesColumn } from './SharedColumns';

const columnHelper = createColumnHelper<CollectionEntry<'domains'>>();

Expand Down Expand Up @@ -40,14 +42,6 @@ export const columns = () => [
},
filterFn: filterByName,
}),
// columnHelper.accessor('data.version', {
// header: () => <span>Version</span>,
// cell: (info) => {
// const service = info.row.original;
// return <div className="text-left font-light">{`v${info.getValue()} ${service.data.latestVersion === service.data.version ? '(latest)': ''}`}</div>
// },
// footer: (info) => info.column.id,
// }),
columnHelper.accessor('data.summary', {
id: 'summary',
header: () => 'Summary',
Expand Down Expand Up @@ -96,9 +90,9 @@ export const columns = () => [
</ul>
);
},
// footer: (info) => info.column.id,
filterFn: filterCollectionByName('services'),
}),
createBadgesColumn(columnHelper),
columnHelper.accessor('data.name', {
header: () => <span />,
cell: (info) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { ServerIcon } from '@heroicons/react/20/solid';
import { RectangleGroupIcon } from '@heroicons/react/20/solid';
import { createColumnHelper } from '@tanstack/react-table';
import type { CollectionEntry } from 'astro:content';
import { filterByName, filterCollectionByName } from '../filters/custom-filters';
import { filterByName } from '../filters/custom-filters';
import { buildUrl } from '@utils/url-builder';
import { QueueListIcon } from '@heroicons/react/24/solid';
import { createBadgesColumn } from './SharedColumns';

const columnHelper = createColumnHelper<CollectionEntry<'flows'>>();

Expand Down Expand Up @@ -61,6 +60,7 @@ export const columns = () => [
className: 'max-w-md',
},
}),
createBadgesColumn(columnHelper),
columnHelper.accessor('data.name', {
header: () => <span />,
cell: (info) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { createColumnHelper } from '@tanstack/react-table';
import type { CollectionMessageTypes } from '@types';
import type { CollectionEntry } from 'astro:content';
import { useMemo } from 'react';
import { filterByName, filterCollectionByName } from '../filters/custom-filters';
import { filterByName, filterCollectionByName, filterByBadge } from '../filters/custom-filters';
import { buildUrl } from '@utils/url-builder';
import { createBadgesColumn } from './SharedColumns';

const columnHelper = createColumnHelper<CollectionEntry<CollectionMessageTypes>>();

Expand Down Expand Up @@ -55,14 +56,15 @@ export const columns = () => [
},
filterFn: filterByName,
}),

columnHelper.accessor('data.summary', {
id: 'summary',
header: () => 'Summary',
cell: (info) => <span className="font-light ">{info.renderValue()}</span>,
footer: (info) => info.column.id,
meta: {
showFilter: false,
className: 'max-w-md',
className: 'max-w-[200px]',
},
}),

Expand Down Expand Up @@ -145,6 +147,7 @@ export const columns = () => [
footer: (info) => info.column.id,
filterFn: filterCollectionByName('consumers'),
}),
createBadgesColumn(columnHelper),
columnHelper.accessor('data.name', {
header: () => <span />,
cell: (info) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useMemo, useState } from 'react';
import { filterByName, filterCollectionByName } from '../filters/custom-filters';
import { buildUrl } from '@utils/url-builder';
import { getColorAndIconForMessageType } from './MessageTableColumns';
import { createBadgesColumn } from './SharedColumns';

const columnHelper = createColumnHelper<CollectionEntry<'services'>>();

Expand Down Expand Up @@ -40,14 +41,6 @@ export const columns = () => [
},
filterFn: filterByName,
}),
// columnHelper.accessor('data.version', {
// header: () => <span>Version</span>,
// cell: (info) => {
// const service = info.row.original;
// return <div className="text-left">{`v${info.getValue()} ${service.data.latestVersion === service.data.version ? '(latest)': ''}`}</div>
// },
// footer: (info) => info.column.id,
// }),
columnHelper.accessor('data.summary', {
id: 'summary',
header: () => 'Summary',
Expand Down Expand Up @@ -175,6 +168,7 @@ export const columns = () => [
},
filterFn: filterCollectionByName('sends'),
}),
createBadgesColumn(columnHelper),
columnHelper.accessor('data.name', {
header: () => <span />,
cell: (info) => {
Expand Down
44 changes: 44 additions & 0 deletions eventcatalog/src/components/Tables/columns/SharedColumns.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { createColumnHelper } from '@tanstack/react-table';
import { Tag } from 'lucide-react';
import { filterByBadge } from '../filters/custom-filters';
export const createBadgesColumn = <T extends { data: { badges?: any[] } }>(
columnHelper: ReturnType<typeof createColumnHelper<T>>
) => {
return columnHelper.accessor((row) => row.data.badges, {
id: 'badges',
header: () => <span>Badges</span>,
cell: (info) => {
const item = info.row.original;
const badges = item.data.badges || [];

if (badges?.length === 0 || !badges)
return <div className="font-light text-sm text-gray-400/60 text-left italic">No badges documented</div>;

return (
<ul>
{badges.map((badge: any, index: number) => {
return (
<li key={`${badge.id}-${index}`} className="py-1 group font-light ">
<div className="group-hover:text-primary flex space-x-1 items-center ">
<div className="flex items-center border border-gray-300 shadow-sm rounded-md">
<span className="flex items-center">
<span className={`bg-${badge.backgroundColor}-500 h-full rounded-tl rounded-bl p-1`}>
{badge.icon && <badge.icon className="h-4 w-4 text-white" />}
{!badge.icon && <Tag className="h-4 w-4 text-white" />}
</span>
<span className="leading-none px-2 group-hover:underline ">{badge.content}</span>
</span>
</div>
</div>
</li>
);
})}
</ul>
);
},
meta: {
filterVariant: 'badges',
},
filterFn: filterByBadge,
});
};
5 changes: 5 additions & 0 deletions eventcatalog/src/components/Tables/filters/custom-filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ export const filterByName = (row: any, key: string, searchValue: string) => {
const label = `${row?.original?.data.name} (v${row?.original?.data.version})` || '';
return label.toLowerCase().includes(searchValue.toLowerCase());
};

export const filterByBadge = (row: any, key: string, searchValue: string) => {
const badges = row?.original?.data?.badges || [];
return badges.some((badge: any) => badge.content.toLowerCase().includes(searchValue.toLowerCase()));
};
2 changes: 1 addition & 1 deletion eventcatalog/src/layouts/DiscoverLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const tabs = [
</div>

<!-- Table -->
<div class="pb-20 ml-6">
<div class="pb-20 ml-6 md:pr-10">
<div>
<div class="sm:flex sm:items-center py-4 pb-4" id="discover-title">
<div class="sm:flex-auto space-y-2">
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ff449d7

Please sign in to comment.