Merge branch 'feature/CTLE-207-query-joins' into dev

This commit is contained in:
Tim Chamberlain
2023-05-02 15:13:28 -05:00
17 changed files with 931 additions and 205 deletions

View File

@ -194,7 +194,7 @@ function AuditBody({tableMetaData, recordId, record}: Props): JSX.Element
new QFilterOrderBy("timestamp", sortDirection),
new QFilterOrderBy("id", sortDirection),
new QFilterOrderBy("auditDetail.id", true)
]);
], "AND", 0, limit);
///////////////////////////////
// fetch audits in try-catch //
@ -202,7 +202,7 @@ function AuditBody({tableMetaData, recordId, record}: Props): JSX.Element
let audits = [] as QRecord[]
try
{
audits = await qController.query("audit", filter, limit, 0, [new QueryJoin("auditDetail", true, "LEFT")]);
audits = await qController.query("audit", filter, [new QueryJoin("auditDetail", true, "LEFT")]);
setAudits(audits);
}
catch(e)
@ -222,8 +222,8 @@ function AuditBody({tableMetaData, recordId, record}: Props): JSX.Element
// if we fetched the limit
if (audits.length == limit)
{
const count = await qController.count("audit", filter);
setTotal(count);
const [count, distinctCount] = await qController.count("audit", filter, null, true); // todo validate distinct working here!
setTotal(distinctCount);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -50,18 +50,20 @@ export function QCreateNewButton({tablePath}: QCreateNewButtonProps): JSX.Elemen
interface QSaveButtonProps
{
label?: string;
iconName?: string;
onClickHandler?: any,
disabled: boolean
}
QSaveButton.defaultProps = {
label: "Save"
label: "Save",
iconName: "save"
};
export function QSaveButton({label, onClickHandler, disabled}: QSaveButtonProps): JSX.Element
export function QSaveButton({label, iconName, onClickHandler, disabled}: QSaveButtonProps): JSX.Element
{
return (
<Box ml={3} width={standardWidth}>
<MDButton type="submit" variant="gradient" color="info" size="small" onClick={onClickHandler} fullWidth startIcon={<Icon>save</Icon>} disabled={disabled}>
<MDButton type="submit" variant="gradient" color="info" size="small" onClick={onClickHandler} fullWidth startIcon={<Icon>{iconName}</Icon>} disabled={disabled}>
{label}
</MDButton>
</Box>

View File

@ -0,0 +1,144 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2023. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {ClickAwayListener, Grow, MenuList, Paper, Popper} from "@mui/material";
import Button from "@mui/material/Button/Button";
import Icon from "@mui/material/Icon";
import MenuItem from "@mui/material/MenuItem";
import React, {useEffect, useRef, useState} from "react";
interface Props
{
label: string;
iconName?: string
options: string[];
disabled?: boolean;
callback: (selectedIndex: number) => void;
}
MenuButton.defaultProps =
{
disabled: false
};
function MenuButton({label, iconName, options, disabled, callback}: Props)
{
const [open, setOpen] = useState(false);
const anchorRef = useRef<HTMLButtonElement>(null);
const handleToggle = () =>
{
setOpen((prevOpen) => !prevOpen);
};
const handleClose = (event: Event | React.SyntheticEvent) =>
{
if (anchorRef.current && anchorRef.current.contains(event.target as HTMLElement))
{
return;
}
setOpen(false);
};
function handleListKeyDown(event: React.KeyboardEvent)
{
if (event.key === "Tab")
{
event.preventDefault();
setOpen(false);
}
else if (event.key === "Escape")
{
setOpen(false);
}
}
// return focus to the button when we transitioned from !open -> open
const prevOpen = useRef(open);
useEffect(() =>
{
if (prevOpen.current === true && open === false)
{
anchorRef.current!.focus();
}
prevOpen.current = open;
}, [open]);
const menuItemClicked = (e: React.MouseEvent<HTMLLIElement, MouseEvent>, newIndex: number) =>
{
callback(newIndex);
handleClose(e);
}
const menuItems: JSX.Element[] = []
options.map((option, index) =>
{
menuItems.push(<MenuItem key={index} onClick={e => menuItemClicked(e, index)}>
{option}
</MenuItem>);
})
return (
<div>
<Button
ref={anchorRef}
id="composition-button"
aria-controls={open ? "composition-menu" : undefined}
aria-expanded={open ? "true" : undefined}
aria-haspopup="true"
onClick={handleToggle}
startIcon={iconName ? <Icon>{iconName}</Icon> : undefined}
sx={{pl: "1.25rem"}}
disabled={disabled}
>
{label}
</Button>
<Popper
open={open}
anchorEl={anchorRef.current}
role={undefined}
placement="bottom-start"
transition
disablePortal nonce={undefined} onResize={undefined} onResizeCapture={undefined}
sx={{zIndex: 1}}
>
{({TransitionProps, placement}) => (
<Grow{...TransitionProps} style={{transformOrigin: placement === "bottom-start" ? "left top" : "left bottom"}}>
<Paper elevation={3}>
<ClickAwayListener onClickAway={handleClose}>
<MenuList onKeyDown={handleListKeyDown}>
{menuItems}
</MenuList>
</ClickAwayListener>
</Paper>
</Grow>
)}
</Popper>
</div>
);
}
export default MenuButton;

View File

@ -100,8 +100,8 @@ export default function DataBagViewer({dataBagId}: Props): JSX.Element
const criteria = [new QFilterCriteria("dataBagId", QCriteriaOperator.EQUALS, [dataBagId])];
const orderBys = [new QFilterOrderBy("sequenceNo", false)];
const filter = new QQueryFilter(criteria, orderBys);
const versions = await qController.query("dataBagVersion", filter, 25, 0);
const filter = new QQueryFilter(criteria, orderBys, "AND", 0, 25);
const versions = await qController.query("dataBagVersion", filter);
console.log("Fetched versions:");
console.log(versions);
setVersionRecordList(versions);

View File

@ -60,13 +60,13 @@ function RecordGridWidget({widgetMetaData, data}: Props): JSX.Element
}
const tableMetaData = new QTableMetaData(data.childTableMetaData);
const {rows, columnsToRender} = DataGridUtils.makeRows(records, tableMetaData);
const rows = DataGridUtils.makeRows(records, tableMetaData);
/////////////////////////////////////////////////////////////////////////////////
// note - tablePath may be null, if the user doesn't have access to the table. //
/////////////////////////////////////////////////////////////////////////////////
const childTablePath = data.tablePath ? data.tablePath + (data.tablePath.endsWith("/") ? "" : "/") : data.tablePath;
const columns = DataGridUtils.setupGridColumns(tableMetaData, columnsToRender, childTablePath);
const columns = DataGridUtils.setupGridColumns(tableMetaData, childTablePath, null, "bySection");
////////////////////////////////////////////////////////////////
// do not not show the foreign-key column of the parent table //

View File

@ -133,8 +133,8 @@ export default function ScriptViewer({scriptId, associatedScriptTableName, assoc
const criteria = [new QFilterCriteria("scriptId", QCriteriaOperator.EQUALS, [scriptId])];
const orderBys = [new QFilterOrderBy("sequenceNo", false)];
const filter = new QQueryFilter(criteria, orderBys);
const versions = await qController.query("scriptRevision", filter, 25, 0);
const filter = new QQueryFilter(criteria, orderBys, "AND", 0, 25);
const versions = await qController.query("scriptRevision", filter);
console.log("Fetched versions:");
console.log(versions);
setVersionRecordList(versions);
@ -281,7 +281,8 @@ export default function ScriptViewer({scriptId, associatedScriptTableName, assoc
{
(async () =>
{
scriptLogs[scriptRevisionId] = await qController.query("scriptLog", new QQueryFilter([new QFilterCriteria("scriptRevisionId", QCriteriaOperator.EQUALS, [scriptRevisionId])]), 100, 0);
let filter = new QQueryFilter([new QFilterCriteria("scriptRevisionId", QCriteriaOperator.EQUALS, [scriptRevisionId])], [new QFilterOrderBy("id", false)], "AND", 0, 100);
scriptLogs[scriptRevisionId] = await qController.query("scriptLog", filter);
setScriptLogs(scriptLogs);
forceUpdate();
})();