Fixes issues #7884

* Introduced a 'exclude' option in the 'Field' to exclude it from the
change completely. Use the option 'exclude' to add field
'notNullColumns', which will be excluded from the data, but - can be
used to force rerender the 'Not Null Columns' select control on
change of it.

* Fixed the linter issue

* Rerender the cell as well, when dependent changes values. (#7884)

* Listen for the depenent changes even for the non-visible controls

* Use 'useRef' on every rendering to avoid the React 'Something wrong' page
pull/7937/head
Ashesh Vashi 2024-09-16 17:55:43 +05:30 committed by GitHub
parent 92dd13e72a
commit 315d1a40a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 27 additions and 13 deletions

View File

@ -70,7 +70,8 @@ export default function DataGridView({
);
}, [refreshKey]);
listenDepChanges(accessPath, field, options.visible, schemaState);
// We won't refresh the whole grid on dependent changes.
listenDepChanges(accessPath, field, schemaState);
if (!features.current) {
features.current = new FeatureSet();

View File

@ -39,8 +39,13 @@ export function getMappedCell({field}) {
);
let value = useFieldValue(colAccessPath, schemaState, subscriberManager);
let rowValue = useFieldValue(rowAccessPath, schemaState);
const rerenderCellOnDepChange = (...args) => {
subscriberManager.current?.signal(...args);
};
listenDepChanges(colAccessPath, field, true, schemaState);
listenDepChanges(
colAccessPath, field, schemaState, rerenderCellOnDepChange
);
if (!field.id) {
console.error(`No id set for the field: ${field}`);
@ -93,9 +98,13 @@ export function getMappedCell({field}) {
props.cell = 'unknown';
}
const memDeps = [
...flatternObject(colOptions), value, row.index,
field?.deps?.map((dep) => rowValue[dep])
];
return useMemo(
() => <MappedCellControl {...props}/>,
[...flatternObject(colOptions), value, row.index]
() => <MappedCellControl {...props}/>, memDeps
);
};

View File

@ -36,7 +36,9 @@ export default function FieldSetView({
const label = field.label;
listenDepChanges(accessPath, field, options.visible, schemaState);
listenDepChanges(
accessPath, field, schemaState, () => subscriberManager.current?.signal()
);
const fieldGroups = useMemo(
() => createFieldControls({

View File

@ -133,7 +133,9 @@ export default function FormView({
}
}, [isOnScreen]);
listenDepChanges(accessPath, field, visible, schemaState);
listenDepChanges(
accessPath, field, schemaState, () => subscriberManager.current?.signal()
);
// Upon reset, set the tab to first.
useEffect(() => {

View File

@ -28,8 +28,9 @@ export default function InlineView({
const { visible } =
accessPath ? useFieldOptions(accessPath, schemaState) : { visible: true };
// We won't rerender the InlineView on changes of the dependencies.
if (!accessPath || isPropertyMode)
listenDepChanges(accessPath, field, visible, schemaState);
listenDepChanges(accessPath, field, schemaState);
// Check whether form is kept hidden by visible prop.
// We don't support inline-view in 'property' mode

View File

@ -363,8 +363,7 @@ export const MappedFormControl = ({
};
const depVals = listenDepChanges(
accessPath, field, options.visible, schemaState, state,
avoidRenderingWhenNotMounted
accessPath, field, schemaState, avoidRenderingWhenNotMounted
);
let newProps = {

View File

@ -14,7 +14,7 @@ import { evalFunc } from 'sources/utils';
export const listenDepChanges = (
accessPath, field, visible, schemaState, data, setRefreshKey
accessPath, field, schemaState, setRefreshKey
) => {
const deps = field?.deps ? (evalFunc(null, field.deps) || []) : null;
const parentPath = accessPath ? [...accessPath] : [];
@ -25,7 +25,7 @@ export const listenDepChanges = (
}
useEffect(() => {
if (!visible || !schemaState || !field) return;
if (!schemaState || !field) return;
if(field.depChange || field.deferredDepChange) {
schemaState.addDepListener(

View File

@ -188,12 +188,12 @@ export default function MacrosDialog({onClose, onSave}) {
value: m.id,
}));
const schema = React.useRef(null);
if(keyOptions.length <= 0) {
return <></>;
}
const schema = React.useRef(null);
if (!schema.current)
schema.current = new MacrosSchema(keyOptions);