add Aggregate, Derivative fields

This commit is contained in:
Sidney Alcantara
2020-12-02 19:52:19 +11:00
parent 2ce8328f78
commit 9f2399cff5
6 changed files with 60 additions and 12 deletions

View File

@@ -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}
>

View File

@@ -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;

View File

@@ -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;
},

View 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;

View 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 rows 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;

View File

@@ -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,