[] => {
+ const temperatureUnit =
+ user?.tempUnit() ?? pond.TemperatureUnit.TEMPERATURE_UNIT_CELSIUS;
+
+ return [
+ {
+ title: "Name",
+ cellStyle: {padding: "16px"},
+ render: row => {
+ return ({row.settings.name}
);
+ }
+ },
+ {
+ title: "Grain",
+ cellStyle: {padding: "16px"},
+ render: row => {
+ let grain = row.settings.inventory?.grainType;
+ if (grain) {
+ return GrainDescriber(grain).name;
+ }
+ }
+ },
+ {
+ title: "Bin Height",
+ cellStyle: {padding: "16px"},
+ render: row => {
+ let d = row.settings.specs?.heightCm;
+ if (d) {
+ if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
+ return (d / 100).toFixed(2) + " m";
+ } else {
+ return (d / 30.48).toFixed(2) + " ft";
+ }
+ }
+ }
+ },
+ {
+ title: "Bin Diameter",
+ cellStyle: {padding: "16px"},
+ render: row => {
+ let d = row.settings.specs?.diameterCm;
+ if (d) {
+ if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
+ return (d / 100).toFixed(2) + " m";
+ } else {
+ return (d / 30.48).toFixed(2) + " ft";
+ }
+ }
+ }
+ },
+ {
+ title: "Custom Grain Name",
+ cellStyle: {padding: "16px"},
+ render: row => {
+ return row.settings.inventory?.customTypeName;
+ }
+ },
+ {
+ title: "Grain Variant",
+ cellStyle: {padding: "16px"},
+ render: row => {
+ return row.settings.inventory?.grainSubtype;
+ }
+ },
+ {
+ title: "Grain Bushels",
+ cellStyle: {padding: "16px"},
+ render: row => {
+ return ({row.settings.inventory ? isNaN(row.settings.inventory.grainBushels) ? 0 : row.settings.inventory.grainBushels : 0}
);
+ }
+ },
+ {
+ title: "Grain Capacity",
+ cellStyle: {padding: "16px"},
+ render: row => {
+ return row.settings.specs?.bushelCapacity;
+ }
+ },
+ {
+ title: "High Temp Warning",
+ cellStyle: {padding: "16px"},
+ render: row => {
+ let t = row.settings.highTemp;
+ if (t) {
+ if (temperatureUnit === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
+ return (t * 1.8 + 32).toFixed(2) + " °F";
+ }
+ return t.toFixed(2) + " °C";
+ }
+ }
+ },
+ {
+ title: "Low Temp Warning",
+ cellStyle: {padding: "16px"},
+ render: row => {
+ let t = row.settings.lowTemp;
+ if (t) {
+ if (temperatureUnit === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
+ return (t * 1.8 + 32).toFixed(2) + " °F";
+ }
+ return t.toFixed(2) + " °C";
+ }
+ }
+ }
+ ] as Column[];
+};
+
export const ObjectExtensions: Map = new Map([
[pond.ObjectType.OBJECT_TYPE_UNKNOWN, defaultObject],
[
@@ -50,109 +159,8 @@ export const ObjectExtensions: Map = new Map([
name: "Bin",
inventoryGroup: "grain",
isTransactionObject: true,
- tableColumns: [
- {
- title: "Name",
- cellStyle: {padding: "16px"},
- render: row => {
- return ({row.settings.name}
);
- }
- },
- {
- title: "Grain",
- cellStyle: {padding: "16px"},
- render: row => {
- let grain = row.settings.inventory?.grainType;
- if (grain) {
- return GrainDescriber(grain).name;
- }
- }
- },
- {
- title: "Bin Height",
- cellStyle: {padding: "16px"},
- render: row => {
- let d = row.settings.specs?.heightCm;
- if (d) {
- if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
- return (d / 100).toFixed(2) + " m";
- } else {
- return (d / 30.48).toFixed(2) + " ft";
- }
- }
- }
- },
- {
- title: "Bin Diameter",
- cellStyle: {padding: "16px"},
- render: row => {
- let d = row.settings.specs?.diameterCm;
- if (d) {
- if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
- return (d / 100).toFixed(2) + " m";
- } else {
- return (d / 30.48).toFixed(2) + " ft";
- }
- }
- }
- },
- {
- title: "Custom Grain Name",
- cellStyle: {padding: "16px"},
- render: row => {
- return row.settings.inventory?.customTypeName;
- }
- },
- {
- title: "Grain Variant",
- cellStyle: {padding: "16px"},
- render: row => {
- return row.settings.inventory?.grainSubtype;
- }
- },
- {
- title: "Grain Bushels",
- cellStyle: {padding: "16px"},
- render: row => {
- return ({row.settings.inventory ? isNaN(row.settings.inventory.grainBushels) ? 0 : row.settings.inventory.grainBushels : 0}
);
- }
- },
- {
- title: "Grain Capacity",
- cellStyle: {padding: "16px"},
- render: row => {
- return row.settings.specs?.bushelCapacity;
- }
- },
- {
- title: "High Temp Warning",
- cellStyle: {padding: "16px"},
- render: row => {
- let t = row.settings.highTemp;
- if (t) {
- if (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
- return (t * 1.8 + 32).toFixed(2) + " °F";
- } else {
- return t.toFixed(2) + " °C";
- }
- }
- }
- },
- {
- title: "Low Temp Warning",
- cellStyle: {padding: "16px"},
- render: row => {
- let t = row.settings.lowTemp;
- if (t) {
- if (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
- return (t * 1.8 + 32).toFixed(2) + " °F";
- } else {
- return t.toFixed(2) + " °C";
- }
- }
- }
- }
- ] as Column[],
+ tableColumns: binColumns(),
+ getTableColumns: (user?: User) => binColumns(user),
tableSort: new Map([
["Name", { order: "name", numerical: false }],
["Grain", { order: "inventory.grainType", numerical: false }],
@@ -708,8 +716,7 @@ export const ObjectExtensions: Map = new Map([
]);
export default function ObjectDescriber(type: pond.ObjectType): ObjectExtension {
- let describer = ObjectExtensions.get(type);
- return describer ? describer : defaultObject;
+ return ObjectExtensions.get(type) ?? defaultObject;
}
/**
@@ -745,7 +752,8 @@ export function SearchableObjects(): Option[] {
Object.values(pond.ObjectType).forEach(obj => {
if (typeof obj !== "string") {
let ext = ObjectDescriber(obj);
- if (ext.tableColumns.length > 0) {
+ const columns = ext.getTableColumns ? ext.getTableColumns() : ext.tableColumns;
+ if (columns.length > 0) {
options.push({
label: ext.name,
value: obj
diff --git a/src/objects/ObjectTable.tsx b/src/objects/ObjectTable.tsx
index 7a7b677..2ef6c86 100644
--- a/src/objects/ObjectTable.tsx
+++ b/src/objects/ObjectTable.tsx
@@ -1,6 +1,5 @@
import { Box, Button, Grid2 as Grid } from "@mui/material";
// import { getTableIcons } from "common/ResponsiveTable";
-import SearchBar from "common/SearchBar";
import SearchSelect, { Option } from "common/SearchSelect";
// import MaterialTable, { MTableToolbar } from "material-table";
// import { Bin, BinYard, Field } from "models";
@@ -22,9 +21,8 @@ import {
import { useCallback, useEffect, useState } from "react";
import TeamSearch from "teams/TeamSearch";
import BulkBinSettings from "./bulkEditForms/bulkBinSettings";
-import BulkGrainBagSettings from "./bulkEditForms/bulkGrainBagSettings";
import ResponsiveTable from "common/ResponsiveTable";
-import { cloneDeep, indexOf } from "lodash";
+import { cloneDeep } from "lodash";
//import BulkGateSettings from "./bulkEditForms/bulkGateSettings";
interface customButton {
@@ -61,6 +59,9 @@ export default function ObjectTable(props: Props) {
const [selectedUser, setSelectedUser] = useState(as ?? user.id());
const [selectedPageRows, setSelectedPageRows] = useState