Pass other values from process into possible values (for filter)

This commit is contained in:
2023-03-08 10:22:18 -06:00
parent 39eea433fb
commit b6d79817de
5 changed files with 71 additions and 39 deletions

View File

@ -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.54",
"@kingsrook/qqq-frontend-core": "1.0.55",
"@mui/icons-material": "5.4.1",
"@mui/material": "5.11.1",
"@mui/styles": "5.11.1",

View File

@ -48,6 +48,7 @@ interface Props
isMultiple?: boolean;
bulkEditMode?: boolean;
bulkEditSwitchChangeHandler?: any;
otherValues?: Map<string, any>;
}
DynamicSelect.defaultProps = {
@ -61,6 +62,7 @@ DynamicSelect.defaultProps = {
isEditable: true,
isMultiple: false,
bulkEditMode: false,
otherValues: new Map<string, any>(),
bulkEditSwitchChangeHandler: () =>
{
},
@ -68,7 +70,7 @@ DynamicSelect.defaultProps = {
const qController = Client.getInstance();
function DynamicSelect({tableName, processName, 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, otherValues}: Props)
{
const [ open, setOpen ] = useState(false);
const [ options, setOptions ] = useState<readonly QPossibleValue[]>([]);
@ -112,7 +114,7 @@ function DynamicSelect({tableName, processName, fieldName, fieldLabel, inForm, i
(async () =>
{
// console.log(`doing a search with ${searchTerm}`);
const results: QPossibleValue[] = await qController.possibleValues(tableName, processName, fieldName, searchTerm ?? "");
const results: QPossibleValue[] = await qController.possibleValues(tableName, processName, fieldName, searchTerm ?? "", null, otherValues);
if(tableMetaData == null && tableName)
{
@ -237,8 +239,6 @@ function DynamicSelect({tableName, processName, fieldName, fieldLabel, inForm, i
bulkEditSwitchChangeHandler(fieldName, newSwitchValue);
};
console.log("multiple? " + isMultiple);
const autocomplete = (
<Autocomplete
id={fieldName}

View File

@ -366,14 +366,24 @@ function ProcessRun({process, table, defaultProcessValues, isModal, isWidget, is
// 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. //
// they also need to know the 'otherValues' in this process - e.g., for filtering //
////////////////////////////////////////////////////////////////////////////////////
if(formFields && processValues)
{
Object.keys(formFields).forEach((key) =>
{
if(formFields[key].possibleValueProps && processValues[key])
if(formFields[key].possibleValueProps)
{
formFields[key].possibleValueProps.initialDisplayValue = processValues[key]
if(processValues[key])
{
formFields[key].possibleValueProps.initialDisplayValue = processValues[key]
}
formFields[key].possibleValueProps.otherValues = formFields[key].possibleValueProps.otherValues ?? new Map<string, any>();
Object.keys(formFields).forEach((otherKey) =>
{
formFields[key].possibleValueProps.otherValues.set(otherKey, processValues[otherKey]);
});
}
})
}
@ -721,6 +731,35 @@ function ProcessRun({process, table, defaultProcessValues, isModal, isWidget, is
let formValidations: any = {};
let initialValues: any = {};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// define an inner function here, for adding more fields to the form, if any components have form fields built into them //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const addField = (fieldName: string, dynamicFormValue: any, initialValue: any, validation: any) =>
{
dynamicFormFields[fieldName] = dynamicFormValue;
initialValues[fieldName] = initialValue;
formValidations[fieldName] = validation;
};
if(tableMetaData)
{
console.log("Adding table name field... ?", tableMetaData.name);
addField("tableName", {type: "hidden", omitFromQDynamicForm: true}, tableMetaData.name, null);
}
if (doesStepHaveComponent(activeStep, QComponentType.VALIDATION_REVIEW_SCREEN))
{
addField("doFullValidation", {type: "radio"}, "true", null);
setOverrideOnLastStep(false);
}
if (doesStepHaveComponent(activeStep, QComponentType.GOOGLE_DRIVE_SELECT_FOLDER))
{
addField("googleDriveAccessToken", {type: "hidden", omitFromQDynamicForm: true}, "", null);
addField("googleDriveFolderId", {type: "hidden", omitFromQDynamicForm: true}, "", null);
addField("googleDriveFolderName", {type: "hidden", omitFromQDynamicForm: true}, "", null);
}
///////////////////////////////////////////////////
// if this step has form fields, set up the form //
///////////////////////////////////////////////////
@ -750,6 +789,21 @@ function ProcessRun({process, table, defaultProcessValues, isModal, isWidget, is
initialValues[field.name] = processValues[field.name];
});
////////////////////////////////////////////////////////////////////////////////////
// set initial values in the possible value fields as otherValues (for filtering) //
////////////////////////////////////////////////////////////////////////////////////
Object.keys(dynamicFormFields).forEach((key: any) =>
{
if(dynamicFormFields[key].possibleValueProps)
{
dynamicFormFields[key].possibleValueProps.otherValues = dynamicFormFields[key].possibleValueProps.otherValues ?? new Map<string, any>();
Object.keys(initialValues).forEach((ivKey: any) =>
{
dynamicFormFields[key].possibleValueProps.otherValues.set(ivKey, initialValues[ivKey]);
})
}
})
////////////////////////////////////////////////////
// disable all fields if this is a bulk edit form //
////////////////////////////////////////////////////
@ -766,35 +820,6 @@ function ProcessRun({process, table, defaultProcessValues, isModal, isWidget, is
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// define an inner function here, for adding more fields to the form, if any components have form fields built into them //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const addField = (fieldName: string, dynamicFormValue: any, initialValue: any, validation: any) =>
{
dynamicFormFields[fieldName] = dynamicFormValue;
initialValues[fieldName] = initialValue;
formValidations[fieldName] = validation;
};
if(tableMetaData)
{
console.log("Adding table name field... ?", tableMetaData.name);
addField("tableName", {type: "hidden", omitFromQDynamicForm: true}, tableMetaData.name, null);
}
if (doesStepHaveComponent(activeStep, QComponentType.VALIDATION_REVIEW_SCREEN))
{
addField("doFullValidation", {type: "radio"}, "true", null);
setOverrideOnLastStep(false);
}
if (doesStepHaveComponent(activeStep, QComponentType.GOOGLE_DRIVE_SELECT_FOLDER))
{
addField("googleDriveAccessToken", {type: "hidden", omitFromQDynamicForm: true}, "", null);
addField("googleDriveFolderId", {type: "hidden", omitFromQDynamicForm: true}, "", null);
addField("googleDriveFolderName", {type: "hidden", omitFromQDynamicForm: true}, "", null);
}
if (Object.keys(dynamicFormFields).length > 0)
{
///////////////////////////////////////////

View File

@ -1135,11 +1135,8 @@ function RecordQuery({table, launchProcess}: Props): JSX.Element
);
}
const runRecordScriptProcess = metaData?.processes.get("runRecordScript");
const pushDividerIfNeeded = (menuItems: JSX.Element[]) =>
{
console.log("Type: " + menuItems[menuItems.length - 1]);
if(menuItems.length > 0)
{
menuItems.push(<Divider />);

View File

@ -357,3 +357,13 @@ input[type="search"]::-webkit-search-results-decoration { display: none; }
color: rgb(123, 128, 154);
font-weight: 400;
}
.fullScreenWidget
{
position: fixed !important;
left: 30px !important;
width: calc(100vw - 60px) !important;
top: 30px !important;
height: calc(100vh - 60px) !important;
z-index: 1300 !important;
}