mirror of
https://github.com/rowyio/rowy.git
synced 2026-07-12 13:28:48 +02:00
add Aggregate, Derivative fields
This commit is contained in:
@@ -89,7 +89,7 @@ export default function Form({ values }: IFormProps) {
|
||||
return (
|
||||
<FieldWrapper
|
||||
key={field.key ?? i}
|
||||
type={type}
|
||||
type={field.type}
|
||||
name={field.key}
|
||||
label={field.name}
|
||||
>
|
||||
|
||||
@@ -35,10 +35,11 @@ const useStyles = makeStyles((theme) =>
|
||||
export default function TextEditor({ row, column }: EditorProps<any>) {
|
||||
const classes = useStyles();
|
||||
|
||||
const type = (column as any).config?.renderFieldType ?? (column as any).type;
|
||||
|
||||
const cellValue = getCellValue(row, column.key);
|
||||
const defaultValue =
|
||||
(column as any).type === FieldType.percentage &&
|
||||
typeof cellValue === "number"
|
||||
type === FieldType.percentage && typeof cellValue === "number"
|
||||
? cellValue * 100
|
||||
: cellValue;
|
||||
|
||||
@@ -48,10 +49,7 @@ export default function TextEditor({ row, column }: EditorProps<any>) {
|
||||
return () => {
|
||||
const newValue = inputRef.current?.value;
|
||||
if (newValue !== undefined) {
|
||||
if (
|
||||
(column as any).type === FieldType.number ||
|
||||
(column as any).type === FieldType.percentage
|
||||
) {
|
||||
if (type === FieldType.number || type === FieldType.percentage) {
|
||||
row.ref.update({ [column.key]: Number(newValue) });
|
||||
} else {
|
||||
row.ref.update({ [column.key]: newValue });
|
||||
@@ -61,7 +59,7 @@ export default function TextEditor({ row, column }: EditorProps<any>) {
|
||||
}, []);
|
||||
|
||||
let inputType = "text";
|
||||
switch ((column as any).type) {
|
||||
switch (type) {
|
||||
case FieldType.email:
|
||||
inputType = "email";
|
||||
break;
|
||||
|
||||
@@ -84,12 +84,18 @@ export default function Table() {
|
||||
frozen: column.fixed,
|
||||
headerRenderer: ColumnHeader,
|
||||
formatter:
|
||||
getFieldProp("TableCell", column.type) ??
|
||||
getFieldProp(
|
||||
"TableCell",
|
||||
column.config?.renderFieldType ?? column.type
|
||||
) ??
|
||||
function InDev() {
|
||||
return null;
|
||||
},
|
||||
editor:
|
||||
getFieldProp("TableEditor", column.type) ??
|
||||
getFieldProp(
|
||||
"TableEditor",
|
||||
column.config?.renderFieldType ?? column.type
|
||||
) ??
|
||||
function InDev() {
|
||||
return null;
|
||||
},
|
||||
|
||||
21
www/src/components/fields/Aggregate/index.tsx
Normal file
21
www/src/components/fields/Aggregate/index.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import React from "react";
|
||||
import { IFieldConfig, FieldType } from "components/fields/types";
|
||||
import withCustomCell from "components/Table/withCustomCell";
|
||||
|
||||
import AggregateIcon from "@material-ui/icons/Layers";
|
||||
import BasicCell from "../_BasicCell/BasicCellNull";
|
||||
import NullEditor from "components/Table/editors/NullEditor";
|
||||
|
||||
export const config: IFieldConfig = {
|
||||
type: FieldType.aggregate,
|
||||
name: "Aggregate",
|
||||
dataType: "string",
|
||||
initialValue:
|
||||
"Value aggregated from a specified sub-table of the row. Displayed using any other field type. Requires Cloud Function setup.",
|
||||
icon: <AggregateIcon />,
|
||||
description: "Numeric data.",
|
||||
TableCell: withCustomCell(BasicCell as any, BasicCell),
|
||||
TableEditor: NullEditor,
|
||||
SideDrawerField: BasicCell as any,
|
||||
};
|
||||
export default config;
|
||||
21
www/src/components/fields/Derivative/index.tsx
Normal file
21
www/src/components/fields/Derivative/index.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import React from "react";
|
||||
import { IFieldConfig, FieldType } from "components/fields/types";
|
||||
import withCustomCell from "components/Table/withCustomCell";
|
||||
|
||||
import DerivativeIcon from "assets/icons/Derivative";
|
||||
import BasicCell from "../_BasicCell/BasicCellNull";
|
||||
import NullEditor from "components/Table/editors/NullEditor";
|
||||
|
||||
export const config: IFieldConfig = {
|
||||
type: FieldType.derivative,
|
||||
name: "Derivative",
|
||||
dataType: "string",
|
||||
initialValue:
|
||||
"Value derived from the rest of the row’s values. Displayed using any other field type. Requires Cloud Function setup.",
|
||||
icon: <DerivativeIcon />,
|
||||
description: "Numeric data.",
|
||||
TableCell: withCustomCell(BasicCell as any, BasicCell),
|
||||
TableEditor: NullEditor,
|
||||
SideDrawerField: BasicCell as any,
|
||||
};
|
||||
export default config;
|
||||
@@ -18,6 +18,8 @@ import DateTime from "./DateTime";
|
||||
import Duration from "./Duration";
|
||||
import SubTable from "./SubTable";
|
||||
import Action from "./Action";
|
||||
import Derivative from "./Derivative";
|
||||
import Aggregate from "./Aggregate";
|
||||
import User from "./User";
|
||||
import Id from "./Id";
|
||||
|
||||
@@ -56,8 +58,8 @@ export const FIELDS: IFieldConfig[] = [
|
||||
// TODO: richText,
|
||||
// CLOUD FUNCTION
|
||||
Action,
|
||||
// TODO: derivative,
|
||||
// TODO: aggregate,
|
||||
Derivative,
|
||||
Aggregate,
|
||||
// FIRETABLE
|
||||
User,
|
||||
Id,
|
||||
|
||||
Reference in New Issue
Block a user