Skip to content
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 addChild option templates #3559

Merged
merged 3 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "UNLICENSED",
"private": false,
"devDependencies": {
"@betty-blocks/cli": "^25.100.0",
"@betty-blocks/cli": "^25.102.0",
"@commitlint/cli": "^16.1.0",
"@commitlint/config-angular": "^16.0.0",
"@semantic-release/changelog": "^6.0.1",
Expand Down Expand Up @@ -57,7 +57,7 @@
"dist"
],
"dependencies": {
"@betty-blocks/component-sdk": "^1.86.0",
"@betty-blocks/component-sdk": "^1.86.1",
"@date-io/date-fns": "^1.3.13",
"@material-ui/core": "^4.9.11",
"@material-ui/icons": "^4.11.2",
Expand Down
10 changes: 4 additions & 6 deletions src/prefabs/structures/ActionJSForm/children.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,18 @@ import {
dateTimePickerOptions,
fileUploadOptions,
multiAutocompleteOptions,
priceInputOptions,
radioInputOptions,
ratingInputOptions,
richTextOptions,
selectInputOptions,
textAreaOptions,
textInputOptions,
} from '..';

export const inputTypes = [
TextInput({ label: 'Text field', options: { ...textInputOptions } }),
SelectInput({ label: 'Select', options: { ...selectInputOptions } }),
PriceInput({ label: 'Price', options: { ...priceInputOptions } }),
TextArea({ label: 'Textarea', options: { ...textAreaOptions } }),
TextInput({ label: 'Text field' }),
SelectInput({ label: 'Select' }),
PriceInput({ label: 'Price' }),
TextArea({ label: 'Textarea' }),
];

const defaultOptions = {
Expand Down
2 changes: 2 additions & 0 deletions src/prefabs/structures/Configuration.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import {
OptionCategory,
OptionProducer,
OptionTemplates,
PrefabComponentStyle,
} from '@betty-blocks/component-sdk';

export interface Configuration {
options?: Record<string, OptionProducer>;
optionTemplates?: OptionTemplates;
adornmentIcon?: string;
label?: string;
inputLabel?: string;
Expand Down
15 changes: 14 additions & 1 deletion src/prefabs/structures/PriceInput/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { updateOption } from '../../../utils';
import { TextInput } from '../TextInput';
import { options } from './options';
import { Configuration } from '../Configuration';
import { addChildOptions } from './options/addChild';

export const PriceInput = (
config: Configuration,
Expand All @@ -13,5 +14,17 @@ export const PriceInput = (
value: 'start',
});

return TextInput({ ...config, options, label }, descendants);
return TextInput(
{
...config,
options,
label,
optionTemplates: {
addChild: {
options: addChildOptions,
},
},
},
descendants,
);
};
41 changes: 41 additions & 0 deletions src/prefabs/structures/PriceInput/options/addChild.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {
buttongroup,
CreateActionInputVariableKind,
option,
optionTemplateOptions,
property,
showIf,
} from '@betty-blocks/component-sdk';

export const addChildOptions = optionTemplateOptions({
propertyBased: buttongroup(
'Type',
[
['Property-based', 'true'],
['Non-property-based', 'false'],
],
{ value: 'true' },
),
actionVariableId: option('ACTION_JS_VARIABLE', {
label: 'Action input variable',
value: '',
configuration: {
condition: showIf('propertyBased', 'EQ', 'false'),
createActionInputVariable: {
type: CreateActionInputVariableKind.NUMBER,
},
},
}),

property: property('Property', {
value: '',
showInReconfigure: true,
configuration: {
allowedKinds: ['INTEGER', 'PRICE', 'PRICE_EXPRESSION'],
condition: showIf('propertyBased', 'EQ', 'true'),
createActionInputVariable: {
type: CreateActionInputVariableKind.NUMBER,
},
},
}),
});
32 changes: 3 additions & 29 deletions src/prefabs/structures/PriceInput/options/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
buttongroup,
CreateActionInputVariableKind,
hideIf,
option,
property,
showIf,
Expand All @@ -18,45 +17,20 @@ const styles = { ...defaultStyles };
delete (<PartialBy<typeof styles, 'adornmentIcon'>>styles).adornmentIcon;

export const options = {
propertyBased: buttongroup(
'Type',
[
['Property-based', 'true'],
['Non-property-based', 'false'],
],
{
value: 'true',
showInAddChild: true,
configuration: {
showOnDrop: true,
},
},
),

actionVariableId: option('ACTION_JS_VARIABLE', {
label: 'Action input variable',
value: '',
showInAddChild: true,
configuration: {
condition: showIf('propertyBased', 'EQ', 'false'),
showOnDrop: true,
createActionInputVariable: {
type: CreateActionInputVariableKind.NUMBER,
},
condition: showIf('property', 'EQ', ''),
},
}),

property: property('Property', {
value: '',
showInAddChild: true,
configuration: {
allowedKinds: ['INTEGER', 'PRICE', 'PRICE_EXPRESSION'],
disabled: true,
condition: showIf('propertyBased', 'EQ', 'true'),
showOnDrop: true,
createActionInputVariable: {
type: CreateActionInputVariableKind.NUMBER,
},
condition: hideIf('property', 'EQ', ''),
},
}),

Expand Down
14 changes: 13 additions & 1 deletion src/prefabs/structures/SelectInput/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { component, PrefabReference } from '@betty-blocks/component-sdk';
import { Configuration } from '../Configuration';
import { options as defaults } from './options/index';
import { updateOption } from '../../../utils';
import { addChildOptions } from './options/addChild';

export const SelectInput = (
config: Configuration,
Expand Down Expand Up @@ -47,7 +48,18 @@ export const SelectInput = (

return component(
'SelectInput',
{ options, style, ref, label, optionCategories: categories },
{
options,
style,
ref,
label,
optionCategories: categories,
optionTemplates: {
addChild: {
options: addChildOptions,
},
},
},
children,
);
};
44 changes: 44 additions & 0 deletions src/prefabs/structures/SelectInput/options/addChild.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {
buttongroup,
CreateActionInputVariableKind,
option,
optionTemplateOptions,
property,
showIf,
} from '@betty-blocks/component-sdk';

export const addChildOptions = optionTemplateOptions({
propertyBased: buttongroup(
'Type',
[
['Property-based', 'true'],
['Non-property-based', 'false'],
],
{
value: 'true',
},
),

actionVariableId: option('ACTION_JS_VARIABLE', {
label: 'Action input variable',
value: '',
configuration: {
condition: showIf('propertyBased', 'EQ', 'false'),
createActionInputVariable: {
type: CreateActionInputVariableKind.NUMBER,
},
},
}),

property: property('Property', {
value: '',
configuration: {
allowedKinds: ['LIST', 'BELONGS_TO'],
allowRelations: true,
condition: showIf('propertyBased', 'EQ', 'true'),
createActionInputVariable: {
type: CreateActionInputVariableKind.NUMBER,
},
},
}),
});
31 changes: 2 additions & 29 deletions src/prefabs/structures/SelectInput/options/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
buttongroup,
CreateActionInputVariableKind,
filter,
hideIf,
modelAndRelation,
Expand All @@ -15,47 +14,21 @@ import { validation } from './validation';
import { styles } from './styles';

export const options = {
propertyBased: buttongroup(
'Type',
[
['Property-based', 'true'],
['Non-property-based', 'false'],
],
{
value: 'true',
showInAddChild: true,
configuration: {
showOnDrop: true,
},
},
),

actionVariableId: option('ACTION_JS_VARIABLE', {
label: 'Action input variable',
value: '',
showInAddChild: true,
configuration: {
condition: showIf('propertyBased', 'EQ', 'false'),
createActionInputVariable: {
type: CreateActionInputVariableKind.NUMBER,
},
showOnDrop: true,
condition: showIf('property', 'EQ', ''),
},
}),

property: property('Property', {
value: '',
showInReconfigure: true,
showInAddChild: true,
configuration: {
allowedKinds: ['LIST', 'BELONGS_TO'],
allowRelations: true,
disabled: true,
condition: showIf('propertyBased', 'EQ', 'true'),
showOnDrop: true,
createActionInputVariable: {
type: CreateActionInputVariableKind.NUMBER,
},
condition: hideIf('property', 'EQ', ''),
},
}),

Expand Down
33 changes: 3 additions & 30 deletions src/prefabs/structures/TextArea/options/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
buttongroup,
CreateActionInputVariableKind,
hideIf,
option,
property,
showIf,
Expand All @@ -13,46 +12,20 @@ import { styles } from '../../TextInput/options/styles';
import { validation } from '../../TextInput/options/validation';

export const options = {
propertyBased: buttongroup(
'Type',
[
['Property-based', 'true'],
['Non-property-based', 'false'],
],
{
value: 'true',
showInAddChild: true,
configuration: {
showOnDrop: true,
},
},
),

actionVariableId: option('ACTION_JS_VARIABLE', {
label: 'Action input variable',
value: '',
showInAddChild: true,
configuration: {
condition: showIf('propertyBased', 'EQ', 'false'),
createActionInputVariable: {
type: CreateActionInputVariableKind.TEXT,
},
showOnDrop: true,
condition: showIf('property', 'EQ', ''),
},
}),

property: property('Property', {
value: '',
showInAddChild: true,
showInReconfigure: true,
configuration: {
allowedKinds: ['TEXT', 'URL', 'IBAN', 'STRING'],
disabled: true,
condition: showIf('propertyBased', 'EQ', 'true'),
showOnDrop: true,
createActionInputVariable: {
type: CreateActionInputVariableKind.TEXT,
},
condition: hideIf('property', 'EQ', ''),
},
}),

Expand Down
Loading
Loading