Skip to content

Commit 8ad21d0

Browse files
authored
Merge pull request prometheus#16390 from ryanwuer/copy-notification-in-explore-metrics-modal
Make copy operation responsive after clicking copy icon in metrics explore modal
2 parents 08aa5e3 + 831f792 commit 8ad21d0

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

web/ui/mantine-ui/src/pages/query/MetricsExplorer/MetricsExplorer.tsx

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { FC, useMemo, useState } from "react";
22
import { useSuspenseAPIQuery } from "../../../api/api";
33
import { MetadataResult } from "../../../api/responseTypes/metadata";
4-
import { ActionIcon, Group, Stack, Table, TextInput } from "@mantine/core";
4+
import { ActionIcon, CopyButton, Group, Stack, Table, TextInput } from "@mantine/core";
55
import React from "react";
66
import { Fuzzy } from "@nexucis/fuzzy";
77
import sanitizeHTML from "sanitize-html";
8-
import { IconCodePlus, IconCopy, IconZoomCode } from "@tabler/icons-react";
8+
import { IconCheck, IconCodePlus, IconCopy, IconZoomCode } from "@tabler/icons-react";
99
import LabelsExplorer from "./LabelsExplorer";
1010
import { useDebouncedValue } from "@mantine/hooks";
1111
import classes from "./MetricsExplorer.module.css";
@@ -139,20 +139,29 @@ const MetricsExplorer: FC<MetricsExplorerProps> = ({
139139
stroke={1.5}
140140
/>
141141
</ActionIcon>
142-
<ActionIcon
143-
size="sm"
144-
color="gray"
145-
variant="light"
146-
title="Copy to clipboard"
147-
onClick={() => {
148-
navigator.clipboard.writeText(m.original);
149-
}}
150-
>
151-
<IconCopy
152-
style={{ width: "70%", height: "70%" }}
153-
stroke={1.5}
154-
/>
155-
</ActionIcon>
142+
<CopyButton value={m.original}>
143+
{({ copied, copy }) => (
144+
<ActionIcon
145+
size="sm"
146+
color="gray"
147+
variant="light"
148+
title="Copy to clipboard"
149+
onClick={copy}
150+
>
151+
{copied ? (
152+
<IconCheck
153+
style={{ width: "70%", height: "70%" }}
154+
stroke={1.5}
155+
/>
156+
) : (
157+
<IconCopy
158+
style={{ width: "70%", height: "70%" }}
159+
stroke={1.5}
160+
/>
161+
)}
162+
</ActionIcon>
163+
)}
164+
</CopyButton>
156165
</Group>
157166
</Group>
158167
</Table.Td>

0 commit comments

Comments
 (0)