diff --git a/packages/app-builder/src/models/scenario-iteration-rule.ts b/packages/app-builder/src/models/scenario-iteration-rule.ts index b0e62ca94..5c7565744 100644 --- a/packages/app-builder/src/models/scenario-iteration-rule.ts +++ b/packages/app-builder/src/models/scenario-iteration-rule.ts @@ -12,7 +12,7 @@ export interface ScenarioIterationRule { displayOrder: number; name: string; description: string; - ruleGroup: string | null; + ruleGroup: string; formula: AstNode | null; scoreModifier: number; createdAt: string; @@ -27,7 +27,7 @@ export function adaptScenarioIterationRule( displayOrder: dto.displayOrder, name: dto.name, description: dto.description, - ruleGroup: null, + ruleGroup: dto.rule_group, formula: dto.formula_ast_expression ? adaptAstNode(dto.formula_ast_expression) : null, @@ -41,6 +41,7 @@ export interface CreateScenarioIterationRuleInput { displayOrder: number; name: string; description: string; + ruleGroup: string; formula: AstNode | null; scoreModifier: number; } @@ -53,6 +54,7 @@ export function adaptCreateScenarioIterationRuleBodyDto( displayOrder: input.displayOrder, name: input.name, description: input.description, + rule_group: input.ruleGroup, formula_ast_expression: input.formula ? adaptNodeDto(input.formula) : null, scoreModifier: input.scoreModifier, }; @@ -63,6 +65,7 @@ export interface UpdateScenarioIterationRuleInput { displayOrder?: number; name?: string; description?: string; + ruleGroup?: string; formula?: AstNode | null; scoreModifier?: number; } @@ -74,6 +77,7 @@ export function adaptUpdateScenarioIterationRuleBodyDto( displayOrder: input.displayOrder, name: input.name, description: input.description, + rule_group: input.ruleGroup, formula_ast_expression: input.formula ? adaptNodeDto(input.formula) : input.formula, diff --git a/packages/app-builder/src/routes/_builder+/scenarios+/$scenarioId+/i+/$iterationId+/_edit-view+/rules.tsx b/packages/app-builder/src/routes/_builder+/scenarios+/$scenarioId+/i+/$iterationId+/_edit-view+/rules.tsx index c7d46ab0b..9f0c4c8c7 100644 --- a/packages/app-builder/src/routes/_builder+/scenarios+/$scenarioId+/i+/$iterationId+/_edit-view+/rules.tsx +++ b/packages/app-builder/src/routes/_builder+/scenarios+/$scenarioId+/i+/$iterationId+/_edit-view+/rules.tsx @@ -59,7 +59,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) { const ruleGroups = R.pipe( rules, R.map((rule) => rule.ruleGroup), - R.filter(R.isNonNullish), + R.filter((val) => !R.isEmpty(val)), R.unique(), ); diff --git a/packages/app-builder/src/routes/_builder+/scenarios+/$scenarioId+/i+/$iterationId+/rules.$ruleId.tsx b/packages/app-builder/src/routes/_builder+/scenarios+/$scenarioId+/i+/$iterationId+/rules.$ruleId.tsx index 8a9e96de8..8f3440050 100644 --- a/packages/app-builder/src/routes/_builder+/scenarios+/$scenarioId+/i+/$iterationId+/rules.$ruleId.tsx +++ b/packages/app-builder/src/routes/_builder+/scenarios+/$scenarioId+/i+/$iterationId+/rules.$ruleId.tsx @@ -109,7 +109,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) { const editRuleFormSchema = z.object({ name: z.string().min(1), description: z.string(), - ruleGroup: z.string().nullable(), + ruleGroup: z.string(), scoreModifier: z.coerce.number().int().min(-1000).max(1000), }); type EditRuleFormValues = z.infer; @@ -150,6 +150,7 @@ export async function action({ request, params }: ActionFunctionArgs) { formula: astNode, name: formValues.name, description: formValues.description, + ruleGroup: formValues.ruleGroup, scoreModifier: formValues.scoreModifier, }); @@ -539,17 +540,9 @@ function RuleGroup({ field: ControllerRenderProps; }) { const { t } = useTranslation(handle.i18n); - const value = field.value ?? ''; - const searchValue = React.useDeferredValue(value); + const searchValue = React.useDeferredValue(field.value); const ruleGroups = useRuleGroups(); - const onChange = React.useCallback( - (value: string) => { - field.onChange(value || null); - }, - [field], - ); - const matches = React.useMemo( () => matchSorter(ruleGroups, searchValue), [searchValue, ruleGroups], @@ -558,10 +551,10 @@ function RuleGroup({ return ( }> diff --git a/packages/app-builder/src/routes/ressources+/scenarios+/$scenarioId+/$iterationId+/rules+/create.tsx b/packages/app-builder/src/routes/ressources+/scenarios+/$scenarioId+/$iterationId+/rules+/create.tsx index e16259190..60cabf0a3 100644 --- a/packages/app-builder/src/routes/ressources+/scenarios+/$scenarioId+/$iterationId+/rules+/create.tsx +++ b/packages/app-builder/src/routes/ressources+/scenarios+/$scenarioId+/$iterationId+/rules+/create.tsx @@ -31,6 +31,7 @@ export async function action({ request, params }: ActionFunctionArgs) { formula: null, name: t('create_rule.default_name'), description: '', + ruleGroup: '', scoreModifier: 0, }); diff --git a/packages/app-builder/src/services/editor/current-scenario-iteration.tsx b/packages/app-builder/src/services/editor/current-scenario-iteration.tsx index 1bc7fb347..5c882977f 100644 --- a/packages/app-builder/src/services/editor/current-scenario-iteration.tsx +++ b/packages/app-builder/src/services/editor/current-scenario-iteration.tsx @@ -34,7 +34,7 @@ export const useRuleGroups = () => { R.pipe( rules, R.map((rule) => rule.ruleGroup), - R.filter(R.isNonNullish), + R.filter((val) => !R.isEmpty(val)), R.unique(), ), [rules], diff --git a/packages/marble-api/scripts/openapi.yaml b/packages/marble-api/scripts/openapi.yaml index 197914ed2..d642c8f00 100644 --- a/packages/marble-api/scripts/openapi.yaml +++ b/packages/marble-api/scripts/openapi.yaml @@ -4368,15 +4368,6 @@ components: type: string ScenarioIterationRuleDto: type: object - required: - - id - - scenarioIterationId - - displayOrder - - name - - description - - formula_ast_expression - - scoreModifier - - createdAt properties: id: type: string @@ -4390,6 +4381,8 @@ components: type: string description: type: string + rule_group: + type: string formula_ast_expression: nullable: true oneOf: @@ -4399,6 +4392,16 @@ components: createdAt: type: string format: date-time + required: + - id + - scenarioIterationId + - displayOrder + - name + - description + - rule_group + - formula_ast_expression + - scoreModifier + - createdAt ScenarioValidationDto: type: object required: @@ -4452,13 +4455,6 @@ components: $ref: '#/components/schemas/ScenarioValidationErrorDto' CreateScenarioIterationRuleBodyDto: type: object - required: - - scenarioIterationId - - displayOrder - - name - - description - - formula_ast_expression - - scoreModifier properties: scenarioIterationId: type: string @@ -4469,12 +4465,22 @@ components: type: string description: type: string + rule_group: + type: string formula_ast_expression: nullable: true oneOf: - $ref: '#/components/schemas/NodeDto' scoreModifier: type: integer + required: + - scenarioIterationId + - displayOrder + - name + - description + - rule_group + - formula_ast_expression + - scoreModifier UpdateScenarioIterationRuleBodyDto: type: object properties: @@ -4484,6 +4490,8 @@ components: type: string description: type: string + rule_group: + type: string formula_ast_expression: nullable: true oneOf: diff --git a/packages/marble-api/src/generated/marble-api.ts b/packages/marble-api/src/generated/marble-api.ts index e1ca74a40..340085b2f 100644 --- a/packages/marble-api/src/generated/marble-api.ts +++ b/packages/marble-api/src/generated/marble-api.ts @@ -322,6 +322,7 @@ export type CreateScenarioIterationRuleBodyDto = { displayOrder: number; name: string; description: string; + rule_group: string; formula_ast_expression: (NodeDto) | null; scoreModifier: number; }; @@ -340,6 +341,7 @@ export type ScenarioIterationRuleDto = { displayOrder: number; name: string; description: string; + rule_group: string; formula_ast_expression: (NodeDto) | null; scoreModifier: number; createdAt: string; @@ -388,6 +390,7 @@ export type UpdateScenarioIterationRuleBodyDto = { displayOrder?: number; name?: string; description?: string; + rule_group?: string; formula_ast_expression?: (NodeDto) | null; scoreModifier?: number; };