Skip to content

Commit

Permalink
fix: Add i18n for query explainer and add missing url matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedBassem committed Jan 2, 2025
1 parent 5ecdc36 commit 3bcb1e1
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 15 deletions.
2 changes: 1 addition & 1 deletion apps/browser-extension/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"jsx": "react-jsx",

"strict": true,
"noUnusedLocals": true,
"noUnusedLocals": false,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
Expand Down
71 changes: 57 additions & 14 deletions apps/web/components/dashboard/search/QueryExplainerTooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import InfoTooltip from "@/components/ui/info-tooltip";
import { Table, TableBody, TableCell, TableRow } from "@/components/ui/table";
import { useTranslation } from "@/lib/i18n/client";

import { TextAndMatcher } from "@hoarder/shared/searchQueryParser";
import { Matcher } from "@hoarder/shared/types/search";
Expand All @@ -13,6 +14,7 @@ export default function QueryExplainerTooltip({
parsedSearchQuery: TextAndMatcher & { result: string };
className?: string;
}) {
const { t } = useTranslation();
if (parsedSearchQuery.result == "invalid") {
return null;
}
Expand All @@ -23,7 +25,9 @@ export default function QueryExplainerTooltip({
return (
<TableRow>
<TableCell>
{matcher.inverse ? "Doesn't have" : "Has"} Tag
{matcher.inverse
? t("search.does_not_have_tag")
: t("search.has_tag")}
</TableCell>
<TableCell>{matcher.tagName}</TableCell>
</TableRow>
Expand All @@ -32,58 +36,82 @@ export default function QueryExplainerTooltip({
return (
<TableRow>
<TableCell>
{matcher.inverse ? "Is not in" : "Is in "} List
{matcher.inverse
? t("search.is_not_in_list")
: t("search.is_in_list")}
</TableCell>
<TableCell>{matcher.listName}</TableCell>
</TableRow>
);
case "dateAfter":
return (
<TableRow>
<TableCell>{matcher.inverse ? "Not" : ""} Created After</TableCell>
<TableCell>
{matcher.inverse
? t("search.not_created_on_or_after")
: t("search.created_on_or_after")}
</TableCell>
<TableCell>{matcher.dateAfter.toDateString()}</TableCell>
</TableRow>
);
case "dateBefore":
return (
<TableRow>
<TableCell>{matcher.inverse ? "Not" : ""} Created Before</TableCell>
<TableCell>
{matcher.inverse
? t("search.not_created_on_or_before")
: t("search.created_on_or_before")}
</TableCell>
<TableCell>{matcher.dateBefore.toDateString()}</TableCell>
</TableRow>
);
case "favourited":
return (
<TableRow>
<TableCell>Favourited</TableCell>
<TableCell>{matcher.favourited.toString()}</TableCell>
<TableCell colSpan={2} className="text-center">
{matcher.favourited
? t("search.is_favorited")
: t("search.is_not_favorited")}
</TableCell>
</TableRow>
);
case "archived":
return (
<TableRow>
<TableCell>Archived</TableCell>
<TableCell>{matcher.archived.toString()}</TableCell>
<TableCell colSpan={2} className="text-center">
{matcher.archived
? t("search.is_archived")
: t("search.is_not_archived")}
</TableCell>
</TableRow>
);
case "tagged":
return (
<TableRow>
<TableCell>Has Tags</TableCell>
<TableCell>{matcher.tagged.toString()}</TableCell>
<TableCell colSpan={2} className="text-center">
{matcher.tagged
? t("search.has_any_tag")
: t("search.has_no_tags")}
</TableCell>
</TableRow>
);
case "inlist":
return (
<TableRow>
<TableCell>In Any List</TableCell>
<TableCell>{matcher.inList.toString()}</TableCell>
<TableCell colSpan={2} className="text-center">
{matcher.inList
? t("search.is_in_any_list")
: t("search.is_not_in_any_list")}
</TableCell>
</TableRow>
);
case "and":
case "or":
return (
<TableRow>
<TableCell className="capitalize">{matcher.type}</TableCell>
<TableCell>
{matcher.type === "and" ? t("search.and") : t("search.or")}
</TableCell>
<TableCell>
<Table>
<TableBody>
Expand All @@ -95,6 +123,21 @@ export default function QueryExplainerTooltip({
</TableCell>
</TableRow>
);
case "url":
return (
<TableRow>
<TableCell>
{matcher.inverse
? t("search.url_does_not_contain")
: t("search.url_contains")}
</TableCell>
<TableCell>{matcher.url}</TableCell>
</TableRow>
);
default: {
const _exhaustiveCheck: never = matcher;
return null;
}
}
};

Expand All @@ -105,7 +148,7 @@ export default function QueryExplainerTooltip({
<TableBody>
{parsedSearchQuery.text && (
<TableRow>
<TableCell>Text</TableCell>
<TableCell>{t("search.full_text_search")}</TableCell>
<TableCell>{parsedSearchQuery.text}</TableCell>
</TableRow>
)}
Expand Down
23 changes: 23 additions & 0 deletions apps/web/lib/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,29 @@
"drag_and_drop_merging_info": "Drag and drop tags on each other to merge them",
"sort_by_name": "Sort by Name"
},
"search": {
"is_favorited": "Is Favorited",
"is_not_favorited": "Is Not Favorited",
"is_archived": "Is Archived",
"is_not_archived": "Is Not Archived",
"has_any_tag": "Has Any Tag",
"has_no_tags": "Has No Tag",
"is_in_any_list": "Is In Any List",
"is_not_in_any_list": "Is not In Any List",
"created_on_or_after": "Created on or After",
"not_created_on_or_after": "Not Created on or After",
"created_on_or_before": "Created on or Before",
"not_created_on_or_before": "Not Created on or Before",
"url_contains": "URL Contains",
"url_does_not_contain": "URL Does Not Contain",
"is_in_list": "Is In List",
"is_not_in_list": "Is not In List",
"has_tag": "Has Tag",
"does_not_have_tag": "Does Not Have Tag",
"full_text_search": "Full Text Search",
"and": "And",
"or": "Or"
},
"preview": {
"view_original": "View Original",
"cached_content": "Cached Content"
Expand Down
1 change: 1 addition & 0 deletions packages/trpc/lib/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ async function getIds(
return union(vals);
}
default: {
const _exhaustiveCheck: never = matcher;
throw new Error("Unknown matcher type");
}
}
Expand Down

0 comments on commit 3bcb1e1

Please sign in to comment.