-
-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Introduce advanced search capabilities (#753)
* feat: Implement search filtering in the backend * feat: Implement search language parser * rename matcher name * Add ability to interleve text * More fixes * be more tolerable to parsing errors * Add a search query explainer widget * Handle date parsing gracefully * Fix the lockfile * Encode query search param * Fix table body error * Fix error when writing quotes
- Loading branch information
1 parent
f476fca
commit cbaf9e6
Showing
11 changed files
with
1,054 additions
and
20 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
apps/web/components/dashboard/search/QueryExplainerTooltip.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,98 @@ | ||
import InfoTooltip from "@/components/ui/info-tooltip"; | ||
import { Table, TableBody, TableCell, TableRow } from "@/components/ui/table"; | ||
|
||
import { TextAndMatcher } from "@hoarder/shared/searchQueryParser"; | ||
import { Matcher } from "@hoarder/shared/types/search"; | ||
|
||
export default function QueryExplainerTooltip({ | ||
parsedSearchQuery, | ||
className, | ||
}: { | ||
parsedSearchQuery: TextAndMatcher & { result: string }; | ||
className?: string; | ||
}) { | ||
if (parsedSearchQuery.result == "invalid") { | ||
return null; | ||
} | ||
|
||
const MatcherComp = ({ matcher }: { matcher: Matcher }) => { | ||
switch (matcher.type) { | ||
case "tagName": | ||
return ( | ||
<TableRow> | ||
<TableCell>Tag Name</TableCell> | ||
<TableCell>{matcher.tagName}</TableCell> | ||
</TableRow> | ||
); | ||
case "listName": | ||
return ( | ||
<TableRow> | ||
<TableCell>List Name</TableCell> | ||
<TableCell>{matcher.listName}</TableCell> | ||
</TableRow> | ||
); | ||
case "dateAfter": | ||
return ( | ||
<TableRow> | ||
<TableCell>Created After</TableCell> | ||
<TableCell>{matcher.dateAfter.toDateString()}</TableCell> | ||
</TableRow> | ||
); | ||
case "dateBefore": | ||
return ( | ||
<TableRow> | ||
<TableCell>Created Before</TableCell> | ||
<TableCell>{matcher.dateBefore.toDateString()}</TableCell> | ||
</TableRow> | ||
); | ||
case "favourited": | ||
return ( | ||
<TableRow> | ||
<TableCell>Favourited</TableCell> | ||
<TableCell>{matcher.favourited.toString()}</TableCell> | ||
</TableRow> | ||
); | ||
case "archived": | ||
return ( | ||
<TableRow> | ||
<TableCell>Archived</TableCell> | ||
<TableCell>{matcher.archived.toString()}</TableCell> | ||
</TableRow> | ||
); | ||
case "and": | ||
case "or": | ||
return ( | ||
<TableRow> | ||
<TableCell className="capitalize">{matcher.type}</TableCell> | ||
<TableCell> | ||
<Table> | ||
<TableBody> | ||
{matcher.matchers.map((m, i) => ( | ||
<MatcherComp key={i} matcher={m} /> | ||
))} | ||
</TableBody> | ||
</Table> | ||
</TableCell> | ||
</TableRow> | ||
); | ||
} | ||
}; | ||
|
||
return ( | ||
<InfoTooltip className={className}> | ||
<Table> | ||
<TableBody> | ||
{parsedSearchQuery.text && ( | ||
<TableRow> | ||
<TableCell>Text</TableCell> | ||
<TableCell>{parsedSearchQuery.text}</TableCell> | ||
</TableRow> | ||
)} | ||
{parsedSearchQuery.matcher && ( | ||
<MatcherComp matcher={parsedSearchQuery.matcher} /> | ||
)} | ||
</TableBody> | ||
</Table> | ||
</InfoTooltip> | ||
); | ||
} |
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
Oops, something went wrong.