Skip to content

useRuleContainer() ​

WARNING

Experimental since 6.7.16.0: the APIs can change without a deprecation, so do not ship on them yet. Give us feedback.

ts
import { useRuleContainer } from 'shopware:composables';

function useRuleContainer(options: {
    condition: () => RuleConditionNode;
    level: () => number;
    disabled: () => boolean;
    onAddPlaceholder: () => void;
}): {
    conditionDataProviderService: ComputedRef<unknown>;
    childAssociationField: ComputedRef<string>;
    createCondition: (conditionData: unknown, parentId: string | null, position: number) => RuleConditionNode;
    insertNodeIntoTree: (parentCondition: RuleConditionNode, childToInsert: RuleConditionNode) => void;
    removeNodeFromTree: (parentCondition: RuleConditionNode, childToRemove: RuleConditionNode) => void;
    containerRowClass: ComputedRef<ContainerRowClass>;
    nextPosition: ComputedRef<number>;
};

The state a condition container inside sw-condition-tree works against - what you need when building a custom container for the rule builder.

The tree provides the condition service and the three tree-editing functions; the composable injects them and adds containerRowClass, which alternates the background by nesting level and carries the disabled state.

onAddPlaceholder is called when the container runs out of children, which is how a container keeps an empty row for the next condition.

conditionDataProviderService and childAssociationField stay refs here. The Options API unwrapped them on the instance proxy, so a migrated template that used them without .value needs one.

Replaces the ruleContainer mixin.

Was this page helpful?
UnsatisfiedSatisfied
Be the first to vote!
0.0 / 5  (0 votes)