-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
871 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import unset from 'lodash/unset'; | ||
import { | ||
ProcessorScope, | ||
ProcessorContext, | ||
ProcessorInfo, | ||
ProcessorFnSync | ||
} from "types"; | ||
|
||
type ClearHiddenScope = ProcessorScope & { | ||
clearHidden: { | ||
[path: string]: boolean; | ||
} | ||
} | ||
|
||
/** | ||
* This processor function checks components for the `hidden` property and unsets corresponding data | ||
*/ | ||
export const clearHiddenProcess: ProcessorFnSync<ClearHiddenScope> = (context) => { | ||
const { component, data, path, value, scope } = context; | ||
if (!scope.clearHidden) { | ||
scope.clearHidden = {}; | ||
} | ||
if (component.hidden && value !== undefined && (!component.hasOwnProperty('clearOnHide') || component.clearOnHide)) { | ||
unset(data, path); | ||
scope.clearHidden[path] = true; | ||
} | ||
} | ||
|
||
export const clearHiddenProcessInfo: ProcessorInfo<ProcessorContext<ClearHiddenScope>, void> = { | ||
name: 'clearHidden', | ||
shouldProcess: () => true, | ||
processSync: clearHiddenProcess, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,54 @@ | ||
import { expect } from 'chai'; | ||
import { process } from '../../process' | ||
import { processSync } from '../../process' | ||
import { conditionProcessInfo } from '../index'; | ||
import { ConditionsScope, ProcessContext } from 'types'; | ||
|
||
const processForm = async (form: any, submission: any) => { | ||
const processForm = (form: any, submission: any) => { | ||
const context: ProcessContext<ConditionsScope> = { | ||
processors: [conditionProcessInfo], | ||
components: form.components, | ||
data: submission.data, | ||
scope: {} | ||
}; | ||
await process(context); | ||
processSync(context); | ||
return context; | ||
}; | ||
|
||
describe('Condition processor', () => { | ||
it('Perform conditional data with "clearOnHide" enabled.', async () => { | ||
it('Should modify component\'s "hidden" property when conditionally visible is false', async () => { | ||
const form = { | ||
components: [ | ||
{ | ||
type: 'number', | ||
type: 'textfield', | ||
key: 'a', | ||
input: true | ||
}, | ||
{ | ||
type: 'number', | ||
type: 'textfield', | ||
key: 'b', | ||
input: true | ||
input: true, | ||
conditional: { | ||
show: false, | ||
conjunction: 'all', | ||
conditions: [ | ||
{ | ||
component: 'a', | ||
operator: 'isEmpty' | ||
} | ||
] | ||
}, | ||
} | ||
] | ||
}; | ||
|
||
const submission = { | ||
data: { | ||
a: 1, | ||
b: 2 | ||
a: '', | ||
} | ||
}; | ||
|
||
const context: ProcessContext<ConditionsScope> = await processForm(form, submission); | ||
console.log(context); | ||
|
||
const context: ProcessContext<ConditionsScope> = processForm(form, submission); | ||
expect(context.components[1]).to.haveOwnProperty('hidden'); | ||
expect(context.components[1].hidden).to.be.true; | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.