123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- import { ComparisonOperator } from './types'
- import { VarType } from '@/app/components/workflow/types'
- import type { Branch } from '@/app/components/workflow/types'
- export const isEmptyRelatedOperator = (operator: ComparisonOperator) => {
- return [ComparisonOperator.empty, ComparisonOperator.notEmpty, ComparisonOperator.isNull, ComparisonOperator.isNotNull, ComparisonOperator.exists, ComparisonOperator.notExists].includes(operator)
- }
- const notTranslateKey = [
- ComparisonOperator.equal, ComparisonOperator.notEqual,
- ComparisonOperator.largerThan, ComparisonOperator.largerThanOrEqual,
- ComparisonOperator.lessThan, ComparisonOperator.lessThanOrEqual,
- ]
- export const isComparisonOperatorNeedTranslate = (operator?: ComparisonOperator) => {
- if (!operator)
- return false
- return !notTranslateKey.includes(operator)
- }
- export const getOperators = (type?: VarType, file?: { key: string }) => {
- const isFile = !!file
- if (isFile) {
- const { key } = file
- switch (key) {
- case 'name':
- return [
- ComparisonOperator.contains,
- ComparisonOperator.notContains,
- ComparisonOperator.startWith,
- ComparisonOperator.endWith,
- ComparisonOperator.is,
- ComparisonOperator.isNot,
- ComparisonOperator.empty,
- ComparisonOperator.notEmpty,
- ]
- case 'type':
- return [
- ComparisonOperator.in,
- ComparisonOperator.notIn,
- ]
- case 'size':
- return [
- ComparisonOperator.largerThan,
- ComparisonOperator.largerThanOrEqual,
- ComparisonOperator.lessThan,
- ComparisonOperator.lessThanOrEqual,
- ]
- case 'extension':
- return [
- ComparisonOperator.is,
- ComparisonOperator.isNot,
- ComparisonOperator.contains,
- ComparisonOperator.notContains,
- ]
- case 'mime_type':
- return [
- ComparisonOperator.contains,
- ComparisonOperator.notContains,
- ComparisonOperator.startWith,
- ComparisonOperator.endWith,
- ComparisonOperator.is,
- ComparisonOperator.isNot,
- ComparisonOperator.empty,
- ComparisonOperator.notEmpty,
- ]
- case 'transfer_method':
- return [
- ComparisonOperator.in,
- ComparisonOperator.notIn,
- ]
- case 'url':
- return [
- ComparisonOperator.contains,
- ComparisonOperator.notContains,
- ComparisonOperator.startWith,
- ComparisonOperator.endWith,
- ComparisonOperator.is,
- ComparisonOperator.isNot,
- ComparisonOperator.empty,
- ComparisonOperator.notEmpty,
- ]
- }
- return []
- }
- switch (type) {
- case VarType.string:
- return [
- ComparisonOperator.contains,
- ComparisonOperator.notContains,
- ComparisonOperator.startWith,
- ComparisonOperator.endWith,
- ComparisonOperator.is,
- ComparisonOperator.isNot,
- ComparisonOperator.empty,
- ComparisonOperator.notEmpty,
- ]
- case VarType.number:
- return [
- ComparisonOperator.equal,
- ComparisonOperator.notEqual,
- ComparisonOperator.largerThan,
- ComparisonOperator.lessThan,
- ComparisonOperator.largerThanOrEqual,
- ComparisonOperator.lessThanOrEqual,
- ComparisonOperator.empty,
- ComparisonOperator.notEmpty,
- ]
- case VarType.file:
- return [
- ComparisonOperator.exists,
- ComparisonOperator.notExists,
- ]
- case VarType.arrayString:
- case VarType.arrayNumber:
- return [
- ComparisonOperator.contains,
- ComparisonOperator.notContains,
- ComparisonOperator.empty,
- ComparisonOperator.notEmpty,
- ]
- case VarType.array:
- case VarType.arrayObject:
- return [
- ComparisonOperator.empty,
- ComparisonOperator.notEmpty,
- ]
- case VarType.arrayFile:
- return [
- ComparisonOperator.contains,
- ComparisonOperator.notContains,
- ComparisonOperator.allOf,
- ComparisonOperator.empty,
- ComparisonOperator.notEmpty,
- ]
- default:
- return [
- ComparisonOperator.is,
- ComparisonOperator.isNot,
- ComparisonOperator.empty,
- ComparisonOperator.notEmpty,
- ]
- }
- }
- export const comparisonOperatorNotRequireValue = (operator?: ComparisonOperator) => {
- if (!operator)
- return false
- return [ComparisonOperator.empty, ComparisonOperator.notEmpty, ComparisonOperator.isNull, ComparisonOperator.isNotNull, ComparisonOperator.exists, ComparisonOperator.notExists].includes(operator)
- }
- export const branchNameCorrect = (branches: Branch[]) => {
- const branchLength = branches.length
- if (branchLength < 2)
- throw new Error('if-else node branch number must than 2')
- if (branchLength === 2) {
- return branches.map((branch) => {
- return {
- ...branch,
- name: branch.id === 'false' ? 'ELSE' : 'IF',
- }
- })
- }
- return branches.map((branch, index) => {
- return {
- ...branch,
- name: branch.id === 'false' ? 'ELSE' : `CASE ${index + 1}`,
- }
- })
- }
|