From 0757bd2b556996b9c434ac43e3e4a3b042ef5802 Mon Sep 17 00:00:00 2001
From: Nate Sesti <sestinj@gmail.com>
Date: Fri, 25 Aug 2023 16:59:02 -0700
Subject: feat: :sparkles: filter history by workspace

---
 extension/react-app/src/pages/history.tsx | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

(limited to 'extension/react-app/src/pages/history.tsx')

diff --git a/extension/react-app/src/pages/history.tsx b/extension/react-app/src/pages/history.tsx
index 2eb895b1..2a3070e6 100644
--- a/extension/react-app/src/pages/history.tsx
+++ b/extension/react-app/src/pages/history.tsx
@@ -7,6 +7,7 @@ import { useNavigate } from "react-router-dom";
 import { secondaryDark, vscBackground } from "../components";
 import styled from "styled-components";
 import { ArrowLeftIcon } from "@heroicons/react/24/outline";
+import CheckDiv from "../components/CheckDiv";
 
 const Tr = styled.tr`
   &:hover {
@@ -36,6 +37,11 @@ function History() {
   const [sessions, setSessions] = useState<SessionInfo[]>([]);
   const client = useContext(GUIClientContext);
   const apiUrl = useSelector((state: RootStore) => state.config.apiUrl);
+  const workspacePaths = useSelector(
+    (state: RootStore) => state.config.workspacePaths
+  );
+
+  const [filteringByWorkspace, setFilteringByWorkspace] = useState(false);
 
   useEffect(() => {
     const fetchSessions = async () => {
@@ -67,9 +73,24 @@ function History() {
         />
         <h1 className="text-2xl font-bold m-4 inline-block">History</h1>
       </div>
+      <CheckDiv
+        checked={filteringByWorkspace}
+        onClick={() => setFilteringByWorkspace((prev) => !prev)}
+        title="Filter by workspace"
+      />
       <table className="w-full">
         <tbody>
           {sessions
+            .filter((session) => {
+              if (
+                !filteringByWorkspace ||
+                typeof workspacePaths === "undefined" ||
+                typeof session.workspace_directory === "undefined"
+              ) {
+                return true;
+              }
+              return workspacePaths.includes(session.workspace_directory);
+            })
             .sort(
               (a, b) =>
                 parseDate(b.date_created).getTime() -
-- 
cgit v1.2.3-70-g09d2

