/** * * The purpose of this function is to apply the show_when rules defined in the form specification to the * form payload (formData), and remove any data that should not be shown according to those rules. * (the reason this data exists in the payload is that users can answer a question in such a way that * other questions are 'shown' to them, which are then complete. The user can then go back and change the original * question to then 'hide' those questions, but the answers they gave persist in the payload. The must be cleansed * before being submitted. * * There are 2 types of payload data that have to be treated differently by this function for it to work. * * 1. Data from non-repeating pages, containing components. * * Each data item captured will be written to the payload as a field with the name of the fieldId of the payload. * In the case of components that are nested within 'container' components, the payload will reflect the nesting. * There is no limit to the level of nesting in a form. * * To cleanse the payload for this type of data, we do the following (high level description, see method comments for detail): * * - build a map of all components, keyed by their payload path (required for the next step) * - for all of these components that have dependencies (show_when rules), create a graph datastructure to show all components * on which a component is dependent, and then all components that those components may be dependent on. There is no limit to * the depth of these chained dependencies. * - the reason for building a graph of these dependency chains is so we know the sequence in which we must resolve the dependencies. * For any given chain of dependencies it is essential that we resolve the dependencies starting at the end of the chains, and work our way * back up the chain. If not, we could be resolving a dependency based on a payload item that itself will later be deleted. * Therefore, the final step is to recursively traverse the dependency graph, resolving the dependency rule for the components in * the chain from the leaf back up to the parent node. * * 2. Page collection data * * A page collection is a set of one or more pages which (as a group) can be filled in as many times is required * by the user. For example, in EAB, you can add as many item-seal-details to an EAB form as are required. An item-seal-detail * is made up of several different pages, all grouped. The data saved will be an array representing the whole collection, with * each object in the array representing a single collection entry (a single item-seal-detail in this example). * * Cleanse collection data has to be driven from the payload rather than the form, as there are repeated objects in an array * representing the data. Each one has to be treated independently as the data to be cleansed can be different in each one. * * - For each collection type, iterate through each payload object and treat it like an independent payload.. * - For each collection payload object, iterate through the collection's pages and components, and apply all the show_when rules * found at both page and component level to the payload. * - Repeat for each payload object * - Repeat for all collections * * @param {*} form * @param {*} formData * @returns {*} cleansed form data */ declare const clearOutUncompletedRoutes: (cleanseHiddenData: any, form: any, formData: any) => any; export default clearOutUncompletedRoutes;