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

Adds new inverse rule operators #594

Merged
merged 1 commit into from
Dec 28, 2024
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
2 changes: 1 addition & 1 deletion apps/platform/src/lists/ListService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}

Expand Down
2 changes: 1 addition & 1 deletion apps/platform/src/rules/Rule.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
4 changes: 4 additions & 0 deletions apps/platform/src/rules/StringRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion apps/ui/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
2 changes: 2 additions & 0 deletions apps/ui/src/views/users/RuleBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ const operatorTypes: Record<RuleType, OperatorOption[]> = {
...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,
Expand Down
Loading