diff --git a/src/qqq/components/widgets/misc/RecordGridWidget.tsx b/src/qqq/components/widgets/misc/RecordGridWidget.tsx index f9cd56e..2c90096 100644 --- a/src/qqq/components/widgets/misc/RecordGridWidget.tsx +++ b/src/qqq/components/widgets/misc/RecordGridWidget.tsx @@ -111,7 +111,7 @@ function RecordGridWidget({widgetMetaData, data, addNewRecordCallback, disableRo } const tableMetaData = data.childTableMetaData instanceof QTableMetaData ? data.childTableMetaData as QTableMetaData : new QTableMetaData(data.childTableMetaData); - const rows = DataGridUtils.makeRows(records, tableMetaData, true); + const rows = DataGridUtils.makeRows(records, tableMetaData); ///////////////////////////////////////////////////////////////////////////////// // note - tablePath may be null, if the user doesn't have access to the table. // diff --git a/src/qqq/pages/records/query/RecordQuery.tsx b/src/qqq/pages/records/query/RecordQuery.tsx index 6efcd7a..c26fe8c 100644 --- a/src/qqq/pages/records/query/RecordQuery.tsx +++ b/src/qqq/pages/records/query/RecordQuery.tsx @@ -1103,7 +1103,7 @@ const RecordQuery = forwardRef(({table, usage, isModal, isPreview, allowVariable //////////////////////////////// // make the rows for the grid // //////////////////////////////// - const rows = DataGridUtils.makeRows(results, tableMetaData); + const rows = DataGridUtils.makeRows(results, tableMetaData, tableVariant); setRows(rows); setLoading(false); diff --git a/src/qqq/pages/records/view/RecordView.tsx b/src/qqq/pages/records/view/RecordView.tsx index ca7789c..41cf916 100644 --- a/src/qqq/pages/records/view/RecordView.tsx +++ b/src/qqq/pages/records/view/RecordView.tsx @@ -92,7 +92,7 @@ const TABLE_VARIANT_LOCAL_STORAGE_KEY_ROOT = "qqq.tableVariant"; /******************************************************************************* ** *******************************************************************************/ -export function renderSectionOfFields(key: string, fieldNames: string[], tableMetaData: QTableMetaData, helpHelpActive: boolean, record: QRecord, fieldMap?: { [name: string]: QFieldMetaData }, styleOverrides?: {label?: SxProps, value?: SxProps}) +export function renderSectionOfFields(key: string, fieldNames: string[], tableMetaData: QTableMetaData, helpHelpActive: boolean, record: QRecord, fieldMap?: { [name: string]: QFieldMetaData }, styleOverrides?: {label?: SxProps, value?: SxProps}, tableVariant?: QTableVariant) { return { @@ -118,7 +118,7 @@ export function renderSectionOfFields(key: string, fieldNames: string[], tableMe }
 
- {ValueUtils.getDisplayValue(field, record, "view", fieldName)} + {ValueUtils.getDisplayValue(field, record, "view", fieldName, tableVariant)}
@@ -597,7 +597,7 @@ function RecordView({table, record: overrideRecord, launchProcess}: Props): JSX. // for a section with field names, render the field values. // // for the T1 section, the "wrapper" will come out below - but for other sections, produce a wrapper too. // //////////////////////////////////////////////////////////////////////////////////////////////////////////// - const fields = renderSectionOfFields(section.name, section.fieldNames, tableMetaData, helpHelpActive, record); + const fields = renderSectionOfFields(section.name, section.fieldNames, tableMetaData, helpHelpActive, record, undefined, undefined, tableVariant); if (section.tier === "T1") { diff --git a/src/qqq/utils/DataGridUtils.tsx b/src/qqq/utils/DataGridUtils.tsx index 2ee5343..b7effe7 100644 --- a/src/qqq/utils/DataGridUtils.tsx +++ b/src/qqq/utils/DataGridUtils.tsx @@ -24,6 +24,7 @@ import {QFieldMetaData} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QF import {QFieldType} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QFieldType"; import {QInstance} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QInstance"; import {QTableMetaData} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QTableMetaData"; +import {QTableVariant} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QTableVariant"; import {QRecord} from "@kingsrook/qqq-frontend-core/lib/model/QRecord"; import Tooltip from "@mui/material/Tooltip/Tooltip"; import {GridColDef, GridRowsProp, MuiEvent} from "@mui/x-data-grid-pro"; @@ -70,7 +71,7 @@ export default class DataGridUtils /******************************************************************************* ** *******************************************************************************/ - public static makeRows = (results: QRecord[], tableMetaData: QTableMetaData, allowEmptyId = false): GridRowsProp[] => + public static makeRows = (results: QRecord[], tableMetaData: QTableMetaData, tableVariant?: QTableVariant): GridRowsProp[] => { const fields = [...tableMetaData.fields.values()]; const rows = [] as any[]; @@ -82,7 +83,7 @@ export default class DataGridUtils fields.forEach((field) => { - row[field.name] = ValueUtils.getDisplayValue(field, record, "query"); + row[field.name] = ValueUtils.getDisplayValue(field, record, "query", undefined, tableVariant); }); if (tableMetaData.exposedJoins) @@ -97,7 +98,7 @@ export default class DataGridUtils fields.forEach((field) => { let fieldName = join.joinTable.name + "." + field.name; - row[fieldName] = ValueUtils.getDisplayValue(field, record, "query", fieldName); + row[fieldName] = ValueUtils.getDisplayValue(field, record, "query", fieldName, tableVariant); }); } } @@ -111,7 +112,7 @@ export default class DataGridUtils ///////////////////////////////////////////////////////////////////////////////////////// // DataGrid gets very upset about a null or undefined here, so, try to make it happier // ///////////////////////////////////////////////////////////////////////////////////////// - if (!allowEmptyId) + if (!tableVariant) { row["id"] = "--"; } @@ -241,6 +242,20 @@ export default class DataGridUtils cellValues.value ? e.stopPropagation()}>{cellValues.value} : "" ); } + /* todo wip ... not sure if/how to get tooltipFieldName set in the row... */ + /* + else if (field.hasAdornment(AdornmentType.TOOLTIP)) + { + const tooltipAdornment = field.getAdornment(AdornmentType.TOOLTIP); + const tooltipFieldName: string = tooltipAdornment.getValue("tooltipFieldName"); + if(tooltipFieldName) + { + column.renderCell = (cellValues: any) => ( + cellValues.value ? {cellValues.value} : "" + ); + } + } + */ }); } diff --git a/src/qqq/utils/qqq/ValueUtils.tsx b/src/qqq/utils/qqq/ValueUtils.tsx index 2339c5b..086ea15 100644 --- a/src/qqq/utils/qqq/ValueUtils.tsx +++ b/src/qqq/utils/qqq/ValueUtils.tsx @@ -23,6 +23,7 @@ import {AdornmentType} from "@kingsrook/qqq-frontend-core/lib/model/metaData/Ado import {QFieldMetaData} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QFieldMetaData"; import {QFieldType} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QFieldType"; import {QInstance} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QInstance"; +import {QTableVariant} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QTableVariant"; import {QRecord} from "@kingsrook/qqq-frontend-core/lib/model/QRecord"; import "datejs"; // https://github.com/datejs/Datejs import {Chip, ClickAwayListener, Icon} from "@mui/material"; @@ -76,14 +77,14 @@ class ValueUtils ** When you have a field, and a record - call this method to get a string or ** element back to display the field's value. *******************************************************************************/ - public static getDisplayValue(field: QFieldMetaData, record: QRecord, usage: "view" | "query" = "view", overrideFieldName?: string): string | JSX.Element | JSX.Element[] + public static getDisplayValue(field: QFieldMetaData, record: QRecord, usage: "view" | "query" = "view", overrideFieldName?: string, tableVariant?: QTableVariant): string | JSX.Element | JSX.Element[] { const fieldName = overrideFieldName ?? field.name; const displayValue = record.displayValues ? record.displayValues.get(fieldName) : undefined; const rawValue = record.values ? record.values.get(fieldName) : undefined; - return ValueUtils.getValueForDisplay(field, rawValue, displayValue, usage); + return ValueUtils.getValueForDisplay(field, rawValue, displayValue, usage, tableVariant); } @@ -91,7 +92,7 @@ class ValueUtils ** When you have a field and a value (either just a raw value, or a raw and ** display value), call this method to get a string Element to display. *******************************************************************************/ - public static getValueForDisplay(field: QFieldMetaData, rawValue: any, displayValue: any = rawValue, usage: "view" | "query" = "view"): string | JSX.Element | JSX.Element[] + public static getValueForDisplay(field: QFieldMetaData, rawValue: any, displayValue: any = rawValue, usage: "view" | "query" = "view", tableVariant?: QTableVariant): string | JSX.Element | JSX.Element[] { if (field.hasAdornment(AdornmentType.LINK)) { @@ -199,9 +200,20 @@ class ValueUtils if (field.type == QFieldType.BLOB || field.hasAdornment(AdornmentType.FILE_DOWNLOAD)) { - return (); + let url = rawValue; + if(tableVariant) + { + url += "?tableVariant=" + encodeURIComponent(JSON.stringify(tableVariant)); + } + + return (); } + // todo if(field.hasAdornment(AdornmentType.CODE)) + // todo { + // todo return {ValueUtils.getUnadornedValueForDisplay(field, rawValue, displayValue)} + // todo } + return (ValueUtils.getUnadornedValueForDisplay(field, rawValue, displayValue)); }