Skip to content

Commit

Permalink
Merge branch 'next' into nv-3303-delay-with-filters-doesnt-filter-if-…
Browse files Browse the repository at this point in the history
…its-the-first-step
  • Loading branch information
ainouzgali authored Jan 18, 2024
2 parents e246c66 + 25a41e1 commit aa1e4d3
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 34 deletions.
34 changes: 34 additions & 0 deletions apps/web/cypress/tests/notification-editor/variants.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,40 @@ describe('Workflow Editor - Variants', function () {
cy.wait('@getWorkflow');
cy.getByTestId('variants-count').should('not.exist');
});

it('should not allow removing all conditions from a variant', function () {
createWorkflow('Test Removing All Conditions');

dragAndDrop('inApp');
editChannel('inApp');
fillEditorContent('inApp');
goBack();

showStepActions('inApp');
addVariantActionClick('inApp');
addConditions();

cy.getByTestId('notification-template-submit-btn').click();
cy.wait('@updateWorkflow');

cy.reload();
cy.wait('@getWorkflow');

// edit the variant condition
cy.getByTestId('editor-sidebar-edit-conditions').click();

// open conditions row menu
cy.getByTestId('conditions-row-btn').click();

// delete the condition
cy.contains('Delete').click();

// submit ("Apply conditions") should be disabled
cy.getByTestId('apply-conditions-btn').should('be.disabled').click({ force: true });

// tooltip should warn the user
cy.get('div[role="tooltip"]').contains('At least one condition is required');
});
});

describe('Variants List Errors', function () {
Expand Down
51 changes: 33 additions & 18 deletions apps/web/src/components/conditions/Conditions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ import { OnlineConditionRow } from './OnlineConditionRow';
import { DefaultGroupOperatorData, DefaultOperatorData } from './constants';
import { PreviousStepsConditionRow } from './PreviousStepsConditionRow';

export interface IConditionsComponentProps {
isOpened: boolean;
isReadonly?: boolean;
onClose: () => void;
updateConditions: (data: IConditions[]) => void;
conditions?: IConditions[];
name: string;
label?: string;
filterPartsList: IFilterTypeList[];
defaultFilter?: FilterPartTypeEnum;
shouldDisallowEmptyConditions?: boolean;
}

export function Conditions({
isOpened,
isReadonly = false,
Expand All @@ -36,17 +49,8 @@ export function Conditions({
label = '',
filterPartsList,
defaultFilter,
}: {
isOpened: boolean;
isReadonly?: boolean;
onClose: () => void;
updateConditions: (data: IConditions[]) => void;
conditions?: IConditions[];
name: string;
label?: string;
filterPartsList: IFilterTypeList[];
defaultFilter?: FilterPartTypeEnum;
}) {
shouldDisallowEmptyConditions,
}: IConditionsComponentProps) {
const { colorScheme } = useMantineTheme();

const {
Expand Down Expand Up @@ -95,9 +99,17 @@ export function Conditions({
remove(index);
}

/** Flag for determining if conditions are empty but expected not to be */
const hasDisallowedEmptyConditions = Boolean(
shouldDisallowEmptyConditions && getValues().conditions?.some(({ children }) => !children?.[0])
);

const isSubmitDisabled =
!isDirty || isReadonly || (conditions?.length === 0 && fields?.length === 0) || hasDisallowedEmptyConditions;

const onApplyConditions = async () => {
await trigger('conditions');
if (!errors.conditions) {
if (!errors.conditions && !isSubmitDisabled) {
updateConditions(getValues('conditions'));
onClose();
}
Expand All @@ -121,13 +133,16 @@ export function Conditions({
<Button variant="outline" onClick={onClose} data-test-id="conditions-form-cancel-btn">
Cancel
</Button>
<Tooltip position="top" error disabled={isValid} label={'Some conditions are missing values'}>
<Tooltip
position="top"
error
disabled={isValid && !hasDisallowedEmptyConditions}
label={
hasDisallowedEmptyConditions ? 'At least one condition is required' : 'Some conditions are missing values'
}
>
<div>
<Button
disabled={!isDirty || isReadonly || (conditions?.length === 0 && fields?.length === 0)}
onClick={onApplyConditions}
data-test-id="apply-conditions-btn"
>
<Button disabled={isSubmitDisabled} onClick={onApplyConditions} data-test-id="apply-conditions-btn">
Apply conditions
</Button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export const EditorSidebarHeaderActions = () => {
conditions={conditions}
filterPartsList={filterPartsList}
defaultFilter={FilterPartTypeEnum.PAYLOAD}
shouldDisallowEmptyConditions={isUnderVariantPath}
/>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ export const VariantItemCard = ({
conditions={conditions}
filterPartsList={filterPartsList}
defaultFilter={FilterPartTypeEnum.PAYLOAD}
shouldDisallowEmptyConditions
/>
)}
<DeleteConfirmModal
Expand Down
33 changes: 17 additions & 16 deletions libs/embed/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
FROM nikolaik/python-nodejs:python3.10-nodejs20-alpine

WORKDIR /usr/src/app

RUN npm install -g [email protected] --loglevel notice --force

COPY .npmrc .
COPY package.json .
USER 1000
WORKDIR /usr/src/app

COPY --chown=1000:1000 .npmrc .
COPY --chown=1000:1000 package.json .

COPY libs/testing ./libs/testing
COPY libs/dal ./libs/dal
COPY libs/shared ./libs/shared
COPY packages/client ./packages/client
COPY packages/node ./packages/node
COPY libs/embed ./libs/embed
COPY packages/notification-center ./packages/notification-center
COPY --chown=1000:1000 libs/testing ./libs/testing
COPY --chown=1000:1000 libs/dal ./libs/dal
COPY --chown=1000:1000 libs/shared ./libs/shared
COPY --chown=1000:1000 packages/client ./packages/client
COPY --chown=1000:1000 packages/node ./packages/node
COPY --chown=1000:1000 libs/embed ./libs/embed
COPY --chown=1000:1000 packages/notification-center ./packages/notification-center

COPY tsconfig.json .
COPY tsconfig.base.json .
COPY --chown=1000:1000 tsconfig.json .
COPY --chown=1000:1000 tsconfig.base.json .

COPY nx.json .
COPY pnpm-workspace.yaml .
COPY pnpm-lock.yaml .
COPY --chown=1000:1000 nx.json .
COPY --chown=1000:1000 pnpm-workspace.yaml .
COPY --chown=1000:1000 pnpm-lock.yaml .

RUN pnpm install --reporter=silent
RUN pnpm build
Expand Down

0 comments on commit aa1e4d3

Please sign in to comment.