From 6f982eb7e4ee67aa171a0966034b9702ba8baa29 Mon Sep 17 00:00:00 2001 From: Good Wood Date: Mon, 26 May 2025 18:20:53 +0800 Subject: [PATCH] feat: add author_name for app list card (#16900) Co-authored-by: crazywoola <427733928@qq.com> Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com> --- api/fields/app_fields.py | 2 ++ api/models/model.py | 9 +++++++++ web/app/(commonLayout)/apps/AppCard.tsx | 22 +++++++++++++++------- web/types/app.ts | 4 ++++ 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/api/fields/app_fields.py b/api/fields/app_fields.py index 416870cafa..500ca47c7e 100644 --- a/api/fields/app_fields.py +++ b/api/fields/app_fields.py @@ -100,6 +100,8 @@ app_partial_fields = { "updated_at": TimestampField, "tags": fields.List(fields.Nested(tag_fields)), "access_mode": fields.String, + "create_user_name": fields.String, + "author_name": fields.String, } diff --git a/api/models/model.py b/api/models/model.py index ee79fbd6b5..92a5c0d121 100644 --- a/api/models/model.py +++ b/api/models/model.py @@ -294,6 +294,15 @@ class App(Base): return tags or [] + @property + def author_name(self): + if self.created_by: + account = db.session.query(Account).filter(Account.id == self.created_by).first() + if account: + return account.name + + return None + class AppModelConfig(Base): __tablename__ = "app_model_configs" diff --git a/web/app/(commonLayout)/apps/AppCard.tsx b/web/app/(commonLayout)/apps/AppCard.tsx index 468c8244c0..42967b96f4 100644 --- a/web/app/(commonLayout)/apps/AppCard.tsx +++ b/web/app/(commonLayout)/apps/AppCard.tsx @@ -2,7 +2,7 @@ import { useContext, useContextSelector } from 'use-context-selector' import { useRouter } from 'next/navigation' -import { useCallback, useEffect, useState } from 'react' +import { useCallback, useEffect, useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import { RiBuildingLine, RiGlobalLine, RiLockLine, RiMoreFill } from '@remixicon/react' import cn from '@/utils/classnames' @@ -35,6 +35,7 @@ import Tooltip from '@/app/components/base/tooltip' import AccessControl from '@/app/components/app/app-access-control' import { AccessMode } from '@/models/access-control' import { useGlobalPublicStore } from '@/context/global-public-context' +import { formatTime } from '@/utils/time' export type AppCardProps = { app: App @@ -296,6 +297,15 @@ const AppCard = ({ app, onRefresh }: AppCardProps) => { setTags(app.tags) }, [app.tags]) + const EditTimeText = useMemo(() => { + const timeText = formatTime({ + date: (app.updated_at || app.created_at) * 1000, + dateFormat: 'MM/DD/YYYY h:mm', + }) + return `${t('datasetDocuments.segment.editedAt')} ${timeText}` + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [app.updated_at, app.created_at]) + return ( <>
{
{app.name}
-
- {app.mode === 'advanced-chat' &&
{t('app.types.advanced').toUpperCase()}
} - {app.mode === 'chat' &&
{t('app.types.chatbot').toUpperCase()}
} - {app.mode === 'agent-chat' &&
{t('app.types.agent').toUpperCase()}
} - {app.mode === 'workflow' &&
{t('app.types.workflow').toUpperCase()}
} - {app.mode === 'completion' &&
{t('app.types.completion').toUpperCase()}
} +
+
{app.author_name}
+
ยท
+
{EditTimeText}
diff --git a/web/types/app.ts b/web/types/app.ts index a6d2faea55..e4227adbe9 100644 --- a/web/types/app.ts +++ b/web/types/app.ts @@ -316,6 +316,8 @@ export type App = { name: string /** Description */ description: string + /** Author Name */ + author_name: string; /** * Icon Type @@ -348,6 +350,8 @@ export type App = { app_model_config: ModelConfig /** Timestamp of creation */ created_at: number + /** Timestamp of update */ + updated_at: number /** Web Application Configuration */ site: SiteConfig /** api site url */