Merge pull request #1320 from mnmt7/reference-field-copy-paste

Add copy/paste functionality for reference field
This commit is contained in:
Shams
2023-07-04 09:34:29 +02:00
committed by GitHub
2 changed files with 19 additions and 0 deletions

View File

@@ -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<any>();
const [selectedCol, setSelectedCol] = useState<ColumnConfig>();
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;
}

View File

@@ -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: <Reference />,
description: "Firestore document reference",
contextMenuActions: BasicContextMenuActions,
TableCell: withRenderTableCell(DisplayCell, EditorCell, "focus", {
disablePadding: true,
}),