@pega/cosmos-react-condition-builder 4.0.0-dev.6.1 → 4.0.0-dev.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/ConditionBuilder/AtomicCondition.d.ts +9 -3
- package/lib/components/ConditionBuilder/AtomicCondition.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/AtomicCondition.js +45 -10
- package/lib/components/ConditionBuilder/AtomicCondition.js.map +1 -1
- package/lib/components/ConditionBuilder/ConditionBuilder.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/ConditionBuilder.js +26 -3
- package/lib/components/ConditionBuilder/ConditionBuilder.js.map +1 -1
- package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts +2 -0
- package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/ConditionBuilder.types.js.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/DateFunctionMenu.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/DateFunctionMenu.js +9 -1
- package/lib/components/ConditionBuilder/RhsControls/DateFunctionMenu.js.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.js +14 -4
- package/lib/components/ConditionBuilder/RhsControls/RelativeDateMenu.js.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.js +9 -2
- package/lib/components/ConditionBuilder/RhsControls/TimePeriodInput.js.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/ValueSelector.d.ts +5 -3
- package/lib/components/ConditionBuilder/RhsControls/ValueSelector.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/ValueSelector.js +69 -18
- package/lib/components/ConditionBuilder/RhsControls/ValueSelector.js.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/index.d.ts +5 -3
- package/lib/components/ConditionBuilder/RhsControls/index.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/RhsControls/index.js +36 -9
- package/lib/components/ConditionBuilder/RhsControls/index.js.map +1 -1
- package/lib/components/ConditionBuilder/core/evaluator.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/core/evaluator.js +14 -2
- package/lib/components/ConditionBuilder/core/evaluator.js.map +1 -1
- package/lib/components/ConditionBuilder/core/formatter.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/core/formatter.js +21 -0
- package/lib/components/ConditionBuilder/core/formatter.js.map +1 -1
- package/lib/components/ConditionBuilder/core/transformer.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/core/transformer.js +1 -0
- package/lib/components/ConditionBuilder/core/transformer.js.map +1 -1
- package/lib/components/ConditionBuilder/core/types.d.ts +2 -2
- package/lib/components/ConditionBuilder/core/types.d.ts.map +1 -1
- package/lib/components/ConditionBuilder/core/types.js.map +1 -1
- package/lib/components/ConditionInput/ConditionInput.d.ts.map +1 -1
- package/lib/components/ConditionInput/ConditionInput.js +100 -51
- package/lib/components/ConditionInput/ConditionInput.js.map +1 -1
- package/lib/components/ConditionInput/ConditionInput.styles.d.ts +2 -2
- package/lib/components/ConditionInput/ConditionInput.styles.d.ts.map +1 -1
- package/lib/components/ConditionInput/ConditionInput.styles.js +4 -4
- package/lib/components/ConditionInput/ConditionInput.styles.js.map +1 -1
- package/lib/components/ConditionInput/ConditionInput.types.d.ts +3 -0
- package/lib/components/ConditionInput/ConditionInput.types.d.ts.map +1 -1
- package/lib/components/ConditionInput/ConditionInput.types.js.map +1 -1
- package/lib/components/ConditionInput/utils.d.ts +2 -0
- package/lib/components/ConditionInput/utils.d.ts.map +1 -1
- package/lib/components/ConditionInput/utils.js +23 -0
- package/lib/components/ConditionInput/utils.js.map +1 -1
- package/lib/components/PromotedFilters/PromotedFilters.d.ts.map +1 -1
- package/lib/components/PromotedFilters/PromotedFilters.js +9 -5
- package/lib/components/PromotedFilters/PromotedFilters.js.map +1 -1
- package/lib/components/PromotedFilters/PromotedFilters.types.d.ts +3 -1
- package/lib/components/PromotedFilters/PromotedFilters.types.d.ts.map +1 -1
- package/lib/components/PromotedFilters/PromotedFilters.types.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/formatter.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,mEAAmE;AACnE,OAAO,EACL,cAAc,EACd,OAAO,EACP,WAAW,EACX,WAAW,EAEZ,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qDAAqD,CAAC;AAExF,OAAO,EAAE,UAAU,EAAE,MAAM,6DAA6D,CAAC;AAIzF,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAGlC,MAAM,MAAM,GAAG,GAAG,CAAC;AACnB,MAAM,MAAM,GAAG,GAAG,CAAC;AAQnB,MAAM,UAAU,kBAAkB,CAChC,SAA+C,EAC/C,UAAsB,EACtB,QAAkB,EAClB,QAAiB;IAEjB,MAAM,cAAc,GAClB,UAAU,KAAK,SAAS;QACtB,CAAC,CAAC,6BAA6B,QAAQ,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;QACpE,CAAC,CAAC,qBAAqB,UAAU,CAAC,WAAW,EAAE,MAAM,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC;IAClF,OAAO,SAAS,CAAC,cAAuC,EAAE,CAAC,QAAQ,IAAI,CAAC,CAAC,EAAE;QACzE,KAAK,EAAE,QAAQ,IAAI,CAAC;KACrB,CAAC,CAAC;AACL,CAAC;AAED,SAAS,kBAAkB,CACzB,IAAe,EACf,QAAyB,EACzB,MAAc,EACd,SAA+C;IAE/C,QAAQ,IAAI,EAAE;QACZ,KAAK,WAAW;YACd,4EAA4E;YAC5E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CAAC;QAC1F,OAAO,IAAI,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;KACzC;IAED,IAAI,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE;QACxB,MAAM,WAAW,GAAG,mBAAmB,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;QAC9E,IAAI,WAAW,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;YAClE,8DAA8D;YAC9D,OAAO,OAAO,WAAW,EAAE,CAAC;SAC7B;QACD,OAAO,QAAQ,WAAW,GAAG,CAAC;KAC/B;IAED,OAAO,mBAAmB,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,2BAA2B;AACrG,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,SAAoB,EACpB,MAAe,EACf,SAA+C,EAC/C,OAAgC;IAEhC,yDAAyD;IACzD,IAAI,IAAI,GAAG,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IAEtE,2EAA2E;IAC3E,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QACpD,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;KAC1B;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["// cSpell:words LPAREN RPAREN\n// FIXME: TR (Several constructs in this file need to be localized)\nimport {\n formatDateTime,\n hasProp,\n isValidDate,\n parseToDate,\n TranslationPack\n} from '@pega/cosmos-react-core';\nimport { getFormattedValue } from '@pega/cosmos-react-core/lib/components/Number/utils';\nimport { TranslationFunction } from '@pega/cosmos-react-core/lib/i18n/translate';\nimport { getQuarter } from '@pega/cosmos-react-core/lib/components/DateTime/Input/utils';\n\nimport { Condition, LeafCondition, Field } from '../ConditionBuilder.types';\n\nimport { getItem } from './utils';\nimport { DatePart, FieldType, TimePeriod } from './types';\n\nconst LPAREN = '(';\nconst RPAREN = ')';\n\n/** Options object optionally passed to formatCondition method. */\ninterface ConditionFormatOptions {\n locale?: string;\n omitLhs?: boolean;\n}\n\nexport function formatRelativeDate(\n translate: TranslationFunction<TranslationPack>,\n timePeriod: TimePeriod,\n datePart: DatePart,\n interval?: number\n): string {\n const translationKey =\n timePeriod === 'CURRENT'\n ? `condition_builder_current_${datePart.toLowerCase().slice(0, -1)}`\n : `condition_builder_${timePeriod.toLowerCase()}_X_${datePart.toLowerCase()}`;\n return translate(translationKey as keyof TranslationPack, [interval ?? 0], {\n count: interval ?? 0\n });\n}\n\nfunction formatLiteralValue(\n type: FieldType,\n rhsValue: string | number,\n locale: string,\n translate: TranslationFunction<TranslationPack>\n): string {\n switch (type) {\n case 'TIME_ONLY':\n // For these cases, rhs.value is stored as # of milliseconds since day-start\n return (rhsValue || rhsValue === 0) && isValidDate(parseToDate(rhsValue))\n ? formatDateTime(parseToDate(rhsValue), {\n t: translate,\n locale,\n format: 'long',\n variant: 'time',\n timeZone: 'UTC'\n })\n : '';\n case 'DATE_ONLY':\n // For these cases, rhs.value is stored as # of milliseconds since day-start\n return (rhsValue || rhsValue === 0) && isValidDate(parseToDate(rhsValue))\n ? formatDateTime(parseToDate(rhsValue), {\n t: translate,\n locale,\n format: 'numeric',\n variant: 'date',\n timeZone: 'UTC'\n })\n : '';\n case 'DATE_TIME':\n // For these cases, rhs.value is stored as # of milliseconds since day-start\n return (rhsValue || rhsValue === 0) && isValidDate(parseToDate(rhsValue))\n ? formatDateTime(parseToDate(rhsValue), {\n t: translate,\n locale,\n format: 'numeric',\n variant: 'datetime',\n timeZone: 'UTC'\n })\n : '';\n case 'NUMBER':\n return getFormattedValue(rhsValue.toString(), locale, undefined, {\n useGrouping: true\n });\n break;\n default:\n return rhsValue.toString();\n }\n}\n\n/** Returns a user-friendly text representation of a given leaf condition */\nfunction formatLeafCondition(\n leaf: LeafCondition,\n fields: Field[],\n translate: TranslationFunction<TranslationPack>,\n { locale = 'en-US', omitLhs = false }: ConditionFormatOptions = {}\n): string {\n const { lhs, comparator, rhs } = leaf;\n\n // Determine texts for LHS and RHS\n const lhsField = getItem(fields, lhs.field) as Field; // Expecting valid inputs\n const lhsText = omitLhs ? '' : `${lhsField.primary} `;\n let rhsText = '';\n if (!hasProp(lhsField, 'type')) return '';\n if (rhs) {\n if (hasProp(rhs, 'field')) {\n // If RHS is another field\n const rhsField = getItem(fields, rhs.field) as Field; // Expecting valid inputs\n rhsText = rhsField.primary;\n } else if (hasProp(rhs, 'value')) {\n if (hasProp(rhs, 'dateFunction')) {\n // If RHS is a date function value\n switch (rhs.dateFunction) {\n case 'YEARS':\n rhsText = new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {\n year: 'numeric'\n });\n break;\n case 'QUARTERS': {\n const formattedYear = new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {\n year: 'numeric'\n });\n const quarterNumber = getQuarter(rhs.value);\n rhsText = `${translate(`date_quarter_q${quarterNumber}`, [formattedYear])}`;\n break;\n }\n case 'MONTHS':\n rhsText = new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {\n year: 'numeric',\n month: 'short'\n });\n break;\n case 'WEEKS':\n rhsText = `Week of ${new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {\n year: 'numeric',\n month: 'short',\n day: 'numeric'\n })}`;\n break;\n case 'DAYS':\n rhsText = new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {\n year: 'numeric',\n month: 'short',\n day: 'numeric'\n });\n break;\n case 'HOURS':\n rhsText = new Date(rhs.value).toLocaleString(locale, {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n hour: 'numeric',\n hour12: true\n });\n break;\n case 'MONTHS_OF_YEAR':\n rhsText = new Date(2021, (rhs.value as number) - 1, 1).toLocaleString(locale, {\n month: 'long'\n });\n break;\n case 'HOURS_OF_DAY':\n rhsText = `Hour ${rhs.value} of day`;\n break;\n case 'DAYS_OF_MONTH':\n rhsText = `Day ${rhs.value} of month`;\n break;\n case 'DAYS_OF_WEEK':\n // Choosing Feb-2021 as it starts on a Monday\n rhsText = new Date(2021, 1, rhs.value as number).toLocaleString(locale, {\n weekday: 'long'\n });\n break;\n default: // Not needed\n }\n } else {\n // If RHS is a single literal value\n rhsText = formatLiteralValue(lhsField.type, rhs.value, locale, translate);\n }\n } else if (hasProp(rhs, 'relativeDate')) {\n const {\n relativeDate: { timePeriod, interval, datePart }\n } = rhs;\n rhsText = formatRelativeDate(translate, timePeriod, datePart, interval);\n } else if (hasProp(rhs, 'parameterId')) {\n const parameterValue = lhsField.parameters?.find(item => item.id === rhs.parameterId);\n rhsText = parameterValue?.primary ?? '';\n } else if (hasProp(rhs, 'values')) {\n rhsText = rhs.values.join(', ');\n } else if (hasProp(rhs, 'start')) {\n const startValue = formatLiteralValue(lhsField.type, rhs.start, locale, translate);\n const endValue = formatLiteralValue(lhsField.type, rhs.end, locale, translate);\n\n rhsText = `${startValue} - ${endValue}`;\n }\n }\n\n switch (comparator) {\n case 'IS_NULL':\n return `${lhsText}is null`;\n case 'IS_NOT_NULL':\n return `${lhsText}is not null`;\n case 'IS_TRUE':\n return `${lhsText}is true`;\n case 'IS_FALSE':\n return `${lhsText}is false`;\n case 'EQ':\n return `${lhsText}is ${rhsText}`;\n case 'NEQ':\n return `${lhsText}isn't ${rhsText}`;\n case 'IN':\n return `${lhsText}is among ${rhsText}`;\n case 'NOT_IN':\n return `${lhsText}is not among ${rhsText}`;\n case 'GT':\n return `${lhsText}> ${rhsText}`;\n case 'GTE':\n return `${lhsText}>= ${rhsText}`;\n case 'LT':\n return `${lhsText}< ${rhsText}`;\n case 'LTE':\n return `${lhsText}<= ${rhsText}`;\n case 'BTW':\n return `${lhsText}is between ${rhsText}`;\n case 'NOT_BTW':\n return `${lhsText}is not between ${rhsText}`;\n case 'STARTS_WITH':\n return `${lhsText}starts with ${rhsText}`;\n case 'NOT_STARTS_WITH':\n return `${lhsText}doesn't start with ${rhsText}`;\n case 'ENDS_WITH':\n return `${lhsText}ends with ${rhsText}`;\n case 'NOT_ENDS_WITH':\n return `${lhsText}doesn't end with ${rhsText}`;\n case 'CONTAINS':\n return `${lhsText}contains ${rhsText}`;\n case 'NOT_CONTAINS':\n return `${lhsText}doesn't contain ${rhsText}`;\n default:\n return ''; // Not needed\n }\n}\n\n/** Returns a user-friendly text representation of the given node in a condition */\nfunction formatConditionNode(\n node: Condition,\n fields: Field[],\n translate: TranslationFunction<TranslationPack>,\n options?: ConditionFormatOptions\n): string {\n if (hasProp(node, 'AND')) {\n const childStrings = node.AND.map(n => formatConditionNode(n, fields, translate, options));\n return `(${childStrings.join(' AND ')})`;\n }\n\n if (hasProp(node, 'OR')) {\n const childStrings = node.OR.map(n => formatConditionNode(n, fields, translate, options));\n return `(${childStrings.join(' OR ')})`;\n }\n\n if (hasProp(node, 'NOT')) {\n const childString = formatConditionNode(node.NOT, fields, translate, options);\n if (childString.startsWith(LPAREN) && childString.endsWith(RPAREN)) {\n // Avoid double brackets when the child node is an AND/OR node\n return `NOT ${childString}`;\n }\n return `NOT (${childString})`;\n }\n\n return formatLeafCondition(node.condition, fields, translate, options); // If leaf-level is reached\n}\n\n/**\n * Returns a user-friendly text representation of a given complex condition\n * The input `fields` are used to look up display labels for the fields\n */\nexport default function formatCondition(\n condition: Condition,\n fields: Field[],\n translate: TranslationFunction<TranslationPack>,\n options?: ConditionFormatOptions\n): string {\n // Recursively format the tree, starting at the root node\n let text = formatConditionNode(condition, fields, translate, options);\n\n // If the root node is AND/OR, there will be extra parentheses. Remove them\n if (text.startsWith(LPAREN) && text.endsWith(RPAREN)) {\n text = text.slice(1, -1);\n }\n\n return text;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../../../src/components/Con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G,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;KAC1B;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["// cSpell:words LPAREN RPAREN\n// FIXME: TR (Several constructs in this file need to be localized)\nimport {\n formatDateTime,\n hasProp,\n isValidDate,\n parseToDate,\n TranslationPack\n} from '@pega/cosmos-react-core';\nimport { getFormattedValue } from '@pega/cosmos-react-core/lib/components/Number/utils';\nimport { TranslationFunction } from '@pega/cosmos-react-core/lib/i18n/translate';\nimport { getQuarter } from '@pega/cosmos-react-core/lib/components/DateTime/Input/utils';\n\nimport { Condition, LeafCondition, Field } from '../ConditionBuilder.types';\n\nimport { getItem } from './utils';\nimport { DatePart, FieldType, TimePeriod } from './types';\n\nconst LPAREN = '(';\nconst RPAREN = ')';\n\n/** Options object optionally passed to formatCondition method. */\ninterface ConditionFormatOptions {\n locale?: string;\n omitLhs?: boolean;\n}\n\nexport function formatRelativeDate(\n translate: TranslationFunction<TranslationPack>,\n timePeriod: TimePeriod,\n datePart: DatePart,\n interval?: number\n): string {\n const translationKey =\n timePeriod === 'CURRENT'\n ? `condition_builder_current_${datePart.toLowerCase().slice(0, -1)}`\n : `condition_builder_${timePeriod.toLowerCase()}_X_${datePart.toLowerCase()}`;\n return translate(translationKey as keyof TranslationPack, [interval ?? 0], {\n count: interval ?? 0\n });\n}\n\nfunction formatLiteralValue(\n type: FieldType,\n rhsValue: string | number,\n locale: string,\n translate: TranslationFunction<TranslationPack>\n): string {\n switch (type) {\n case 'TIME_ONLY':\n // For these cases, rhs.value is stored as # of milliseconds since day-start\n return (rhsValue || rhsValue === 0) && isValidDate(parseToDate(rhsValue))\n ? formatDateTime(parseToDate(rhsValue), {\n t: translate,\n locale,\n format: 'long',\n variant: 'time',\n timeZone: 'UTC'\n })\n : '';\n case 'DATE_ONLY':\n // For these cases, rhs.value is stored as # of milliseconds since day-start\n return (rhsValue || rhsValue === 0) && isValidDate(parseToDate(rhsValue))\n ? formatDateTime(parseToDate(rhsValue), {\n t: translate,\n locale,\n format: 'numeric',\n variant: 'date',\n timeZone: 'UTC'\n })\n : '';\n case 'DATE_TIME':\n // For these cases, rhs.value is stored as # of milliseconds since day-start\n return (rhsValue || rhsValue === 0) && isValidDate(parseToDate(rhsValue))\n ? formatDateTime(parseToDate(rhsValue), {\n t: translate,\n locale,\n format: 'numeric',\n variant: 'datetime',\n timeZone: 'UTC'\n })\n : '';\n case 'NUMBER':\n return getFormattedValue(rhsValue.toString(), locale, undefined, {\n useGrouping: true\n });\n break;\n default:\n return rhsValue.toString();\n }\n}\n\n/** Returns a user-friendly text representation of a given leaf condition */\nfunction formatLeafCondition(\n leaf: LeafCondition,\n fields: Field[],\n translate: TranslationFunction<TranslationPack>,\n { locale = 'en-US', omitLhs = false }: ConditionFormatOptions = {}\n): string {\n const { lhs, comparator, rhs } = leaf;\n\n // Determine texts for LHS and RHS\n const lhsField = getItem(fields, lhs.field) as Field; // Expecting valid inputs\n const lhsText = omitLhs ? '' : `${lhsField.primary} `;\n let rhsText = '';\n if (!hasProp(lhsField, 'type')) return '';\n if (rhs) {\n if (hasProp(rhs, 'field')) {\n // If RHS is another field\n const rhsField = getItem(fields, rhs.field) as Field; // Expecting valid inputs\n rhsText = rhsField.primary;\n } else if (hasProp(rhs, 'value')) {\n if (hasProp(rhs, 'dateFunction')) {\n // If RHS is a date function value\n switch (rhs.dateFunction) {\n case 'YEARS':\n rhsText = new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {\n year: 'numeric'\n });\n break;\n case 'QUARTERS': {\n const formattedYear = new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {\n year: 'numeric'\n });\n const quarterNumber = getQuarter(rhs.value);\n rhsText = `${translate(`date_quarter_q${quarterNumber}`, [formattedYear])}`;\n break;\n }\n case 'MONTHS':\n rhsText = new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {\n year: 'numeric',\n month: 'short'\n });\n break;\n case 'WEEKS':\n rhsText = `Week of ${new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {\n year: 'numeric',\n month: 'short',\n day: 'numeric'\n })}`;\n break;\n case 'DAYS':\n rhsText = new Date(`${rhs.value}T00:00:00`).toLocaleString(locale, {\n year: 'numeric',\n month: 'short',\n day: 'numeric'\n });\n break;\n case 'HOURS':\n rhsText = new Date(rhs.value).toLocaleString(locale, {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n hour: 'numeric',\n hour12: true\n });\n break;\n case 'MINUTES':\n rhsText = new Date(rhs.value).toLocaleString(locale, {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n hour: 'numeric',\n hour12: true,\n minute: 'numeric'\n });\n break;\n case 'SECONDS':\n rhsText = new Date(rhs.value).toLocaleString(locale, {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n hour: 'numeric',\n hour12: true,\n minute: 'numeric',\n second: 'numeric'\n });\n break;\n case 'MONTHS_OF_YEAR':\n rhsText = new Date(2021, (rhs.value as number) - 1, 1).toLocaleString(locale, {\n month: 'long'\n });\n break;\n case 'HOURS_OF_DAY':\n rhsText = `Hour ${rhs.value} of day`;\n break;\n case 'DAYS_OF_MONTH':\n rhsText = `Day ${rhs.value} of month`;\n break;\n case 'DAYS_OF_WEEK':\n // Choosing Feb-2021 as it starts on a Monday\n rhsText = new Date(2021, 1, rhs.value as number).toLocaleString(locale, {\n weekday: 'long'\n });\n break;\n default: // Not needed\n }\n } else {\n // If RHS is a single literal value\n rhsText = formatLiteralValue(lhsField.type, rhs.value, locale, translate);\n }\n } else if (hasProp(rhs, 'relativeDate')) {\n const {\n relativeDate: { timePeriod, interval, datePart }\n } = rhs;\n rhsText = formatRelativeDate(translate, timePeriod, datePart, interval);\n } else if (hasProp(rhs, 'parameterId')) {\n const parameterValue = lhsField.parameters?.find(item => item.id === rhs.parameterId);\n rhsText = parameterValue?.primary ?? '';\n } else if (hasProp(rhs, 'values')) {\n rhsText = rhs.values.join(', ');\n } else if (hasProp(rhs, 'start')) {\n const startValue = formatLiteralValue(lhsField.type, rhs.start, locale, translate);\n const endValue = formatLiteralValue(lhsField.type, rhs.end, locale, translate);\n\n rhsText = `${startValue} - ${endValue}`;\n }\n }\n\n switch (comparator) {\n case 'IS_NULL':\n return `${lhsText}is null`;\n case 'IS_NOT_NULL':\n return `${lhsText}is not null`;\n case 'IS_TRUE':\n return `${lhsText}is true`;\n case 'IS_FALSE':\n return `${lhsText}is false`;\n case 'EQ':\n return `${lhsText}is ${rhsText}`;\n case 'NEQ':\n return `${lhsText}isn't ${rhsText}`;\n case 'IN':\n return `${lhsText}is among ${rhsText}`;\n case 'NOT_IN':\n return `${lhsText}is not among ${rhsText}`;\n case 'GT':\n return `${lhsText}> ${rhsText}`;\n case 'GTE':\n return `${lhsText}>= ${rhsText}`;\n case 'LT':\n return `${lhsText}< ${rhsText}`;\n case 'LTE':\n return `${lhsText}<= ${rhsText}`;\n case 'BTW':\n return `${lhsText}is between ${rhsText}`;\n case 'NOT_BTW':\n return `${lhsText}is not between ${rhsText}`;\n case 'STARTS_WITH':\n return `${lhsText}starts with ${rhsText}`;\n case 'NOT_STARTS_WITH':\n return `${lhsText}doesn't start with ${rhsText}`;\n case 'ENDS_WITH':\n return `${lhsText}ends with ${rhsText}`;\n case 'NOT_ENDS_WITH':\n return `${lhsText}doesn't end with ${rhsText}`;\n case 'CONTAINS':\n return `${lhsText}contains ${rhsText}`;\n case 'NOT_CONTAINS':\n return `${lhsText}doesn't contain ${rhsText}`;\n default:\n return ''; // Not needed\n }\n}\n\n/** Returns a user-friendly text representation of the given node in a condition */\nfunction formatConditionNode(\n node: Condition,\n fields: Field[],\n translate: TranslationFunction<TranslationPack>,\n options?: ConditionFormatOptions\n): string {\n if (hasProp(node, 'AND')) {\n const childStrings = node.AND.map(n => formatConditionNode(n, fields, translate, options));\n return `(${childStrings.join(' AND ')})`;\n }\n\n if (hasProp(node, 'OR')) {\n const childStrings = node.OR.map(n => formatConditionNode(n, fields, translate, options));\n return `(${childStrings.join(' OR ')})`;\n }\n\n if (hasProp(node, 'NOT')) {\n const childString = formatConditionNode(node.NOT, fields, translate, options);\n if (childString.startsWith(LPAREN) && childString.endsWith(RPAREN)) {\n // Avoid double brackets when the child node is an AND/OR node\n return `NOT ${childString}`;\n }\n return `NOT (${childString})`;\n }\n\n return formatLeafCondition(node.condition, fields, translate, options); // If leaf-level is reached\n}\n\n/**\n * Returns a user-friendly text representation of a given complex condition\n * The input `fields` are used to look up display labels for the fields\n */\nexport default function formatCondition(\n condition: Condition,\n fields: Field[],\n translate: TranslationFunction<TranslationPack>,\n options?: ConditionFormatOptions\n): string {\n // Recursively format the tree, starting at the root node\n let text = formatConditionNode(condition, fields, translate, options);\n\n // If the root node is AND/OR, there will be extra parentheses. Remove them\n if (text.startsWith(LPAREN) && text.endsWith(RPAREN)) {\n text = text.slice(1, -1);\n }\n\n return text;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformer.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/transformer.ts"],"names":[],"mappings":"AAGA,OAAO,eAAe,CAAC;AAIvB,OAAO,EAAE,SAAS,EAAiB,KAAK,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"transformer.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/transformer.ts"],"names":[],"mappings":"AAGA,OAAO,eAAe,CAAC;AAIvB,OAAO,EAAE,SAAS,EAAiB,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAiN5E;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAC/C,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,KAAK,EAAE,EACf,eAAe,CAAC,EAAE,MAAM,GACvB,SAAS,CA0BX"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformer.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/transformer.ts"],"names":[],"mappings":"AAAA,qBAAqB;AAErB,OAA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GAEG;AACH,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAC/C,SAAoB,EACpB,MAAe,EACf,eAAwB;IAExB,IAAI,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,EAAE;QAC7B,MAAM,UAAU,GAAgB,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CACpD,yBAAyB,CAAC,CAAC,EAAE,MAAM,EAAE,eAAe,CAAC,CACtD,CAAC;QACF,OAAO;YACL,GAAG,EAAE,UAAU;SAChB,CAAC;KACH;IAED,IAAI,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE;QAC5B,MAAM,UAAU,GAAgB,SAAS,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CACnD,yBAAyB,CAAC,CAAC,EAAE,MAAM,EAAE,eAAe,CAAC,CACtD,CAAC;QACF,OAAO;YACL,EAAE,EAAE,UAAU;SACf,CAAC;KACH;IAED,IAAI,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,EAAE;QAC7B,OAAO;YACL,GAAG,EAAE,yBAAyB,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,eAAe,CAAC;SACvE,CAAC;KACH;IAED,OAAO,sBAAsB,CAAC,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,CAAC,CAAC;AAC9E,CAAC","sourcesContent":["// cSpell:words DDTHH\n\nimport dayjs, { QUnitType, Dayjs } from 'dayjs';\nimport './extendDayJs';\n\nimport { hasProp } from '@pega/cosmos-react-core';\n\nimport { Condition, LeafCondition, Field } from '../ConditionBuilder.types';\n\nimport { getItem } from './utils';\nimport { DatePart, FieldType } from './types';\n\nconst dayjsDateParts: Record<DatePart, QUnitType> = {\n MINUTES: 'minute',\n HOURS: 'hour',\n DAYS: 'day',\n WEEKS: 'week' as QUnitType,\n QUARTERS: 'quarter',\n MONTHS: 'month',\n YEARS: 'year'\n};\n\n/** Construct Condition with two range comparators based on the given bounds */\nfunction getConditionForBetweenComparator(\n start: string | number,\n end: string | number,\n node: LeafCondition\n): Condition {\n return node.comparator === 'BTW'\n ? {\n AND: [\n {\n condition: {\n lhs: node.lhs,\n comparator: 'GTE',\n rhs: { value: start }\n }\n },\n {\n condition: {\n lhs: node.lhs,\n comparator: 'LTE',\n rhs: { value: end }\n }\n }\n ]\n }\n : {\n OR: [\n {\n condition: {\n lhs: node.lhs,\n comparator: 'LT',\n rhs: { value: start }\n }\n },\n {\n condition: {\n lhs: node.lhs,\n comparator: 'GT',\n rhs: { value: end }\n }\n }\n ]\n };\n}\n\n/** Construct a date-range filter based on the given date bounds and the comparator */\nfunction getConditionFromRange(\n startDate: Dayjs,\n endDate: Dayjs,\n node: LeafCondition,\n lhsFieldType: FieldType\n): Condition {\n const formatDate = (d: Dayjs) => {\n const isoString = d.toISOString();\n return isoString.substring(0, isoString.indexOf(lhsFieldType === 'DATE_ONLY' ? 'T' : '.'));\n };\n\n switch (node.comparator) {\n case 'EQ':\n return {\n AND: [\n {\n condition: {\n lhs: node.lhs,\n comparator: 'LTE',\n rhs: { value: formatDate(endDate) }\n }\n },\n {\n condition: {\n lhs: node.lhs,\n comparator: 'GTE',\n rhs: { value: formatDate(startDate) }\n }\n }\n ]\n };\n case 'NEQ':\n return {\n OR: [\n {\n condition: {\n lhs: node.lhs,\n comparator: 'GT',\n rhs: { value: formatDate(endDate) }\n }\n },\n {\n condition: {\n lhs: node.lhs,\n comparator: 'LT',\n rhs: { value: formatDate(startDate) }\n }\n }\n ]\n };\n case 'GT':\n return {\n condition: {\n lhs: node.lhs,\n comparator: 'GT',\n rhs: { value: formatDate(endDate) }\n }\n };\n case 'GTE':\n return {\n condition: {\n lhs: node.lhs,\n comparator: 'GTE',\n rhs: { value: formatDate(startDate) }\n }\n };\n case 'LT':\n return {\n condition: {\n lhs: node.lhs,\n comparator: 'LT',\n rhs: { value: formatDate(startDate) }\n }\n };\n case 'LTE':\n return {\n condition: {\n lhs: node.lhs,\n comparator: 'LTE',\n rhs: { value: formatDate(endDate) }\n }\n };\n case 'BTW':\n case 'NOT_BTW':\n return getConditionForBetweenComparator(formatDate(startDate), formatDate(endDate), node);\n default:\n return { condition: node };\n }\n}\n\nfunction transformLeafCondition(\n node: LeafCondition,\n fields: Field[],\n currentDateTime?: string\n): Condition {\n const field = getItem(fields, node.lhs.field);\n if (!field || !hasProp(field, 'type')) {\n return { condition: node }; // Safety check\n }\n\n // Transform Relative date filters into equivalent date range filters\n if (node.rhs && hasProp(node.rhs, 'relativeDate')) {\n const { timePeriod, interval, datePart } = node.rhs.relativeDate;\n const dayjsDatePart = dayjsDateParts[datePart];\n const now = dayjs(currentDateTime);\n\n let startDate = now;\n let endDate = now;\n if (timePeriod === 'CURRENT') {\n startDate = now.startOf(dayjsDatePart);\n endDate = now.endOf(dayjsDatePart);\n } else if (timePeriod === 'LAST' && interval && interval >= 1) {\n startDate = now.subtract(interval, dayjsDatePart);\n } else if (timePeriod === 'PREVIOUS' && interval && interval >= 1) {\n startDate = now.startOf(dayjsDatePart).subtract(interval, dayjsDatePart);\n endDate = now.subtract(1, dayjsDatePart).endOf(dayjsDatePart);\n } else if (timePeriod === 'NEXT' && interval && interval >= 1) {\n startDate = now.add(1, dayjsDatePart).startOf(dayjsDatePart);\n endDate = now.endOf(dayjsDatePart).add(interval, dayjsDatePart);\n }\n\n return getConditionFromRange(startDate, endDate, node, field.type);\n }\n\n // Transform WEEKS-filters into equivalent date-range filters\n // NOTE: This is a work-around until we make startOfDay customizable for Weeks\n if (node.rhs && hasProp(node.rhs, 'dateFunction') && node.rhs.dateFunction === 'WEEKS') {\n const startDate = dayjs(node.rhs.value); // Since we store it as YYYY-MM-DD, it's already the start of day\n const endDate = startDate.add(6, 'day').endOf('day'); // Last millisecond on the 7th day from startDate\n return getConditionFromRange(startDate, endDate, node, field.type);\n }\n\n // Transform double range comparators (BTW, NOT_BTW) into equivalent pair of single range comparators\n if (node.rhs && hasProp(node.rhs, 'start')) {\n if (field.type === 'NUMBER' || field.type === 'TIME_ONLY') {\n return getConditionForBetweenComparator(node.rhs.start, node.rhs.end, node);\n }\n\n const startDate = dayjs(node.rhs.start);\n const endDate = dayjs(node.rhs.end);\n return getConditionFromRange(startDate, endDate, node, field.type);\n }\n\n // For all other cases\n return { condition: node };\n}\n\n/** This function transforms Conditions with Relative Dates into Conditions with Date Ranges.\n * Do not use this function unless you need to convert Relative Dates into Date Ranges.\n */\nexport default function transformComplexCondition(\n condition: Condition,\n fields: Field[],\n currentDateTime?: string\n): Condition {\n if (hasProp(condition, 'AND')) {\n const childNodes: Condition[] = condition.AND.map(n =>\n transformComplexCondition(n, fields, currentDateTime)\n );\n return {\n AND: childNodes\n };\n }\n\n if (hasProp(condition, 'OR')) {\n const childNodes: Condition[] = condition.OR.map(n =>\n transformComplexCondition(n, fields, currentDateTime)\n );\n return {\n OR: childNodes\n };\n }\n\n if (hasProp(condition, 'NOT')) {\n return {\n NOT: transformComplexCondition(condition.NOT, fields, currentDateTime)\n };\n }\n\n return transformLeafCondition(condition.condition, fields, currentDateTime);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"transformer.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/transformer.ts"],"names":[],"mappings":"AAAA,qBAAqB;AAErB,OAAO,KAA2B,MAAM,OAAO,CAAC;AAChD,OAAO,eAAe,CAAC;AAEvB,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAIlD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAGlC,MAAM,cAAc,GAAgC;IAClD,OAAO,EAAE,QAAQ;IACjB,OAAO,EAAE,QAAQ;IACjB,KAAK,EAAE,MAAM;IACb,IAAI,EAAE,KAAK;IACX,KAAK,EAAE,MAAmB;IAC1B,QAAQ,EAAE,SAAS;IACnB,MAAM,EAAE,OAAO;IACf,KAAK,EAAE,MAAM;CACd,CAAC;AAEF,+EAA+E;AAC/E,SAAS,gCAAgC,CACvC,KAAsB,EACtB,GAAoB,EACpB,IAAmB;IA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,GAAG,CAAC,CAAC,CAAC,EAAE,CACnD,yBAAyB,CAAC,CAAC,EAAE,MAAM,EAAE,eAAe,CAAC,CACtD,CAAC;QACF,OAAO;YACL,EAAE,EAAE,UAAU;SACf,CAAC;KACH;IAED,IAAI,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,EAAE;QAC7B,OAAO;YACL,GAAG,EAAE,yBAAyB,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,eAAe,CAAC;SACvE,CAAC;KACH;IAED,OAAO,sBAAsB,CAAC,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,CAAC,CAAC;AAC9E,CAAC","sourcesContent":["// cSpell:words DDTHH\n\nimport dayjs, { QUnitType, Dayjs } from 'dayjs';\nimport './extendDayJs';\n\nimport { hasProp } from '@pega/cosmos-react-core';\n\nimport { Condition, LeafCondition, Field } from '../ConditionBuilder.types';\n\nimport { getItem } from './utils';\nimport { DatePart, FieldType } from './types';\n\nconst dayjsDateParts: Record<DatePart, QUnitType> = {\n SECONDS: 'second',\n MINUTES: 'minute',\n HOURS: 'hour',\n DAYS: 'day',\n WEEKS: 'week' as QUnitType,\n QUARTERS: 'quarter',\n MONTHS: 'month',\n YEARS: 'year'\n};\n\n/** Construct Condition with two range comparators based on the given bounds */\nfunction getConditionForBetweenComparator(\n start: string | number,\n end: string | number,\n node: LeafCondition\n): Condition {\n return node.comparator === 'BTW'\n ? {\n AND: [\n {\n condition: {\n lhs: node.lhs,\n comparator: 'GTE',\n rhs: { value: start }\n }\n },\n {\n condition: {\n lhs: node.lhs,\n comparator: 'LTE',\n rhs: { value: end }\n }\n }\n ]\n }\n : {\n OR: [\n {\n condition: {\n lhs: node.lhs,\n comparator: 'LT',\n rhs: { value: start }\n }\n },\n {\n condition: {\n lhs: node.lhs,\n comparator: 'GT',\n rhs: { value: end }\n }\n }\n ]\n };\n}\n\n/** Construct a date-range filter based on the given date bounds and the comparator */\nfunction getConditionFromRange(\n startDate: Dayjs,\n endDate: Dayjs,\n node: LeafCondition,\n lhsFieldType: FieldType\n): Condition {\n const formatDate = (d: Dayjs) => {\n const isoString = d.toISOString();\n return isoString.substring(0, isoString.indexOf(lhsFieldType === 'DATE_ONLY' ? 'T' : '.'));\n };\n\n switch (node.comparator) {\n case 'EQ':\n return {\n AND: [\n {\n condition: {\n lhs: node.lhs,\n comparator: 'LTE',\n rhs: { value: formatDate(endDate) }\n }\n },\n {\n condition: {\n lhs: node.lhs,\n comparator: 'GTE',\n rhs: { value: formatDate(startDate) }\n }\n }\n ]\n };\n case 'NEQ':\n return {\n OR: [\n {\n condition: {\n lhs: node.lhs,\n comparator: 'GT',\n rhs: { value: formatDate(endDate) }\n }\n },\n {\n condition: {\n lhs: node.lhs,\n comparator: 'LT',\n rhs: { value: formatDate(startDate) }\n }\n }\n ]\n };\n case 'GT':\n return {\n condition: {\n lhs: node.lhs,\n comparator: 'GT',\n rhs: { value: formatDate(endDate) }\n }\n };\n case 'GTE':\n return {\n condition: {\n lhs: node.lhs,\n comparator: 'GTE',\n rhs: { value: formatDate(startDate) }\n }\n };\n case 'LT':\n return {\n condition: {\n lhs: node.lhs,\n comparator: 'LT',\n rhs: { value: formatDate(startDate) }\n }\n };\n case 'LTE':\n return {\n condition: {\n lhs: node.lhs,\n comparator: 'LTE',\n rhs: { value: formatDate(endDate) }\n }\n };\n case 'BTW':\n case 'NOT_BTW':\n return getConditionForBetweenComparator(formatDate(startDate), formatDate(endDate), node);\n default:\n return { condition: node };\n }\n}\n\nfunction transformLeafCondition(\n node: LeafCondition,\n fields: Field[],\n currentDateTime?: string\n): Condition {\n const field = getItem(fields, node.lhs.field);\n if (!field || !hasProp(field, 'type')) {\n return { condition: node }; // Safety check\n }\n\n // Transform Relative date filters into equivalent date range filters\n if (node.rhs && hasProp(node.rhs, 'relativeDate')) {\n const { timePeriod, interval, datePart } = node.rhs.relativeDate;\n const dayjsDatePart = dayjsDateParts[datePart];\n const now = dayjs(currentDateTime);\n\n let startDate = now;\n let endDate = now;\n if (timePeriod === 'CURRENT') {\n startDate = now.startOf(dayjsDatePart);\n endDate = now.endOf(dayjsDatePart);\n } else if (timePeriod === 'LAST' && interval && interval >= 1) {\n startDate = now.subtract(interval, dayjsDatePart);\n } else if (timePeriod === 'PREVIOUS' && interval && interval >= 1) {\n startDate = now.startOf(dayjsDatePart).subtract(interval, dayjsDatePart);\n endDate = now.subtract(1, dayjsDatePart).endOf(dayjsDatePart);\n } else if (timePeriod === 'NEXT' && interval && interval >= 1) {\n startDate = now.add(1, dayjsDatePart).startOf(dayjsDatePart);\n endDate = now.endOf(dayjsDatePart).add(interval, dayjsDatePart);\n }\n\n return getConditionFromRange(startDate, endDate, node, field.type);\n }\n\n // Transform WEEKS-filters into equivalent date-range filters\n // NOTE: This is a work-around until we make startOfDay customizable for Weeks\n if (node.rhs && hasProp(node.rhs, 'dateFunction') && node.rhs.dateFunction === 'WEEKS') {\n const startDate = dayjs(node.rhs.value); // Since we store it as YYYY-MM-DD, it's already the start of day\n const endDate = startDate.add(6, 'day').endOf('day'); // Last millisecond on the 7th day from startDate\n return getConditionFromRange(startDate, endDate, node, field.type);\n }\n\n // Transform double range comparators (BTW, NOT_BTW) into equivalent pair of single range comparators\n if (node.rhs && hasProp(node.rhs, 'start')) {\n if (field.type === 'NUMBER' || field.type === 'TIME_ONLY') {\n return getConditionForBetweenComparator(node.rhs.start, node.rhs.end, node);\n }\n\n const startDate = dayjs(node.rhs.start);\n const endDate = dayjs(node.rhs.end);\n return getConditionFromRange(startDate, endDate, node, field.type);\n }\n\n // For all other cases\n return { condition: node };\n}\n\n/** This function transforms Conditions with Relative Dates into Conditions with Date Ranges.\n * Do not use this function unless you need to convert Relative Dates into Date Ranges.\n */\nexport default function transformComplexCondition(\n condition: Condition,\n fields: Field[],\n currentDateTime?: string\n): Condition {\n if (hasProp(condition, 'AND')) {\n const childNodes: Condition[] = condition.AND.map(n =>\n transformComplexCondition(n, fields, currentDateTime)\n );\n return {\n AND: childNodes\n };\n }\n\n if (hasProp(condition, 'OR')) {\n const childNodes: Condition[] = condition.OR.map(n =>\n transformComplexCondition(n, fields, currentDateTime)\n );\n return {\n OR: childNodes\n };\n }\n\n if (hasProp(condition, 'NOT')) {\n return {\n NOT: transformComplexCondition(condition.NOT, fields, currentDateTime)\n };\n }\n\n return transformLeafCondition(condition.condition, fields, currentDateTime);\n}\n"]}
|
|
@@ -38,10 +38,10 @@ export declare type ComparatorsByType = {
|
|
|
38
38
|
};
|
|
39
39
|
export declare type RHSType = 'LITERAL' | 'FIELD' | 'DATE_FUNCTION' | 'RELATIVE_DATE' | 'PARAMETER';
|
|
40
40
|
/** Date function types supported on the RHS */
|
|
41
|
-
export declare type DateFunction = 'YEARS' | 'QUARTERS' | 'MONTHS' | 'WEEKS' | 'DAYS' | 'HOURS' | 'HOURS_OF_DAY' | 'MONTHS_OF_YEAR' | 'DAYS_OF_MONTH' | 'DAYS_OF_WEEK';
|
|
41
|
+
export declare type DateFunction = 'YEARS' | 'QUARTERS' | 'MONTHS' | 'WEEKS' | 'DAYS' | 'HOURS' | 'MINUTES' | 'SECONDS' | 'HOURS_OF_DAY' | 'MONTHS_OF_YEAR' | 'DAYS_OF_MONTH' | 'DAYS_OF_WEEK';
|
|
42
42
|
/** "Relative Date" Time Periods supported on the RHS */
|
|
43
43
|
export declare type TimePeriod = 'LAST' | 'PREVIOUS' | 'CURRENT' | 'NEXT';
|
|
44
44
|
/** "Relative Date" Date Parts supported on the RHS */
|
|
45
|
-
export declare type DatePart = 'MINUTES' | 'HOURS' | 'DAYS' | 'WEEKS' | 'MONTHS' | 'QUARTERS' | 'YEARS';
|
|
45
|
+
export declare type DatePart = 'SECONDS' | 'MINUTES' | 'HOURS' | 'DAYS' | 'WEEKS' | 'MONTHS' | 'QUARTERS' | 'YEARS';
|
|
46
46
|
export {};
|
|
47
47
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../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AAS,GACT,SAAS,GACT,cAAc,GACd,gBAAgB,GAChB,eAAe,GACf,cAAc,CAAC;AAEnB,wDAAwD;AACxD,oBAAY,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,SAAS,GAAG,MAAM,CAAC;AAElE,sDAAsD;AACtD,oBAAY,QAAQ,GAChB,SAAS,GACT,SAAS,GACT,OAAO,GACP,MAAM,GACN,OAAO,GACP,QAAQ,GACR,UAAU,GACV,OAAO,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/types.ts"],"names":[],"mappings":"","sourcesContent":["/** Supported field types */\nexport type FieldType = 'BOOLEAN' | 'TEXT' | 'NUMBER' | 'DATE_TIME' | 'DATE_ONLY' | 'TIME_ONLY';\n\ntype NullComparator = 'IS_NULL' | 'IS_NOT_NULL';\ntype EqualityComparator = 'EQ' | 'NEQ';\ntype RangeComparator = 'GT' | 'GTE' | 'LT' | 'LTE' | 'BTW' | 'NOT_BTW';\ntype TruenessComparator = 'IS_TRUE' | 'IS_FALSE';\ntype ListComparator = 'IN' | 'NOT_IN';\ntype TextMatchComparator =\n | 'STARTS_WITH'\n | 'NOT_STARTS_WITH'\n | 'ENDS_WITH'\n | 'NOT_ENDS_WITH'\n | 'CONTAINS'\n | 'NOT_CONTAINS';\n\n/** All supported Comparators */\nexport type Comparator =\n | TruenessComparator\n | NullComparator\n | EqualityComparator\n | ListComparator\n | RangeComparator\n | TextMatchComparator;\n\n/** Comparators supported for BOOLEAN fields */\ntype BooleanComparator = TruenessComparator | EqualityComparator | NullComparator;\n\n/** Comparators supported for TEXT fields */\ntype TextComparator = EqualityComparator | ListComparator | TextMatchComparator | NullComparator;\n\n/** Comparators supported for NUMBER fields */\ntype NumberComparator = EqualityComparator | ListComparator | RangeComparator | NullComparator;\n\n/** Comparators supported for DATE_TIME/DATE_ONLY/TIME_ONLY fields */\ntype DateTimeComparator = EqualityComparator | RangeComparator | NullComparator;\n\n/** Type definition to specify supported comparators by field-type */\nexport type ComparatorsByType =\n | { type: 'BOOLEAN'; comparators: BooleanComparator[] }\n | { type: 'TEXT'; comparators: TextComparator[] }\n | { type: 'NUMBER'; comparators: NumberComparator[] }\n | { type: 'DATE_TIME'; comparators: DateTimeComparator[] }\n | { type: 'DATE_ONLY'; comparators: DateTimeComparator[] }\n | { type: 'TIME_ONLY'; comparators: DateTimeComparator[] };\n\nexport type RHSType = 'LITERAL' | 'FIELD' | 'DATE_FUNCTION' | 'RELATIVE_DATE' | 'PARAMETER';\n\n/** Date function types supported on the RHS */\nexport type DateFunction =\n | 'YEARS'\n | 'QUARTERS'\n | 'MONTHS'\n | 'WEEKS'\n | 'DAYS'\n | 'HOURS'\n | 'HOURS_OF_DAY'\n | 'MONTHS_OF_YEAR'\n | 'DAYS_OF_MONTH'\n | 'DAYS_OF_WEEK';\n\n/** \"Relative Date\" Time Periods supported on the RHS */\nexport type TimePeriod = 'LAST' | 'PREVIOUS' | 'CURRENT' | 'NEXT';\n\n/** \"Relative Date\" Date Parts supported on the RHS */\nexport type DatePart
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/types.ts"],"names":[],"mappings":"","sourcesContent":["/** Supported field types */\nexport type FieldType = 'BOOLEAN' | 'TEXT' | 'NUMBER' | 'DATE_TIME' | 'DATE_ONLY' | 'TIME_ONLY';\n\ntype NullComparator = 'IS_NULL' | 'IS_NOT_NULL';\ntype EqualityComparator = 'EQ' | 'NEQ';\ntype RangeComparator = 'GT' | 'GTE' | 'LT' | 'LTE' | 'BTW' | 'NOT_BTW';\ntype TruenessComparator = 'IS_TRUE' | 'IS_FALSE';\ntype ListComparator = 'IN' | 'NOT_IN';\ntype TextMatchComparator =\n | 'STARTS_WITH'\n | 'NOT_STARTS_WITH'\n | 'ENDS_WITH'\n | 'NOT_ENDS_WITH'\n | 'CONTAINS'\n | 'NOT_CONTAINS';\n\n/** All supported Comparators */\nexport type Comparator =\n | TruenessComparator\n | NullComparator\n | EqualityComparator\n | ListComparator\n | RangeComparator\n | TextMatchComparator;\n\n/** Comparators supported for BOOLEAN fields */\ntype BooleanComparator = TruenessComparator | EqualityComparator | NullComparator;\n\n/** Comparators supported for TEXT fields */\ntype TextComparator = EqualityComparator | ListComparator | TextMatchComparator | NullComparator;\n\n/** Comparators supported for NUMBER fields */\ntype NumberComparator = EqualityComparator | ListComparator | RangeComparator | NullComparator;\n\n/** Comparators supported for DATE_TIME/DATE_ONLY/TIME_ONLY fields */\ntype DateTimeComparator = EqualityComparator | RangeComparator | NullComparator;\n\n/** Type definition to specify supported comparators by field-type */\nexport type ComparatorsByType =\n | { type: 'BOOLEAN'; comparators: BooleanComparator[] }\n | { type: 'TEXT'; comparators: TextComparator[] }\n | { type: 'NUMBER'; comparators: NumberComparator[] }\n | { type: 'DATE_TIME'; comparators: DateTimeComparator[] }\n | { type: 'DATE_ONLY'; comparators: DateTimeComparator[] }\n | { type: 'TIME_ONLY'; comparators: DateTimeComparator[] };\n\nexport type RHSType = 'LITERAL' | 'FIELD' | 'DATE_FUNCTION' | 'RELATIVE_DATE' | 'PARAMETER';\n\n/** Date function types supported on the RHS */\nexport type DateFunction =\n | 'YEARS'\n | 'QUARTERS'\n | 'MONTHS'\n | 'WEEKS'\n | 'DAYS'\n | 'HOURS'\n | 'MINUTES'\n | 'SECONDS'\n | 'HOURS_OF_DAY'\n | 'MONTHS_OF_YEAR'\n | 'DAYS_OF_MONTH'\n | 'DAYS_OF_WEEK';\n\n/** \"Relative Date\" Time Periods supported on the RHS */\nexport type TimePeriod = 'LAST' | 'PREVIOUS' | 'CURRENT' | 'NEXT';\n\n/** \"Relative Date\" Date Parts supported on the RHS */\nexport type DatePart =\n | 'SECONDS'\n | 'MINUTES'\n | 'HOURS'\n | 'DAYS'\n | 'WEEKS'\n | 'MONTHS'\n | 'QUARTERS'\n | 'YEARS';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConditionInput.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionInput/ConditionInput.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,
|
|
1
|
+
{"version":3,"file":"ConditionInput.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionInput/ConditionInput.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAOlB,MAAM,OAAO,CAAC;AAEf,OAAO,EAGL,YAAY,EAab,MAAM,yBAAyB,CAAC;AAkBjC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAkBlE,QAAA,MAAM,cAAc,EAAE,iBAAiB,CAAC,mBAAmB,GAAG,YAAY,CAwdzE,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef, useState, useEffect } from 'react';
|
|
2
|
+
import { forwardRef, useState, useEffect, useImperativeHandle, useRef } from 'react';
|
|
3
3
|
import { CompositeInput, hasProp, Input, RadioButton, useI18n, useConfiguration, DateRangeInput, TimeRangeInput, useUID, NumberRangeInput, RadioButtonGroup } from '@pega/cosmos-react-core';
|
|
4
4
|
import AtomicCondition, { getInitConditionForLhs, isValidCondition } from '../ConditionBuilder/AtomicCondition';
|
|
5
5
|
import formatCondition from '../ConditionBuilder/core/formatter';
|
|
6
6
|
import ValueSelector from '../ConditionBuilder/RhsControls/ValueSelector';
|
|
7
7
|
import { truncateISODateString } from '../ConditionBuilder/RhsControls';
|
|
8
8
|
import { convertTimeValueToMs } from '../ConditionBuilder/core/time-utils';
|
|
9
|
-
import {
|
|
10
|
-
import { basicFieldMap, defaultComparators, compareValues, compareRangeValues } from './utils';
|
|
11
|
-
const
|
|
9
|
+
import { StyledVerticalAtomicCondition, StyledConditionRadioGroup, StyledVerticalFieldGroup } from './ConditionInput.styles';
|
|
10
|
+
import { basicFieldMap, defaultComparators, compareValues, compareRangeValues, compareCondition } from './utils';
|
|
11
|
+
const isDateValid = (dateTimeParam) => {
|
|
12
|
+
return dateTimeParam.valueAsISOString && !dateTimeParam.state;
|
|
13
|
+
};
|
|
14
|
+
const ConditionInput = forwardRef(({ field: fieldProp, condition: conditionProp, label, mode, onChange, flat = false, handle }, ref) => {
|
|
12
15
|
const id = useUID();
|
|
13
16
|
const t = useI18n();
|
|
14
17
|
const { locale } = useConfiguration();
|
|
@@ -32,15 +35,26 @@ const ConditionInput = forwardRef(({ field: fieldProp, condition: conditionProp,
|
|
|
32
35
|
rhs: valueObj
|
|
33
36
|
};
|
|
34
37
|
};
|
|
35
|
-
const convertDateTimeValue = (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
const convertDateTimeValue = (range) => {
|
|
39
|
+
if (!isDateValid(range.start) || !isDateValid(range.end))
|
|
40
|
+
return undefined;
|
|
41
|
+
const truncatedStartValue = truncateISODateString(range.start.valueAsISOString, basicType);
|
|
42
|
+
const truncatedEndValue = truncateISODateString(range.end.valueAsISOString, basicType);
|
|
43
|
+
return {
|
|
44
|
+
start: fieldType === 'TIME_ONLY'
|
|
45
|
+
? convertTimeValueToMs(truncatedStartValue)
|
|
46
|
+
: truncatedStartValue,
|
|
47
|
+
end: fieldType === 'TIME_ONLY' ? convertTimeValueToMs(truncatedEndValue) : truncatedEndValue
|
|
48
|
+
};
|
|
38
49
|
};
|
|
39
50
|
const createConditionForRange = (value) => {
|
|
51
|
+
if (!value || value.start === undefined || value.end === undefined)
|
|
52
|
+
return;
|
|
40
53
|
return {
|
|
41
54
|
lhs: { field: fieldName },
|
|
42
55
|
comparator: defaultComparators[fieldType],
|
|
43
|
-
|
|
56
|
+
// undefined checked before, type added to satisfy typescript
|
|
57
|
+
rhs: { ...value }
|
|
44
58
|
};
|
|
45
59
|
};
|
|
46
60
|
const validComparators = fieldType === 'PICKLIST' ? [{ type: 'TEXT', comparators: ['IN'] }] : undefined;
|
|
@@ -49,6 +63,10 @@ const ConditionInput = forwardRef(({ field: fieldProp, condition: conditionProp,
|
|
|
49
63
|
? undefined
|
|
50
64
|
: getInitConditionForLhs({ field: fieldName }, fields, new Set(['LITERAL']), validComparators));
|
|
51
65
|
const [newCondition, setNewCondition] = useState(condition);
|
|
66
|
+
// holds current status of condition to control if invalid values are kept in forms and errors are displaying
|
|
67
|
+
const newConditionStatus = useRef(undefined);
|
|
68
|
+
// status of the form control
|
|
69
|
+
const [status, setStatus] = useState(undefined);
|
|
52
70
|
let rhsValue = fieldType === 'PICKLIST' ? [] : undefined;
|
|
53
71
|
let rhsRangeValue;
|
|
54
72
|
if (condition?.rhs) {
|
|
@@ -65,7 +83,10 @@ const ConditionInput = forwardRef(({ field: fieldProp, condition: conditionProp,
|
|
|
65
83
|
const [inputValue, setInputValue] = useState(rhsValue);
|
|
66
84
|
const [rangeInputValue, setRangeInputValue] = useState(rhsRangeValue);
|
|
67
85
|
useEffect(() => {
|
|
68
|
-
|
|
86
|
+
// condition state is updated only when condition status is valid
|
|
87
|
+
// allows to keep invalid values in inputs
|
|
88
|
+
if (!newConditionStatus.current)
|
|
89
|
+
setNewCondition(condition);
|
|
69
90
|
setInputValue(rhsValue);
|
|
70
91
|
setRangeInputValue(rhsRangeValue);
|
|
71
92
|
}, [conditionProp]);
|
|
@@ -76,11 +97,37 @@ const ConditionInput = forwardRef(({ field: fieldProp, condition: conditionProp,
|
|
|
76
97
|
onChange(newValue ? createConditionForDefaultMode(newValue) : undefined);
|
|
77
98
|
}
|
|
78
99
|
};
|
|
79
|
-
const
|
|
100
|
+
const handleRangeUpdate = (newRangeValue) => {
|
|
80
101
|
// trigger onChange only when value has changed
|
|
81
102
|
if (!compareRangeValues(rhsRangeValue, newRangeValue)) {
|
|
82
|
-
onChange(
|
|
103
|
+
onChange(createConditionForRange(newRangeValue));
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
const handleRangeBlur = (newRangeValue) => {
|
|
107
|
+
// if both values are undefined, condition is treated as undefined
|
|
108
|
+
// if only one value is undefined, condition is treated as invalid
|
|
109
|
+
if (newRangeValue &&
|
|
110
|
+
((newRangeValue.start === undefined && newRangeValue.end !== undefined) ||
|
|
111
|
+
(newRangeValue.end === undefined && newRangeValue.start !== undefined))) {
|
|
112
|
+
setStatus('error');
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
setStatus(undefined);
|
|
116
|
+
}
|
|
117
|
+
handleRangeUpdate(newRangeValue);
|
|
118
|
+
};
|
|
119
|
+
const handleDateRangeBlur = (newRangeValue) => {
|
|
120
|
+
// if both timestamps are undefined, condition is treated as undefined
|
|
121
|
+
// if only one value is undefined, or any of them is invalid, then condition is treated as invalid
|
|
122
|
+
if ((newRangeValue.start.valueAsTimestamp !== undefined ||
|
|
123
|
+
newRangeValue.end.valueAsTimestamp !== undefined) &&
|
|
124
|
+
(!isDateValid(newRangeValue.start) || !isDateValid(newRangeValue.end))) {
|
|
125
|
+
setStatus('error');
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
setStatus(undefined);
|
|
83
129
|
}
|
|
130
|
+
handleRangeUpdate(convertDateTimeValue(newRangeValue));
|
|
84
131
|
};
|
|
85
132
|
const onRadioButtonChange = (value) => {
|
|
86
133
|
const updatedCondition = value === undefined
|
|
@@ -91,10 +138,19 @@ const ConditionInput = forwardRef(({ field: fieldProp, condition: conditionProp,
|
|
|
91
138
|
};
|
|
92
139
|
onChange(updatedCondition);
|
|
93
140
|
};
|
|
94
|
-
const
|
|
141
|
+
const clearHandle = useRef(null);
|
|
142
|
+
const clear = () => {
|
|
95
143
|
onChange(undefined);
|
|
96
|
-
setNewCondition(
|
|
144
|
+
setNewCondition(undefined);
|
|
145
|
+
setRangeInputValue(undefined);
|
|
146
|
+
newConditionStatus.current = undefined;
|
|
147
|
+
setStatus(undefined);
|
|
148
|
+
if (clearHandle.current)
|
|
149
|
+
clearHandle.current.clear();
|
|
97
150
|
};
|
|
151
|
+
useImperativeHandle(handle, () => ({
|
|
152
|
+
clear
|
|
153
|
+
}), [clear]);
|
|
98
154
|
const handleDateRangeValueChange = (value) => {
|
|
99
155
|
setRangeInputValue({
|
|
100
156
|
start: value.start.valueAsISOString || undefined,
|
|
@@ -114,13 +170,11 @@ const ConditionInput = forwardRef(({ field: fieldProp, condition: conditionProp,
|
|
|
114
170
|
start: rangeInputValue?.start?.toString() ?? '',
|
|
115
171
|
end: rangeInputValue?.end?.toString() ?? ''
|
|
116
172
|
}, onChange: setRangeInputValue, onBlur: newRangeValue => {
|
|
117
|
-
handleRangeBlur(
|
|
118
|
-
?
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
: undefined);
|
|
123
|
-
}, numberOfDecimals: fieldType === 'INTEGER' ? 0 : undefined }));
|
|
173
|
+
handleRangeBlur({
|
|
174
|
+
start: newRangeValue.start ? Number(newRangeValue.start) : undefined,
|
|
175
|
+
end: newRangeValue.end ? Number(newRangeValue.end) : undefined
|
|
176
|
+
});
|
|
177
|
+
}, numberOfDecimals: fieldType === 'INTEGER' ? 0 : undefined, status: status, info: status === 'error' ? t('condition_builder_invalid_number_range') : undefined, handle: clearHandle }));
|
|
124
178
|
break;
|
|
125
179
|
case 'BOOLEAN':
|
|
126
180
|
defaultControl = (_jsxs(RadioButtonGroup, { as: StyledConditionRadioGroup, id: id, ref: ref, label: label, labelHidden: flat, name: fieldName, inline: true, children: [_jsx(RadioButton, { label: t('show_all'), checked: condition === undefined, onChange: () => onRadioButtonChange() }), _jsx(RadioButton, { label: t('boolean_display_true_label'), checked: condition?.comparator === 'IS_TRUE', onChange: () => onRadioButtonChange(true) }), _jsx(RadioButton, { label: t('boolean_display_false_label'), checked: condition?.comparator === 'IS_FALSE', onChange: () => onRadioButtonChange(false) })] }));
|
|
@@ -128,43 +182,22 @@ const ConditionInput = forwardRef(({ field: fieldProp, condition: conditionProp,
|
|
|
128
182
|
case 'DATE_ONLY':
|
|
129
183
|
defaultControl = (_jsx(DateRangeInput, { id: id, ref: ref, label: label, labelHidden: flat, value: rangeInputValue
|
|
130
184
|
? { start: rangeInputValue.start, end: rangeInputValue.end }
|
|
131
|
-
: undefined, onChange: handleDateRangeValueChange, onBlur:
|
|
132
|
-
handleRangeBlur(newRangeValue.start.valueAsISOString && newRangeValue.end.valueAsISOString
|
|
133
|
-
? {
|
|
134
|
-
start: convertDateTimeValue(newRangeValue.start.valueAsISOString),
|
|
135
|
-
end: convertDateTimeValue(newRangeValue.end.valueAsISOString)
|
|
136
|
-
}
|
|
137
|
-
: undefined);
|
|
138
|
-
}, fromLabel: '', toLabel: '', info: '' }));
|
|
185
|
+
: undefined, onChange: handleDateRangeValueChange, onBlur: handleDateRangeBlur, fromLabel: '', toLabel: '', status: status, info: status === 'error' ? t('condition_builder_invalid_date_range') : undefined, handle: clearHandle }));
|
|
139
186
|
break;
|
|
140
187
|
case 'TIME_ONLY':
|
|
141
188
|
defaultControl = (_jsx(TimeRangeInput, { id: id, ref: ref, mode: 'time', label: label, labelHidden: flat, value: rangeInputValue
|
|
142
189
|
? { start: rangeInputValue.start, end: rangeInputValue.end }
|
|
143
|
-
: undefined, onChange: handleDateRangeValueChange, onBlur:
|
|
144
|
-
handleRangeBlur(newRangeValue.start.valueAsISOString && newRangeValue.end.valueAsISOString
|
|
145
|
-
? {
|
|
146
|
-
start: convertDateTimeValue(newRangeValue.start.valueAsISOString),
|
|
147
|
-
end: convertDateTimeValue(newRangeValue.end.valueAsISOString)
|
|
148
|
-
}
|
|
149
|
-
: undefined);
|
|
150
|
-
}, info: '' }));
|
|
190
|
+
: undefined, onChange: handleDateRangeValueChange, onBlur: handleDateRangeBlur, status: status, info: status === 'error' ? t('condition_builder_invalid_time_range') : undefined, handle: clearHandle }));
|
|
151
191
|
break;
|
|
152
192
|
case 'DATE_TIME':
|
|
153
193
|
defaultControl = (_jsx(TimeRangeInput, { id: id, ref: ref, mode: 'datetime', label: label, labelHidden: flat, value: rangeInputValue
|
|
154
194
|
? { start: rangeInputValue.start, end: rangeInputValue.end }
|
|
155
|
-
: undefined, onChange: handleDateRangeValueChange, onBlur:
|
|
156
|
-
handleRangeBlur(newRangeValue.start.valueAsISOString && newRangeValue.end.valueAsISOString
|
|
157
|
-
? {
|
|
158
|
-
start: convertDateTimeValue(newRangeValue.start.valueAsISOString),
|
|
159
|
-
end: convertDateTimeValue(newRangeValue.end.valueAsISOString)
|
|
160
|
-
}
|
|
161
|
-
: undefined);
|
|
162
|
-
}, info: '' }));
|
|
195
|
+
: undefined, onChange: handleDateRangeValueChange, onBlur: handleDateRangeBlur, status: status, info: status === 'error' ? t('condition_builder_invalid_date_range') : undefined, handle: clearHandle }));
|
|
163
196
|
break;
|
|
164
197
|
case 'PICKLIST':
|
|
165
198
|
defaultControl = (_jsx(ValueSelector, { label: flat ? undefined : label, mode: 'multi-select', values: inputValue ?? [], selectedField: fieldProp, comparator: condition?.comparator ?? defaultComparators[fieldType], onChange: value => {
|
|
166
199
|
setInputValue(value.length > 0 ? value : undefined);
|
|
167
|
-
}, onBlur: handleBlur, onClear:
|
|
200
|
+
}, onBlur: handleBlur, onClear: clear, placeholder: t('all'), parameters: [], rhs: { values: [] }, handle: clearHandle }));
|
|
168
201
|
break;
|
|
169
202
|
case 'TEXT':
|
|
170
203
|
case 'EMAIL':
|
|
@@ -185,24 +218,40 @@ const ConditionInput = forwardRef(({ field: fieldProp, condition: conditionProp,
|
|
|
185
218
|
itemDirection: 'column',
|
|
186
219
|
lhsMode: 'hidden',
|
|
187
220
|
validRhsTypes: new Set(['LITERAL']),
|
|
188
|
-
indicateErrors:
|
|
221
|
+
indicateErrors: !!status,
|
|
189
222
|
rhsLabelHidden: true
|
|
190
223
|
},
|
|
191
224
|
onCancel: ({ close }) => {
|
|
192
225
|
setNewCondition(condition);
|
|
226
|
+
setStatus(undefined);
|
|
193
227
|
close();
|
|
194
228
|
},
|
|
195
229
|
onApply: ({ close }) => {
|
|
196
|
-
|
|
197
|
-
|
|
230
|
+
setStatus(undefined);
|
|
231
|
+
if (newCondition === undefined || isValidCondition(newCondition, fields, true)) {
|
|
232
|
+
onChange(newCondition);
|
|
233
|
+
close();
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
setStatus('error');
|
|
237
|
+
}
|
|
198
238
|
}
|
|
199
239
|
};
|
|
200
240
|
if (flat) {
|
|
201
|
-
return showAdvanced ? (_jsx(
|
|
202
|
-
getInitConditionForLhs({ field: fieldName }, fields, new Set(['LITERAL'])),
|
|
241
|
+
return showAdvanced ? (_jsx(StyledVerticalAtomicCondition, { collapsible: true, actions: [{ id: 'clear', text: t('clear'), onClick: clear }], condition: newCondition ??
|
|
242
|
+
getInitConditionForLhs({ field: fieldName }, fields, new Set(['LITERAL'])), onBlur: (value) => {
|
|
243
|
+
// comparing with conditionProp as it is not initialized as default condition
|
|
244
|
+
if (!compareCondition(value, conditionProp)) {
|
|
245
|
+
onChange(value);
|
|
246
|
+
}
|
|
247
|
+
setStatus(newConditionStatus.current);
|
|
248
|
+
}, onChange: (value, conditionStatus) => {
|
|
249
|
+
newConditionStatus.current = conditionStatus;
|
|
250
|
+
setNewCondition(value);
|
|
251
|
+
}, fields: fields, itemDirection: 'column', lhsMode: 'label', validRhsTypes: new Set(['LITERAL']), indicateErrors: status === 'error', ref: ref, handle: clearHandle })) : (_jsx(StyledVerticalFieldGroup, { name: label, collapsible: true, actions: [{ id: 'clear', text: t('clear'), onClick: clear }], children: defaultControl }));
|
|
203
252
|
}
|
|
204
253
|
if (showAdvanced) {
|
|
205
|
-
return (_jsx(CompositeInput, { dialog: dialog, label: label, onClear:
|
|
254
|
+
return (_jsx(CompositeInput, { dialog: dialog, label: label, onClear: clear, value: conditionProp
|
|
206
255
|
? formatCondition({ condition: conditionProp }, fields, t, {
|
|
207
256
|
locale,
|
|
208
257
|
omitLhs: true
|