From fa2daa610210b5c03d8b24ea396c4a2430cd7212 Mon Sep 17 00:00:00 2001 From: Germiniku Date: Thu, 19 Oct 2023 18:08:35 +0800 Subject: [PATCH] feat: panel edit icon button --- .../dashboard/components/PanelDatePicker.tsx | 6 +- .../dashboard/grid/PanelGrid/PanelGrid.tsx | 136 +++++++++++++++--- 2 files changed, 118 insertions(+), 24 deletions(-) diff --git a/ui/src/views/dashboard/components/PanelDatePicker.tsx b/ui/src/views/dashboard/components/PanelDatePicker.tsx index 42f971cce..134a4963a 100644 --- a/ui/src/views/dashboard/components/PanelDatePicker.tsx +++ b/ui/src/views/dashboard/components/PanelDatePicker.tsx @@ -90,17 +90,17 @@ const PanelDatePicker = ({id, timeRange, showTime = true, showRealTime = false, {/* */} - {showIcon && + {showIcon && } { showTime && <> - {!isMobileScreen && + {!isMobileScreen && {value.startRaw.toString().startsWith('now') ? value.startRaw : dateTimeFormat(value.start)} to {value.endRaw.toString().startsWith('now') ? value.endRaw : dateTimeFormat(value.end)} } { isLargeScreen && showRealTime && value.startRaw.toString().startsWith('now') && - + {dateTimeFormat(value.start)} - {dateTimeFormat(value.end)} } diff --git a/ui/src/views/dashboard/grid/PanelGrid/PanelGrid.tsx b/ui/src/views/dashboard/grid/PanelGrid/PanelGrid.tsx index e4b9b1ec9..7b0a31045 100644 --- a/ui/src/views/dashboard/grid/PanelGrid/PanelGrid.tsx +++ b/ui/src/views/dashboard/grid/PanelGrid/PanelGrid.tsx @@ -11,8 +11,8 @@ // See the License for the specific language governing permissions and // limitations under the License. import { Dashboard, Panel, PanelProps, PanelQuery } from "types/dashboard" -import { Box, Center, HStack, Menu, MenuButton, MenuDivider, MenuItem, MenuList, Popover, PopoverArrow, PopoverBody, PopoverContent, PopoverTrigger, Portal, Text, Tooltip, useColorMode, useColorModeValue, useDisclosure, useToast } from "@chakra-ui/react"; -import { FaBook, FaBug, FaEdit, FaRegClock, FaRegClone, FaRegCopy, FaRegEye, FaRegEyeSlash, FaTrashAlt } from "react-icons/fa"; +import { Box, Center, HStack, Menu, MenuButton, MenuDivider, MenuItem, MenuList, Popover, PopoverArrow, PopoverBody, PopoverContent, PopoverTrigger, Portal, Text, Tooltip, useColorMode, useColorModeValue, useDisclosure, useToast, IconButton } from "@chakra-ui/react"; +import { FaBook, FaBug, FaEdit, FaEllipsisV, FaRegClock, FaRegClone, FaRegCopy, FaRegEye, FaRegEyeSlash, FaTrashAlt } from "react-icons/fa"; import { IoMdInformation } from "react-icons/io"; import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react"; import { DatasourceMaxDataPoints, DatasourceMinInterval, PANEL_HEADER_HEIGHT } from "src/data/constants"; @@ -56,6 +56,8 @@ import { PanelTypeGraph } from "../../plugins/built-in/panel/graph/types"; import { DatasourceTypeTestData } from "../../plugins/built-in/datasource/testdata/types"; import PanelDatePicker from "../../components/PanelDatePicker"; import useEmbed from "hooks/useEmbed"; +import { css } from "@emotion/react"; +import customColors from "theme/colors"; interface PanelGridProps { dashboard: Dashboard @@ -347,7 +349,13 @@ export const PanelComponent = ({ dashboard, panel, variables, onRemovePanel, onH return res }, [panel.transform, panel.enableTransform, panelData]) - return + return {data && @@ -364,12 +372,13 @@ export const PanelComponent = ({ dashboard, panel, variables, onRemovePanel, onH } {loading && } - {!loading && panel.enableScopeTime && + + {/* {!loading && panel.enableScopeTime && - + { panel.scopeTime = tr @@ -377,11 +386,11 @@ export const PanelComponent = ({ dashboard, panel, variables, onRemovePanel, onH type: UpdatePanelEvent, data: cloneDeep(panel) }) - }} showIcon/> + }} showIcon /> Panel time range - } + } */} } @@ -425,24 +434,109 @@ const PanelHeader = ({ dashboardId, queryError, panel, onCopyPanel, onRemovePane }
- - e.stopPropagation()} - disabled={embed} - > -
{!isEmpty(title) ? {title} :  }
-
- - + { + panel.enableScopeTime && ( + <> + + + + + + { + panel.scopeTime = tr + dispatch({ + type: UpdatePanelEvent, + data: cloneDeep(panel) + }) + }} showIcon /> + + + + ) + } +
+ {!isEmpty(title) ? + + + + {title} + + + :  } +
+ + + e.stopPropagation()} + disabled={embed} + cursor={'pointer'} + as={IconButton} + aria-label='Options' + icon={ + + + } + size={'sm'} + variant={'none'} + > +
+ { + !isEmpty(title) + ? + + + {title} + + + : +   + } +
+
+ + } onClick={() => addParamToUrl({ edit: panel.id })}>{t.edit} } onClick={() => onCopyPanel(panel, "copy")}>{t.copy} } onClick={() => onCopyPanel(panel, "clone")}>{t.clone} } onClick={onOpen}>{t1.debugPanel} } onClick={() => addParamToUrl({ viewPanel: viewPanel ? null : panel.id })}>{viewPanel ? t1.exitlView : t1.viewPanel} - {!viewPanel && <> } onClick={() => onHidePanel(panel)}>{t1.hidePanel} @@ -451,8 +545,8 @@ const PanelHeader = ({ dashboardId, queryError, panel, onCopyPanel, onRemovePane } - -
+
+
{/* */}