mirror of
https://github.com/rowyio/rowy.git
synced 2025-12-29 00:16:39 +01:00
Merge pull request #1320 from mnmt7/reference-field-copy-paste
Add copy/paste functionality for reference field
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user