From cb19d930be8f3748a4819e5431eabfe1c9a18ce1 Mon Sep 17 00:00:00 2001 From: Ike Saunders Date: Thu, 19 Dec 2024 16:41:21 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20persist=20alt=20text=20between=20im?= =?UTF-8?q?age=20revisions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adminSiteClient/ImagesIndexPage.tsx | 80 ++++++++++++++++++++--------- adminSiteServer/apiRouter.ts | 2 + 2 files changed, 57 insertions(+), 25 deletions(-) diff --git a/adminSiteClient/ImagesIndexPage.tsx b/adminSiteClient/ImagesIndexPage.tsx index 24ba88b42c..ecd8a452f9 100644 --- a/adminSiteClient/ImagesIndexPage.tsx +++ b/adminSiteClient/ImagesIndexPage.tsx @@ -14,6 +14,7 @@ import { Popover, Table, Upload, + notification, } from "antd" import { AdminLayout } from "./AdminLayout.js" import { AdminAppContext } from "./AdminAppContext.js" @@ -31,6 +32,7 @@ import { RcFile } from "antd/es/upload/interface.js" import { CLOUDFLARE_IMAGES_URL } from "../settings/clientSettings.js" import { Dictionary, keyBy } from "lodash" import cx from "classnames" +import { NotificationInstance } from "antd/es/notification/interface.js" type ImageMap = Record @@ -237,10 +239,12 @@ function createColumns({ api, users, usage, + notificationApi, }: { api: ImageEditorApi users: UserMap usage: Dictionary + notificationApi: NotificationInstance }): ColumnsType { return [ { @@ -376,7 +380,11 @@ function createColumns({ return ( - + - - + <> + + + + ) } +const NotificationContext = React.createContext(null) + export function ImageIndexPage() { const { admin } = useContext(AdminAppContext) + const [notificationApi, notificationContextHolder] = + notification.useNotification() const [images, setImages] = useState({}) const [users, setUsers] = useState({}) const [usage, setUsage] = useState>({}) @@ -605,8 +630,8 @@ export function ImageIndexPage() { ) const columns = useMemo( - () => createColumns({ api, users, usage }), - [api, users, usage] + () => createColumns({ api, users, usage, notificationApi }), + [api, users, usage, notificationApi] ) useEffect(() => { @@ -617,18 +642,23 @@ export function ImageIndexPage() { return ( -
- - setFilenameSearchValue(e.target.value)} - style={{ width: 500, marginBottom: 20 }} - /> - - - - + + {notificationContextHolder} +
+ + + setFilenameSearchValue(e.target.value) + } + style={{ width: 500, marginBottom: 20 }} + /> + + +
+ + ) } diff --git a/adminSiteServer/apiRouter.ts b/adminSiteServer/apiRouter.ts index 945d6b6670..5cf0e042bc 100644 --- a/adminSiteServer/apiRouter.ts +++ b/adminSiteServer/apiRouter.ts @@ -3241,6 +3241,7 @@ putRouteWithRWTransaction(apiRouter, "/images/:id", async (req, res, trx) => { const originalCloudflareId = image.cloudflareId const originalFilename = image.filename + const originalAltText = image.defaultAlt if (!originalCloudflareId) { throw new JsonError( @@ -3262,6 +3263,7 @@ putRouteWithRWTransaction(apiRouter, "/images/:id", async (req, res, trx) => { cloudflareId: newCloudflareId, updatedAt: new Date().getTime(), userId: res.locals.user.id, + defaultAlt: originalAltText, hash, version: image.version + 1, })