@openforis/arena-core 2.18.2 → 2.18.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { NodeValues, Nodes } from '../../node';
11
11
  import { NodeDefs } from '../../nodeDef';
12
12
  import { Surveys } from '../../survey';
13
- import { Dates } from '../../utils';
13
+ import { Arrays, Dates } from '../../utils';
14
14
  import { Records } from '../records';
15
15
  import { RecordUpdateResult } from './recordUpdateResult';
16
16
  // A dependent code attribute's stored item is still valid as long as its category item's parent is the
@@ -48,8 +48,9 @@ export const updateDependentCodeAttributes = (params) => __awaiter(void 0, void
48
48
  const { survey, record, node, categoryItemProvider, sideEffect = false } = params;
49
49
  const updateResult = new RecordUpdateResult({ record });
50
50
  const recordUpdateOptions = { sideEffect };
51
- // 1. get dependent code attributes
52
- const dependentCodeAttributes = Records.getDependentCodeAttributes(node)(record);
51
+ // 1. get dependent code attributes: only the direct ones (the index registers every ancestor code attribute);
52
+ // deeper levels are checked when the cleared direct dependents are visited
53
+ const dependentCodeAttributes = Records.getDependentCodeAttributes(node)(record).filter((dependentCodeAttribute) => Arrays.last(Nodes.getHierarchyCode(dependentCodeAttribute)) === node.uuid);
53
54
  if (dependentCodeAttributes.length === 0)
54
55
  return updateResult;
55
56
  const parentItemUuid = NodeValues.getItemUuid(node);
@@ -1 +1 @@
1
- {"version":3,"file":"recordNodeDependentsCodeAttributesUpdater.js","sourceRoot":"","sources":["../../../../src/record/recordNodesUpdater/recordNodeDependentsCodeAttributesUpdater.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAmB,UAAU,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAC/D,OAAO,EAAe,QAAQ,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,KAAK,EAAE,M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tD,YAAY,CAAC,iBAAiB,CAAC,WAAW,CAAC,WAAW,CAAC,CAAA;IACzD,CAAC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA","sourcesContent":["import { ArenaRecordNode, NodeValues, Nodes } from '../../node'\nimport { NodeDefCode, NodeDefs } from '../../nodeDef'\nimport { Surveys } from '../../survey'\nimport { Dates } from '../../utils'\nimport { Records } from '../records'\nimport type { ArenaRecord } from '../record'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\n// A dependent code attribute's stored item is still valid as long as its category item's parent is the\n// (possibly unchanged) item currently selected on the parent code attribute node - so this single check\n// covers both \"did the parent's value change\" and \"is the dependent's value still valid\": if the parent's\n// item didn't change, the dependent's item still has the same parent and is left alone.\n//\n// The dependent's item may belong to a \"big\" category whose items aren't loaded into the survey's\n// in-memory ref data index (e.g. an externally-referenced category) - Surveys.getCategoryItemByUuid only\n// ever looks there, so it falls back to the async categoryItemProvider (same pattern as attribute value\n// validation) before concluding the item doesn't exist.\nconst isDependentCodeAttributeValueStillValid = async (\n params: Pick<RecordNodeDependentsUpdateParams, 'survey' | 'categoryItemProvider'> & {\n parentItemUuid?: string\n dependentCodeAttribute: ArenaRecordNode\n dependentCodeAttributeDef: NodeDefCode\n record: ArenaRecord\n }\n): Promise<boolean> => {\n const { survey, parentItemUuid, dependentCodeAttribute, dependentCodeAttributeDef, record, categoryItemProvider } =\n params\n if (!parentItemUuid) return false\n\n const dependentItemUuid = NodeValues.getItemUuid(dependentCodeAttribute)\n if (!dependentItemUuid) return false\n\n let dependentItem = Surveys.getCategoryItemByUuid({ survey, itemUuid: dependentItemUuid })\n if (!dependentItem && categoryItemProvider) {\n const categoryUuid = NodeDefs.getCategoryUuid(dependentCodeAttributeDef)\n if (categoryUuid) {\n const draft = !!record.preview\n dependentItem = await categoryItemProvider.getItemByUuid({\n survey,\n categoryUuid,\n itemUuid: dependentItemUuid,\n draft,\n })\n }\n }\n return dependentItem?.parentUuid === parentItemUuid\n}\n\nexport const updateDependentCodeAttributes = async (params: RecordNodeDependentsUpdateParams) => {\n const { survey, record, node, categoryItemProvider, sideEffect = false } = params\n\n const updateResult = new RecordUpdateResult({ record })\n\n const recordUpdateOptions = { sideEffect }\n\n // 1. get dependent code attributes\n const dependentCodeAttributes = Records.getDependentCodeAttributes(node)(record)\n if (dependentCodeAttributes.length === 0) return updateResult\n\n const parentItemUuid = NodeValues.getItemUuid(node)\n\n // 2. clear dependent code attributes' values that are no longer valid children of the parent's current item\n for (const dependentCodeAttribute of dependentCodeAttributes) {\n const dependentCodeAttributeDef = Surveys.getNodeDefByUuid({\n survey,\n uuid: dependentCodeAttribute.nodeDefUuid,\n }) as NodeDefCode\n if (NodeDefs.isReadOnly(dependentCodeAttributeDef) || !Nodes.hasUserInputValue(dependentCodeAttribute)) continue\n\n const validityCheckParams = {\n survey,\n parentItemUuid,\n dependentCodeAttribute,\n dependentCodeAttributeDef,\n record,\n categoryItemProvider,\n }\n // check attributes sequentially: invalid values are cleared in the record at every iteration\n const stillValid = await isDependentCodeAttributeValueStillValid(validityCheckParams) // NOSONAR\n if (stillValid) continue\n\n const nodeUpdated: ArenaRecordNode = {\n ...dependentCodeAttribute,\n value: null,\n updated: true,\n dateModified: Dates.nowFormattedForStorage(),\n }\n updateResult.addNode(nodeUpdated, recordUpdateOptions)\n updateResult.addClearedDefUuid(nodeUpdated.nodeDefUuid)\n }\n\n return updateResult\n}\n"]}
1
+ {"version":3,"file":"recordNodeDependentsCodeAttributesUpdater.js","sourceRoot":"","sources":["../../../../src/record/recordNodesUpdater/recordNodeDependentsCodeAttributesUpdater.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAmB,UAAU,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAC/D,OAAO,EAAe,QAAQ,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC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AAQ;QAExB,MAAM,WAAW,mCACZ,sBAAsB,KACzB,KAAK,EAAE,IAAI,EACX,OAAO,EAAE,IAAI,EACb,YAAY,EAAE,KAAK,CAAC,sBAAsB,EAAE,GAC7C,CAAA;QACD,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,mBAAmB,CAAC,CAAA;QACtD,YAAY,CAAC,iBAAiB,CAAC,WAAW,CAAC,WAAW,CAAC,CAAA;IACzD,CAAC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA","sourcesContent":["import { ArenaRecordNode, NodeValues, Nodes } from '../../node'\nimport { NodeDefCode, NodeDefs } from '../../nodeDef'\nimport { Surveys } from '../../survey'\nimport { Arrays, Dates } from '../../utils'\nimport { Records } from '../records'\nimport type { ArenaRecord } from '../record'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\n// A dependent code attribute's stored item is still valid as long as its category item's parent is the\n// (possibly unchanged) item currently selected on the parent code attribute node - so this single check\n// covers both \"did the parent's value change\" and \"is the dependent's value still valid\": if the parent's\n// item didn't change, the dependent's item still has the same parent and is left alone.\n//\n// The dependent's item may belong to a \"big\" category whose items aren't loaded into the survey's\n// in-memory ref data index (e.g. an externally-referenced category) - Surveys.getCategoryItemByUuid only\n// ever looks there, so it falls back to the async categoryItemProvider (same pattern as attribute value\n// validation) before concluding the item doesn't exist.\nconst isDependentCodeAttributeValueStillValid = async (\n params: Pick<RecordNodeDependentsUpdateParams, 'survey' | 'categoryItemProvider'> & {\n parentItemUuid?: string\n dependentCodeAttribute: ArenaRecordNode\n dependentCodeAttributeDef: NodeDefCode\n record: ArenaRecord\n }\n): Promise<boolean> => {\n const { survey, parentItemUuid, dependentCodeAttribute, dependentCodeAttributeDef, record, categoryItemProvider } =\n params\n if (!parentItemUuid) return false\n\n const dependentItemUuid = NodeValues.getItemUuid(dependentCodeAttribute)\n if (!dependentItemUuid) return false\n\n let dependentItem = Surveys.getCategoryItemByUuid({ survey, itemUuid: dependentItemUuid })\n if (!dependentItem && categoryItemProvider) {\n const categoryUuid = NodeDefs.getCategoryUuid(dependentCodeAttributeDef)\n if (categoryUuid) {\n const draft = !!record.preview\n dependentItem = await categoryItemProvider.getItemByUuid({\n survey,\n categoryUuid,\n itemUuid: dependentItemUuid,\n draft,\n })\n }\n }\n return dependentItem?.parentUuid === parentItemUuid\n}\n\nexport const updateDependentCodeAttributes = async (params: RecordNodeDependentsUpdateParams) => {\n const { survey, record, node, categoryItemProvider, sideEffect = false } = params\n\n const updateResult = new RecordUpdateResult({ record })\n\n const recordUpdateOptions = { sideEffect }\n\n // 1. get dependent code attributes: only the direct ones (the index registers every ancestor code attribute);\n // deeper levels are checked when the cleared direct dependents are visited\n const dependentCodeAttributes = Records.getDependentCodeAttributes(node)(record).filter(\n (dependentCodeAttribute) => Arrays.last(Nodes.getHierarchyCode(dependentCodeAttribute)) === node.uuid\n )\n if (dependentCodeAttributes.length === 0) return updateResult\n\n const parentItemUuid = NodeValues.getItemUuid(node)\n\n // 2. clear dependent code attributes' values that are no longer valid children of the parent's current item\n for (const dependentCodeAttribute of dependentCodeAttributes) {\n const dependentCodeAttributeDef = Surveys.getNodeDefByUuid({\n survey,\n uuid: dependentCodeAttribute.nodeDefUuid,\n }) as NodeDefCode\n if (NodeDefs.isReadOnly(dependentCodeAttributeDef) || !Nodes.hasUserInputValue(dependentCodeAttribute)) continue\n\n const validityCheckParams = {\n survey,\n parentItemUuid,\n dependentCodeAttribute,\n dependentCodeAttributeDef,\n record,\n categoryItemProvider,\n }\n // check attributes sequentially: invalid values are cleared in the record at every iteration\n const stillValid = await isDependentCodeAttributeValueStillValid(validityCheckParams) // NOSONAR\n if (stillValid) continue\n\n const nodeUpdated: ArenaRecordNode = {\n ...dependentCodeAttribute,\n value: null,\n updated: true,\n dateModified: Dates.nowFormattedForStorage(),\n }\n updateResult.addNode(nodeUpdated, recordUpdateOptions)\n updateResult.addClearedDefUuid(nodeUpdated.nodeDefUuid)\n }\n\n return updateResult\n}\n"]}
@@ -51,8 +51,9 @@ const updateDependentCodeAttributes = (params) => __awaiter(void 0, void 0, void
51
51
  const { survey, record, node, categoryItemProvider, sideEffect = false } = params;
52
52
  const updateResult = new recordUpdateResult_1.RecordUpdateResult({ record });
53
53
  const recordUpdateOptions = { sideEffect };
54
- // 1. get dependent code attributes
55
- const dependentCodeAttributes = records_1.Records.getDependentCodeAttributes(node)(record);
54
+ // 1. get dependent code attributes: only the direct ones (the index registers every ancestor code attribute);
55
+ // deeper levels are checked when the cleared direct dependents are visited
56
+ const dependentCodeAttributes = records_1.Records.getDependentCodeAttributes(node)(record).filter((dependentCodeAttribute) => utils_1.Arrays.last(node_1.Nodes.getHierarchyCode(dependentCodeAttribute)) === node.uuid);
56
57
  if (dependentCodeAttributes.length === 0)
57
58
  return updateResult;
58
59
  const parentItemUuid = node_1.NodeValues.getItemUuid(node);
@@ -1 +1 @@
1
- {"version":3,"file":"recordNodeDependentsCodeAttributesUpdater.js","sourceRoot":"","sources":["../../../src/record/recordNodesUpdater/recordNodeDependentsCodeAttributesUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAA+D;AAC/D,2CAAqD;AACrD,yCAAsC;AACtC,uCAAmC;AACnC,wCAAoC;AAGpC,6DAAyD;AAEzD,uGAAuG;AACvG,wGAAwG;AACxG,0GAA0G;AAC1G,wFAAwF;AACxF,EAAE;AACF,kGAAkG;AAClG,yGAAyG;AACzG,wGAAwG;AACxG,wDAAwD;AACxD,MAAM,uCAAuC,GAAG,CAC9C,MAKC,EACiB,EAAE;IACpB,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,MAAM,EAAE,oBAAoB,EAAE,GAC/G,MAAM,CAAA;IACR,IAAI,CAAC,cAAc;QAAE,OAAO,KAAK,CAAA;IAEjC,MAAM,iBAAiB,GAAG,iBAAU,CAAC,WAAW,CAAC,sBAAsB,CAAC,CAAA;I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E,CAAC;QAC7D,MAAM,yBAAyB,GAAG,gBAAO,CAAC,gBAAgB,CAAC;YACzD,MAAM;YACN,IAAI,EAAE,sBAAsB,CAAC,WAAW;SACzC,CAAgB,CAAA;QACjB,IAAI,kBAAQ,CAAC,UAAU,CAAC,yBAAyB,CAAC,IAAI,CAAC,YAAK,CAAC,iBAAiB,CAAC,sBAAsB,CAAC;YAAE,SAAQ;QAEhH,MAAM,mBAAmB,GAAG;YAC1B,MAAM;YACN,cAAc;YACd,sBAAsB;YACtB,yBAAyB;YACzB,MAAM;YACN,oBAAoB;SACrB,CAAA;QACD,6FAA6F;QAC7F,MAAM,UAAU,GAAG,MAAM,uCAAuC,CAAC,mBAAmB,CAAC,CAAA,CAAC,UAAU;QAChG,IAAI,UAAU;YAAE,SAAQ;QAExB,MAAM,WAAW,mCACZ,sBAAsB,KACzB,KAAK,EAAE,IAAI,EACX,OAAO,EAAE,IAAI,EACb,YAAY,EAAE,aAAK,CAAC,sBAAsB,EAAE,GAC7C,CAAA;QACD,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,mBAAmB,CAAC,CAAA;QACtD,YAAY,CAAC,iBAAiB,CAAC,WAAW,CAAC,WAAW,CAAC,CAAA;IACzD,CAAC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA;AA5CY,QAAA,6BAA6B,GAA7B,6BAA6B,CA4CzC","sourcesContent":["import { ArenaRecordNode, NodeValues, Nodes } from '../../node'\nimport { NodeDefCode, NodeDefs } from '../../nodeDef'\nimport { Surveys } from '../../survey'\nimport { Dates } from '../../utils'\nimport { Records } from '../records'\nimport type { ArenaRecord } from '../record'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\n// A dependent code attribute's stored item is still valid as long as its category item's parent is the\n// (possibly unchanged) item currently selected on the parent code attribute node - so this single check\n// covers both \"did the parent's value change\" and \"is the dependent's value still valid\": if the parent's\n// item didn't change, the dependent's item still has the same parent and is left alone.\n//\n// The dependent's item may belong to a \"big\" category whose items aren't loaded into the survey's\n// in-memory ref data index (e.g. an externally-referenced category) - Surveys.getCategoryItemByUuid only\n// ever looks there, so it falls back to the async categoryItemProvider (same pattern as attribute value\n// validation) before concluding the item doesn't exist.\nconst isDependentCodeAttributeValueStillValid = async (\n params: Pick<RecordNodeDependentsUpdateParams, 'survey' | 'categoryItemProvider'> & {\n parentItemUuid?: string\n dependentCodeAttribute: ArenaRecordNode\n dependentCodeAttributeDef: NodeDefCode\n record: ArenaRecord\n }\n): Promise<boolean> => {\n const { survey, parentItemUuid, dependentCodeAttribute, dependentCodeAttributeDef, record, categoryItemProvider } =\n params\n if (!parentItemUuid) return false\n\n const dependentItemUuid = NodeValues.getItemUuid(dependentCodeAttribute)\n if (!dependentItemUuid) return false\n\n let dependentItem = Surveys.getCategoryItemByUuid({ survey, itemUuid: dependentItemUuid })\n if (!dependentItem && categoryItemProvider) {\n const categoryUuid = NodeDefs.getCategoryUuid(dependentCodeAttributeDef)\n if (categoryUuid) {\n const draft = !!record.preview\n dependentItem = await categoryItemProvider.getItemByUuid({\n survey,\n categoryUuid,\n itemUuid: dependentItemUuid,\n draft,\n })\n }\n }\n return dependentItem?.parentUuid === parentItemUuid\n}\n\nexport const updateDependentCodeAttributes = async (params: RecordNodeDependentsUpdateParams) => {\n const { survey, record, node, categoryItemProvider, sideEffect = false } = params\n\n const updateResult = new RecordUpdateResult({ record })\n\n const recordUpdateOptions = { sideEffect }\n\n // 1. get dependent code attributes\n const dependentCodeAttributes = Records.getDependentCodeAttributes(node)(record)\n if (dependentCodeAttributes.length === 0) return updateResult\n\n const parentItemUuid = NodeValues.getItemUuid(node)\n\n // 2. clear dependent code attributes' values that are no longer valid children of the parent's current item\n for (const dependentCodeAttribute of dependentCodeAttributes) {\n const dependentCodeAttributeDef = Surveys.getNodeDefByUuid({\n survey,\n uuid: dependentCodeAttribute.nodeDefUuid,\n }) as NodeDefCode\n if (NodeDefs.isReadOnly(dependentCodeAttributeDef) || !Nodes.hasUserInputValue(dependentCodeAttribute)) continue\n\n const validityCheckParams = {\n survey,\n parentItemUuid,\n dependentCodeAttribute,\n dependentCodeAttributeDef,\n record,\n categoryItemProvider,\n }\n // check attributes sequentially: invalid values are cleared in the record at every iteration\n const stillValid = await isDependentCodeAttributeValueStillValid(validityCheckParams) // NOSONAR\n if (stillValid) continue\n\n const nodeUpdated: ArenaRecordNode = {\n ...dependentCodeAttribute,\n value: null,\n updated: true,\n dateModified: Dates.nowFormattedForStorage(),\n }\n updateResult.addNode(nodeUpdated, recordUpdateOptions)\n updateResult.addClearedDefUuid(nodeUpdated.nodeDefUuid)\n }\n\n return updateResult\n}\n"]}
1
+ {"version":3,"file":"recordNodeDependentsCodeAttributesUpdater.js","sourceRoot":"","sources":["../../../src/record/recordNodesUpdater/recordNodeDependentsCodeAttributesUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAA+D;AAC/D,2CAAqD;AACrD,yCAAsC;AACtC,uCAA2C;AAC3C,wCAAoC;AAGpC,6DAAyD;AAEzD,uGAAuG;AACvG,wGAAwG;AACxG,0GAA0G;AAC1G,wFAAwF;AACxF,EAAE;AACF,kGAAkG;AAClG,yGAAyG;AACzG,wGAAwG;AACxG,wDAAwD;AACxD,MAAM,uCAAuC,GAAG,CAC9C,MAKC,EACiB,EAAE;IACpB,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,MAAM,EAAE,oBAAoB,EAAE,GAC/G,MAAM,CAAA;IACR,IAAI,CAAC,cAAc;QAAE,OAAO,KAAK,CAAA;IAEjC,MAAM,iBAAiB,GAAG,iBAAU,CAAC,WAAW,CAAC,sBAAsB,CAAC,CAAA;IACxE,IAAI,CAAC,iBAAiB;QAAE,OAAO,KAAK,CAAA;IAEpC,IAAI,aAAa,GAAG,gBAAO,CAAC,qBAAqB,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,iBAAiB,EAAE,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,IAAI,uBAAuB,EAAE,CAAC;QAC7D,MAAM,yBAAyB,GAAG,gBAAO,CAAC,gBAAgB,CAAC;YACzD,MAAM;YACN,IAAI,EAAE,sBAAsB,CAAC,WAAW;SACzC,CAAgB,CAAA;QACjB,IAAI,kBAAQ,CAAC,UAAU,CAAC,yBAAyB,CAAC,IAAI,CAAC,YAAK,CAAC,iBAAiB,CAAC,sBAAsB,CAAC;YAAE,SAAQ;QAEhH,MAAM,mBAAmB,GAAG;YAC1B,MAAM;YACN,cAAc;YACd,sBAAsB;YACtB,yBAAyB;YACzB,MAAM;YACN,oBAAoB;SACrB,CAAA;QACD,6FAA6F;QAC7F,MAAM,UAAU,GAAG,MAAM,uCAAuC,CAAC,mBAAmB,CAAC,CAAA,CAAC,UAAU;QAChG,IAAI,UAAU;YAAE,SAAQ;QAExB,MAAM,WAAW,mCACZ,sBAAsB,KACzB,KAAK,EAAE,IAAI,EACX,OAAO,EAAE,IAAI,EACb,YAAY,EAAE,aAAK,CAAC,sBAAsB,EAAE,GAC7C,CAAA;QACD,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,mBAAmB,CAAC,CAAA;QACtD,YAAY,CAAC,iBAAiB,CAAC,WAAW,CAAC,WAAW,CAAC,CAAA;IACzD,CAAC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA;AA/CY,QAAA,6BAA6B,GAA7B,6BAA6B,CA+CzC","sourcesContent":["import { ArenaRecordNode, NodeValues, Nodes } from '../../node'\nimport { NodeDefCode, NodeDefs } from '../../nodeDef'\nimport { Surveys } from '../../survey'\nimport { Arrays, Dates } from '../../utils'\nimport { Records } from '../records'\nimport type { ArenaRecord } from '../record'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\n// A dependent code attribute's stored item is still valid as long as its category item's parent is the\n// (possibly unchanged) item currently selected on the parent code attribute node - so this single check\n// covers both \"did the parent's value change\" and \"is the dependent's value still valid\": if the parent's\n// item didn't change, the dependent's item still has the same parent and is left alone.\n//\n// The dependent's item may belong to a \"big\" category whose items aren't loaded into the survey's\n// in-memory ref data index (e.g. an externally-referenced category) - Surveys.getCategoryItemByUuid only\n// ever looks there, so it falls back to the async categoryItemProvider (same pattern as attribute value\n// validation) before concluding the item doesn't exist.\nconst isDependentCodeAttributeValueStillValid = async (\n params: Pick<RecordNodeDependentsUpdateParams, 'survey' | 'categoryItemProvider'> & {\n parentItemUuid?: string\n dependentCodeAttribute: ArenaRecordNode\n dependentCodeAttributeDef: NodeDefCode\n record: ArenaRecord\n }\n): Promise<boolean> => {\n const { survey, parentItemUuid, dependentCodeAttribute, dependentCodeAttributeDef, record, categoryItemProvider } =\n params\n if (!parentItemUuid) return false\n\n const dependentItemUuid = NodeValues.getItemUuid(dependentCodeAttribute)\n if (!dependentItemUuid) return false\n\n let dependentItem = Surveys.getCategoryItemByUuid({ survey, itemUuid: dependentItemUuid })\n if (!dependentItem && categoryItemProvider) {\n const categoryUuid = NodeDefs.getCategoryUuid(dependentCodeAttributeDef)\n if (categoryUuid) {\n const draft = !!record.preview\n dependentItem = await categoryItemProvider.getItemByUuid({\n survey,\n categoryUuid,\n itemUuid: dependentItemUuid,\n draft,\n })\n }\n }\n return dependentItem?.parentUuid === parentItemUuid\n}\n\nexport const updateDependentCodeAttributes = async (params: RecordNodeDependentsUpdateParams) => {\n const { survey, record, node, categoryItemProvider, sideEffect = false } = params\n\n const updateResult = new RecordUpdateResult({ record })\n\n const recordUpdateOptions = { sideEffect }\n\n // 1. get dependent code attributes: only the direct ones (the index registers every ancestor code attribute);\n // deeper levels are checked when the cleared direct dependents are visited\n const dependentCodeAttributes = Records.getDependentCodeAttributes(node)(record).filter(\n (dependentCodeAttribute) => Arrays.last(Nodes.getHierarchyCode(dependentCodeAttribute)) === node.uuid\n )\n if (dependentCodeAttributes.length === 0) return updateResult\n\n const parentItemUuid = NodeValues.getItemUuid(node)\n\n // 2. clear dependent code attributes' values that are no longer valid children of the parent's current item\n for (const dependentCodeAttribute of dependentCodeAttributes) {\n const dependentCodeAttributeDef = Surveys.getNodeDefByUuid({\n survey,\n uuid: dependentCodeAttribute.nodeDefUuid,\n }) as NodeDefCode\n if (NodeDefs.isReadOnly(dependentCodeAttributeDef) || !Nodes.hasUserInputValue(dependentCodeAttribute)) continue\n\n const validityCheckParams = {\n survey,\n parentItemUuid,\n dependentCodeAttribute,\n dependentCodeAttributeDef,\n record,\n categoryItemProvider,\n }\n // check attributes sequentially: invalid values are cleared in the record at every iteration\n const stillValid = await isDependentCodeAttributeValueStillValid(validityCheckParams) // NOSONAR\n if (stillValid) continue\n\n const nodeUpdated: ArenaRecordNode = {\n ...dependentCodeAttribute,\n value: null,\n updated: true,\n dateModified: Dates.nowFormattedForStorage(),\n }\n updateResult.addNode(nodeUpdated, recordUpdateOptions)\n updateResult.addClearedDefUuid(nodeUpdated.nodeDefUuid)\n }\n\n return updateResult\n}\n"]}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "OpenForis",
5
5
  "email": "openforis.arena@gmail.com"
6
6
  },
7
- "version": "2.18.2",
7
+ "version": "2.18.3",
8
8
  "description": "Arena core module",
9
9
  "repository": {
10
10
  "type": "git",