-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Subblocks #26
Comments
ApproachAs per the underlying Flux philosophy, the All data in the store is in the form of Immutable.js Maps which means that we need to use the API that the Map interface exposes in order to efficiently query and mutate the data. To this end, there are 3 main methods using which data is mutated - The API for these functions looks like this - Map.setIn([.. array of indices], value)
Map.updateIn([... array of indices], (value) => newValue)
Map.deleteIn([... array of indices]) In order to construct these getQuestionIndex(questionId, block) {
return block.get('questions').findIndex(q => q.get('id') === questionId);
}, ChallengeThe challenge now is to rewrite these helpers (& and its calling functions) making no such assumptions of the structure i.e. blocks, questions & options can be nested arbitrarily. Ideally, the signatures of these functions can be like so - /**
* Returns an array of indices that can be directly go in first arguments to Immutable deep persistent functions.
* @param blockId - id of the block who's index is required
* @param parentBlock (optional) - The parent block at which to begin the search. If left out, the search starts from the top of the survey
*/
function getBlockIndex(blockId, parentBlock = 'top') {
// recursively build the array
} These functions can then be used like so - // when adding a new block
let newSurvey = survey.updateIn(this.getBlockIndex(blockId), list =>
list.splice(0, 0, newBlock)
);
// when deleting a block
let newSurvey = survey.deleteIn(this.getBlockIndex(blockId));
// when toggling params
let newSurvey = survey.updateIn(this.getBlockIndex(blockId), b =>
b.set(toggleName, !b.get(toggleName))
); Similar functions for Questions & Options can be written which expose the same API. TodoList of tasks required to complete this feature
|
@etosch - The last part pending in this feature is the ability to allow items to be dragged and dropped on subblocks. I wanted to quickly clarify on what all kinds of interactions should I work on. I have started with an example below -
A counter example might be that |
|
Schemata - https://github.com/SurveyMan/Schemata/blob/gh-pages/survey_block.json. Subblocks can be nested arbitrarily.
The text was updated successfully, but these errors were encountered: