Skip to content

Commit

Permalink
[Upd #101] Use traverse question from s-forms
Browse files Browse the repository at this point in the history
  • Loading branch information
LaChope committed Mar 23, 2024
1 parent 754442f commit edc1a91
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 37 deletions.
5 changes: 2 additions & 3 deletions src/components/record/Record.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import { processTypeaheadOptions } from "./TypeaheadAnswer";
import { EXTENSIONS } from "../../../config";
import { isAdmin } from "../../utils/SecurityUtils";
import PromiseTrackingMask from "../misc/PromiseTrackingMask";
import { dfsTraverseQuestionTree } from "../../utils/Utils.js";
import { Constants as SConstants } from "@kbss-cvut/s-forms";
import { Constants as SConstants, FormUtils } from "@kbss-cvut/s-forms";
import FormValidationDialog from "../FormValidationDialog.jsx";

class Record extends React.Component {
Expand Down Expand Up @@ -70,7 +69,7 @@ class Record extends React.Component {
}
};

dfsTraverseQuestionTree(this.getFormQuestionsData(), collectIfTriggered);
FormUtils.dfsTraverseQuestionTree(this.getFormQuestionsData(), collectIfTriggered);

return matchedQuestion;
};
Expand Down
34 changes: 0 additions & 34 deletions src/utils/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,37 +416,3 @@ export function sortToParams(sort) {
.filter((k) => sort[k] !== undefined)
.map((k) => `${sort[k]}${k}`);
}

/**
* Wraps passed object into new array if it is not array already.
* @param object_or_array An object or array.
* @returns {*} New array containing passed object or passed array.
*/
function asArray(object_or_array) {
if (!object_or_array) {
return [];
}
if (object_or_array.constructor === Array) {
return object_or_array;
}
return [object_or_array];
}

/**
* Traverse provided array of questions recursively by DFS algorithm
* and execute on each traversed question provided function.
* @param {Array<Object>} questions - The array of questions to be traversed.
* @param func - The function to be executed on each recursively traversed question.
*/
export function dfsTraverseQuestionTree(questions, func) {
function recursiveTraverse(question) {
func(question);
this.asArray(question[SConstants.HAS_SUBQUESTION]).forEach((q) => {
recursiveTraverse(q);
});
}

questions.forEach((q) => {
recursiveTraverse(q);
});
}

0 comments on commit edc1a91

Please sign in to comment.