Skip to content

Commit

Permalink
feat: search bar filters on name and desc
Browse files Browse the repository at this point in the history
  • Loading branch information
rudouglas committed Jun 3, 2021
1 parent f26428d commit 181f043
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/pages/observability-packs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PropTypes from 'prop-types';
import { graphql } from 'gatsby';
import React from 'react';
import React, { useState } from 'react';
import DevSiteSeo from '../components/DevSiteSeo';
import { css } from '@emotion/react';
import PackTile from '../components/PackTile';
Expand All @@ -11,6 +11,8 @@ const ObservabilityPacksPage = ({ data, location }) => {
const {
allObservabilityPacks: { nodes: o11yPacks },
} = data;
const [filteredPacks, setFilteredPacks] = useState(o11yPacks);
console.log(o11yPacks)

return (
<>
Expand All @@ -23,6 +25,16 @@ const ObservabilityPacksPage = ({ data, location }) => {
`}
onClear={() => null}
placeholder="Search for an observability pack"
onChange={(e) => {
const tempFilteredPacks = o11yPacks.filter(
(pack) =>
pack.name.toLowerCase().includes(e.target.value.toLowerCase()) ||
pack.description
.toLowerCase()
.includes(e.target.value.toLowerCase())
);
setFilteredPacks(tempFilteredPacks);
}}
/>
<div
css={css`
Expand All @@ -38,7 +50,7 @@ const ObservabilityPacksPage = ({ data, location }) => {
}
`}
>
<span>Showing {o11yPacks.length} results</span>
<span>Showing {filteredPacks.length} results</span>
<div
css={css`
display: flex;
Expand Down Expand Up @@ -118,7 +130,7 @@ const ObservabilityPacksPage = ({ data, location }) => {
</div>
<div>
<PackList>
{o11yPacks.map((pack) => {
{filteredPacks.map((pack) => {
// TODO: Figure out what image should be shown
// if not added to API explicitly
const imgSrc = pack.dashboards?.[0]?.screenshots?.[0];
Expand Down

0 comments on commit 181f043

Please sign in to comment.