mirror of
https://github.com/rowyio/rowy.git
synced 2025-12-29 00:16:39 +01:00
derivative evaluation
This commit is contained in:
@@ -14,7 +14,7 @@ import { useTheme } from "@mui/material";
|
||||
import type { SystemStyleObject, Theme } from "@mui/system";
|
||||
|
||||
import { useProjectContext } from "@src/contexts/ProjectContext";
|
||||
import { getFieldProp } from "@src/components/fields";
|
||||
import { getColumnType, getFieldProp } from "@src/components/fields";
|
||||
|
||||
/* eslint-disable import/no-webpack-loader-syntax */
|
||||
import firestoreDefs from "!!raw-loader!./firestore.d.ts";
|
||||
@@ -181,11 +181,7 @@ export default function useMonacoCustomizations({
|
||||
Object.keys(tableState?.columns!)
|
||||
.map((columnKey: string) => {
|
||||
const column = tableState?.columns[columnKey];
|
||||
if (
|
||||
column.type === "JSON" ||
|
||||
(column.type === "DERIVATIVE" &&
|
||||
column.config.renderFieldType === "JSON")
|
||||
) {
|
||||
if (getColumnType(column) === "JSON") {
|
||||
const interfaceName =
|
||||
columnKey[0].toUpperCase() + columnKey.slice(1);
|
||||
addJsonFieldDefinition(columnKey, interfaceName);
|
||||
|
||||
@@ -12,8 +12,9 @@ export default function ContextMenu() {
|
||||
const selectedColumn = _find(columns, { index: selectedColIndex });
|
||||
if (!selectedColumn) return <></>;
|
||||
const configActions =
|
||||
getFieldProp("contextMenuActions", getColumnType(selectedColumn)) ||
|
||||
getFieldProp("contextMenuActions", selectedColumn.type) ||
|
||||
function empty() {};
|
||||
console.log(configActions);
|
||||
const actions = configActions(selectedCell, resetContextMenu) || [];
|
||||
|
||||
if (!anchorEle || actions.length === 0) return <></>;
|
||||
|
||||
@@ -6,11 +6,12 @@ import { TextField } from "@mui/material";
|
||||
import { FieldType } from "@src/constants/fields";
|
||||
import { getCellValue } from "@src/utils/fns";
|
||||
import { useProjectContext } from "@src/contexts/ProjectContext";
|
||||
import { getColumnType } from "@src/components/fields";
|
||||
|
||||
export default function TextEditor({ row, column }: EditorProps<any>) {
|
||||
const { updateCell } = useProjectContext();
|
||||
|
||||
const type = (column as any).config?.renderFieldType ?? (column as any).type;
|
||||
const type = getColumnType(column as any);
|
||||
|
||||
const cellValue = getCellValue(row, column.key);
|
||||
const defaultValue =
|
||||
|
||||
@@ -25,7 +25,7 @@ import FinalColumn from "./formatters/FinalColumn";
|
||||
import TableRow from "./TableRow";
|
||||
import BulkActions from "./BulkActions";
|
||||
|
||||
import { getFieldProp } from "@src/components/fields";
|
||||
import { getColumnType, getFieldProp } from "@src/components/fields";
|
||||
import { FieldType } from "@src/constants/fields";
|
||||
import { formatSubTableName } from "@src/utils/fns";
|
||||
|
||||
@@ -76,18 +76,12 @@ export default function Table() {
|
||||
frozen: column.fixed,
|
||||
headerRenderer: ColumnHeader,
|
||||
formatter:
|
||||
getFieldProp(
|
||||
"TableCell",
|
||||
column.config?.renderFieldType ?? column.type
|
||||
) ??
|
||||
getFieldProp("TableCell", getColumnType(column)) ??
|
||||
function InDev() {
|
||||
return null;
|
||||
},
|
||||
editor:
|
||||
getFieldProp(
|
||||
"TableEditor",
|
||||
column.config?.renderFieldType ?? column.type
|
||||
) ??
|
||||
getFieldProp("TableEditor", getColumnType(column)) ??
|
||||
function InDev() {
|
||||
return null;
|
||||
},
|
||||
|
||||
@@ -98,13 +98,14 @@ export default function FilterInputs({
|
||||
}}
|
||||
/>
|
||||
<Suspense fallback={<FieldSkeleton />}>
|
||||
{createElement(getFieldProp("SideDrawerField", columnType), {
|
||||
column: selectedColumn,
|
||||
control,
|
||||
docRef: {},
|
||||
disabled,
|
||||
onChange: () => {},
|
||||
})}
|
||||
{columnType &&
|
||||
createElement(getFieldProp("SideDrawerField", columnType), {
|
||||
column: selectedColumn,
|
||||
control,
|
||||
docRef: {},
|
||||
disabled,
|
||||
onChange: () => {},
|
||||
})}
|
||||
</Suspense>
|
||||
</form>
|
||||
)}
|
||||
|
||||
@@ -36,10 +36,9 @@ export const useFilterInputs = (columns: TableState["columns"]) => {
|
||||
// Get the column config
|
||||
const selectedColumn = _find(filterColumns, ["key", query?.key]);
|
||||
// Get available filters from selected column type
|
||||
const availableFilters = getFieldProp(
|
||||
"filter",
|
||||
getColumnType(selectedColumn)
|
||||
);
|
||||
const availableFilters = selectedColumn
|
||||
? getFieldProp("filter", getColumnType(selectedColumn))
|
||||
: null;
|
||||
|
||||
return {
|
||||
filterColumns,
|
||||
|
||||
63
src/components/fields/Derivative/ContextMenuActions.tsx
Normal file
63
src/components/fields/Derivative/ContextMenuActions.tsx
Normal file
@@ -0,0 +1,63 @@
|
||||
import _find from "lodash/find";
|
||||
import _get from "lodash/get";
|
||||
|
||||
import Cut from "@mui/icons-material/ContentCut";
|
||||
import CopyCells from "@src/assets/icons/CopyCells";
|
||||
import Paste from "@mui/icons-material/ContentPaste";
|
||||
import EvalIcon from "@mui/icons-material/Replay";
|
||||
|
||||
import { useProjectContext } from "@src/contexts/ProjectContext";
|
||||
import { useSnackbar } from "notistack";
|
||||
import { SelectedCell } from "@src/atoms/ContextMenu";
|
||||
import { getFieldProp, getColumnType } from "@src/components/fields";
|
||||
import { runRoutes } from "@src/constants/runRoutes";
|
||||
|
||||
export interface IContextMenuActions {
|
||||
label: string;
|
||||
icon: React.ReactNode;
|
||||
onClick: () => void;
|
||||
}
|
||||
|
||||
export default function ContextMenuActions(
|
||||
selectedCell: SelectedCell,
|
||||
reset: () => void | Promise<void>
|
||||
): IContextMenuActions[] {
|
||||
const { tableState, deleteCell, updateCell, rowyRun } = useProjectContext();
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
const columns = tableState?.columns;
|
||||
const rows = tableState?.rows;
|
||||
const selectedRowIndex = selectedCell.rowIndex as number;
|
||||
const selectedColIndex = selectedCell?.colIndex;
|
||||
const selectedCol = _find(columns, { index: selectedColIndex });
|
||||
const selectedRow = rows?.[selectedRowIndex];
|
||||
const cellValue = _get(selectedRow, selectedCol.key);
|
||||
console.log({
|
||||
selectedCol,
|
||||
schemaDocPath: tableState?.config.tableConfig.path,
|
||||
});
|
||||
const handleClose = async () => await reset?.();
|
||||
|
||||
const handleEvaluate = async () => {
|
||||
try {
|
||||
if (!selectedCol || !rowyRun || !selectedRow) return;
|
||||
rowyRun({
|
||||
route: runRoutes.evaluateDerivative,
|
||||
body: {
|
||||
ref: {
|
||||
path: selectedRow.ref.path,
|
||||
},
|
||||
schemaDocPath: tableState?.config.tableConfig.path,
|
||||
columnKey: selectedCol.key,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
enqueueSnackbar(`Failed: ${error}`, { variant: "error" });
|
||||
}
|
||||
handleClose();
|
||||
};
|
||||
const contextMenuActions = [
|
||||
{ label: "evalute", icon: <EvalIcon />, onClick: handleEvaluate },
|
||||
];
|
||||
|
||||
return contextMenuActions;
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import DerivativeIcon from "@src/assets/icons/Derivative";
|
||||
import BasicCell from "../_BasicCell/BasicCellNull";
|
||||
import NullEditor from "@src/components/Table/editors/NullEditor";
|
||||
import Settings, { settingsValidator } from "./Settings";
|
||||
|
||||
import ContextMenuActions from "./ContextMenuActions";
|
||||
export const config: IFieldConfig = {
|
||||
type: FieldType.derivative,
|
||||
name: "Derivative",
|
||||
@@ -20,6 +20,7 @@ export const config: IFieldConfig = {
|
||||
TableCell: withBasicCell(BasicCell),
|
||||
TableEditor: NullEditor as any,
|
||||
SideDrawerField: BasicCell as any,
|
||||
contextMenuActions: ContextMenuActions,
|
||||
settings: Settings,
|
||||
settingsValidator,
|
||||
};
|
||||
|
||||
@@ -55,6 +55,7 @@ export default function BasicContextMenuActions(
|
||||
|
||||
const handlePaste = async () => {
|
||||
try {
|
||||
if (!selectedCol) return;
|
||||
const text = await navigator.clipboard.readText();
|
||||
const cellDataType = getFieldProp("dataType", getColumnType(selectedCol));
|
||||
let parsed;
|
||||
|
||||
@@ -121,9 +121,12 @@ export const hasDataTypes = (dataTypes: string[]) => {
|
||||
);
|
||||
};
|
||||
|
||||
export const getColumnType = (column?: TableColumn) =>
|
||||
!column
|
||||
? null
|
||||
: column.type === FieldType.derivative
|
||||
export const getColumnType = (column: {
|
||||
type: FieldType;
|
||||
config: {
|
||||
renderFieldType: FieldType;
|
||||
};
|
||||
}) =>
|
||||
column.type === FieldType.derivative
|
||||
? column.config.renderFieldType
|
||||
: column.type;
|
||||
|
||||
@@ -54,4 +54,8 @@ export const runRoutes = {
|
||||
algoliaAppId: { path: `/algoliaAppId`, method: "GET" } as RunRoute,
|
||||
functionLogs: { path: `/functionLogs`, method: "GET" } as RunRoute,
|
||||
auditChange: { path: `/auditChange`, method: "POST" } as RunRoute,
|
||||
evaluateDerivative: {
|
||||
path: `/evaluateDerivative`,
|
||||
method: "POST",
|
||||
} as RunRoute,
|
||||
} as const;
|
||||
|
||||
Reference in New Issue
Block a user