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

fix(dashboard): step conditions allow duplicating max 10 rules or groups #7602

Merged
merged 3 commits into from
Jan 29, 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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMemo } from 'react';
import { type Field, QueryBuilder, RuleGroupType } from 'react-querybuilder';
import { type Field, QueryBuilder, RuleGroupType, Translations } from 'react-querybuilder';
import 'react-querybuilder/dist/query-builder.css';

import { LiquidVariable } from '@/utils/parseStepVariablesToLiquidVariables';
Expand All @@ -23,7 +23,7 @@ const controlClassnames = {
rule: ruleClassName,
};

const translations = {
const translations: Partial<Translations> = {
addRule: {
label: 'Add condition',
title: 'Add condition',
Expand Down Expand Up @@ -69,6 +69,7 @@ function InternalConditionsEditor({
onQueryChange={onQueryChange}
controlClassnames={controlClassnames}
translations={translations}
accessibleDescriptionGenerator={() => ''}
/>
);
}
Expand Down
33 changes: 23 additions & 10 deletions apps/dashboard/src/components/conditions-editor/rule-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import { useConditionsEditorContext } from './conditions-editor-context';
import { CompactButton } from '@/components/primitives/button-compact';
import { Delete } from '@/components/icons/delete';
import { SquareTwoStack } from '@/components/icons/square-two-stack';
import { Tooltip, TooltipContent, TooltipPortal, TooltipTrigger } from '@/components/primitives/tooltip';

export const RuleActions = React.memo(
({ path, ruleOrGroup }: ActionWithRulesProps) => {
const { removeRuleOrGroup, cloneRuleOrGroup, getParentGroup } = useConditionsEditorContext();
const parentGroup = useMemo(() => getParentGroup(ruleOrGroup.id), [ruleOrGroup.id, getParentGroup]);
const parentGroup = useMemo(() => getParentGroup(ruleOrGroup.id), [ruleOrGroup, getParentGroup]);
const isGroup = isRuleGroup(ruleOrGroup);
const isDuplicateDisabled = !!(parentGroup && parentGroup.rules && parentGroup.rules.length >= 10);

Expand All @@ -34,15 +35,27 @@ export const RuleActions = React.memo(
</DropdownMenuTrigger>
<DropdownMenuContent side="bottom" align="end" withPortal={false}>
<DropdownMenuGroup className="*:cursor-pointer">
<DropdownMenuItem
onClick={() => {
cloneRuleOrGroup(ruleOrGroup, getParentPath(path));
}}
className="text-foreground-600 text-label-xs h-7"
disabled={isDuplicateDisabled}
>
<SquareTwoStack className="[&&]:size-3.5" /> Duplicate {isGroup ? `group` : `condition`}
</DropdownMenuItem>
<Tooltip>
<TooltipTrigger>
<DropdownMenuItem
onClick={() => {
cloneRuleOrGroup(ruleOrGroup, getParentPath(path));
}}
className="text-foreground-600 text-label-xs h-7"
disabled={isDuplicateDisabled}
>
<SquareTwoStack className="[&&]:size-3.5" /> Duplicate {isGroup ? `group` : `condition`}
</DropdownMenuItem>
</TooltipTrigger>
<TooltipPortal>
{isDuplicateDisabled && (
<TooltipContent className="max-w-52">
You cannot duplicate more than 10 groups or conditions
</TooltipContent>
)}
</TooltipPortal>
</Tooltip>

<DropdownMenuItem onClick={() => removeRuleOrGroup(path)} className="text-error-base text-label-xs h-7">
<Delete className="[&&]:size-3.5" />
Delete {isGroup ? `group` : `condition`}
Expand Down
Loading