From d3aa97ab9938a649abe1374641d185a05525c679 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Fri, 19 Apr 2024 08:35:37 +1000 Subject: [PATCH] feat(ui): add copy graph button to queue item detail view --- .../ImageMetadataViewer/DataViewer.tsx | 37 +++++++++++++++++-- .../components/QueueList/QueueItemDetail.tsx | 11 +++++- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/invokeai/frontend/web/src/features/gallery/components/ImageMetadataViewer/DataViewer.tsx b/invokeai/frontend/web/src/features/gallery/components/ImageMetadataViewer/DataViewer.tsx index 8f6cef2c20..a6d0481b89 100644 --- a/invokeai/frontend/web/src/features/gallery/components/ImageMetadataViewer/DataViewer.tsx +++ b/invokeai/frontend/web/src/features/gallery/components/ImageMetadataViewer/DataViewer.tsx @@ -1,4 +1,4 @@ -import { Box, Flex, IconButton, Tooltip } from '@invoke-ai/ui-library'; +import { Box, Flex, IconButton, Tooltip, useShiftModifier } from '@invoke-ai/ui-library'; import { getOverlayScrollbarsParams } from 'common/components/OverlayScrollbars/constants'; import { isString } from 'lodash-es'; import { OverlayScrollbarsComponent } from 'overlayscrollbars-react'; @@ -9,18 +9,19 @@ import { PiCopyBold, PiDownloadSimpleBold } from 'react-icons/pi'; type Props = { label: string; - data: object | string; + data: unknown; fileName?: string; withDownload?: boolean; withCopy?: boolean; + extraCopyActions?: { label: string; getData: (data: unknown) => unknown }[]; }; const overlayscrollbarsOptions = getOverlayScrollbarsParams('scroll', 'scroll').options; const DataViewer = (props: Props) => { - const { label, data, fileName, withDownload = true, withCopy = true } = props; + const { label, data, fileName, withDownload = true, withCopy = true, extraCopyActions } = props; const dataString = useMemo(() => (isString(data) ? data : JSON.stringify(data, null, 2)), [data]); - + const shift = useShiftModifier(); const handleCopy = useCallback(() => { navigator.clipboard.writeText(dataString); }, [dataString]); @@ -67,6 +68,10 @@ const DataViewer = (props: Props) => { /> )} + {shift && + extraCopyActions?.map(({ label, getData }) => ( + + ))} ); @@ -78,3 +83,27 @@ const overlayScrollbarsStyles: CSSProperties = { height: '100%', width: '100%', }; + +type ExtraCopyActionProps = { + label: string; + data: unknown; + getData: (data: unknown) => unknown; +}; +const ExtraCopyAction = ({ label, data, getData }: ExtraCopyActionProps) => { + const { t } = useTranslation(); + const handleCopy = useCallback(() => { + navigator.clipboard.writeText(JSON.stringify(getData(data), null, 2)); + }, [data, getData]); + + return ( + + } + variant="ghost" + opacity={0.7} + onClick={handleCopy} + /> + + ); +}; diff --git a/invokeai/frontend/web/src/features/queue/components/QueueList/QueueItemDetail.tsx b/invokeai/frontend/web/src/features/queue/components/QueueList/QueueItemDetail.tsx index a26a7d4360..b719ae0a92 100644 --- a/invokeai/frontend/web/src/features/queue/components/QueueList/QueueItemDetail.tsx +++ b/invokeai/frontend/web/src/features/queue/components/QueueList/QueueItemDetail.tsx @@ -3,6 +3,7 @@ import DataViewer from 'features/gallery/components/ImageMetadataViewer/DataView import { useCancelBatch } from 'features/queue/hooks/useCancelBatch'; import { useCancelQueueItem } from 'features/queue/hooks/useCancelQueueItem'; import { getSecondsFromTimestamps } from 'features/queue/util/getSecondsFromTimestamps'; +import { get } from 'lodash-es'; import type { ReactNode } from 'react'; import { memo, useMemo } from 'react'; import { useTranslation } from 'react-i18next'; @@ -92,7 +93,15 @@ const QueueItemComponent = ({ queueItemDTO }: Props) => { )} - {queueItem ? : } + {queueItem ? ( + get(data, 'session.graph') }]} + /> + ) : ( + + )} );