Skip to content

Commit

Permalink
Merge pull request #46 from bruinenxyz/hungle/bru-1054-enable-copy-paste
Browse files Browse the repository at this point in the history
BRU-1054 Enable copy paste
  • Loading branch information
hungle-bruinen authored Apr 15, 2024
2 parents d010cbf + 66be51f commit acb85cb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
16 changes: 15 additions & 1 deletion frontend/src/components/table/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
Column,
ColumnHeaderCell,
Table2,
TableLoadingOption,
TruncatedFormat,
TruncatedPopoverMode,
} from "@blueprintjs/table";
Expand All @@ -27,6 +26,7 @@ import React, { useEffect, useState } from "react";
import * as _ from "lodash";
import { HeaderCellRenderer } from "@blueprintjs/table/lib/esm/headers/header";
import { useUpdateTable } from "@/data/use-tables";
import { AppToaster } from "../toaster/toaster";
interface Props {
table?: HydratedTable;
results:
Expand Down Expand Up @@ -336,6 +336,19 @@ const Table: React.FC<Props> = (props) => {
}
}

function getCellData(rowIndex: number, columnIndex: number) {
const cellData = tableData?.columns[orderedColumns[columnIndex]][rowIndex];

AppToaster(document.body).then((toaster) => {
toaster.show({
message: `Copied ${cellData} to clipboard`,
icon: "clipboard",
});
});

return cellData;
}

if (isLoadingResults && !tableData) {
return <Loading />;
}
Expand Down Expand Up @@ -364,6 +377,7 @@ const Table: React.FC<Props> = (props) => {
enableColumnResizing
onColumnsReordered={orderColumn}
enableFocusedCell={true}
getCellClipboardData={getCellData}
// loadingOptions={[TableLoadingOption.CELLS]}
>
{orderedColumns.map((key) => (
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/components/toaster/toaster.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { OverlayToaster, Position } from "@blueprintjs/core";

/** Singleton toaster instance. Create separate instances for different options. */
export const AppToaster = OverlayToaster.createAsync({
position: Position.BOTTOM_RIGHT,
});
export const AppToaster = (container?: HTMLElement) =>
OverlayToaster.createAsync(
{
position: Position.BOTTOM_RIGHT,
},
{ container: container },
);

0 comments on commit acb85cb

Please sign in to comment.