From 2b1a32fd9ceb22ad6256467c58eb927ae0ee9d9c Mon Sep 17 00:00:00 2001 From: Shun Miyazawa <34241526+miya@users.noreply.github.com> Date: Fri, 3 Jan 2025 16:38:36 +0900 Subject: [PATCH] feat: Add filter to show only apps created by the user (#11968) --- api/controllers/console/app/app.py | 3 ++- api/services/app_service.py | 5 ++++- web/app/(commonLayout)/apps/Apps.tsx | 13 +++++++++++-- web/i18n/de-DE/app.ts | 1 + web/i18n/en-US/app.ts | 1 + web/i18n/es-ES/app.ts | 1 + web/i18n/fa-IR/app.ts | 1 + web/i18n/fr-FR/app.ts | 1 + web/i18n/hi-IN/app.ts | 1 + web/i18n/it-IT/app.ts | 1 + web/i18n/ja-JP/app.ts | 1 + web/i18n/ko-KR/app.ts | 1 + web/i18n/pl-PL/app.ts | 1 + web/i18n/pt-BR/app.ts | 1 + web/i18n/ro-RO/app.ts | 1 + web/i18n/ru-RU/app.ts | 1 + web/i18n/sl-SI/app.ts | 1 + web/i18n/th-TH/app.ts | 1 + web/i18n/tr-TR/app.ts | 1 + web/i18n/uk-UA/app.ts | 1 + web/i18n/vi-VN/app.ts | 1 + web/i18n/zh-Hans/app.ts | 1 + web/i18n/zh-Hant/app.ts | 1 + 23 files changed, 37 insertions(+), 4 deletions(-) diff --git a/api/controllers/console/app/app.py b/api/controllers/console/app/app.py index 9cd56cef0b..4aa10ac6e9 100644 --- a/api/controllers/console/app/app.py +++ b/api/controllers/console/app/app.py @@ -57,12 +57,13 @@ class AppListApi(Resource): ) parser.add_argument("name", type=str, location="args", required=False) parser.add_argument("tag_ids", type=uuid_list, location="args", required=False) + parser.add_argument("is_created_by_me", type=inputs.boolean, location="args", required=False) args = parser.parse_args() # get app list app_service = AppService() - app_pagination = app_service.get_paginate_apps(current_user.current_tenant_id, args) + app_pagination = app_service.get_paginate_apps(current_user.id, current_user.current_tenant_id, args) if not app_pagination: return {"data": [], "total": 0, "page": 1, "limit": 20, "has_more": False} diff --git a/api/services/app_service.py b/api/services/app_service.py index 41c15bbf0a..1fd7cb5e33 100644 --- a/api/services/app_service.py +++ b/api/services/app_service.py @@ -26,9 +26,10 @@ from tasks.remove_app_and_related_data_task import remove_app_and_related_data_t class AppService: - def get_paginate_apps(self, tenant_id: str, args: dict) -> Pagination | None: + def get_paginate_apps(self, user_id: str, tenant_id: str, args: dict) -> Pagination | None: """ Get app list with pagination + :param user_id: user id :param tenant_id: tenant id :param args: request args :return: @@ -44,6 +45,8 @@ class AppService: elif args["mode"] == "channel": filters.append(App.mode == AppMode.CHANNEL.value) + if args.get("is_created_by_me", False): + filters.append(App.created_by == user_id) if args.get("name"): name = args["name"][:30] filters.append(App.name.ilike(f"%{name}%")) diff --git a/web/app/(commonLayout)/apps/Apps.tsx b/web/app/(commonLayout)/apps/Apps.tsx index 5269571c21..34a28d908e 100644 --- a/web/app/(commonLayout)/apps/Apps.tsx +++ b/web/app/(commonLayout)/apps/Apps.tsx @@ -25,16 +25,18 @@ import Input from '@/app/components/base/input' import { useStore as useTagStore } from '@/app/components/base/tag-management/store' import TagManagementModal from '@/app/components/base/tag-management' import TagFilter from '@/app/components/base/tag-management/filter' +import CheckboxWithLabel from '@/app/components/datasets/create/website/base/checkbox-with-label' const getKey = ( pageIndex: number, previousPageData: AppListResponse, activeTab: string, + isCreatedByMe: boolean, tags: string[], keywords: string, ) => { if (!pageIndex || previousPageData.has_more) { - const params: any = { url: 'apps', params: { page: pageIndex + 1, limit: 30, name: keywords } } + const params: any = { url: 'apps', params: { page: pageIndex + 1, limit: 30, name: keywords, is_created_by_me: isCreatedByMe } } if (activeTab !== 'all') params.params.mode = activeTab @@ -58,6 +60,7 @@ const Apps = () => { defaultTab: 'all', }) const { query: { tagIDs = [], keywords = '' }, setQuery } = useAppsQueryState() + const [isCreatedByMe, setIsCreatedByMe] = useState(false) const [tagFilterValue, setTagFilterValue] = useState(tagIDs) const [searchKeywords, setSearchKeywords] = useState(keywords) const setKeywords = useCallback((keywords: string) => { @@ -68,7 +71,7 @@ const Apps = () => { }, [setQuery]) const { data, isLoading, setSize, mutate } = useSWRInfinite( - (pageIndex: number, previousPageData: AppListResponse) => getKey(pageIndex, previousPageData, activeTab, tagIDs, searchKeywords), + (pageIndex: number, previousPageData: AppListResponse) => getKey(pageIndex, previousPageData, activeTab, isCreatedByMe, tagIDs, searchKeywords), fetchAppList, { revalidateFirstPage: true }, ) @@ -132,6 +135,12 @@ const Apps = () => { options={options} />
+ setIsCreatedByMe(!isCreatedByMe)} + />