Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(admin): Replace nested table with raw JSON and copy to clipboard button #2310

Merged
merged 1 commit into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion snuba/admin/dist/bundle.js

Large diffs are not rendered by default.

24 changes: 20 additions & 4 deletions snuba/admin/static/clickhouse_queries/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useEffect, useState } from "react";
import Client from "../api_client";
import { Table } from "../table";
import { COLORS } from "../theme";

import {
ClickhouseNodeData,
Expand Down Expand Up @@ -67,6 +68,10 @@ function ClickhouseQueries(props: { api: Client }) {
});
}

function copyText(text: string) {
window.navigator.clipboard.writeText(text);
}

return (
<div>
<form>
Expand Down Expand Up @@ -131,15 +136,26 @@ function ClickhouseQueries(props: { api: Client }) {
headerData={["Query", "Response"]}
rowData={queryResultHistory.map((queryResult) => [
<span>{queryResult.input_query}</span>,
<Table
headerData={queryResult.column_names}
rowData={queryResult.rows}
/>,
<div>
<div style={jsonStyle}>{JSON.stringify(queryResult)}</div>
<button onClick={() => copyText(JSON.stringify(queryResult))}>
Copy to clipboard
</button>
</div>,
])}
/>
</div>
</div>
);
}

const jsonStyle = {
padding: 10,
border: `1px solid ${COLORS.TABLE_BORDER}`,
fontFamily: "monospace",
borderRadius: 4,
backgroundColor: COLORS.BG_LIGHT,
marginBottom: 10,
};

export default ClickhouseQueries;
1 change: 1 addition & 0 deletions snuba/admin/static/theme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const COLORS = {
TEXT_DEFAULT: "black",
TEXT_LIGHTER: "#464646",
TEXT_INACTIVE: "#858585",
BG_LIGHT: "#E3E3E3",
};

export { COLORS };