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

feat: add search via query parameter for events, services and domains (#498) #499

Merged
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
5 changes: 5 additions & 0 deletions .changeset/cyan-zebras-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@eventcatalog/core": patch
---

feat: add search via query parameter for events, services and domains (#498)
15 changes: 14 additions & 1 deletion packages/eventcatalog/pages/domains.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { SearchIcon } from '@heroicons/react/outline';
import DomainGrid from '@/components/Grids/DomainGrid';
import { useConfig } from '@/hooks/EventCatalog';
import { getAllDomains } from '@/lib/domains';
import { useRouter } from 'next/router';

export interface PageProps {
domains: Domain[];
Expand Down Expand Up @@ -80,6 +81,14 @@ export default function Page({ domains }: PageProps) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedFilters, searchFilter]);

const router = useRouter();

useEffect(() => {
if (router.query.q) {
setSearchFilter(router.query.q as string);
}
}, [router.query.q]);

const debouncedFilter = useCallback(
debounce((e) => {
setSearchFilter(e.target.value);
Expand Down Expand Up @@ -116,7 +125,11 @@ export default function Page({ domains }: PageProps) {
type="text"
name="domain"
id="domain"
onChange={debouncedFilter}
onChange={(e) => {
setSearchFilter(e.target.value);
debouncedFilter(e);
}}
value={searchFilter}
className="focus:ring-gray-500 focus:border-gray-500 block w-full pl-10 sm:text-sm border-gray-300 rounded-md"
/>
</div>
Expand Down
15 changes: 14 additions & 1 deletion packages/eventcatalog/pages/events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import EventGrid from '@/components/Grids/EventGrid';
import { getAllEvents, getUniqueServicesNamesFromEvents } from '@/lib/events';
import { getUniqueDomainNamesFromEvents } from '@/lib/domains';
import { useConfig } from '@/hooks/EventCatalog';
import { useRouter } from 'next/router';

function classNames(...classes) {
return classes.filter(Boolean).join(' ');
Expand Down Expand Up @@ -134,6 +135,14 @@ export default function Page({ events, services, domains }: PageProps) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedFilters, searchFilter]);

const router = useRouter();

useEffect(() => {
if (router.query.q) {
setSearchFilter(router.query.q as string);
}
}, [router.query.q]);

// eslint-disable-next-line react-hooks/exhaustive-deps
const debouncedFilter = useCallback(
debounce((e) => {
Expand Down Expand Up @@ -220,7 +229,11 @@ export default function Page({ events, services, domains }: PageProps) {
type="text"
name="event"
id="event"
onChange={debouncedFilter}
onChange={(e) => {
setSearchFilter(e.target.value);
debouncedFilter(e);
}}
value={searchFilter}
className="focus:ring-gray-500 focus:border-gray-500 block w-full pl-10 sm:text-sm border-gray-300 rounded-md"
/>
</div>
Expand Down
15 changes: 14 additions & 1 deletion packages/eventcatalog/pages/services.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ChevronDownIcon, SearchIcon } from '@heroicons/react/solid';
import ServiceGrid from '@/components/Grids/ServiceGrid';
import { getAllServices } from '@/lib/services';
import { useConfig } from '@/hooks/EventCatalog';
import { useRouter } from 'next/router';

function classNames(...classes) {
return classes.filter(Boolean).join(' ');
Expand Down Expand Up @@ -91,6 +92,14 @@ export default function Page({ services }: PageProps) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedFilters, searchFilter]);

const router = useRouter();

useEffect(() => {
if (router.query.q) {
setSearchFilter(router.query.q as string);
}
}, [router.query.q]);

const debouncedFilter = useCallback(
debounce((e) => {
setSearchFilter(e.target.value);
Expand Down Expand Up @@ -174,7 +183,11 @@ export default function Page({ services }: PageProps) {
type="text"
name="service"
id="service"
onChange={debouncedFilter}
onChange={(e) => {
setSearchFilter(e.target.value);
debouncedFilter(e);
}}
value={searchFilter}
className="focus:ring-gray-500 focus:border-gray-500 block w-full pl-10 sm:text-sm border-gray-300 rounded-md"
/>
</div>
Expand Down
Loading