diff --git a/package.json b/package.json index 0a1a82b..e1ed165 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "@auth0/auth0-react": "1.10.2", "@emotion/react": "11.7.1", "@emotion/styled": "11.6.0", - "@kingsrook/qqq-frontend-core": "1.0.52", + "@kingsrook/qqq-frontend-core": "1.0.53", "@mui/icons-material": "5.4.1", "@mui/material": "5.11.1", "@mui/styles": "5.11.1", diff --git a/src/qqq/components/forms/DynamicForm.tsx b/src/qqq/components/forms/DynamicForm.tsx index 88400c4..e1159c8 100644 --- a/src/qqq/components/forms/DynamicForm.tsx +++ b/src/qqq/components/forms/DynamicForm.tsx @@ -131,6 +131,7 @@ function QDynamicForm(props: Props): JSX.Element ) + public static addPossibleValueProps(dynamicFormFields: any, qFields: QFieldMetaData[], tableName: string, processName: string, displayValues: Map) { for (let i = 0; i < qFields.length; i++) { @@ -126,12 +126,24 @@ class DynamicFormUtils initialDisplayValue = displayValues.get(field.name); } - dynamicFormFields[field.name].possibleValueProps = - { - isPossibleValue: true, - tableName: tableName, - initialDisplayValue: initialDisplayValue, - }; + if (tableName) + { + dynamicFormFields[field.name].possibleValueProps = + { + isPossibleValue: true, + tableName: tableName, + initialDisplayValue: initialDisplayValue, + }; + } + else + { + dynamicFormFields[field.name].possibleValueProps = + { + isPossibleValue: true, + processName: processName, + initialDisplayValue: initialDisplayValue, + }; + } } } } diff --git a/src/qqq/components/forms/DynamicSelect.tsx b/src/qqq/components/forms/DynamicSelect.tsx index 054d23c..a562b64 100644 --- a/src/qqq/components/forms/DynamicSelect.tsx +++ b/src/qqq/components/forms/DynamicSelect.tsx @@ -35,7 +35,8 @@ import Client from "qqq/utils/qqq/Client"; interface Props { - tableName: string; + tableName?: string; + processName?: string; fieldName: string; fieldLabel: string; inForm: boolean; @@ -50,6 +51,8 @@ interface Props } DynamicSelect.defaultProps = { + tableName: null, + processName: null, inForm: true, initialValue: null, initialDisplayValue: null, @@ -65,7 +68,7 @@ DynamicSelect.defaultProps = { const qController = Client.getInstance(); -function DynamicSelect({tableName, fieldName, fieldLabel, inForm, initialValue, initialDisplayValue, initialValues, onChange, isEditable, isMultiple, bulkEditMode, bulkEditSwitchChangeHandler}: Props) +function DynamicSelect({tableName, processName, fieldName, fieldLabel, inForm, initialValue, initialDisplayValue, initialValues, onChange, isEditable, isMultiple, bulkEditMode, bulkEditSwitchChangeHandler}: Props) { const [ open, setOpen ] = useState(false); const [ options, setOptions ] = useState([]); @@ -109,9 +112,9 @@ function DynamicSelect({tableName, fieldName, fieldLabel, inForm, initialValue, (async () => { // console.log(`doing a search with ${searchTerm}`); - const results: QPossibleValue[] = await qController.possibleValues(tableName, fieldName, searchTerm ?? ""); + const results: QPossibleValue[] = await qController.possibleValues(tableName, processName, fieldName, searchTerm ?? ""); - if(tableMetaData == null) + if(tableMetaData == null && tableName) { let tableMetaData: QTableMetaData = await qController.loadTableMetaData(tableName); setTableMetaData(tableMetaData); @@ -134,7 +137,7 @@ function DynamicSelect({tableName, fieldName, fieldLabel, inForm, initialValue, const inputChanged = (event: React.SyntheticEvent, value: string, reason: string) => { - console.log(`input changed. Reason: ${reason}, setting search term to ${value}`); + // console.log(`input changed. Reason: ${reason}, setting search term to ${value}`); if(reason !== "reset") { // console.log(` -> setting search term to ${value}`); @@ -186,7 +189,7 @@ function DynamicSelect({tableName, fieldName, fieldLabel, inForm, initialValue, try { - const field = tableMetaData.fields.get(fieldName) + const field = tableMetaData?.fields.get(fieldName) if(field) { const adornment = field.getAdornment(AdornmentType.CHIP); diff --git a/src/qqq/components/forms/EntityForm.tsx b/src/qqq/components/forms/EntityForm.tsx index 311ed30..7f9ddf1 100644 --- a/src/qqq/components/forms/EntityForm.tsx +++ b/src/qqq/components/forms/EntityForm.tsx @@ -236,7 +236,7 @@ function EntityForm(props: Props): JSX.Element /////////////////////////////////////////////////////////////////////////////////////////// if (fieldMetaData.possibleValueSourceName) { - const results: QPossibleValue[] = await qController.possibleValues(tableName, fieldName, null, [initialValues[fieldName]]); + const results: QPossibleValue[] = await qController.possibleValues(tableName, null, fieldName, null, [initialValues[fieldName]]); if (results && results.length > 0) { defaultDisplayValues.set(fieldName, results[0].label); @@ -268,7 +268,7 @@ function EntityForm(props: Props): JSX.Element dynamicFormFields, formValidations, } = DynamicFormUtils.getFormData(fieldArray); - DynamicFormUtils.addPossibleValueProps(dynamicFormFields, fieldArray, tableName, record ? record.displayValues : defaultDisplayValues); + DynamicFormUtils.addPossibleValueProps(dynamicFormFields, fieldArray, tableName, null, record ? record.displayValues : defaultDisplayValues); if(disabledFields) { diff --git a/src/qqq/components/widgets/DashboardWidgets.tsx b/src/qqq/components/widgets/DashboardWidgets.tsx index 94ce913..3630f02 100644 --- a/src/qqq/components/widgets/DashboardWidgets.tsx +++ b/src/qqq/components/widgets/DashboardWidgets.tsx @@ -225,7 +225,7 @@ function DashboardWidgets({widgetMetaDataList, tableName, entityPrimaryKey, omit widgetMetaData={widgetMetaData} widgetData={widgetData[i]} reloadWidgetCallback={(data) => reloadWidget(i, data)}> -
+
diff --git a/src/qqq/components/widgets/Widget.tsx b/src/qqq/components/widgets/Widget.tsx index 320b916..747653a 100644 --- a/src/qqq/components/widgets/Widget.tsx +++ b/src/qqq/components/widgets/Widget.tsx @@ -285,7 +285,7 @@ function Widget(props: React.PropsWithChildren): JSX.Element const hasPermission = props.widgetData?.hasPermission === undefined || props.widgetData?.hasPermission === true; const widgetContent = - + { diff --git a/src/qqq/pages/processes/ProcessRun.tsx b/src/qqq/pages/processes/ProcessRun.tsx index 35d9a62..506784d 100644 --- a/src/qqq/pages/processes/ProcessRun.tsx +++ b/src/qqq/pages/processes/ProcessRun.tsx @@ -38,7 +38,6 @@ import {Alert, Button, CircularProgress, Icon, TablePagination} from "@mui/mater import Box from "@mui/material/Box"; import Card from "@mui/material/Card"; import Grid from "@mui/material/Grid"; -import Link from "@mui/material/Link"; import Step from "@mui/material/Step"; import StepLabel from "@mui/material/StepLabel"; import Stepper from "@mui/material/Stepper"; @@ -46,6 +45,7 @@ import Typography from "@mui/material/Typography"; import {DataGridPro, GridColDef} from "@mui/x-data-grid-pro"; import FormData from "form-data"; import {Form, Formik} from "formik"; +import parse from "html-react-parser"; import React, {useContext, useEffect, useState} from "react"; import {useLocation, useNavigate, useParams} from "react-router-dom"; import * as Yup from "yup"; @@ -75,7 +75,7 @@ interface Props recordIds?: string | QQueryFilter; closeModalHandler?: (event: object, reason: string) => void; forceReInit?: number; - overrideLabel?: string + overrideLabel?: string; } const INITIAL_RETRY_MILLIS = 1_500; @@ -225,12 +225,12 @@ function ProcessRun({process, defaultProcessValues, isModal, isWidget, isReport, xhr.open("POST", url); xhr.responseType = "blob"; let formData = new FormData(); - formData.append("Authorization", qController.getAuthorizationHeaderValue()) + formData.append("Authorization", qController.getAuthorizationHeaderValue()); // @ts-ignore xhr.send(formData); - xhr.onload = function(e) + xhr.onload = function (e) { if (this.status == 200) { @@ -247,7 +247,7 @@ function ProcessRun({process, defaultProcessValues, isModal, isWidget, isReport, } else { - setProcessError("Error downloading file", true) + setProcessError("Error downloading file", true); } }; }; @@ -299,7 +299,7 @@ function ProcessRun({process, defaultProcessValues, isModal, isWidget, isReport, {isModal ? - : + : !isWidget && } @@ -350,7 +350,7 @@ function ProcessRun({process, defaultProcessValues, isModal, isWidget, isReport, const {formFields, values, errors, touched} = formData; let localTableSections = tableSections; - if(localTableSections == null) + if (localTableSections == null) { ////////////////////////////////////////////////////////////////////////////////////////////////////// // if the table sections (ones that actually have fields to edit) haven't been built yet, do so now // @@ -359,6 +359,23 @@ function ProcessRun({process, defaultProcessValues, isModal, isWidget, isReport, setTableSections(localTableSections); } + //////////////////////////////////////////////////////////////////////////////////// + // if there are any fields that are possible values, they need to know what their // + // initial value to display should be. // + // this **needs to be** the actual PVS LABEL - not the raw value (e.g, PVS ID) // + // but our first use case, they're the same, so... this needs fixed. // + //////////////////////////////////////////////////////////////////////////////////// + if(formFields && processValues) + { + Object.keys(formFields).forEach((key) => + { + if(formFields[key].possibleValueProps && processValues[key]) + { + formFields[key].possibleValueProps.initialDisplayValue = processValues[key] + } + }) + } + return ( <> { @@ -420,25 +437,25 @@ function ProcessRun({process, defaultProcessValues, isModal, isWidget, isReport, {localTableSections.map((section: QTableSection, index: number) => { - const name = section.name + const name = section.name; - if(section.isHidden) + if (section.isHidden) { - return ; + return; } const sectionFormFields = {}; - for(let i = 0; i 0) + if (Object.keys(sectionFormFields).length > 0) { const sectionFormData = { formFields: sectionFormFields, @@ -589,6 +606,14 @@ function ProcessRun({process, defaultProcessValues, isModal, isWidget, isReport,
) } + { + component.type === QComponentType.HTML && ( + processValues[`${step.name}.html`] && + + {parse(processValues[`${step.name}.html`])} + + ) + } )))} @@ -655,7 +680,7 @@ function ProcessRun({process, defaultProcessValues, isModal, isWidget, isReport, return; } - if(! isWidget) + if (!isWidget) { setPageHeader(overrideLabel ?? processMetaData.label); } @@ -701,10 +726,9 @@ function ProcessRun({process, defaultProcessValues, isModal, isWidget, isReport, { let fullFieldList = getFullFieldList(activeStep, processValues); const formData = DynamicFormUtils.getFormData(fullFieldList); - if(tableMetaData) - { - DynamicFormUtils.addPossibleValueProps(formData.dynamicFormFields, fullFieldList, tableMetaData.name, null); - } + + const possibleValueDisplayValues = new Map(); + DynamicFormUtils.addPossibleValueProps(formData.dynamicFormFields, fullFieldList, tableMetaData?.name, processName, possibleValueDisplayValues); dynamicFormFields = formData.dynamicFormFields; formValidations = formData.formValidations; @@ -819,7 +843,7 @@ function ProcessRun({process, defaultProcessValues, isModal, isWidget, isReport, } }); - DynamicFormUtils.addPossibleValueProps(newDynamicFormFields, fullFieldList, tableMetaData.name, null); + DynamicFormUtils.addPossibleValueProps(newDynamicFormFields, fullFieldList, tableMetaData.name, null, null); setFormFields(newDynamicFormFields); setValidationScheme(Yup.object().shape(newFormValidations)); @@ -981,11 +1005,11 @@ function ProcessRun({process, defaultProcessValues, isModal, isWidget, isReport, { if ((e as QException).status === "403") { - setProcessError(`You do not have permission to run this ${isReport ? "report" : "process"}.`, true) + setProcessError(`You do not have permission to run this ${isReport ? "report" : "process"}.`, true); return (true); } return (false); - } + }; ////////////////////////////////////////////////////////////////////////////////////////// @@ -1175,7 +1199,7 @@ function ProcessRun({process, defaultProcessValues, isModal, isWidget, isReport, mainCardStyles.background = "none"; mainCardStyles.boxShadow = "none"; } - if(isWidget) + if (isWidget) { mainCardStyles.background = "none"; mainCardStyles.boxShadow = "none"; @@ -1231,10 +1255,10 @@ function ProcessRun({process, defaultProcessValues, isModal, isWidget, isReport, } - + {/*************************************************************************** - ** step content - e.g., the appropriate form or other screen for the step ** - ***************************************************************************/} + ** step content - e.g., the appropriate form or other screen for the step ** + ***************************************************************************/} {getDynamicStepContent( activeStepIndex, activeStep, @@ -1250,9 +1274,9 @@ function ProcessRun({process, defaultProcessValues, isModal, isWidget, isReport, setFieldValue, )} {/******************************** - ** back &| next/submit buttons ** - ********************************/} - + ** back &| next/submit buttons ** + ********************************/} + {true || activeStepIndex === 0 ? ( ) : ( @@ -1279,7 +1303,7 @@ function ProcessRun({process, defaultProcessValues, isModal, isWidget, isReport, { - ! isWidget && ( + !isWidget && ( ) } @@ -1320,7 +1344,7 @@ function ProcessRun({process, defaultProcessValues, isModal, isWidget, isReport, else if (isWidget) { return ( - + {form} ); diff --git a/src/qqq/pages/records/query/RecordQuery.tsx b/src/qqq/pages/records/query/RecordQuery.tsx index 58eb69a..bb6e2f2 100644 --- a/src/qqq/pages/records/query/RecordQuery.tsx +++ b/src/qqq/pages/records/query/RecordQuery.tsx @@ -221,7 +221,7 @@ function RecordQuery({table, launchProcess}: Props): JSX.Element const parts = location.pathname.split("/"); currentSavedFilterId = Number.parseInt(parts[parts.length - 1]); } - else + else if(!searchParams.has("filter")) { if (localStorage.getItem(currentSavedFilterLocalStorageKey)) { @@ -573,10 +573,7 @@ function RecordQuery({table, launchProcess}: Props): JSX.Element setFilterModel(filterModel); if (filterLocalStorageKey) { - localStorage.setItem( - filterLocalStorageKey, - JSON.stringify(filterModel), - ); + localStorage.setItem(filterLocalStorageKey, JSON.stringify(filterModel)); } }; diff --git a/src/qqq/utils/qqq/FilterUtils.ts b/src/qqq/utils/qqq/FilterUtils.ts index dbfb055..c79e10c 100644 --- a/src/qqq/utils/qqq/FilterUtils.ts +++ b/src/qqq/utils/qqq/FilterUtils.ts @@ -30,6 +30,8 @@ import {QQueryFilter} from "@kingsrook/qqq-frontend-core/lib/model/query/QQueryF import {GridFilterModel, GridLinkOperator, GridSortItem} from "@mui/x-data-grid-pro"; import ValueUtils from "qqq/utils/qqq/ValueUtils"; +const CURRENT_SAVED_FILTER_ID_LOCAL_STORAGE_KEY_ROOT = "qqq.currentSavedFilterId"; + /******************************************************************************* ** Utility class for working with QQQ Filters ** @@ -366,7 +368,7 @@ class FilterUtils ////////////////////////////////////////////////////////////////////////////////// if (values && values.length > 0) { - values = await qController.possibleValues(tableMetaData.name, field.name, "", values); + values = await qController.possibleValues(tableMetaData.name, null, field.name, "", values); } //////////////////////////////////////////// @@ -454,6 +456,16 @@ class FilterUtils } } + if (searchParams && searchParams.has("filter")) + { + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // if we're setting the filter based on a filter query-string param, then make sure we don't have a currentSavedFilter in local storage. // + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + localStorage.removeItem(`${CURRENT_SAVED_FILTER_ID_LOCAL_STORAGE_KEY_ROOT}.${tableMetaData.name}`); + localStorage.setItem(filterLocalStorageKey, JSON.stringify(defaultFilter)); + localStorage.setItem(sortLocalStorageKey, JSON.stringify(defaultSort)); + } + return ({filter: defaultFilter, sort: defaultSort}); } catch (e)