From 56f7c7f297d23d00b1345351ce5ef58c5a9744b9 Mon Sep 17 00:00:00 2001 From: Chris Anderson Date: Sat, 28 Dec 2024 16:00:51 -0600 Subject: [PATCH] Adds new inverse rule operators Fixes user name list issue --- apps/platform/src/lists/ListService.ts | 2 +- apps/platform/src/rules/Rule.ts | 2 +- apps/platform/src/rules/StringRule.ts | 4 ++++ apps/ui/src/types.ts | 2 +- apps/ui/src/views/users/RuleBuilder.tsx | 2 ++ 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/platform/src/lists/ListService.ts b/apps/platform/src/lists/ListService.ts index b435c4d7..03436148 100644 --- a/apps/platform/src/lists/ListService.ts +++ b/apps/platform/src/lists/ListService.ts @@ -84,7 +84,7 @@ export const getListUsers = async (id: number, params: PageParams, projectId: nu .where('list_id', id) .select('users.*', 'user_list.created_at', 'user_list.id', 'user_list.user_id'), App.main.db, - (item) => ({ ...item, id: item.user_id }) as any, + (item) => User.fromJson({ ...item, id: item.user_id }) as any, ) } diff --git a/apps/platform/src/rules/Rule.ts b/apps/platform/src/rules/Rule.ts index a759a342..bf351daa 100644 --- a/apps/platform/src/rules/Rule.ts +++ b/apps/platform/src/rules/Rule.ts @@ -1,6 +1,6 @@ import Model, { ModelParams } from '../core/Model' -export type Operator = '=' | '!=' | '<' |'<=' | '>' | '>=' | '=' | 'is set' | 'is not set' | 'or' | 'and' | 'xor' | 'empty' | 'contains' | 'starts with' | 'ends with' | 'any' | 'none' +export type Operator = '=' | '!=' | '<' |'<=' | '>' | '>=' | '=' | 'is set' | 'is not set' | 'or' | 'and' | 'xor' | 'empty' | 'contains' | 'not contain' | 'starts with' | 'not start with' | 'ends with' | 'any' | 'none' export type RuleType = 'wrapper' | 'string' | 'number' | 'boolean' | 'date' | 'array' export type RuleGroup = 'user' | 'event' | 'parent' diff --git a/apps/platform/src/rules/StringRule.ts b/apps/platform/src/rules/StringRule.ts index bac4e069..b956f71c 100644 --- a/apps/platform/src/rules/StringRule.ts +++ b/apps/platform/src/rules/StringRule.ts @@ -33,10 +33,14 @@ export default { return v !== ruleValue case 'starts with': return v?.startsWith(ruleValue) + case 'not start with': + return !v?.startsWith(ruleValue) case 'ends with': return v?.endsWith(ruleValue) case 'contains': return v?.includes(ruleValue) + case 'not contain': + return !v?.includes(ruleValue) default: throw new RuleEvalException(rule, 'unknown operator: ' + rule.operator) } diff --git a/apps/ui/src/types.ts b/apps/ui/src/types.ts index c2d43440..4d605322 100644 --- a/apps/ui/src/types.ts +++ b/apps/ui/src/types.ts @@ -43,7 +43,7 @@ export interface OAuthResponse { refresh_expires_at: Date } -export type Operator = '=' | '!=' | '<' | '<=' | '>' | '>=' | '=' | 'is set' | 'is not set' | 'or' | 'and' | 'xor' | 'empty' | 'contains' | 'starts with' | 'any' | 'none' +export type Operator = '=' | '!=' | '<' | '<=' | '>' | '>=' | '=' | 'is set' | 'is not set' | 'or' | 'and' | 'xor' | 'empty' | 'contains' | 'not contain' | 'starts with' | 'not start with' | 'any' | 'none' export type RuleType = 'wrapper' | 'string' | 'number' | 'boolean' | 'date' | 'array' export type RuleGroup = 'user' | 'event' | 'parent' diff --git a/apps/ui/src/views/users/RuleBuilder.tsx b/apps/ui/src/views/users/RuleBuilder.tsx index 6d6d975a..a4db92e5 100644 --- a/apps/ui/src/views/users/RuleBuilder.tsx +++ b/apps/ui/src/views/users/RuleBuilder.tsx @@ -64,7 +64,9 @@ const operatorTypes: Record = { ...baseOperators, { key: 'empty', label: 'is empty' }, { key: 'contains', label: 'contains' }, + { key: 'not contain', label: 'does not contain' }, { key: 'starts with', label: 'starts with' }, + { key: 'not start with', label: 'does not start with' }, ], number: [ ...baseOperators,