-
Notifications
You must be signed in to change notification settings - Fork 8
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
feat: add row in action forms #1173
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b628f49
feat: add separator in action forms
b099557
fix: schema serialization
7ccb8f6
fix: default values
e50894e
test: add tests
17fc6d5
feat: add html block in action forms
35f0c42
feat: add row in action forms
786931c
fix: types
1953b49
fix: remove console
d958837
fix: watchChanges
e235b38
fix: merge main
31b8fee
fix: tests
ab8a371
test: add collection tests
79f503b
fix: example
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,133 @@ | ||
import { CardCustomizer } from '../typings'; | ||
|
||
export default (collection: CardCustomizer) => | ||
collection.addManyToOneRelation('customer', 'customer', { foreignKey: 'customer_id' }); | ||
collection | ||
.addManyToOneRelation('customer', 'customer', { foreignKey: 'customer_id' }) | ||
.addAction('create new card', { | ||
scope: 'Global', | ||
execute: (context, resultBuilder) => { | ||
return resultBuilder.success('ok', { | ||
html: `test<script type="text/javascript">alert("test")</script>`, | ||
}); | ||
}, | ||
form: [ | ||
{ | ||
type: 'Number', | ||
label: 'Customer', | ||
widget: 'Dropdown', | ||
search: 'dynamic', | ||
options: async (ctx, searchValue) => { | ||
const results = await ctx.dataSource.getCollection('customer').list( | ||
{ | ||
...(searchValue | ||
? { | ||
conditionTree: { | ||
aggregator: 'Or', | ||
conditions: [ | ||
{ field: 'name', operator: 'Contains', value: searchValue }, | ||
{ field: 'firstName', operator: 'Contains', value: searchValue }, | ||
], | ||
}, | ||
} | ||
: {}), | ||
}, | ||
['id'], | ||
); | ||
|
||
return results.map(({ id }) => id); | ||
}, | ||
}, | ||
{ | ||
type: 'String', | ||
label: 'Plan', | ||
widget: 'Dropdown', | ||
options: ['Base', 'Gold', 'Black'], | ||
}, | ||
{ | ||
type: 'Layout', | ||
component: 'HtmlBlock', | ||
content: ctx => { | ||
switch (ctx.formValues.Plan) { | ||
case 'Base': | ||
return `<h1>Should setup:</h1> | ||
<ul> | ||
<li>separator</li> | ||
<li>price</li> | ||
<li>max withdraw / max payment</li> | ||
</ul>`; | ||
case 'Gold': | ||
return `<h1>Should setup:</h1> | ||
<ul> | ||
<li>max payment / Systematic check (if max payment > 1000)</li> | ||
<li>discount / discount months</li> | ||
</ul>`; | ||
case 'Back': | ||
return `<h1>Should setup:</h1> | ||
<ul> | ||
<li>max withdraw</li> | ||
</ul>`; | ||
default: | ||
return `Select a card plan`; | ||
} | ||
}, | ||
}, | ||
{ | ||
type: 'Layout', | ||
component: 'Separator', | ||
if: ctx => ['Base'].includes(ctx.formValues.Plan), | ||
}, | ||
{ | ||
type: 'Number', | ||
label: 'price', | ||
defaultValue: 40, | ||
if: ctx => ['Base'].includes(ctx.formValues.Plan), | ||
}, | ||
{ | ||
type: 'Number', | ||
label: 'price', | ||
defaultValue: 80, | ||
if: ctx => ['Gold'].includes(ctx.formValues.Plan), | ||
}, | ||
{ type: 'Layout', component: 'Separator' }, | ||
{ type: 'Layout', component: 'HtmlBlock', content: '<h3>constraints:</h3>' }, | ||
{ | ||
type: 'Layout', | ||
component: 'Row', | ||
fields: [ | ||
{ | ||
type: 'Number', | ||
label: 'Max withdraw', | ||
if: ctx => ['Base', 'Black'].includes(ctx.formValues.Plan), | ||
}, | ||
{ | ||
type: 'Number', | ||
label: 'Max payment', | ||
if: ctx => ['Base', 'Gold'].includes(ctx.formValues.Plan), | ||
}, | ||
{ | ||
type: 'Boolean', | ||
label: 'Systematic check', | ||
if: ctx => | ||
['Base', 'Gold'].includes(ctx.formValues.Plan) && | ||
ctx.formValues['Max payment'] > 1000, | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'Layout', | ||
component: 'Row', | ||
fields: [ | ||
{ | ||
type: 'Number', | ||
label: 'Discount', | ||
if: ctx => ['Gold'].includes(ctx.formValues['display fields']), | ||
}, | ||
{ | ||
type: 'Number', | ||
label: 'Discount months', | ||
if: ctx => ['Gold'].includes(ctx.formValues['display fields']), | ||
}, | ||
], | ||
}, | ||
], | ||
}); |
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 |
---|---|---|
|
@@ -133,15 +133,6 @@ describe('SchemaGeneratorActions', () => { | |
value: null, | ||
watchChanges: false, | ||
}, | ||
{ | ||
type: 'Layout', | ||
component: 'Separator', | ||
}, | ||
{ | ||
type: 'Layout', | ||
component: 'HtmlBlock', | ||
content: 'some text content', | ||
}, | ||
Comment on lines
-136
to
-144
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👀 |
||
{ | ||
label: 'inclusive gender', | ||
description: 'Choose None, Male, Female or Both', | ||
|
@@ -313,9 +304,20 @@ describe('SchemaGeneratorActions', () => { | |
content: 'some text content', | ||
}, | ||
{ | ||
label: 'description', | ||
type: 'String', | ||
watchChanges: false, | ||
type: 'Layout', | ||
component: 'Row', | ||
fields: [ | ||
{ | ||
label: 'description', | ||
type: 'String', | ||
watchChanges: false, | ||
}, | ||
{ | ||
label: 'address', | ||
type: 'String', | ||
watchChanges: false, | ||
}, | ||
], | ||
}, | ||
], | ||
), | ||
|
@@ -327,7 +329,7 @@ describe('SchemaGeneratorActions', () => { | |
|
||
const schema = SchemaGeneratorActions.buildFieldsAndLayout(collection.dataSource, form); | ||
|
||
expect(schema.fields.length).toEqual(2); | ||
expect(schema.fields.length).toEqual(3); | ||
expect(schema.layout).toEqual([ | ||
{ | ||
component: 'input', | ||
|
@@ -336,8 +338,17 @@ describe('SchemaGeneratorActions', () => { | |
{ component: 'separator' }, | ||
{ component: 'htmlBlock', content: 'some text content' }, | ||
{ | ||
component: 'input', | ||
fieldId: 'description', | ||
component: 'row', | ||
fields: [ | ||
{ | ||
component: 'input', | ||
fieldId: 'description', | ||
}, | ||
{ | ||
component: 'input', | ||
fieldId: 'address', | ||
}, | ||
], | ||
}, | ||
]); | ||
}); | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😢 Mutating function parameters. 😬