From 59425b2c7d7a7a5ea3bd0d45491ec575c8107940 Mon Sep 17 00:00:00 2001 From: Manmeet Date: Mon, 26 Jun 2023 14:10:14 +0530 Subject: [PATCH] add copy/paste functionality for reference field --- src/components/Table/useMenuAction.tsx | 17 +++++++++++++++++ src/components/fields/Reference/index.tsx | 2 ++ 2 files changed, 19 insertions(+) diff --git a/src/components/Table/useMenuAction.tsx b/src/components/Table/useMenuAction.tsx index 2ef19c1b..7fd2276e 100644 --- a/src/components/Table/useMenuAction.tsx +++ b/src/components/Table/useMenuAction.tsx @@ -19,6 +19,9 @@ import { format } from "date-fns"; import { DATE_FORMAT, DATE_TIME_FORMAT } from "@src/constants/dates"; import { isDate, isFunction } from "lodash-es"; import { getDurationString } from "@src/components/fields/Duration/utils"; +import { doc } from "firebase/firestore"; +import { firebaseDbAtom } from "@src/sources/ProjectSourceFirebase"; +import { projectScope } from "@src/atoms/projectScope"; export const SUPPORTED_TYPES_COPY = new Set([ // TEXT @@ -56,6 +59,8 @@ export const SUPPORTED_TYPES_COPY = new Set([ FieldType.updatedBy, FieldType.createdAt, FieldType.updatedAt, + // CONNECTION + FieldType.reference, ]); export const SUPPORTED_TYPES_PASTE = new Set([ @@ -75,6 +80,8 @@ export const SUPPORTED_TYPES_PASTE = new Set([ FieldType.json, FieldType.code, FieldType.markdown, + // CONNECTION + FieldType.reference, ]); export function useMenuAction( @@ -87,6 +94,7 @@ export function useMenuAction( const updateField = useSetAtom(updateFieldAtom, tableScope); const [cellValue, setCellValue] = useState(); const [selectedCol, setSelectedCol] = useState(); + const [firebaseDb] = useAtom(firebaseDbAtom, projectScope); const handleCopy = useCallback(async () => { try { @@ -165,6 +173,13 @@ export function useMenuAction( case "string": parsed = text; break; + case "reference": + try { + parsed = doc(firebaseDb, text); + } catch (e: any) { + enqueueSnackbar(`Invalid reference.`, { variant: "error" }); + } + break; default: parsed = JSON.parse(text); break; @@ -319,6 +334,8 @@ export function useMenuAction( case FieldType.createdBy: case FieldType.updatedBy: return cellValue.displayName; + case FieldType.reference: + return cellValue.path; default: return cellValue; } diff --git a/src/components/fields/Reference/index.tsx b/src/components/fields/Reference/index.tsx index 5e95f2a6..7a7ee267 100644 --- a/src/components/fields/Reference/index.tsx +++ b/src/components/fields/Reference/index.tsx @@ -7,6 +7,7 @@ import DisplayCell from "./DisplayCell"; import EditorCell from "./EditorCell"; import { filterOperators } from "@src/components/fields/ShortText/Filter"; import { valueFormatter } from "./filters"; +import BasicContextMenuActions from "@src/components/Table/ContextMenu/BasicCellContextMenuActions"; const SideDrawerField = lazy( () => @@ -24,6 +25,7 @@ export const config: IFieldConfig = { initializable: true, icon: , description: "Firestore document reference", + contextMenuActions: BasicContextMenuActions, TableCell: withRenderTableCell(DisplayCell, EditorCell, "focus", { disablePadding: true, }),