Compare commits

..

8 Commits

5 changed files with 486 additions and 356 deletions

View File

@ -36,7 +36,7 @@ import Icon from "@mui/material/Icon";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import {makeStyles} from "@mui/styles"; import {makeStyles} from "@mui/styles";
import {Command} from "cmdk"; import {Command} from "cmdk";
import React, {useContext, useEffect, useRef} from "react"; import React, {useContext, useEffect, useRef, useState} from "react";
import {useNavigate} from "react-router-dom"; import {useNavigate} from "react-router-dom";
import QContext from "QContext"; import QContext from "QContext";
import HistoryUtils, {QHistoryEntry} from "qqq/utils/HistoryUtils"; import HistoryUtils, {QHistoryEntry} from "qqq/utils/HistoryUtils";
@ -62,8 +62,13 @@ const useStyles = makeStyles((theme: any) => ({
} }
})); }));
const A_FIRST = -1;
const B_FIRST = 1;
const CommandMenu = ({metaData}: Props) => const CommandMenu = ({metaData}: Props) =>
{ {
const [searchString, setSearchString] = useState("");
const navigate = useNavigate(); const navigate = useNavigate();
const pathParts = location.pathname.replace(/\/+$/, "").split("/"); const pathParts = location.pathname.replace(/\/+$/, "").split("/");
@ -71,7 +76,7 @@ const CommandMenu = ({metaData}: Props) =>
const classes = useStyles(); const classes = useStyles();
function evalueKeyPress(e: KeyboardEvent) function evaluateKeyPress(e: KeyboardEvent)
{ {
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// if a dot pressed, not from a "text" element, then toggle command menu // // if a dot pressed, not from a "text" element, then toggle command menu //
@ -107,20 +112,20 @@ const CommandMenu = ({metaData}: Props) =>
const down = (e: KeyboardEvent) => const down = (e: KeyboardEvent) =>
{ {
evalueKeyPress(e); evaluateKeyPress(e);
} };
document.addEventListener("keydown", down) document.addEventListener("keydown", down);
return () => return () =>
{ {
document.removeEventListener("keydown", down) document.removeEventListener("keydown", down);
} };
}, [tableMetaData, dotMenuOpen, keyboardHelpOpen]) }, [tableMetaData, dotMenuOpen, keyboardHelpOpen]);
useEffect(() => useEffect(() =>
{ {
setDotMenuOpen(false); setDotMenuOpen(false);
}, [location.pathname]) }, [location.pathname]);
function goToItem(path: string) function goToItem(path: string)
{ {
@ -162,25 +167,68 @@ const CommandMenu = ({metaData}: Props) =>
return (null); return (null);
} }
/*******************************************************************************
** sort a section (e.g, tables, apps).
**
** put labels that start-with the search word first.
*******************************************************************************/
function comparator(labelA: string, labelB: string)
{
if (searchString != "")
{
let aStartsWith = labelA.toLowerCase().startsWith(searchString.toLowerCase());
let bStartsWith = labelB.toLowerCase().startsWith(searchString.toLowerCase());
if (aStartsWith && !bStartsWith)
{
return A_FIRST;
}
else if (bStartsWith && !aStartsWith)
{
return B_FIRST;
}
const indexOfSpace = searchString.indexOf(" ");
if (indexOfSpace > 0)
{
aStartsWith = labelA.toLowerCase().startsWith(searchString.substring(0, indexOfSpace).toLowerCase());
bStartsWith = labelB.toLowerCase().startsWith(searchString.substring(0, indexOfSpace).toLowerCase());
if (aStartsWith && !bStartsWith)
{
return A_FIRST;
}
else if (bStartsWith && !aStartsWith)
{
return B_FIRST;
}
}
}
return (labelA.localeCompare(labelB));
}
/******************************************************************************* /*******************************************************************************
** **
*******************************************************************************/ *******************************************************************************/
function ActionsSection() function ActionsSection()
{ {
let tableNames : string[]= []; let tableNames: string[] = [];
metaData.tables.forEach((value: QTableMetaData, key: string) => metaData.tables.forEach((value: QTableMetaData, key: string) =>
{ {
tableNames.push(value.name); tableNames.push(value.name);
}) });
tableNames = tableNames.sort((a: string, b:string) => tableNames = tableNames.sort((a: string, b: string) =>
{ {
const labelA = metaData.tables.get(a).label ?? ""; const labelA = metaData.tables.get(a).label ?? "";
const labelB = metaData.tables.get(b).label ?? ""; const labelB = metaData.tables.get(b).label ?? "";
return (labelA.localeCompare(labelB)); return comparator(labelA, labelB);
}) });
const path = location.pathname; const path = location.pathname;
return tableMetaData && !path.endsWith("/edit") && !path.endsWith("/create") && !path.endsWith("#audit") && ! path.endsWith("copy") && return tableMetaData && !path.endsWith("/edit") && !path.endsWith("/create") && !path.endsWith("#audit") && !path.endsWith("copy") &&
( (
<Command.Group heading={`${tableMetaData.label} Actions`}> <Command.Group heading={`${tableMetaData.label} Actions`}>
{ {
@ -212,23 +260,24 @@ const CommandMenu = ({metaData}: Props) =>
); );
} }
/******************************************************************************* /*******************************************************************************
** **
*******************************************************************************/ *******************************************************************************/
function TablesSection() function TablesSection()
{ {
let tableNames : string[]= []; let tableNames: string[] = [];
metaData.tables.forEach((value: QTableMetaData, key: string) => metaData.tables.forEach((value: QTableMetaData, key: string) =>
{ {
tableNames.push(value.name); tableNames.push(value.name);
}) });
tableNames = tableNames.sort((a: string, b:string) => tableNames = tableNames.sort((a: string, b: string) =>
{ {
const labelA = metaData.tables.get(a).label ?? ""; const labelA = metaData.tables.get(a).label ?? "";
const labelB = metaData.tables.get(b).label ?? ""; const labelB = metaData.tables.get(b).label ?? "";
return (labelA.localeCompare(labelB)); return comparator(labelA, labelB);
}) });
return( return (
<Command.Group heading="Tables"> <Command.Group heading="Tables">
{ {
tableNames.map((tableName: string, index: number) => tableNames.map((tableName: string, index: number) =>
@ -243,6 +292,7 @@ const CommandMenu = ({metaData}: Props) =>
); );
} }
/******************************************************************************* /*******************************************************************************
** **
*******************************************************************************/ *******************************************************************************/
@ -252,16 +302,16 @@ const CommandMenu = ({metaData}: Props) =>
metaData.apps.forEach((value: QAppMetaData, key: string) => metaData.apps.forEach((value: QAppMetaData, key: string) =>
{ {
appNames.push(value.name); appNames.push(value.name);
}) });
appNames = appNames.sort((a: string, b:string) => appNames = appNames.sort((a: string, b: string) =>
{ {
const labelA = getFullAppLabel(metaData.appTree, a, 1, "") ?? ""; const labelA = getFullAppLabel(metaData.appTree, a, 1, "") ?? "";
const labelB = getFullAppLabel(metaData.appTree, b, 1, "") ?? ""; const labelB = getFullAppLabel(metaData.appTree, b, 1, "") ?? "";
return (labelA.localeCompare(labelB)); return comparator(labelA, labelB);
}) });
return( return (
<Command.Group heading="Apps"> <Command.Group heading="Apps">
{ {
appNames.map((appName: string, index: number) => appNames.map((appName: string, index: number) =>
@ -276,33 +326,37 @@ const CommandMenu = ({metaData}: Props) =>
); );
} }
/*******************************************************************************
**
*******************************************************************************/
function RecentlyViewedSection() function RecentlyViewedSection()
{ {
const history = HistoryUtils.get(); const history = HistoryUtils.get();
const options = [] as any; const options = [] as any;
history.entries.reverse().forEach((entry, index) => history.entries.reverse().forEach((entry, index) =>
options.push({label: `${entry.label} index`, id: index, key: index, path: entry.path, iconName: entry.iconName}) options.push({label: `${entry.label} index`, id: index, key: index, path: entry.path, iconName: entry.iconName})
) );
let appNames: string[] = []; let appNames: string[] = [];
metaData.apps.forEach((value: QAppMetaData, key: string) => metaData.apps.forEach((value: QAppMetaData, key: string) =>
{ {
appNames.push(value.name); appNames.push(value.name);
}) });
appNames = appNames.sort((a: string, b:string) => appNames = appNames.sort((a: string, b: string) =>
{ {
const labelA = metaData.apps.get(a).label ?? ""; const labelA = metaData.apps.get(a).label ?? "";
const labelB = metaData.apps.get(b).label ?? ""; const labelB = metaData.apps.get(b).label ?? "";
return (labelA.localeCompare(labelB)); return comparator(labelA, labelB);
}) });
const entryMap = new Map<string, boolean>(); const entryMap = new Map<string, boolean>();
return( return (
<Command.Group heading="Recently Viewed Records"> <Command.Group heading="Recently Viewed Records">
{ {
history.entries.reverse().map((entry: QHistoryEntry, index: number) => history.entries.reverse().map((entry: QHistoryEntry, index: number) =>
! entryMap.has(entry.label) && entryMap.set(entry.label, true) && ( !entryMap.has(entry.label) && entryMap.set(entry.label, true) && (
<Command.Item onSelect={() => goToItem(`${entry.path}`)} key={`${entry.label}-${index}`} value={entry.label}><Icon sx={{color: accentColor}}>{entry.iconName}</Icon>{entry.label}</Command.Item> <Command.Item onSelect={() => goToItem(`${entry.path}`)} key={`${entry.label}-${index}`} value={entry.label}><Icon sx={{color: accentColor}}>{entry.iconName}</Icon>{entry.label}</Command.Item>
) )
) )
@ -311,26 +365,87 @@ const CommandMenu = ({metaData}: Props) =>
); );
} }
const containerElement = useRef(null) const containerElement = useRef(null);
/*******************************************************************************
**
*******************************************************************************/
function closeKeyboardHelp() function closeKeyboardHelp()
{ {
setKeyboardHelpOpen(false); setKeyboardHelpOpen(false);
} }
/*******************************************************************************
**
*******************************************************************************/
function closeDotMenu() function closeDotMenu()
{ {
setDotMenuOpen(false); setDotMenuOpen(false);
} }
/*******************************************************************************
** filter function for cmd-k library
**
*******************************************************************************/
function doFilter(value: string, search: string)
{
setSearchString(search);
/////////////////////
// split on spaces //
/////////////////////
const searchParts = search.toLowerCase().split(" ");
if (searchParts.length == 1)
{
//////////////////////////////////////////////
// if only 1 word, just do an includes test //
//////////////////////////////////////////////
return (value.toLowerCase().includes(search.toLowerCase()) ? 1 : 0);
}
else
{
////////////////////////////////////////
// else split the value on spaces too //
////////////////////////////////////////
const valueParts = value.toLowerCase().split(" ");
if (searchParts.length > valueParts.length)
{
//////////////////////////////////////////////////////////////////////////////////
// if there are more words in the search than in the value, then it can't match //
// e.g. "order c" can't ever match, say "order" //
//////////////////////////////////////////////////////////////////////////////////
return (0);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// iterate over the search parts - if any don't match the corresponding value parts, then it's a non-match //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
for (let i = 0; i < searchParts.length; i++)
{
if (!valueParts[i].includes(searchParts[i]))
{
return (0);
}
}
/////////////////////////////////
// if no failure, return a hit //
/////////////////////////////////
return (1);
}
}
return ( return (
<React.Fragment> <React.Fragment>
<Box ref={containerElement} className="raycast" sx={{position: "relative", zIndex: 10_000}}> <Box ref={containerElement} className="raycast" sx={{position: "relative", zIndex: 10_000}}>
{ {
<Dialog open={dotMenuOpen} onClose={closeDotMenu}> <Dialog open={dotMenuOpen} onClose={closeDotMenu}>
<Command.Dialog open={dotMenuOpen} onOpenChange={setDotMenuOpen} container={containerElement.current} label="Test Global Command Menu"> <Command.Dialog open={dotMenuOpen} onOpenChange={setDotMenuOpen} container={containerElement.current} filter={(value, search) => doFilter(value, search)}>
<Box sx={{display: "flex"}}> <Box sx={{display: "flex"}}>
<Command.Input placeholder="Search for Tables, Actions, or Recently Viewed Items..."/> <Command.Input placeholder="Search for Tables, Actions, or Recently Viewed Items..." />
<Button onClick={closeDotMenu}><Icon>close</Icon></Button> <Button onClick={closeDotMenu}><Icon>close</Icon></Button>
</Box> </Box>
<Command.Loading /> <Command.Loading />
@ -381,6 +496,6 @@ const CommandMenu = ({metaData}: Props) =>
</Dialog> </Dialog>
} }
</React.Fragment> </React.Fragment>
) );
} };
export default CommandMenu; export default CommandMenu;

View File

@ -205,7 +205,7 @@ function EntityForm(props: Props): JSX.Element
/******************************************************************************* /*******************************************************************************
** **
*******************************************************************************/ *******************************************************************************/
const deleteChildRecord = (name: string, widgetData: any, rowIndex: number) => function deleteChildRecord(name: string, widgetData: any, rowIndex: number)
{ {
updateChildRecordList(name, "delete", rowIndex); updateChildRecordList(name, "delete", rowIndex);
}; };
@ -377,7 +377,7 @@ function EntityForm(props: Props): JSX.Element
widgetData.viewAllLink = null; widgetData.viewAllLink = null;
widgetMetaData.showExportButton = false; widgetMetaData.showExportButton = false;
return <RecordGridWidget return Object.keys(childListWidgetData).length > 0 && (<RecordGridWidget
key={`${formValues["tableName"]}-${modalDataChangedCounter}`} key={`${formValues["tableName"]}-${modalDataChangedCounter}`}
widgetMetaData={widgetMetaData} widgetMetaData={widgetMetaData}
data={widgetData} data={widgetData}
@ -387,7 +387,7 @@ function EntityForm(props: Props): JSX.Element
addNewRecordCallback={() => openAddChildRecord(widgetMetaData.name, widgetData)} addNewRecordCallback={() => openAddChildRecord(widgetMetaData.name, widgetData)}
editRecordCallback={(rowIndex) => openEditChildRecord(widgetMetaData.name, widgetData, rowIndex)} editRecordCallback={(rowIndex) => openEditChildRecord(widgetMetaData.name, widgetData, rowIndex)}
deleteRecordCallback={(rowIndex) => deleteChildRecord(widgetMetaData.name, widgetData, rowIndex)} deleteRecordCallback={(rowIndex) => deleteChildRecord(widgetMetaData.name, widgetData, rowIndex)}
/>; />);
} }
if (widgetMetaData.type == "filterAndColumnsSetup") if (widgetMetaData.type == "filterAndColumnsSetup")
@ -480,6 +480,8 @@ function EntityForm(props: Props): JSX.Element
////////////////// //////////////////
// initial load // // initial load //
////////////////// //////////////////
useEffect(() =>
{
if (!asyncLoadInited) if (!asyncLoadInited)
{ {
setAsyncLoadInited(true); setAsyncLoadInited(true);
@ -762,6 +764,7 @@ function EntityForm(props: Props): JSX.Element
forceUpdate(); forceUpdate();
})(); })();
} }
}, []);
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
@ -881,11 +884,22 @@ function EntityForm(props: Props): JSX.Element
let haveAssociationsToPost = false; let haveAssociationsToPost = false;
for (let name of Object.keys(childListWidgetData)) for (let name of Object.keys(childListWidgetData))
{ {
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// if cannot find association name, continue loop, since cannot tell backend which association this is for //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
const manageAssociationName = metaData.widgets.get(name)?.defaultValues?.get("manageAssociationName"); const manageAssociationName = metaData.widgets.get(name)?.defaultValues?.get("manageAssociationName");
if (!manageAssociationName) if (!manageAssociationName)
{ {
console.log(`Cannot send association data to backend - missing a manageAssociationName defaultValue in widget meta data for widget name ${name}`); console.log(`Cannot send association data to backend - missing a manageAssociationName defaultValue in widget meta data for widget name ${name}`);
continue;
} }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// if the records array exists, add to associations to post - note: even if empty list, the backend will expect this //
// association name to be present if it is to act on it (for the case when all associations have been deleted) //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (childListWidgetData[name].queryOutput.records)
{
associationsToPost[manageAssociationName] = []; associationsToPost[manageAssociationName] = [];
haveAssociationsToPost = true; haveAssociationsToPost = true;
for (let i = 0; i < childListWidgetData[name].queryOutput?.records?.length; i++) for (let i = 0; i < childListWidgetData[name].queryOutput?.records?.length; i++)
@ -893,6 +907,7 @@ function EntityForm(props: Props): JSX.Element
associationsToPost[manageAssociationName].push(childListWidgetData[name].queryOutput.records[i].values); associationsToPost[manageAssociationName].push(childListWidgetData[name].queryOutput.records[i].values);
} }
} }
}
if (haveAssociationsToPost) if (haveAssociationsToPost)
{ {
valuesToPost["associations"] = JSON.stringify(associationsToPost); valuesToPost["associations"] = JSON.stringify(associationsToPost);

View File

@ -24,7 +24,6 @@ import {QTableMetaData} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QT
import {QWidgetMetaData} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QWidgetMetaData"; import {QWidgetMetaData} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QWidgetMetaData";
import {QCriteriaOperator} from "@kingsrook/qqq-frontend-core/lib/model/query/QCriteriaOperator"; import {QCriteriaOperator} from "@kingsrook/qqq-frontend-core/lib/model/query/QCriteriaOperator";
import {QFilterCriteria} from "@kingsrook/qqq-frontend-core/lib/model/query/QFilterCriteria"; import {QFilterCriteria} from "@kingsrook/qqq-frontend-core/lib/model/query/QFilterCriteria";
import {QFilterOrderBy} from "@kingsrook/qqq-frontend-core/lib/model/query/QFilterOrderBy";
import {QQueryFilter} from "@kingsrook/qqq-frontend-core/lib/model/query/QQueryFilter"; import {QQueryFilter} from "@kingsrook/qqq-frontend-core/lib/model/query/QQueryFilter";
import {Alert, Collapse} from "@mui/material"; import {Alert, Collapse} from "@mui/material";
import Box from "@mui/material/Box"; import Box from "@mui/material/Box";
@ -108,31 +107,37 @@ export default function FilterAndColumnsSetupWidget({isEditable, widgetMetaData,
let columns: QQueryColumns = null; let columns: QQueryColumns = null;
let usingDefaultEmptyFilter = false; let usingDefaultEmptyFilter = false;
let queryFilter = recordValues["queryFilterJson"] && JSON.parse(recordValues["queryFilterJson"]) as QQueryFilter; let queryFilter = recordValues["queryFilterJson"] && JSON.parse(recordValues["queryFilterJson"]) as QQueryFilter;
const defaultFilterFields = getDefaultFilterFieldNames(widgetMetaData);
if (!queryFilter) if (!queryFilter)
{ {
queryFilter = new QQueryFilter(); queryFilter = new QQueryFilter();
if (defaultFilterFields?.length == 0)
{
usingDefaultEmptyFilter = true;
}
}
else
{
queryFilter = Object.assign(new QQueryFilter(), queryFilter);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////
// if there is no queryFilter provided, see if there are default fields from which a query should be seeded // // if there are default fields from which a query should be seeded, add/update the filter with them //
////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////
const defaultFilterFields = getDefaultFilterFieldNames(widgetMetaData);
if (defaultFilterFields?.length > 0) if (defaultFilterFields?.length > 0)
{ {
defaultFilterFields.forEach((fieldName: string) => defaultFilterFields.forEach((fieldName: string) =>
{ {
////////////////////////////////////////////////////////////////////////////////////////////
// if a value for the default field exists, remove the criteria for it in our query first //
////////////////////////////////////////////////////////////////////////////////////////////
queryFilter.criteria = queryFilter.criteria?.filter(c => c.fieldName != fieldName);
if (recordValues[fieldName]) if (recordValues[fieldName])
{ {
queryFilter.addCriteria(new QFilterCriteria(fieldName, QCriteriaOperator.EQUALS, [recordValues[fieldName]])); queryFilter.addCriteria(new QFilterCriteria(fieldName, QCriteriaOperator.EQUALS, [recordValues[fieldName]]));
} }
}); });
queryFilter.addOrderBy(new QFilterOrderBy("id", false));
queryFilter = Object.assign({}, queryFilter);
}
else
{
usingDefaultEmptyFilter = true;
}
} }
if (recordValues["columnsJson"]) if (recordValues["columnsJson"])
@ -202,7 +207,7 @@ export default function FilterAndColumnsSetupWidget({isEditable, widgetMetaData,
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
if (missingRequiredFields.length > 0) if (missingRequiredFields.length > 0)
{ {
setAlertContent("The following fields must first be selected to add Additional Order Filters: '" + missingRequiredFields.join(", ") + "'"); setAlertContent("The following fields must first be selected to edit the filter: '" + missingRequiredFields.join(", ") + "'");
return; return;
} }

View File

@ -40,14 +40,14 @@ import {Link, useNavigate} from "react-router-dom";
export interface ChildRecordListData extends WidgetData export interface ChildRecordListData extends WidgetData
{ {
title: string; title: string;
queryOutput: {records: {values: any}[]} queryOutput: { records: { values: any }[] };
childTableMetaData: QTableMetaData; childTableMetaData: QTableMetaData;
tablePath: string; tablePath: string;
viewAllLink: string; viewAllLink: string;
totalRows: number; totalRows: number;
canAddChildRecord: boolean; canAddChildRecord: boolean;
defaultValuesForNewChildRecords: {[fieldName: string]: any}; defaultValuesForNewChildRecords: { [fieldName: string]: any };
disabledFieldsForNewChildRecords: {[fieldName: string]: any}; disabledFieldsForNewChildRecords: { [fieldName: string]: any };
} }
interface Props interface Props
@ -75,9 +75,9 @@ function RecordGridWidget({widgetMetaData, data, addNewRecordCallback, disableRo
{ {
const instance = useRef({timer: null}); const instance = useRef({timer: null});
const [rows, setRows] = useState([]); const [rows, setRows] = useState([]);
const [records, setRecords] = useState([] as QRecord[]) const [records, setRecords] = useState([] as QRecord[]);
const [columns, setColumns] = useState([]); const [columns, setColumns] = useState([]);
const [allColumns, setAllColumns] = useState([]) const [allColumns, setAllColumns] = useState([]);
const [csv, setCsv] = useState(null as string); const [csv, setCsv] = useState(null as string);
const [fileName, setFileName] = useState(null as string); const [fileName, setFileName] = useState(null as string);
const [gridMouseDownX, setGridMouseDownX] = useState(0); const [gridMouseDownX, setGridMouseDownX] = useState(0);
@ -110,20 +110,20 @@ function RecordGridWidget({widgetMetaData, data, addNewRecordCallback, disableRo
///////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////
// capture all-columns to use for the export (before we might splice some away from the on-screen display) // // capture all-columns to use for the export (before we might splice some away from the on-screen display) //
///////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////
const allColumns = [... columns]; const allColumns = [...columns];
setAllColumns(JSON.parse(JSON.stringify(columns))); setAllColumns(JSON.parse(JSON.stringify(columns)));
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
// do not not show the foreign-key column of the parent table // // do not not show the foreign-key column of the parent table //
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
if(data.defaultValuesForNewChildRecords) if (data.defaultValuesForNewChildRecords)
{ {
for (let i = 0; i < columns.length; i++) for (let i = 0; i < columns.length; i++)
{ {
if(data.defaultValuesForNewChildRecords[columns[i].field]) if (data.defaultValuesForNewChildRecords[columns[i].field])
{ {
columns.splice(i, 1); columns.splice(i, 1);
i-- i--;
} }
} }
} }
@ -131,7 +131,7 @@ function RecordGridWidget({widgetMetaData, data, addNewRecordCallback, disableRo
//////////////////////////////////// ////////////////////////////////////
// add actions cell, if available // // add actions cell, if available //
//////////////////////////////////// ////////////////////////////////////
if(allowRecordEdit || allowRecordDelete) if (allowRecordEdit || allowRecordDelete)
{ {
columns.unshift({ columns.unshift({
field: "_actions", field: "_actions",
@ -145,19 +145,19 @@ function RecordGridWidget({widgetMetaData, data, addNewRecordCallback, disableRo
return <Box> return <Box>
{allowRecordEdit && <IconButton onClick={() => editRecordCallback(params.row.__rowIndex)}><Icon>edit</Icon></IconButton>} {allowRecordEdit && <IconButton onClick={() => editRecordCallback(params.row.__rowIndex)}><Icon>edit</Icon></IconButton>}
{allowRecordDelete && <IconButton onClick={() => deleteRecordCallback(params.row.__rowIndex)}><Icon>delete</Icon></IconButton>} {allowRecordDelete && <IconButton onClick={() => deleteRecordCallback(params.row.__rowIndex)}><Icon>delete</Icon></IconButton>}
</Box> </Box>;
})
}) })
});
} }
setRows(rows); setRows(rows);
setRecords(records) setRecords(records);
setColumns(columns); setColumns(columns);
let csv = ""; let csv = "";
for (let i = 0; i < allColumns.length; i++) for (let i = 0; i < allColumns.length; i++)
{ {
csv += `${i > 0 ? "," : ""}"${ValueUtils.cleanForCsv(allColumns[i].headerName)}"` csv += `${i > 0 ? "," : ""}"${ValueUtils.cleanForCsv(allColumns[i].headerName)}"`;
} }
csv += "\n"; csv += "\n";
@ -165,8 +165,8 @@ function RecordGridWidget({widgetMetaData, data, addNewRecordCallback, disableRo
{ {
for (let j = 0; j < allColumns.length; j++) for (let j = 0; j < allColumns.length; j++)
{ {
const value = records[i].displayValues.get(allColumns[j].field) ?? records[i].values.get(allColumns[j].field) const value = records[i].displayValues.get(allColumns[j].field) ?? records[i].values.get(allColumns[j].field);
csv += `${j > 0 ? "," : ""}"${ValueUtils.cleanForCsv(value)}"` csv += `${j > 0 ? "," : ""}"${ValueUtils.cleanForCsv(value)}"`;
} }
csv += "\n"; csv += "\n";
} }
@ -182,13 +182,13 @@ function RecordGridWidget({widgetMetaData, data, addNewRecordCallback, disableRo
// view all link // // view all link //
/////////////////// ///////////////////
const labelAdditionalElementsLeft: JSX.Element[] = []; const labelAdditionalElementsLeft: JSX.Element[] = [];
if(data && data.viewAllLink) if (data && data.viewAllLink)
{ {
labelAdditionalElementsLeft.push( labelAdditionalElementsLeft.push(
<Typography key={"viewAllLink"} variant="body2" p={2} display="inline" fontSize=".875rem" pt="0" position="relative"> <Typography key={"viewAllLink"} variant="body2" p={2} display="inline" fontSize=".875rem" pt="0" position="relative">
<Link to={data.viewAllLink}>View All</Link> <Link to={data.viewAllLink}>View All</Link>
</Typography> </Typography>
) );
} }
/////////////////// ///////////////////
@ -200,10 +200,10 @@ function RecordGridWidget({widgetMetaData, data, addNewRecordCallback, disableRo
{ {
isExportDisabled = false; isExportDisabled = false;
if(data.totalRows && data.queryOutput.records.length < data.totalRows) if (data.totalRows && data.queryOutput.records.length < data.totalRows)
{ {
tooltipTitle = "Export these " + data.queryOutput.records.length + " records." tooltipTitle = "Export these " + data.queryOutput.records.length + " records.";
if(data.viewAllLink) if (data.viewAllLink)
{ {
tooltipTitle += "\nClick View All to export all records."; tooltipTitle += "\nClick View All to export all records.";
} }
@ -212,17 +212,17 @@ function RecordGridWidget({widgetMetaData, data, addNewRecordCallback, disableRo
const onExportClick = () => const onExportClick = () =>
{ {
if(csv) if (csv)
{ {
HtmlUtils.download(fileName, csv); HtmlUtils.download(fileName, csv);
} }
else else
{ {
alert("There is no data available to export.") alert("There is no data available to export.");
}
} }
};
if(widgetMetaData?.showExportButton) if (widgetMetaData?.showExportButton)
{ {
labelAdditionalElementsLeft.push( labelAdditionalElementsLeft.push(
<Typography key={"exportButton"} variant="body2" px={0} display="inline" position="relative"> <Typography key={"exportButton"} variant="body2" px={0} display="inline" position="relative">
@ -234,15 +234,15 @@ function RecordGridWidget({widgetMetaData, data, addNewRecordCallback, disableRo
//////////////////// ////////////////////
// add new button // // add new button //
//////////////////// ////////////////////
const labelAdditionalComponentsRight: LabelComponent[] = [] const labelAdditionalComponentsRight: LabelComponent[] = [];
if(data && data.canAddChildRecord) if (data && data.canAddChildRecord)
{ {
let disabledFields = data.disabledFieldsForNewChildRecords; let disabledFields = data.disabledFieldsForNewChildRecords;
if(!disabledFields) if (!disabledFields)
{ {
disabledFields = data.defaultValuesForNewChildRecords; disabledFields = data.defaultValuesForNewChildRecords;
} }
labelAdditionalComponentsRight.push(new AddNewRecordButton(data.childTableMetaData, data.defaultValuesForNewChildRecords, "Add new", disabledFields, addNewRecordCallback)) labelAdditionalComponentsRight.push(new AddNewRecordButton(data.childTableMetaData, data.defaultValuesForNewChildRecords, "Add new", disabledFields, addNewRecordCallback));
} }
@ -251,16 +251,16 @@ function RecordGridWidget({widgetMetaData, data, addNewRecordCallback, disableRo
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
const handleRowClick = (params: GridRowParams, event: MuiEvent<React.MouseEvent>, details: GridCallbackDetails) => const handleRowClick = (params: GridRowParams, event: MuiEvent<React.MouseEvent>, details: GridCallbackDetails) =>
{ {
if(disableRowClick) if (disableRowClick)
{ {
return; return;
} }
(async () => (async () =>
{ {
const qInstance = await qController.loadMetaData() const qInstance = await qController.loadMetaData();
let tablePath = qInstance.getTablePathByName(data.childTableMetaData.name) let tablePath = qInstance.getTablePathByName(data.childTableMetaData.name);
if(tablePath) if (tablePath)
{ {
tablePath = `${tablePath}/${params.row[data.childTableMetaData.primaryKeyField]}`; tablePath = `${tablePath}/${params.row[data.childTableMetaData.primaryKeyField]}`;
DataGridUtils.handleRowClick(tablePath, event, gridMouseDownX, gridMouseDownY, navigate, instance); DataGridUtils.handleRowClick(tablePath, event, gridMouseDownX, gridMouseDownY, navigate, instance);
@ -276,7 +276,7 @@ function RecordGridWidget({widgetMetaData, data, addNewRecordCallback, disableRo
*******************************************************************************/ *******************************************************************************/
function CustomToolbar() function CustomToolbar()
{ {
const handleMouseDown: GridEventListener<"cellMouseDown"> = ( params, event, details ) => const handleMouseDown: GridEventListener<"cellMouseDown"> = (params, event, details) =>
{ {
setGridMouseDownX(event.clientX); setGridMouseDownX(event.clientX);
setGridMouseDownY(event.clientY); setGridMouseDownY(event.clientY);
@ -304,8 +304,8 @@ function RecordGridWidget({widgetMetaData, data, addNewRecordCallback, disableRo
labelAdditionalComponentsRight={labelAdditionalComponentsRight} labelAdditionalComponentsRight={labelAdditionalComponentsRight}
labelBoxAdditionalSx={{position: "relative", top: "-0.375rem"}} labelBoxAdditionalSx={{position: "relative", top: "-0.375rem"}}
> >
<Box mx={-2} mb={-3}> <Box mx={-3} mb={-3}>
<Box className="recordGridWidget"> <Box>
<DataGridPro <DataGridPro
autoHeight autoHeight
sx={{ sx={{

View File

@ -421,7 +421,7 @@ input[type="search"]::-webkit-search-results-decoration
font-size: 2rem !important; font-size: 2rem !important;
} }
.dashboard-order-release-icon .dashboard-table-actions-icon
{ {
font-size: 1.5rem !important; font-size: 1.5rem !important;
position: relative; position: relative;
@ -711,11 +711,6 @@ input[type="search"]::-webkit-search-results-decoration
padding: 24px; padding: 24px;
} }
.recordView .widget .recordGridWidget
{
margin: -8px;
}
.MuiPickersDay-root.Mui-selected, .MuiPickersDay-root.MuiPickersDay-dayWithMargin:hover .MuiPickersDay-root.Mui-selected, .MuiPickersDay-root.MuiPickersDay-dayWithMargin:hover
{ {
color: white; color: white;