From 877b165a9ae54c3a77ee10d965c5218e3dd5f21b Mon Sep 17 00:00:00 2001 From: ManishMadan2882 Date: Tue, 5 Nov 2024 00:44:02 +0530 Subject: [PATCH 1/3] (feat:docs) sort --- application/api/user/routes.py | 4 ++- frontend/src/api/services/userService.ts | 3 +- frontend/src/preferences/preferenceApi.ts | 7 +++-- frontend/src/settings/Documents.tsx | 35 +++++++++++++++++++---- 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/application/api/user/routes.py b/application/api/user/routes.py index c33a6c84c..8e62683e6 100644 --- a/application/api/user/routes.py +++ b/application/api/user/routes.py @@ -433,6 +433,8 @@ class CombinedJson(Resource): @api.doc(description="Provide JSON file with combined available indexes") def get(self): user = "local" + sort_field = request.args.get('sort', 'date') # Default to 'date' + sort_order = request.args.get('order', "desc") # Default to 'desc' data = [ { "name": "default", @@ -445,7 +447,7 @@ def get(self): ] try: - for index in sources_collection.find({"user": user}).sort("date", -1): + for index in sources_collection.find({"user": user}).sort(sort_field, 1 if sort_order=="asc" else -1): data.append( { "id": str(index["_id"]), diff --git a/frontend/src/api/services/userService.ts b/frontend/src/api/services/userService.ts index c5bbba7dd..53b38f50c 100644 --- a/frontend/src/api/services/userService.ts +++ b/frontend/src/api/services/userService.ts @@ -2,7 +2,8 @@ import apiClient from '../client'; import endpoints from '../endpoints'; const userService = { - getDocs: (): Promise => apiClient.get(endpoints.USER.DOCS), + getDocs: (sort = 'date', order = 'desc'): Promise => + apiClient.get(`${endpoints.USER.DOCS}?sort=${sort}&order=${order}`), checkDocs: (data: any): Promise => apiClient.post(endpoints.USER.DOCS_CHECK, data), getAPIKeys: (): Promise => apiClient.get(endpoints.USER.API_KEYS), diff --git a/frontend/src/preferences/preferenceApi.ts b/frontend/src/preferences/preferenceApi.ts index ed730f7c6..af1060b83 100644 --- a/frontend/src/preferences/preferenceApi.ts +++ b/frontend/src/preferences/preferenceApi.ts @@ -3,9 +3,12 @@ import userService from '../api/services/userService'; import { Doc } from '../models/misc'; //Fetches all JSON objects from the source. We only use the objects with the "model" property in SelectDocsModal.tsx. Hopefully can clean up the source file later. -export async function getDocs(): Promise { +export async function getDocs( + sort = 'date', + order = 'desc', +): Promise { try { - const response = await userService.getDocs(); + const response = await userService.getDocs(sort, order); const data = await response.json(); const docs: Doc[] = []; diff --git a/frontend/src/settings/Documents.tsx b/frontend/src/settings/Documents.tsx index 004b6f487..f94d1a87b 100644 --- a/frontend/src/settings/Documents.tsx +++ b/frontend/src/settings/Documents.tsx @@ -45,14 +45,30 @@ const Documents: React.FC = ({ const [modalState, setModalState] = useState('INACTIVE'); // Initialize with inactive state const [isOnboarding, setIsOnboarding] = useState(false); // State for onboarding flag const [loading, setLoading] = useState(false); - + const [sortField, setSortField] = useState<'date' | 'tokens'>('date'); + const [sortOrder, setSortOrder] = useState<'asc' | 'desc'>('desc'); const syncOptions = [ { label: 'Never', value: 'never' }, { label: 'Daily', value: 'daily' }, { label: 'Weekly', value: 'weekly' }, { label: 'Monthly', value: 'monthly' }, ]; - + const refreshDocs = (field: 'date' | 'tokens') => { + if (field === sortField) { + setSortOrder(sortOrder === 'asc' ? 'desc' : 'asc'); + } else { + setSortOrder('desc'); + setSortField(field); + } + getDocs(sortField, sortOrder) + .then((data) => { + dispatch(setSourceDocs(data)); + }) + .catch((error) => console.error(error)) + .finally(() => { + setLoading(false); + }); + }; const handleManageSync = (doc: Doc, sync_frequency: string) => { setLoading(true); userService @@ -110,19 +126,28 @@ const Documents: React.FC = ({
{t('settings.documents.date')} - + refreshDocs('date')} + src={caretSort} + alt="sort" + />
{t('settings.documents.tokenUsage')} - + refreshDocs('tokens')} + src={caretSort} + alt="sort" + />
{t('settings.documents.type')} -
From 7e24995afe15ff08a31af5ea97a12a90ebdafd93 Mon Sep 17 00:00:00 2001 From: ManishMadan2882 Date: Tue, 5 Nov 2024 00:48:12 +0530 Subject: [PATCH 2/3] fix(nav): minor ui --- frontend/src/Navigation.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/Navigation.tsx b/frontend/src/Navigation.tsx index ce23e90ef..3591469b1 100644 --- a/frontend/src/Navigation.tsx +++ b/frontend/src/Navigation.tsx @@ -254,7 +254,7 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) { ref={navRef} className={`${ !navOpen && '-ml-96 md:-ml-[18rem]' - } duration-20 fixed top-0 z-40 flex h-full w-72 flex-col border-r-[1px] border-b-0 bg-white transition-all dark:border-r-purple-taupe dark:bg-chinese-black dark:text-white`} + } duration-20 fixed top-0 z-20 flex h-full w-72 flex-col border-r-[1px] border-b-0 bg-white transition-all dark:border-r-purple-taupe dark:bg-chinese-black dark:text-white`} >
Date: Tue, 5 Nov 2024 01:36:54 +0530 Subject: [PATCH 3/3] fix(all sources): text overflows --- frontend/src/conversation/ConversationBubble.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/conversation/ConversationBubble.tsx b/frontend/src/conversation/ConversationBubble.tsx index a9a05168b..284c2b568 100644 --- a/frontend/src/conversation/ConversationBubble.tsx +++ b/frontend/src/conversation/ConversationBubble.tsx @@ -474,7 +474,7 @@ function AllSources(sources: AllSourcesProps) { > ) : null} -

+

{source.text}