@pega/cosmos-react-condition-builder 3.0.0-dev.15.0 → 3.0.0-dev.17.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.
Files changed (52) hide show
  1. package/lib/components/ConditionBuilder/AtomicCondition.d.ts.map +1 -1
  2. package/lib/components/ConditionBuilder/AtomicCondition.js +6 -7
  3. package/lib/components/ConditionBuilder/AtomicCondition.js.map +1 -1
  4. package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts +15 -15
  5. package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts.map +1 -1
  6. package/lib/components/ConditionBuilder/ConditionBuilder.types.js.map +1 -1
  7. package/lib/components/ConditionBuilder/FieldCondition.types.d.ts +2 -2
  8. package/lib/components/ConditionBuilder/FieldCondition.types.d.ts.map +1 -1
  9. package/lib/components/ConditionBuilder/FieldCondition.types.js.map +1 -1
  10. package/lib/components/ConditionBuilder/RhsControls/FieldSelector.d.ts.map +1 -1
  11. package/lib/components/ConditionBuilder/RhsControls/FieldSelector.js +11 -19
  12. package/lib/components/ConditionBuilder/RhsControls/FieldSelector.js.map +1 -1
  13. package/lib/components/ConditionBuilder/RhsControls/NumericInput.d.ts.map +1 -1
  14. package/lib/components/ConditionBuilder/RhsControls/NumericInput.js +4 -1
  15. package/lib/components/ConditionBuilder/RhsControls/NumericInput.js.map +1 -1
  16. package/lib/components/ConditionBuilder/RhsControls/ValueSelector.d.ts.map +1 -1
  17. package/lib/components/ConditionBuilder/RhsControls/ValueSelector.js +2 -1
  18. package/lib/components/ConditionBuilder/RhsControls/ValueSelector.js.map +1 -1
  19. package/lib/components/ConditionBuilder/RhsControls/index.d.ts.map +1 -1
  20. package/lib/components/ConditionBuilder/RhsControls/index.js +5 -4
  21. package/lib/components/ConditionBuilder/RhsControls/index.js.map +1 -1
  22. package/lib/components/ConditionBuilder/core/evaluator.d.ts.map +1 -1
  23. package/lib/components/ConditionBuilder/core/evaluator.js +3 -2
  24. package/lib/components/ConditionBuilder/core/evaluator.js.map +1 -1
  25. package/lib/components/ConditionBuilder/core/formatter.d.ts.map +1 -1
  26. package/lib/components/ConditionBuilder/core/formatter.js +7 -4
  27. package/lib/components/ConditionBuilder/core/formatter.js.map +1 -1
  28. package/lib/components/ConditionBuilder/core/transformer.d.ts.map +1 -1
  29. package/lib/components/ConditionBuilder/core/transformer.js +3 -2
  30. package/lib/components/ConditionBuilder/core/transformer.js.map +1 -1
  31. package/lib/components/ConditionBuilder/core/utils.d.ts +5 -1
  32. package/lib/components/ConditionBuilder/core/utils.d.ts.map +1 -1
  33. package/lib/components/ConditionBuilder/core/utils.js +18 -0
  34. package/lib/components/ConditionBuilder/core/utils.js.map +1 -1
  35. package/lib/components/ConditionInput/ConditionInput.d.ts.map +1 -1
  36. package/lib/components/ConditionInput/ConditionInput.js +29 -6
  37. package/lib/components/ConditionInput/ConditionInput.js.map +1 -1
  38. package/lib/components/ConditionInput/ConditionInput.types.d.ts +2 -0
  39. package/lib/components/ConditionInput/ConditionInput.types.d.ts.map +1 -1
  40. package/lib/components/ConditionInput/ConditionInput.types.js.map +1 -1
  41. package/lib/components/PromotedFilters/PromotedFilters.d.ts +6 -1
  42. package/lib/components/PromotedFilters/PromotedFilters.d.ts.map +1 -1
  43. package/lib/components/PromotedFilters/PromotedFilters.js +67 -24
  44. package/lib/components/PromotedFilters/PromotedFilters.js.map +1 -1
  45. package/lib/components/PromotedFilters/PromotedFilters.styles.d.ts +4 -0
  46. package/lib/components/PromotedFilters/PromotedFilters.styles.d.ts.map +1 -0
  47. package/lib/components/PromotedFilters/PromotedFilters.styles.js +26 -0
  48. package/lib/components/PromotedFilters/PromotedFilters.styles.js.map +1 -0
  49. package/lib/components/PromotedFilters/PromotedFilters.types.d.ts +4 -2
  50. package/lib/components/PromotedFilters/PromotedFilters.types.d.ts.map +1 -1
  51. package/lib/components/PromotedFilters/PromotedFilters.types.js.map +1 -1
  52. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3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AAE,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IAC3F,OAAO,iBAAiB,CAAC,WAAW,CAAC,CAAC,CAAC,+EAA+E;AACxH,CAAC","sourcesContent":["// cSpell:words LPAREN LPARENs RPAREN RPARENs\n\nimport { createUID, hasProp } from '@pega/cosmos-react-core';\n\nimport { Condition, ConditionRow, LeafCondition } from '../ConditionBuilder.types';\n\nconst AND = 'AND';\nconst OR = 'OR';\nconst NOT = 'NOT';\nconst LPAREN = '(';\nconst RPAREN = ')';\n\nconst precedenceMap: { [op: string]: number } = { OR: 1, AND: 2, NOT: 3 }; // Operator precedence. NOT has the highest precedence over the others\nconst operatorTokens = new Set([AND, OR, NOT]); // Valid logical operators\nconst validTokens = new Set([AND, OR, NOT, LPAREN, RPAREN]); // Other than these, integer tokens are valid\n\nconst isIntegerToken = (token: string): boolean => /^\\d+$/.test(token); // Checks if the input token is an integer\nconst isOperatorToken = (token: string): boolean => operatorTokens.has(token); // Checks if the input token is an operator\n\n/**\n * Tokenize the input expression.\n * Valid tokens are 'AND', 'OR', 'NOT', '(', ')' and any integer token.\n * Throws an error if an invalid token is found.\n */\nfunction tokenizeExpression(\n expression: string,\n disallowNOT: boolean = false\n): { tokens: string[] } | { error: string } {\n expression = expression.trim().toUpperCase(); // To simplify comparisons below; the tokens AND/OR/NOT are anyways expected to be in uppercase\n const words = expression.match(/[A-Z]+|[0-9]+|_|\\W/g); // Split contiguous alphabets and contiguous numbers into the same token. For all other characters, create a token for each character. Although `_` is not expected to be used, handling it just for completeness\n const tokens: string[] = []; // Final list of valid tokens\n const invalidWords: string[] = []; // Any invalid words are captured here\n\n // `words` will never be null because of the regex we used. Using `!` to indicate the same to TS\n words!.forEach(word => {\n // Ignore white-space characters\n if (word.trim().length > 0) {\n // If it's a token from the above Set or if it's an integer token\n if (isIntegerToken(word) || (validTokens.has(word) && !(word === NOT && disallowNOT))) {\n tokens.push(word);\n } else {\n invalidWords.push(word);\n }\n }\n });\n\n // Return an error if any invalid tokens are present\n if (invalidWords.length > 0) {\n return { error: `Unexpected words/characters: ${invalidWords.join(' ')}` }; // FIXME: TR\n }\n\n return { tokens };\n}\n\n/**\n * Captures any invalid/unexpected token patterns\n * NOTE: This does not expect any invalid tokens to be passed in the input\n * NOTE: This doesn't handle mismatched parentheses. That is handled separately in getPostfixFromInfix\n * Returns an error message about the first invalid sequence present in the input. Returns `null` if none found\n */\nfunction findInvalidPatterns(tokens: string[]): string | null {\n // These patterns are identified based on which token can precede/succeed which.\n // A table with all such permutations can be found in DOC-38200\n\n for (let i = 0; i < tokens.length; i += 1) {\n const NUMBER = 'NUMBER'; // To avoid repeating a string literal\n const token = tokens[i];\n const tokenType = isIntegerToken(token) ? NUMBER : token; // To simplify comparisons below\n\n // The expression can only start with NOT, LPAREN or NUMBER\n if (i === 0 && ![NOT, LPAREN, NUMBER].includes(tokenType)) {\n return `Unexpected \"${token}\" at the beginning.`; // FIXME: TR\n }\n\n // The expression can only end with RPAREN or NUMBER\n if (i === tokens.length - 1 && ![RPAREN, NUMBER].includes(tokenType)) {\n return `Unexpected \"${token}\" at the end.`; // FIXME: TR\n }\n\n // If there is a previous token, check if it is supposed to precede the current token\n if (i > 0) {\n const prevToken = tokens[i - 1];\n const prevTokenType = isIntegerToken(prevToken) ? NUMBER : prevToken; // To simplify comparisons below\n switch (tokenType) {\n // AND/OR/RPAREN can only be preceded by RPAREN or NUMBER\n case AND:\n case OR:\n case RPAREN:\n if (![RPAREN, NUMBER].includes(prevTokenType)) {\n return `Unexpected \"${token}\" after \"${prevToken}\"`; // FIXME: TR\n }\n break;\n\n // NOT/LPAREN/NUMBER can not be preceded by RPAREN or NUMBER\n case NOT:\n case LPAREN:\n case NUMBER:\n if ([RPAREN, NUMBER].includes(prevTokenType)) {\n return `Unexpected \"${token}\" after \"${prevToken}\"`; // FIXME: TR\n }\n break;\n default: // do nothing\n }\n }\n }\n\n // Return null if no invalid sequences\n return null;\n}\n\n/**\n * Converts an input array of Infix tokens into a Postfix array.\n * Uses the ShuntingYard algorithm.\n * NOTE: This does not expect any invalid tokens to be passed in the input\n */\nfunction getPostfixFromInfix(tokens: string[]): { postfixArr: string[] } | { error: string } {\n // Refer these for the ShuntingYard algorithm:\n // * https://brilliant.org/wiki/shunting-yard-algorithm/\n // * https://en.wikipedia.org/wiki/Shunting-yard_algorithm#The_algorithm_in_detail\n const postfixQueue: string[] = []; // Output queue\n const stack: string[] = []; // Operations stack\n\n // While there are tokens to be read\n for (let i = 0; i < tokens.length; i += 1) {\n const token = tokens[i];\n\n if (isIntegerToken(token)) {\n // If it's a number add it to queue\n postfixQueue.push(token);\n } else if (isOperatorToken(token)) {\n // If it's an operator\n // While there's an operator on the top of the stack with greater precedence (or equal precedence and the token is left-associative), pop operators from the stack onto the output queue\n if (token !== NOT) {\n // Unary operators should not cause any operators to be popped from the stack.\n // See http://wcipeg.com/wiki/Shunting_yard_algorithm#Unary_operators\n while (stack.length > 0) {\n const stackTop = stack[stack.length - 1];\n if (isOperatorToken(stackTop) && precedenceMap[stackTop] >= precedenceMap[token]) {\n postfixQueue.push(stack.pop()!);\n } else {\n break;\n }\n }\n }\n // Push the current operator onto the stack\n stack.push(token);\n } else if (token === LPAREN) {\n // If it's a left parenthesis, push it onto the stack\n stack.push(token);\n } else {\n // If it's a right parenthesis (RPAREN)\n // While there's not a left parenthesis at the top of the stack, pop operators from the stack onto the output queue\n while (stack.length > 0) {\n const stackTop = stack[stack.length - 1];\n if (stackTop === LPAREN) break;\n postfixQueue.push(stack.pop()!);\n }\n\n // Pop the left parenthesis from the stack and discard it\n if (stack.length > 0) {\n stack.pop();\n } else {\n // FIXME: TR\n return { error: 'Please fix mismatched parentheses.' }; // If no LPAREN found for the current RPAREN\n }\n }\n }\n\n // While there are operators on the stack, pop them to the queue\n while (stack.length > 0) {\n if (stack[stack.length - 1] === LPAREN) {\n // FIXME: TR\n return { error: 'Please fix mismatched parentheses.' }; // If there were excess LPARENs. (Excess RPARENs are already handled in the above loop. Also, RPARENs are never pushed to the stack)\n }\n postfixQueue.push(stack.pop()!);\n }\n\n return { postfixArr: postfixQueue };\n}\n\n/**\n * Converts an input array of Postfix tokens into a Condition tree.\n * NOTE: This expects a properly formed Postfix array as input\n */\nfunction getConditionFromPostfix(\n postfixArr: string[],\n conditionLookup: { [label: string]: LeafCondition },\n ignoreUnusedLabels: boolean\n): { condition: Condition } | { error: string } {\n // To learn more about the below algorithm, refer this: https://brilliant.org/wiki/shunting-yard-algorithm/#reverse-polish\n const operandsStack: Condition[] = [];\n const labelsWithNoRows: string[] = []; // Labels for which there is no corresponding op in conditionLookup\n const usedLabels: string[] = []; // A list of all labels used in the condition. This is used to warn about any unused operations\n postfixArr.forEach(token => {\n if (isIntegerToken(token)) {\n // If it's a numeric token (leaf condition), push it to the stack\n const conditionRow = conditionLookup[token]; // Identify the corresponding condition row\n operandsStack.push({ condition: conditionRow }); // Push it even if null so that the conversion goes on smoothly and identifies any other issues\n if (!conditionRow) {\n labelsWithNoRows.push(token); // Mark it as missing\n } else {\n usedLabels.push(token); // Mark it as used\n }\n } else if (token === NOT) {\n // If it's the NOT operator\n // Pop an operand, perform the operation and push the result back to the stack\n const operand = operandsStack.pop()!;\n operandsStack.push({ NOT: operand });\n } else {\n // If it's the AND/OR operator\n // Pop two operands, perform the operation and push the result back to the stack\n const operand2 = operandsStack.pop()!;\n const operand1 = operandsStack.pop()!;\n\n // If the inner operation is the same as the current one, consolidate them\n // e.g. `1 AND (2 AND 3)` should be consolidated as `1 AND 2 AND 3`\n // e.g. `1 OR (2 OR 3)` should be consolidated as `1 OR 2 OR 3`\n if (token === 'AND') {\n const operands = [\n ...(hasProp(operand1, 'AND') ? operand1.AND : [operand1]),\n ...(hasProp(operand2, 'AND') ? operand2.AND : [operand2])\n ];\n operandsStack.push({ AND: operands });\n } else {\n const operands = [\n ...(hasProp(operand1, 'OR') ? operand1.OR : [operand1]),\n ...(hasProp(operand2, 'OR') ? operand2.OR : [operand2])\n ];\n operandsStack.push({ OR: operands });\n }\n }\n });\n\n // If any labels are used for which there are no corresponding condition-rows\n if (labelsWithNoRows.length > 0) {\n if (labelsWithNoRows.length === 1) {\n return {\n error: `Condition ${labelsWithNoRows[0]} used in the logical string is not defined.` // FIXME: TR\n };\n }\n return {\n error: `Conditions ${labelsWithNoRows.join(', ')} used in the logical string are not defined.` // FIXME: TR\n };\n }\n\n // Warn if any of the condition rows are unused\n if (!ignoreUnusedLabels) {\n const unusedLabels = Object.keys(conditionLookup).filter(l => !usedLabels.includes(l));\n if (unusedLabels.length > 0) {\n if (unusedLabels.length === 1) {\n return { error: `Condition ${unusedLabels[0]} is not used in the logic expression.` }; // FIXME: TR\n }\n return {\n error: `Conditions ${unusedLabels.join(', ')} are not used in the logic expression.` // FIXME: TR\n };\n }\n }\n\n return { condition: operandsStack[0] };\n}\n\n/** Parses a logic-expression into a condition object. */\nexport function parseLogicString(\n expression: string,\n conditionLookup: { [label: string]: LeafCondition }, // To look up condition-rows from the labels\n disallowNOT: boolean = false,\n ignoreUnusedLabels: boolean = false\n): { condition: Condition } | { error: string } {\n // Handle empty expressions\n if (!expression.trim().length) return { error: 'Please provide a logic expression.' }; // FIXME: TR\n\n // Split the expression into individual tokens\n const tokeningResult = tokenizeExpression(expression, disallowNOT);\n if (hasProp(tokeningResult, 'error')) return tokeningResult;\n const { tokens } = tokeningResult;\n\n // Capture any invalid/unexpected token patterns\n // NOTE: This doesn't handle mismatched parentheses. That is handled below in getPostfixFromInfix\n const badPatternError = findInvalidPatterns(tokens);\n if (badPatternError !== null) return { error: badPatternError };\n\n // Convert the Infix tokens to a Postfix notation using the ShuntingYard algorithm\n const postfixResult = getPostfixFromInfix(tokens);\n if (hasProp(postfixResult, 'error')) return postfixResult;\n const { postfixArr } = postfixResult;\n\n // Convert the Postfix token to a Condition tree\n return getConditionFromPostfix(postfixArr, conditionLookup, ignoreUnusedLabels);\n}\n\n/**\n * Takes a valid logic string and formats it with parentheses at appropriate places to keep things unambiguous\n * For example, `1 AND 2 OR 3` is disambiguated as `(1 AND 2) OR 3`\n * NOTE: This expects only valid logic strings to be passed as an input\n */\nexport function disambiguateLogic(expression: string): string {\n // Split the expression into individual tokens\n const tokeningResult = tokenizeExpression(expression);\n const { tokens } = tokeningResult as { tokens: string[] }; // Only valid expressions are expected as inputs\n\n // Convert the Infix tokens to a Postfix notation using the ShuntingYard algorithm\n const postfixResult = getPostfixFromInfix(tokens);\n const { postfixArr } = postfixResult as { postfixArr: string[] };\n\n // Convert the postfix back to infix with parentheses at appropriate places\n // To learn more about the below algorithm, refer this: https://brilliant.org/wiki/shunting-yard-algorithm/#reverse-polish\n const operandsStack: string[] = [];\n postfixArr.forEach(token => {\n if (isIntegerToken(token)) {\n // If it's a numeric token (leaf condition), push it to the stack\n operandsStack.push(token);\n } else if (token === NOT) {\n // If it's the NOT operator\n // Pop an operand, perform the operation and push the result back to the stack\n const operand = operandsStack.pop()!;\n operandsStack.push(`NOT ${operand}`);\n } else {\n // If it's the AND/OR operator\n // Pop two operands, perform the operation and push the result back to the stack\n let operand2 = operandsStack.pop()!;\n let operand1 = operandsStack.pop()!;\n\n // If the inner operation is the same as the current one, consolidate them\n // e.g. `1 AND (2 AND 3)` should be consolidated as `1 AND 2 AND 3`\n // e.g. `1 OR (2 OR 3)` should be consolidated as `1 OR 2 OR 3`\n if (token === 'AND') {\n // Remove any wrapping parentheses if an operand contains just AND(s)\n if (operand1.startsWith(LPAREN) && !operand1.includes(OR) && !operand1.includes(NOT)) {\n operand1 = operand1.slice(1, -1);\n }\n if (operand2.startsWith(LPAREN) && !operand2.includes(OR) && !operand2.includes(NOT)) {\n operand2 = operand2.slice(1, -1);\n }\n operandsStack.push(`(${operand1} AND ${operand2})`);\n } else {\n // Remove any wrapping parentheses if an operand contains just OR(s)\n if (operand1.startsWith(LPAREN) && !operand1.includes(AND) && !operand1.includes(NOT)) {\n operand1 = operand1.slice(1, -1);\n }\n if (operand2.startsWith(LPAREN) && !operand2.includes(AND) && !operand2.includes(NOT)) {\n operand2 = operand2.slice(1, -1);\n }\n operandsStack.push(`(${operand1} OR ${operand2})`);\n }\n }\n });\n\n // If the root node is AND/OR, there will be extra parentheses. Remove them\n let outputLogic = operandsStack[0];\n if (outputLogic.startsWith(LPAREN) && outputLogic.endsWith(RPAREN)) {\n outputLogic = outputLogic.slice(1, -1);\n }\n return outputLogic;\n}\n\n/**\n * Recursively splits the input condition node into a logic-string and a list of condition-rows\n * NOTE: Returns an empty string and an empty array if the condition is malformed\n */\nfunction splitConditionNode(\n node: Condition,\n labelsSoFar: string[]\n): { logic: string; rows: ConditionRow[] } {\n // Using a try-catch block for safety against any malformed conditions\n try {\n let logic: string;\n const rows: ConditionRow[] = [];\n\n if (hasProp(node, 'AND')) {\n const childStrings: string[] = [];\n node.AND.forEach(n => {\n const splitResult = splitConditionNode(n, labelsSoFar); // Recursively get child rows and logic\n childStrings.push(splitResult.logic);\n rows.push(...splitResult.rows);\n });\n logic = `(${childStrings.join(' AND ')})`;\n } else if (hasProp(node, 'OR')) {\n const childStrings: string[] = [];\n node.OR.forEach(n => {\n const splitResult = splitConditionNode(n, labelsSoFar); // Recursively get child rows and logic\n childStrings.push(splitResult.logic);\n rows.push(...splitResult.rows);\n });\n logic = `(${childStrings.join(' OR ')})`;\n } else if (hasProp(node, 'NOT')) {\n const splitResult = splitConditionNode(node.NOT, labelsSoFar); // Recursively get child rows and logic\n logic = `NOT ${splitResult.logic}`;\n rows.push(...splitResult.rows);\n } else {\n // If leaf-level is reached\n const newLabel = `${labelsSoFar.length + 1}`; // Get a new label for the node\n labelsSoFar.push(newLabel); // Update for the next time\n logic = newLabel;\n rows.push({ ...node.condition, label: newLabel, id: createUID() });\n }\n\n return { logic, rows };\n } catch {\n return { logic: '', rows: [] }; // For safety against any malformed conditions\n }\n}\n\n// Splitter for internal consumption\n/** Splits the input condition tree into a logic-string and a list of condition-rows */\nexport function splitConditionForBuilder(tree: Condition): { logic: string; rows: ConditionRow[] } {\n // Recursively split the tree, starting at the root node\n const splitResult = splitConditionNode(tree, []);\n\n // If the root node is AND/OR, there will be extra parentheses. Remove them\n if (splitResult.logic.startsWith(LPAREN) && splitResult.logic.endsWith(RPAREN)) {\n splitResult.logic = splitResult.logic.slice(1, -1);\n }\n\n return splitResult;\n}\n\n// Splitter for public consumption\n/** Converts the input nested condition into a flat tree with the leaf-conditions and a logic string representing the input tree */\nexport function splitConditionTree(\n tree: Condition,\n labelPrefix: string = ''\n): { logic: string; conditions: { [label: string]: LeafCondition } } {\n // Split using the internal splitter\n const { logic, rows } = splitConditionForBuilder(tree);\n\n // Build a condition-lookup from the ConditionRow objects\n const conditionLookup: { [label: string]: LeafCondition } = {};\n rows.forEach(row => {\n const { id, label, ...leaf } = row; // Discard the excess properties set up by ConditionRow when extending LeafCondition interface\n conditionLookup[`${labelPrefix}${label}`] = leaf;\n });\n\n // Prepend labelPrefix to all numeric tokens in the logic\n let outputLogic = logic;\n if (labelPrefix !== '') {\n outputLogic = logic.replace(/\\d+/g, `${labelPrefix}$&`);\n }\n\n return { logic: outputLogic, conditions: conditionLookup };\n}\n\n/** Checks if the input Condition is simple enough to be displayed in the `Basic mode` without loss of information */\nexport function isBasicModeApplicable(condition: Condition): boolean {\n // If an OR condition is present at the outer level,\n // each child should either be a leaf condition or an AND with all leaf nodes inside\n if (hasProp(condition, 'OR')) {\n return condition.OR.every(node => {\n if (hasProp(node, 'condition')) {\n return true;\n }\n if (hasProp(node, 'AND')) {\n return node.AND.every(subNode => hasProp(subNode, 'condition'));\n }\n return false;\n });\n }\n // If an AND condition is present at the outer level, it can't have any nested levels\n if (hasProp(condition, 'AND')) {\n return condition.AND.every(node => hasProp(node, 'condition'));\n }\n // NOT operator is not supported in Basic-mode\n if (hasProp(condition, 'NOT')) {\n return false;\n }\n // If a single leaf condition is present at the outer level\n return true;\n}\n\n/** Returns a list of operators to show in the Basic mode, using a logicString as the input */\nexport function getBasicModeOperators(logic: string): ('AND' | 'OR')[] {\n const matches = logic.match(/(AND|OR)/g);\n if (matches === null) {\n return [];\n }\n return matches as ('AND' | 'OR')[];\n}\n\n/**\n * Takes a list of operators from between the Basic mode rows and constructs a logic-string out of them\n */\nexport function getLogicFromBasicMode(operatorsList: ('AND' | 'OR')[]): string {\n const logicString = operatorsList.reduce((logic, op, i) => `${logic} ${op} ${i + 2}`, '1');\n return disambiguateLogic(logicString); // Disambiguating the logic string by placing parentheses at appropriate places\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/core/utils.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAE7C,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAI7D,MAAM,GAAG,GAAG,KAAK,CAAC;AAClB,MAAM,EAAE,GAAG,IAAI,CAAC;AAChB,MAAM,GAAG,GAAG,KAAK,CAAC;AAClB,MAAM,MAAM,GAAG,GAAG,CAAC;AACnB,MAAM,MAAM,GAAG,GAAG,CAAC;AAEnB,MAAM,aAAa,GAA6B,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,sEAAsE;AACjJ,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,0BAA0B;AAC1E,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,6CAA6C;AAE1G,MAAM,cAAc,GAAG,CAAC,KAAa,EAAW,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,0CAA0C;AAClH,MAAM,eAAe,GAAG,CAAC,KAAa,EAAW,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,C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MAAM,UAAU,qBAAqB,CAAC,KAAa;IACjD,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IACzC,IAAI,OAAO,KAAK,IAAI,EAAE;QACpB,OAAO,EAAE,CAAC;KACX;IACD,OAAO,OAA2B,CAAC;AACrC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,aAA+B;IACnE,MAAM,WAAW,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IAC3F,OAAO,iBAAiB,CAAC,WAAW,CAAC,CAAC,CAAC,+EAA+E;AACxH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,OAAO,CAAC,KAAc,EAAE,EAAU;IAChD,IAAI,KAAwB,CAAC;IAC7B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QAChB,IAAI,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE;YAClB,KAAK,GAAG,IAAI,CAAC;YACb,OAAO,IAAI,CAAC;SACb;QAED,IAAI,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE;YAC1B,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YAChC,OAAO,CAAC,CAAC,KAAK,CAAC;SAChB;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["// cSpell:words LPAREN LPARENs RPAREN RPARENs\n\nimport { createUID, hasProp } from '@pega/cosmos-react-core';\n\nimport { Condition, ConditionRow, LeafCondition, Field } from '../ConditionBuilder.types';\n\nconst AND = 'AND';\nconst OR = 'OR';\nconst NOT = 'NOT';\nconst LPAREN = '(';\nconst RPAREN = ')';\n\nconst precedenceMap: { [op: string]: number } = { OR: 1, AND: 2, NOT: 3 }; // Operator precedence. NOT has the highest precedence over the others\nconst operatorTokens = new Set([AND, OR, NOT]); // Valid logical operators\nconst validTokens = new Set([AND, OR, NOT, LPAREN, RPAREN]); // Other than these, integer tokens are valid\n\nconst isIntegerToken = (token: string): boolean => /^\\d+$/.test(token); // Checks if the input token is an integer\nconst isOperatorToken = (token: string): boolean => operatorTokens.has(token); // Checks if the input token is an operator\n\n/**\n * Tokenize the input expression.\n * Valid tokens are 'AND', 'OR', 'NOT', '(', ')' and any integer token.\n * Throws an error if an invalid token is found.\n */\nfunction tokenizeExpression(\n expression: string,\n disallowNOT: boolean = false\n): { tokens: string[] } | { error: string } {\n expression = expression.trim().toUpperCase(); // To simplify comparisons below; the tokens AND/OR/NOT are anyways expected to be in uppercase\n const words = expression.match(/[A-Z]+|[0-9]+|_|\\W/g); // Split contiguous alphabets and contiguous numbers into the same token. For all other characters, create a token for each character. Although `_` is not expected to be used, handling it just for completeness\n const tokens: string[] = []; // Final list of valid tokens\n const invalidWords: string[] = []; // Any invalid words are captured here\n\n // `words` will never be null because of the regex we used. Using `!` to indicate the same to TS\n words!.forEach(word => {\n // Ignore white-space characters\n if (word.trim().length > 0) {\n // If it's a token from the above Set or if it's an integer token\n if (isIntegerToken(word) || (validTokens.has(word) && !(word === NOT && disallowNOT))) {\n tokens.push(word);\n } else {\n invalidWords.push(word);\n }\n }\n });\n\n // Return an error if any invalid tokens are present\n if (invalidWords.length > 0) {\n return { error: `Unexpected words/characters: ${invalidWords.join(' ')}` }; // FIXME: TR\n }\n\n return { tokens };\n}\n\n/**\n * Captures any invalid/unexpected token patterns\n * NOTE: This does not expect any invalid tokens to be passed in the input\n * NOTE: This doesn't handle mismatched parentheses. That is handled separately in getPostfixFromInfix\n * Returns an error message about the first invalid sequence present in the input. Returns `null` if none found\n */\nfunction findInvalidPatterns(tokens: string[]): string | null {\n // These patterns are identified based on which token can precede/succeed which.\n // A table with all such permutations can be found in DOC-38200\n\n for (let i = 0; i < tokens.length; i += 1) {\n const NUMBER = 'NUMBER'; // To avoid repeating a string literal\n const token = tokens[i];\n const tokenType = isIntegerToken(token) ? NUMBER : token; // To simplify comparisons below\n\n // The expression can only start with NOT, LPAREN or NUMBER\n if (i === 0 && ![NOT, LPAREN, NUMBER].includes(tokenType)) {\n return `Unexpected \"${token}\" at the beginning.`; // FIXME: TR\n }\n\n // The expression can only end with RPAREN or NUMBER\n if (i === tokens.length - 1 && ![RPAREN, NUMBER].includes(tokenType)) {\n return `Unexpected \"${token}\" at the end.`; // FIXME: TR\n }\n\n // If there is a previous token, check if it is supposed to precede the current token\n if (i > 0) {\n const prevToken = tokens[i - 1];\n const prevTokenType = isIntegerToken(prevToken) ? NUMBER : prevToken; // To simplify comparisons below\n switch (tokenType) {\n // AND/OR/RPAREN can only be preceded by RPAREN or NUMBER\n case AND:\n case OR:\n case RPAREN:\n if (![RPAREN, NUMBER].includes(prevTokenType)) {\n return `Unexpected \"${token}\" after \"${prevToken}\"`; // FIXME: TR\n }\n break;\n\n // NOT/LPAREN/NUMBER can not be preceded by RPAREN or NUMBER\n case NOT:\n case LPAREN:\n case NUMBER:\n if ([RPAREN, NUMBER].includes(prevTokenType)) {\n return `Unexpected \"${token}\" after \"${prevToken}\"`; // FIXME: TR\n }\n break;\n default: // do nothing\n }\n }\n }\n\n // Return null if no invalid sequences\n return null;\n}\n\n/**\n * Converts an input array of Infix tokens into a Postfix array.\n * Uses the ShuntingYard algorithm.\n * NOTE: This does not expect any invalid tokens to be passed in the input\n */\nfunction getPostfixFromInfix(tokens: string[]): { postfixArr: string[] } | { error: string } {\n // Refer these for the ShuntingYard algorithm:\n // * https://brilliant.org/wiki/shunting-yard-algorithm/\n // * https://en.wikipedia.org/wiki/Shunting-yard_algorithm#The_algorithm_in_detail\n const postfixQueue: string[] = []; // Output queue\n const stack: string[] = []; // Operations stack\n\n // While there are tokens to be read\n for (let i = 0; i < tokens.length; i += 1) {\n const token = tokens[i];\n\n if (isIntegerToken(token)) {\n // If it's a number add it to queue\n postfixQueue.push(token);\n } else if (isOperatorToken(token)) {\n // If it's an operator\n // While there's an operator on the top of the stack with greater precedence (or equal precedence and the token is left-associative), pop operators from the stack onto the output queue\n if (token !== NOT) {\n // Unary operators should not cause any operators to be popped from the stack.\n // See http://wcipeg.com/wiki/Shunting_yard_algorithm#Unary_operators\n while (stack.length > 0) {\n const stackTop = stack[stack.length - 1];\n if (isOperatorToken(stackTop) && precedenceMap[stackTop] >= precedenceMap[token]) {\n postfixQueue.push(stack.pop()!);\n } else {\n break;\n }\n }\n }\n // Push the current operator onto the stack\n stack.push(token);\n } else if (token === LPAREN) {\n // If it's a left parenthesis, push it onto the stack\n stack.push(token);\n } else {\n // If it's a right parenthesis (RPAREN)\n // While there's not a left parenthesis at the top of the stack, pop operators from the stack onto the output queue\n while (stack.length > 0) {\n const stackTop = stack[stack.length - 1];\n if (stackTop === LPAREN) break;\n postfixQueue.push(stack.pop()!);\n }\n\n // Pop the left parenthesis from the stack and discard it\n if (stack.length > 0) {\n stack.pop();\n } else {\n // FIXME: TR\n return { error: 'Please fix mismatched parentheses.' }; // If no LPAREN found for the current RPAREN\n }\n }\n }\n\n // While there are operators on the stack, pop them to the queue\n while (stack.length > 0) {\n if (stack[stack.length - 1] === LPAREN) {\n // FIXME: TR\n return { error: 'Please fix mismatched parentheses.' }; // If there were excess LPARENs. (Excess RPARENs are already handled in the above loop. Also, RPARENs are never pushed to the stack)\n }\n postfixQueue.push(stack.pop()!);\n }\n\n return { postfixArr: postfixQueue };\n}\n\n/**\n * Converts an input array of Postfix tokens into a Condition tree.\n * NOTE: This expects a properly formed Postfix array as input\n */\nfunction getConditionFromPostfix(\n postfixArr: string[],\n conditionLookup: { [label: string]: LeafCondition },\n ignoreUnusedLabels: boolean\n): { condition: Condition } | { error: string } {\n // To learn more about the below algorithm, refer this: https://brilliant.org/wiki/shunting-yard-algorithm/#reverse-polish\n const operandsStack: Condition[] = [];\n const labelsWithNoRows: string[] = []; // Labels for which there is no corresponding op in conditionLookup\n const usedLabels: string[] = []; // A list of all labels used in the condition. This is used to warn about any unused operations\n postfixArr.forEach(token => {\n if (isIntegerToken(token)) {\n // If it's a numeric token (leaf condition), push it to the stack\n const conditionRow = conditionLookup[token]; // Identify the corresponding condition row\n operandsStack.push({ condition: conditionRow }); // Push it even if null so that the conversion goes on smoothly and identifies any other issues\n if (!conditionRow) {\n labelsWithNoRows.push(token); // Mark it as missing\n } else {\n usedLabels.push(token); // Mark it as used\n }\n } else if (token === NOT) {\n // If it's the NOT operator\n // Pop an operand, perform the operation and push the result back to the stack\n const operand = operandsStack.pop()!;\n operandsStack.push({ NOT: operand });\n } else {\n // If it's the AND/OR operator\n // Pop two operands, perform the operation and push the result back to the stack\n const operand2 = operandsStack.pop()!;\n const operand1 = operandsStack.pop()!;\n\n // If the inner operation is the same as the current one, consolidate them\n // e.g. `1 AND (2 AND 3)` should be consolidated as `1 AND 2 AND 3`\n // e.g. `1 OR (2 OR 3)` should be consolidated as `1 OR 2 OR 3`\n if (token === 'AND') {\n const operands = [\n ...(hasProp(operand1, 'AND') ? operand1.AND : [operand1]),\n ...(hasProp(operand2, 'AND') ? operand2.AND : [operand2])\n ];\n operandsStack.push({ AND: operands });\n } else {\n const operands = [\n ...(hasProp(operand1, 'OR') ? operand1.OR : [operand1]),\n ...(hasProp(operand2, 'OR') ? operand2.OR : [operand2])\n ];\n operandsStack.push({ OR: operands });\n }\n }\n });\n\n // If any labels are used for which there are no corresponding condition-rows\n if (labelsWithNoRows.length > 0) {\n if (labelsWithNoRows.length === 1) {\n return {\n error: `Condition ${labelsWithNoRows[0]} used in the logical string is not defined.` // FIXME: TR\n };\n }\n return {\n error: `Conditions ${labelsWithNoRows.join(', ')} used in the logical string are not defined.` // FIXME: TR\n };\n }\n\n // Warn if any of the condition rows are unused\n if (!ignoreUnusedLabels) {\n const unusedLabels = Object.keys(conditionLookup).filter(l => !usedLabels.includes(l));\n if (unusedLabels.length > 0) {\n if (unusedLabels.length === 1) {\n return { error: `Condition ${unusedLabels[0]} is not used in the logic expression.` }; // FIXME: TR\n }\n return {\n error: `Conditions ${unusedLabels.join(', ')} are not used in the logic expression.` // FIXME: TR\n };\n }\n }\n\n return { condition: operandsStack[0] };\n}\n\n/** Parses a logic-expression into a condition object. */\nexport function parseLogicString(\n expression: string,\n conditionLookup: { [label: string]: LeafCondition }, // To look up condition-rows from the labels\n disallowNOT: boolean = false,\n ignoreUnusedLabels: boolean = false\n): { condition: Condition } | { error: string } {\n // Handle empty expressions\n if (!expression.trim().length) return { error: 'Please provide a logic expression.' }; // FIXME: TR\n\n // Split the expression into individual tokens\n const tokeningResult = tokenizeExpression(expression, disallowNOT);\n if (hasProp(tokeningResult, 'error')) return tokeningResult;\n const { tokens } = tokeningResult;\n\n // Capture any invalid/unexpected token patterns\n // NOTE: This doesn't handle mismatched parentheses. That is handled below in getPostfixFromInfix\n const badPatternError = findInvalidPatterns(tokens);\n if (badPatternError !== null) return { error: badPatternError };\n\n // Convert the Infix tokens to a Postfix notation using the ShuntingYard algorithm\n const postfixResult = getPostfixFromInfix(tokens);\n if (hasProp(postfixResult, 'error')) return postfixResult;\n const { postfixArr } = postfixResult;\n\n // Convert the Postfix token to a Condition tree\n return getConditionFromPostfix(postfixArr, conditionLookup, ignoreUnusedLabels);\n}\n\n/**\n * Takes a valid logic string and formats it with parentheses at appropriate places to keep things unambiguous\n * For example, `1 AND 2 OR 3` is disambiguated as `(1 AND 2) OR 3`\n * NOTE: This expects only valid logic strings to be passed as an input\n */\nexport function disambiguateLogic(expression: string): string {\n // Split the expression into individual tokens\n const tokeningResult = tokenizeExpression(expression);\n const { tokens } = tokeningResult as { tokens: string[] }; // Only valid expressions are expected as inputs\n\n // Convert the Infix tokens to a Postfix notation using the ShuntingYard algorithm\n const postfixResult = getPostfixFromInfix(tokens);\n const { postfixArr } = postfixResult as { postfixArr: string[] };\n\n // Convert the postfix back to infix with parentheses at appropriate places\n // To learn more about the below algorithm, refer this: https://brilliant.org/wiki/shunting-yard-algorithm/#reverse-polish\n const operandsStack: string[] = [];\n postfixArr.forEach(token => {\n if (isIntegerToken(token)) {\n // If it's a numeric token (leaf condition), push it to the stack\n operandsStack.push(token);\n } else if (token === NOT) {\n // If it's the NOT operator\n // Pop an operand, perform the operation and push the result back to the stack\n const operand = operandsStack.pop()!;\n operandsStack.push(`NOT ${operand}`);\n } else {\n // If it's the AND/OR operator\n // Pop two operands, perform the operation and push the result back to the stack\n let operand2 = operandsStack.pop()!;\n let operand1 = operandsStack.pop()!;\n\n // If the inner operation is the same as the current one, consolidate them\n // e.g. `1 AND (2 AND 3)` should be consolidated as `1 AND 2 AND 3`\n // e.g. `1 OR (2 OR 3)` should be consolidated as `1 OR 2 OR 3`\n if (token === 'AND') {\n // Remove any wrapping parentheses if an operand contains just AND(s)\n if (operand1.startsWith(LPAREN) && !operand1.includes(OR) && !operand1.includes(NOT)) {\n operand1 = operand1.slice(1, -1);\n }\n if (operand2.startsWith(LPAREN) && !operand2.includes(OR) && !operand2.includes(NOT)) {\n operand2 = operand2.slice(1, -1);\n }\n operandsStack.push(`(${operand1} AND ${operand2})`);\n } else {\n // Remove any wrapping parentheses if an operand contains just OR(s)\n if (operand1.startsWith(LPAREN) && !operand1.includes(AND) && !operand1.includes(NOT)) {\n operand1 = operand1.slice(1, -1);\n }\n if (operand2.startsWith(LPAREN) && !operand2.includes(AND) && !operand2.includes(NOT)) {\n operand2 = operand2.slice(1, -1);\n }\n operandsStack.push(`(${operand1} OR ${operand2})`);\n }\n }\n });\n\n // If the root node is AND/OR, there will be extra parentheses. Remove them\n let outputLogic = operandsStack[0];\n if (outputLogic.startsWith(LPAREN) && outputLogic.endsWith(RPAREN)) {\n outputLogic = outputLogic.slice(1, -1);\n }\n return outputLogic;\n}\n\n/**\n * Recursively splits the input condition node into a logic-string and a list of condition-rows\n * NOTE: Returns an empty string and an empty array if the condition is malformed\n */\nfunction splitConditionNode(\n node: Condition,\n labelsSoFar: string[]\n): { logic: string; rows: ConditionRow[] } {\n // Using a try-catch block for safety against any malformed conditions\n try {\n let logic: string;\n const rows: ConditionRow[] = [];\n\n if (hasProp(node, 'AND')) {\n const childStrings: string[] = [];\n node.AND.forEach(n => {\n const splitResult = splitConditionNode(n, labelsSoFar); // Recursively get child rows and logic\n childStrings.push(splitResult.logic);\n rows.push(...splitResult.rows);\n });\n logic = `(${childStrings.join(' AND ')})`;\n } else if (hasProp(node, 'OR')) {\n const childStrings: string[] = [];\n node.OR.forEach(n => {\n const splitResult = splitConditionNode(n, labelsSoFar); // Recursively get child rows and logic\n childStrings.push(splitResult.logic);\n rows.push(...splitResult.rows);\n });\n logic = `(${childStrings.join(' OR ')})`;\n } else if (hasProp(node, 'NOT')) {\n const splitResult = splitConditionNode(node.NOT, labelsSoFar); // Recursively get child rows and logic\n logic = `NOT ${splitResult.logic}`;\n rows.push(...splitResult.rows);\n } else {\n // If leaf-level is reached\n const newLabel = `${labelsSoFar.length + 1}`; // Get a new label for the node\n labelsSoFar.push(newLabel); // Update for the next time\n logic = newLabel;\n rows.push({ ...node.condition, label: newLabel, id: createUID() });\n }\n\n return { logic, rows };\n } catch {\n return { logic: '', rows: [] }; // For safety against any malformed conditions\n }\n}\n\n// Splitter for internal consumption\n/** Splits the input condition tree into a logic-string and a list of condition-rows */\nexport function splitConditionForBuilder(tree: Condition): { logic: string; rows: ConditionRow[] } {\n // Recursively split the tree, starting at the root node\n const splitResult = splitConditionNode(tree, []);\n\n // If the root node is AND/OR, there will be extra parentheses. Remove them\n if (splitResult.logic.startsWith(LPAREN) && splitResult.logic.endsWith(RPAREN)) {\n splitResult.logic = splitResult.logic.slice(1, -1);\n }\n\n return splitResult;\n}\n\n// Splitter for public consumption\n/** Converts the input nested condition into a flat tree with the leaf-conditions and a logic string representing the input tree */\nexport function splitConditionTree(\n tree: Condition,\n labelPrefix: string = ''\n): { logic: string; conditions: { [label: string]: LeafCondition } } {\n // Split using the internal splitter\n const { logic, rows } = splitConditionForBuilder(tree);\n\n // Build a condition-lookup from the ConditionRow objects\n const conditionLookup: { [label: string]: LeafCondition } = {};\n rows.forEach(row => {\n const { id, label, ...leaf } = row; // Discard the excess properties set up by ConditionRow when extending LeafCondition interface\n conditionLookup[`${labelPrefix}${label}`] = leaf;\n });\n\n // Prepend labelPrefix to all numeric tokens in the logic\n let outputLogic = logic;\n if (labelPrefix !== '') {\n outputLogic = logic.replace(/\\d+/g, `${labelPrefix}$&`);\n }\n\n return { logic: outputLogic, conditions: conditionLookup };\n}\n\n/** Checks if the input Condition is simple enough to be displayed in the `Basic mode` without loss of information */\nexport function isBasicModeApplicable(condition: Condition): boolean {\n // If an OR condition is present at the outer level,\n // each child should either be a leaf condition or an AND with all leaf nodes inside\n if (hasProp(condition, 'OR')) {\n return condition.OR.every(node => {\n if (hasProp(node, 'condition')) {\n return true;\n }\n if (hasProp(node, 'AND')) {\n return node.AND.every(subNode => hasProp(subNode, 'condition'));\n }\n return false;\n });\n }\n // If an AND condition is present at the outer level, it can't have any nested levels\n if (hasProp(condition, 'AND')) {\n return condition.AND.every(node => hasProp(node, 'condition'));\n }\n // NOT operator is not supported in Basic-mode\n if (hasProp(condition, 'NOT')) {\n return false;\n }\n // If a single leaf condition is present at the outer level\n return true;\n}\n\n/** Returns a list of operators to show in the Basic mode, using a logicString as the input */\nexport function getBasicModeOperators(logic: string): ('AND' | 'OR')[] {\n const matches = logic.match(/(AND|OR)/g);\n if (matches === null) {\n return [];\n }\n return matches as ('AND' | 'OR')[];\n}\n\n/**\n * Takes a list of operators from between the Basic mode rows and constructs a logic-string out of them\n */\nexport function getLogicFromBasicMode(operatorsList: ('AND' | 'OR')[]): string {\n const logicString = operatorsList.reduce((logic, op, i) => `${logic} ${op} ${i + 2}`, '1');\n return disambiguateLogic(logicString); // Disambiguating the logic string by placing parentheses at appropriate places\n}\n\n/**\n * Takes a list of objects and id of the object to be found and recursively finds and returns the object\n */\nexport function getItem(items: Field[], id: string): Field | undefined {\n let found: Field | undefined;\n items.some(item => {\n if (item.id === id) {\n found = item;\n return true;\n }\n\n if (hasProp(item, 'items')) {\n found = getItem(item.items, id);\n return !!found;\n }\n\n return false;\n });\n\n return found;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ConditionInput.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionInput/ConditionInput.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAKlB,MAAM,OAAO,CAAC;AAGf,OAAO,EAIL,YAAY,EAQb,MAAM,yBAAyB,CAAC;AAUjC,OAAO,EAAsB,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAkCjF,QAAA,MAAM,cAAc,EAAE,iBAAiB,CAAC,mBAAmB,GAAG,YAAY,CA6KzE,CAAC;AAEF,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"ConditionInput.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionInput/ConditionInput.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAKlB,MAAM,OAAO,CAAC;AAGf,OAAO,EAIL,YAAY,EAWb,MAAM,yBAAyB,CAAC;AAUjC,OAAO,EAAsB,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AA0DjF,QAAA,MAAM,cAAc,EAAE,iBAAiB,CAAC,mBAAmB,GAAG,YAAY,CAqMzE,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -1,7 +1,7 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { forwardRef, useState, useEffect } from 'react';
3
- import styled from 'styled-components';
4
- import { CompositeInput, defaultThemeProp, hasProp, Input, NumberInput, RadioButton, RadioButtonGroup, StyledGrid, useI18n } from '@pega/cosmos-react-core';
3
+ import styled, { css } from 'styled-components';
4
+ import { CompositeInput, defaultThemeProp, hasProp, Input, NumberInput, RadioButton, RadioButtonGroup, StyledGrid, useI18n, FieldGroup, StyledFieldGroupLegend, StyledButton } from '@pega/cosmos-react-core';
5
5
  import AtomicCondition, { getInitConditionForLhs } from '../ConditionBuilder/AtomicCondition';
6
6
  import formatCondition from '../ConditionBuilder/core/formatter';
7
7
  const defaultComparators = {
@@ -32,11 +32,27 @@ const StyledConditionRadioGroup = styled(RadioButtonGroup) `
32
32
  } ;
33
33
  `;
34
34
  StyledConditionRadioGroup.defaultProps = defaultThemeProp;
35
- const ConditionInput = forwardRef(({ fieldName, fieldType, condition: conditionProp, fieldLabel, mode, onChange }, ref) => {
35
+ const StyledFieldGroup = styled(FieldGroup)(({ theme: { base: { palette } } }) => {
36
+ return css `
37
+ margin-block-start: 0;
38
+
39
+ ${StyledFieldGroupLegend} {
40
+ border-block-start: 0.0625rem solid ${palette['border-line']};
41
+ padding-block-start: 0.625rem;
42
+
43
+ ${StyledButton} {
44
+ border-color: transparent;
45
+ font-weight: initial;
46
+ }
47
+ }
48
+ `;
49
+ });
50
+ StyledFieldGroup.defaultProps = defaultThemeProp;
51
+ const ConditionInput = forwardRef(({ fieldName, fieldType, condition: conditionProp, fieldLabel, mode, onChange, flat = false }, ref) => {
36
52
  const t = useI18n();
37
53
  const basicType = basicFieldMap[fieldType] ?? fieldType;
38
54
  const fields = [
39
- { name: fieldName, type: basicType, label: fieldLabel }
55
+ { id: fieldName, type: basicType, primary: fieldLabel || fieldName }
40
56
  ];
41
57
  const condition = conditionProp ??
42
58
  (fieldType === 'BOOLEAN'
@@ -118,7 +134,14 @@ const ConditionInput = forwardRef(({ fieldName, fieldType, condition: conditionP
118
134
  onChange(undefined);
119
135
  setNewCondition(condition);
120
136
  };
121
- return (_jsx(_Fragment, { children: showAdvanced ? (_jsx(CompositeInput, { dialog: dialog, label: fieldLabel, onClear: onClear, value: conditionProp ? formatCondition({ condition: conditionProp }, fields, t) : undefined, placeholder: t('all'), ref: ref })) : (defaultControl) }));
137
+ if (flat) {
138
+ return (_jsx(StyledFieldGroup, { name: fieldLabel, collapsible: true, actions: [{ id: 'clear', text: t('clear'), onClick: onClear }], children: showAdvanced ? (_jsx(AtomicCondition, { condition: newCondition ??
139
+ getInitConditionForLhs({ field: fieldName }, fields, new Set(['LITERAL'])), onChange: onChange, fields: fields, itemDirection: 'column', showLhsAsLabel: true, validRhsTypes: new Set(['LITERAL']), indicateErrors: false })) : (defaultControl) }));
140
+ }
141
+ if (showAdvanced) {
142
+ return (_jsx(CompositeInput, { dialog: dialog, label: fieldLabel, onClear: onClear, value: conditionProp ? formatCondition({ condition: conditionProp }, fields, t) : undefined, placeholder: t('all'), ref: ref }));
143
+ }
144
+ return defaultControl;
122
145
  });
123
146
  export default ConditionInput;
124
147
  //# sourceMappingURL=ConditionInput.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ConditionInput.js","sourceRoot":"","sources":["../../../src/components/ConditionInput/ConditionInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EAGV,QAAQ,EAER,SAAS,EACV,MAAM,OAAO,CAAC;AACf,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,OAAO,EACL,cAAc,EAEd,gBAAgB,EAEhB,OAAO,EACP,KAAK,EACL,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,UAAU,EACV,OAAO,EACR,MAAM,yBAAyB,CAAC;AAGjC,OAAO,eAAe,EAAE,EAEtB,sBAAsB,EACvB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,eAAe,MAAM,oCAAoC,CAAC;AAKjE,MAAM,kBAAkB,GAA2C;IACjE,IAAI,EAAE,UAAU;IAChB,KAAK,EAAE,UAAU;IACjB,GAAG,EAAE,UAAU;IACf,KAAK,EAAE,UAAU;IACjB,OAAO,EAAE,IAAI;IACb,OAAO,EAAE,IAAI;IACb,UAAU,EAAE,IAAI;IAChB,QAAQ,EAAE,IAAI;IACd,OAAO,EAAE,SAAS;CACV,CAAC;AAEX,MAAM,aAAa,GAA0C;IAC3D,KAAK,EAAE,MAAM;IACb,GAAG,EAAE,MAAM;IACX,KAAK,EAAE,MAAM;IACb,OAAO,EAAE,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,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,EACrB,GAAG,EAAE,GAAG,GACR,CACH,CAAC,CAAC,CAAC,CACF,cAAc,CACf,GACA,CACJ,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,cAAc,CAAC","sourcesContent":["import {\n forwardRef,\n FunctionComponent,\n PropsWithoutRef,\n useState,\n ChangeEvent,\n useEffect\n} from 'react';\nimport styled from 'styled-components';\n\nimport {\n CompositeInput,\n CompositeInputProps,\n defaultThemeProp,\n ForwardProps,\n hasProp,\n Input,\n NumberInput,\n RadioButton,\n RadioButtonGroup,\n StyledGrid,\n useI18n\n} from '@pega/cosmos-react-core';\n\nimport type { Comparator, FieldType } from '../ConditionBuilder/core/types';\nimport AtomicCondition, {\n AtomicConditionProps,\n getInitConditionForLhs\n} from '../ConditionBuilder/AtomicCondition';\nimport formatCondition from '../ConditionBuilder/core/formatter';\nimport type { LeafCondition } from '../ConditionBuilder/ConditionBuilder.types';\n\nimport { ConditionFieldType, ConditionInputProps } from './ConditionInput.types';\n\nconst defaultComparators: Record<ConditionFieldType, Comparator> = {\n TEXT: 'CONTAINS',\n EMAIL: 'CONTAINS',\n URL: 'CONTAINS',\n PHONE: 'CONTAINS',\n INTEGER: 'EQ',\n DECIMAL: 'EQ',\n PERCENTAGE: 'EQ',\n CURRENCY: 'EQ',\n BOOLEAN: 'IS_TRUE'\n} as const;\n\nconst basicFieldMap: Record<ConditionFieldType, FieldType> = {\n EMAIL: 'TEXT',\n URL: 'TEXT',\n PHONE: 'TEXT',\n INTEGER: 'NUMBER',\n DECIMAL: 'NUMBER',\n PERCENTAGE: 'NUMBER',\n CURRENCY: 'NUMBER',\n TEXT: 'TEXT',\n BOOLEAN: 'BOOLEAN'\n} as const;\n\nconst StyledConditionRadioGroup = styled(RadioButtonGroup)`\n ${StyledGrid} {\n display: inline-flex;\n } ;\n`;\n\nStyledConditionRadioGroup.defaultProps = defaultThemeProp;\n\nconst ConditionInput: FunctionComponent<ConditionInputProps & ForwardProps> = forwardRef(\n (\n {\n fieldName,\n fieldType,\n condition: conditionProp,\n fieldLabel,\n mode,\n onChange\n }: PropsWithoutRef<ConditionInputProps>,\n ref: ConditionInputProps['ref']\n ) => {\n const t = useI18n();\n\n const basicType = basicFieldMap[fieldType] ?? fieldType;\n\n const fields: AtomicConditionProps['fields'] = [\n { name: fieldName, type: basicType, label: fieldLabel }\n ];\n\n const condition =\n conditionProp ??\n (fieldType === 'BOOLEAN'\n ? undefined\n : getInitConditionForLhs({ field: fieldName }, fields, new Set(['LITERAL'])));\n\n const onRadioButtonChange = (value?: boolean) => {\n const updatedCondition: LeafCondition | undefined =\n value === undefined\n ? undefined\n : {\n lhs: { field: fieldName },\n comparator: value ? 'IS_TRUE' : 'IS_FALSE'\n };\n onChange(updatedCondition);\n };\n\n const createConditionForDefaultMode = (value: string) => {\n return {\n lhs: { field: fieldName },\n comparator: defaultComparators[fieldType],\n rhs: { value: basicType === 'NUMBER' ? Number(value) : value }\n };\n };\n\n const rhsValue =\n condition?.rhs && hasProp(condition.rhs, 'value')\n ? condition.rhs.value.toString()\n : undefined;\n\n const [inputValue, setInputValue] = useState(rhsValue);\n\n useEffect(() => {\n setInputValue(rhsValue);\n }, [conditionProp]);\n\n const showAdvanced = mode === 'advanced' && fieldType !== 'BOOLEAN';\n\n let defaultControl: JSX.Element | null = null;\n\n if (!showAdvanced) {\n switch (fieldType) {\n case 'INTEGER':\n case 'DECIMAL':\n case 'PERCENTAGE':\n case 'CURRENCY':\n defaultControl = (\n <NumberInput\n label={fieldLabel}\n ref={ref}\n value={inputValue}\n onChange={setInputValue}\n onBlur={value => {\n onChange(createConditionForDefaultMode(value));\n }}\n numberOfDecimals={fieldType === 'INTEGER' ? 0 : undefined}\n />\n );\n break;\n case 'BOOLEAN':\n defaultControl = (\n <StyledConditionRadioGroup ref={ref} label={fieldLabel} name={fieldName} inline>\n <RadioButton\n label={t('show_all')}\n checked={condition === undefined}\n onChange={() => onRadioButtonChange()}\n />\n <RadioButton\n label={t('boolean_display_true_label')}\n checked={condition?.comparator === 'IS_TRUE'}\n onChange={() => onRadioButtonChange(true)}\n />\n <RadioButton\n label={t('boolean_display_false_label')}\n checked={condition?.comparator === 'IS_FALSE'}\n onChange={() => onRadioButtonChange(false)}\n />\n </StyledConditionRadioGroup>\n );\n break;\n case 'TEXT':\n case 'EMAIL':\n case 'URL':\n case 'PHONE':\n default:\n defaultControl = (\n <Input\n label={fieldLabel}\n ref={ref}\n value={inputValue}\n onChange={(e: ChangeEvent<HTMLInputElement>) => setInputValue(e.target.value)}\n onBlur={(e: ChangeEvent<HTMLInputElement>) =>\n onChange(createConditionForDefaultMode(e.target.value))\n }\n />\n );\n break;\n }\n }\n\n const [newCondition, setNewCondition] = useState<LeafCondition | undefined>(condition);\n\n useEffect(() => {\n setNewCondition(condition);\n }, [conditionProp]);\n\n const dialog: CompositeInputProps<AtomicConditionProps & ForwardProps>['dialog'] = {\n renderer: AtomicCondition,\n rendererProps: {\n condition:\n newCondition ??\n getInitConditionForLhs({ field: fieldName }, fields, new Set(['LITERAL'])),\n fields,\n onChange: setNewCondition,\n itemDirection: 'column',\n showLhsAsLabel: true,\n validRhsTypes: new Set(['LITERAL']),\n indicateErrors: false\n },\n onCancel: ({ close }) => {\n setNewCondition(condition);\n close();\n },\n onApply: ({ close }) => {\n onChange(newCondition);\n close();\n }\n };\n\n const onClear = () => {\n onChange(undefined);\n setNewCondition(condition);\n };\n\n return (\n <>\n {showAdvanced ? (\n <CompositeInput\n dialog={dialog}\n label={fieldLabel}\n onClear={onClear}\n value={\n conditionProp ? formatCondition({ condition: conditionProp }, fields, t) : undefined\n }\n placeholder={t('all')}\n ref={ref}\n />\n ) : (\n defaultControl\n )}\n </>\n );\n }\n);\n\nexport default ConditionInput;\n"]}
1
+ {"version":3,"file":"ConditionInput.js","sourceRoot":"","sources":["../../../src/components/ConditionInput/ConditionInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EAGV,QAAQ,EAER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EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,aAAa,EAAC,QAAQ,EACtB,cAAc,QACd,aAAa,EAAE,IAAI,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,EACnC,cAAc,EAAE,KAAK,GACrB,CACH,CAAC,CAAC,CAAC,CACF,cAAc,CACf,GACgB,CACpB,CAAC;KACH;IACD,IAAI,YAAY,EAAE;QAChB,OAAO,CACL,KAAC,cAAc,IACb,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,OAAO,EAChB,KAAK,EACH,aAAa,CAAC,CAAC,CAAC,eAAe,CAAC,EAAE,SAAS,EAAE,aAAa,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,EAEtF,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,EACrB,GAAG,EAAE,GAAG,GACR,CACH,CAAC;KACH;IACD,OAAO,cAAc,CAAC;AACxB,CAAC,CACF,CAAC;AAEF,eAAe,cAAc,CAAC","sourcesContent":["import {\n forwardRef,\n FunctionComponent,\n PropsWithoutRef,\n useState,\n ChangeEvent,\n useEffect\n} from 'react';\nimport styled, { css } from 'styled-components';\n\nimport {\n CompositeInput,\n CompositeInputProps,\n defaultThemeProp,\n ForwardProps,\n hasProp,\n Input,\n NumberInput,\n RadioButton,\n RadioButtonGroup,\n StyledGrid,\n useI18n,\n FieldGroup,\n StyledFieldGroupLegend,\n StyledButton\n} from '@pega/cosmos-react-core';\n\nimport type { Comparator, FieldType } from '../ConditionBuilder/core/types';\nimport AtomicCondition, {\n AtomicConditionProps,\n getInitConditionForLhs\n} from '../ConditionBuilder/AtomicCondition';\nimport formatCondition from '../ConditionBuilder/core/formatter';\nimport type { LeafCondition } from '../ConditionBuilder/ConditionBuilder.types';\n\nimport { ConditionFieldType, ConditionInputProps } from './ConditionInput.types';\n\nconst defaultComparators: Record<ConditionFieldType, Comparator> = {\n TEXT: 'CONTAINS',\n EMAIL: 'CONTAINS',\n URL: 'CONTAINS',\n PHONE: 'CONTAINS',\n INTEGER: 'EQ',\n DECIMAL: 'EQ',\n PERCENTAGE: 'EQ',\n CURRENCY: 'EQ',\n BOOLEAN: 'IS_TRUE'\n} as const;\n\nconst basicFieldMap: Record<ConditionFieldType, FieldType> = {\n EMAIL: 'TEXT',\n URL: 'TEXT',\n PHONE: 'TEXT',\n INTEGER: 'NUMBER',\n DECIMAL: 'NUMBER',\n PERCENTAGE: 'NUMBER',\n CURRENCY: 'NUMBER',\n TEXT: 'TEXT',\n BOOLEAN: 'BOOLEAN'\n} as const;\n\nconst StyledConditionRadioGroup = styled(RadioButtonGroup)`\n ${StyledGrid} {\n display: inline-flex;\n } ;\n`;\n\nStyledConditionRadioGroup.defaultProps = defaultThemeProp;\n\nconst StyledFieldGroup = styled(FieldGroup)(\n ({\n theme: {\n base: { palette }\n }\n }) => {\n return css`\n margin-block-start: 0;\n\n ${StyledFieldGroupLegend} {\n border-block-start: 0.0625rem solid ${palette['border-line']};\n padding-block-start: 0.625rem;\n\n ${StyledButton} {\n border-color: transparent;\n font-weight: initial;\n }\n }\n `;\n }\n);\n\nStyledFieldGroup.defaultProps = defaultThemeProp;\n\nconst ConditionInput: FunctionComponent<ConditionInputProps & ForwardProps> = forwardRef(\n (\n {\n fieldName,\n fieldType,\n condition: conditionProp,\n fieldLabel,\n mode,\n onChange,\n flat = false\n }: PropsWithoutRef<ConditionInputProps>,\n ref: ConditionInputProps['ref']\n ) => {\n const t = useI18n();\n\n const basicType = basicFieldMap[fieldType] ?? fieldType;\n\n const fields: AtomicConditionProps['fields'] = [\n { id: fieldName, type: basicType, primary: fieldLabel || fieldName }\n ];\n\n const condition =\n conditionProp ??\n (fieldType === 'BOOLEAN'\n ? undefined\n : getInitConditionForLhs({ field: fieldName }, fields, new Set(['LITERAL'])));\n\n const onRadioButtonChange = (value?: boolean) => {\n const updatedCondition: LeafCondition | undefined =\n value === undefined\n ? undefined\n : {\n lhs: { field: fieldName },\n comparator: value ? 'IS_TRUE' : 'IS_FALSE'\n };\n onChange(updatedCondition);\n };\n\n const createConditionForDefaultMode = (value: string) => {\n return {\n lhs: { field: fieldName },\n comparator: defaultComparators[fieldType],\n rhs: { value: basicType === 'NUMBER' ? Number(value) : value }\n };\n };\n\n const rhsValue =\n condition?.rhs && hasProp(condition.rhs, 'value')\n ? condition.rhs.value.toString()\n : undefined;\n\n const [inputValue, setInputValue] = useState(rhsValue);\n\n useEffect(() => {\n setInputValue(rhsValue);\n }, [conditionProp]);\n\n const showAdvanced = mode === 'advanced' && fieldType !== 'BOOLEAN';\n\n let defaultControl: JSX.Element | null = null;\n\n if (!showAdvanced) {\n switch (fieldType) {\n case 'INTEGER':\n case 'DECIMAL':\n case 'PERCENTAGE':\n case 'CURRENCY':\n defaultControl = (\n <NumberInput\n label={fieldLabel}\n ref={ref}\n value={inputValue}\n onChange={setInputValue}\n onBlur={value => {\n onChange(createConditionForDefaultMode(value));\n }}\n numberOfDecimals={fieldType === 'INTEGER' ? 0 : undefined}\n />\n );\n break;\n case 'BOOLEAN':\n defaultControl = (\n <StyledConditionRadioGroup ref={ref} label={fieldLabel} name={fieldName} inline>\n <RadioButton\n label={t('show_all')}\n checked={condition === undefined}\n onChange={() => onRadioButtonChange()}\n />\n <RadioButton\n label={t('boolean_display_true_label')}\n checked={condition?.comparator === 'IS_TRUE'}\n onChange={() => onRadioButtonChange(true)}\n />\n <RadioButton\n label={t('boolean_display_false_label')}\n checked={condition?.comparator === 'IS_FALSE'}\n onChange={() => onRadioButtonChange(false)}\n />\n </StyledConditionRadioGroup>\n );\n break;\n case 'TEXT':\n case 'EMAIL':\n case 'URL':\n case 'PHONE':\n default:\n defaultControl = (\n <Input\n label={fieldLabel}\n ref={ref}\n value={inputValue}\n onChange={(e: ChangeEvent<HTMLInputElement>) => setInputValue(e.target.value)}\n onBlur={(e: ChangeEvent<HTMLInputElement>) =>\n onChange(createConditionForDefaultMode(e.target.value))\n }\n />\n );\n break;\n }\n }\n\n const [newCondition, setNewCondition] = useState<LeafCondition | undefined>(condition);\n\n useEffect(() => {\n setNewCondition(condition);\n }, [conditionProp]);\n\n const dialog: CompositeInputProps<AtomicConditionProps & ForwardProps>['dialog'] = {\n renderer: AtomicCondition,\n rendererProps: {\n condition:\n newCondition ??\n getInitConditionForLhs({ field: fieldName }, fields, new Set(['LITERAL'])),\n fields,\n onChange: setNewCondition,\n itemDirection: 'column',\n showLhsAsLabel: true,\n validRhsTypes: new Set(['LITERAL']),\n indicateErrors: false\n },\n onCancel: ({ close }) => {\n setNewCondition(condition);\n close();\n },\n onApply: ({ close }) => {\n onChange(newCondition);\n close();\n }\n };\n\n const onClear = () => {\n onChange(undefined);\n setNewCondition(condition);\n };\n\n if (flat) {\n return (\n <StyledFieldGroup\n name={fieldLabel}\n collapsible\n actions={[{ id: 'clear', text: t('clear'), onClick: onClear }]}\n >\n {showAdvanced ? (\n <AtomicCondition\n condition={\n newCondition ??\n getInitConditionForLhs({ field: fieldName }, fields, new Set(['LITERAL']))\n }\n onChange={onChange}\n fields={fields}\n itemDirection='column'\n showLhsAsLabel\n validRhsTypes={new Set(['LITERAL'])}\n indicateErrors={false}\n />\n ) : (\n defaultControl\n )}\n </StyledFieldGroup>\n );\n }\n if (showAdvanced) {\n return (\n <CompositeInput\n dialog={dialog}\n label={fieldLabel}\n onClear={onClear}\n value={\n conditionProp ? formatCondition({ condition: conditionProp }, fields, t) : undefined\n }\n placeholder={t('all')}\n ref={ref}\n />\n );\n }\n return defaultControl;\n }\n);\n\nexport default ConditionInput;\n"]}
@@ -17,5 +17,7 @@ export interface ConditionInputProps {
17
17
  onChange: (condition?: LeafCondition) => void;
18
18
  /** Reference to the input element. */
19
19
  ref?: Ref<HTMLInputElement>;
20
+ /** Whether advanced view should be wrapped in popup or just flat. */
21
+ flat?: boolean;
20
22
  }
21
23
  //# sourceMappingURL=ConditionInput.types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ConditionInput.types.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionInput/ConditionInput.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,oBAAY,kBAAkB,GAC1B,MAAM,GACN,OAAO,GACP,KAAK,GACL,OAAO,GACP,SAAS,GACT,SAAS,GACT,YAAY,GACZ,SAAS,GACT,UAAU,CAAC;AAEf,oBAAY,kBAAkB,GAAG,SAAS,GAAG,UAAU,CAAC;AAExD,MAAM,WAAW,mBAAmB;IAClC,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,SAAS,EAAE,kBAAkB,CAAC;IAC9B,wEAAwE;IACxE,IAAI,EAAE,kBAAkB,CAAC;IACzB,2BAA2B;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uBAAuB;IACvB,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,wDAAwD;IACxD,QAAQ,EAAE,CAAC,SAAS,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;IAC9C,sCAAsC;IACtC,GAAG,CAAC,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC;CAC7B"}
1
+ {"version":3,"file":"ConditionInput.types.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionInput/ConditionInput.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,oBAAY,kBAAkB,GAC1B,MAAM,GACN,OAAO,GACP,KAAK,GACL,OAAO,GACP,SAAS,GACT,SAAS,GACT,YAAY,GACZ,SAAS,GACT,UAAU,CAAC;AAEf,oBAAY,kBAAkB,GAAG,SAAS,GAAG,UAAU,CAAC;AAExD,MAAM,WAAW,mBAAmB;IAClC,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,SAAS,EAAE,kBAAkB,CAAC;IAC9B,wEAAwE;IACxE,IAAI,EAAE,kBAAkB,CAAC;IACzB,2BAA2B;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uBAAuB;IACvB,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,wDAAwD;IACxD,QAAQ,EAAE,CAAC,SAAS,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;IAC9C,sCAAsC;IACtC,GAAG,CAAC,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAC5B,qEAAqE;IACrE,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB"}
@@ -1 +1 @@
1
- {"version":3,"file":"ConditionInput.types.js","sourceRoot":"","sources":["../../../src/components/ConditionInput/ConditionInput.types.ts"],"names":[],"mappings":"","sourcesContent":["import { Ref } from 'react';\n\nimport { LeafCondition } from '../ConditionBuilder';\n\nexport type ConditionFieldType =\n | 'TEXT'\n | 'EMAIL'\n | 'URL'\n | 'PHONE'\n | 'INTEGER'\n | 'DECIMAL'\n | 'PERCENTAGE'\n | 'BOOLEAN'\n | 'CURRENCY';\n\nexport type ConditionInputMode = 'default' | 'advanced';\n\nexport interface ConditionInputProps {\n /** Name of the field the condition is created for. */\n fieldName: string;\n /** Type of the field the condition is created for. */\n fieldType: ConditionFieldType;\n /** Display mode. Either with default comparator or the full-fledged. */\n mode: ConditionInputMode;\n /** Label for the input. */\n fieldLabel?: string;\n /** Condition value. */\n condition?: LeafCondition;\n /** Callback invoked when user changes the condition. */\n onChange: (condition?: LeafCondition) => void;\n /** Reference to the input element. */\n ref?: Ref<HTMLInputElement>;\n}\n"]}
1
+ {"version":3,"file":"ConditionInput.types.js","sourceRoot":"","sources":["../../../src/components/ConditionInput/ConditionInput.types.ts"],"names":[],"mappings":"","sourcesContent":["import { Ref } from 'react';\n\nimport { LeafCondition } from '../ConditionBuilder';\n\nexport type ConditionFieldType =\n | 'TEXT'\n | 'EMAIL'\n | 'URL'\n | 'PHONE'\n | 'INTEGER'\n | 'DECIMAL'\n | 'PERCENTAGE'\n | 'BOOLEAN'\n | 'CURRENCY';\n\nexport type ConditionInputMode = 'default' | 'advanced';\n\nexport interface ConditionInputProps {\n /** Name of the field the condition is created for. */\n fieldName: string;\n /** Type of the field the condition is created for. */\n fieldType: ConditionFieldType;\n /** Display mode. Either with default comparator or the full-fledged. */\n mode: ConditionInputMode;\n /** Label for the input. */\n fieldLabel?: string;\n /** Condition value. */\n condition?: LeafCondition;\n /** Callback invoked when user changes the condition. */\n onChange: (condition?: LeafCondition) => void;\n /** Reference to the input element. */\n ref?: Ref<HTMLInputElement>;\n /** Whether advanced view should be wrapped in popup or just flat. */\n flat?: boolean;\n}\n"]}
@@ -1,6 +1,11 @@
1
1
  import { FunctionComponent } from 'react';
2
2
  import { ForwardProps } from '@pega/cosmos-react-core';
3
+ import { Condition } from '../ConditionBuilder/ConditionBuilder.types';
3
4
  import { PromotedFiltersProps } from './PromotedFilters.types';
4
- declare const PromotedFilters: FunctionComponent<PromotedFiltersProps & ForwardProps>;
5
+ export interface FilterModalProps extends Pick<PromotedFiltersProps, 'filters' | 'condition'> {
6
+ /** Callback fired on apply of any of the filters */
7
+ onApply?: (condition: Condition | undefined) => void;
8
+ }
9
+ export declare const PromotedFilters: FunctionComponent<PromotedFiltersProps & ForwardProps>;
5
10
  export default PromotedFilters;
6
11
  //# sourceMappingURL=PromotedFilters.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PromotedFilters.d.ts","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,iBAAiB,EAAmB,MAAM,OAAO,CAAC;AAGvE,OAAO,EAAkC,YAAY,EAAW,MAAM,yBAAyB,CAAC;AAMhG,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAkB/D,QAAA,MAAM,eAAe,EAAE,iBAAiB,CAAC,oBAAoB,GAAG,YAAY,CAqE3E,CAAC;AAEF,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"PromotedFilters.d.ts","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAOlB,MAAM,OAAO,CAAC;AAEf,OAAO,EAGL,YAAY,EAMb,MAAM,yBAAyB,CAAC;AAMjC,OAAO,EAAE,SAAS,EAAiB,MAAM,4CAA4C,CAAC;AAItF,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAO/D,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAAC,oBAAoB,EAAE,SAAS,GAAG,WAAW,CAAC;IAC3F,oDAAoD;IACpD,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,KAAK,IAAI,CAAC;CACtD;AA+GD,eAAO,MAAM,eAAe,EAAE,iBAAiB,CAAC,oBAAoB,GAAG,YAAY,CAkHlF,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -1,23 +1,13 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { forwardRef } from 'react';
3
- import styled, { css } from 'styled-components';
4
- import { Button, defaultThemeProp, Flex, useI18n } from '@pega/cosmos-react-core';
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { forwardRef, useCallback, useContext, useEffect, useRef, useState } from 'react';
3
+ import { Button, Flex, Icon, Modal, useBreakpoint, useI18n } from '@pega/cosmos-react-core';
4
+ import { ModalContext, ModalManagerContext } from '@pega/cosmos-react-core/lib/components/Modal/Contexts';
5
5
  import { splitConditionForBuilder } from '../ConditionBuilder/core/utils';
6
6
  import ConditionInput from '../ConditionInput';
7
- const StyledPromotedFilters = styled.div(({ theme }) => {
8
- return css `
9
- border-radius: ${theme.components.card['border-radius']};
10
- background-color: ${theme.base.palette['secondary-background']};
11
- `;
12
- });
13
- StyledPromotedFilters.defaultProps = defaultThemeProp;
14
- const StyledClearAllButton = styled(Button) `
15
- margin-top: 0.625rem;
16
- white-space: nowrap;
17
- `;
18
- StyledClearAllButton.defaultProps = defaultThemeProp;
19
- const PromotedFilters = forwardRef(({ filters, condition, onChange }, ref) => {
20
- const t = useI18n();
7
+ import { StyledPromotedFilters, StyledClearAllButton, StyledTextWithEllipsis } from './PromotedFilters.styles';
8
+ const PromotedFiltersContent = forwardRef(({ filters, condition, onChange, orientation: orientationProp = 'horizontal' }, ref) => {
9
+ const isSmallOrAbove = useBreakpoint('sm');
10
+ const orientation = isSmallOrAbove && orientationProp === 'horizontal' ? 'horizontal' : 'vertical';
21
11
  // map of Conditions indexed by field name
22
12
  const conditionsMap = condition
23
13
  ? splitConditionForBuilder(condition).rows.reduce((result, item) => {
@@ -38,13 +28,66 @@ const PromotedFilters = forwardRef(({ filters, condition, onChange }, ref) => {
38
28
  })
39
29
  };
40
30
  };
41
- return (_jsxs(Flex, { as: StyledPromotedFilters, container: { alignItems: 'start', justify: 'between', pad: 2, gap: 2 }, ref: ref, children: [_jsx(Flex, { container: { wrap: 'wrap', gap: 2 }, children: filters.map(filter => {
42
- return (_jsx(ConditionInput, { fieldName: filter.fieldName, fieldType: filter.fieldType, mode: filter.mode, fieldLabel: filter.fieldLabel ?? filter.fieldName, condition: conditionsMap[filter.fieldName], onChange: (newCondition) => {
43
- onChange(createUpdatedCondition(filter.fieldName, newCondition));
44
- } }, filter.fieldName));
45
- }) }), _jsx("div", { children: _jsx(StyledClearAllButton, { variant: 'simple', onClick: () => {
31
+ return (_jsx(Flex, { container: {
32
+ gap: 2,
33
+ direction: orientation === 'vertical' ? 'column' : 'row',
34
+ wrap: 'wrap'
35
+ }, ref: ref, children: filters.map(({ fieldName, fieldType, mode, fieldLabel }) => {
36
+ return (_jsx(ConditionInput, { fieldName: fieldName, fieldType: fieldType, mode: mode, fieldLabel: fieldLabel ?? fieldName, condition: conditionsMap[fieldName], flat: orientation === 'vertical', onChange: (newCondition) => {
37
+ onChange(createUpdatedCondition(fieldName, newCondition));
38
+ } }, fieldName));
39
+ }) }));
40
+ });
41
+ const FilterModal = ({ filters, condition, onApply }) => {
42
+ const t = useI18n();
43
+ const { dismiss } = useContext(ModalContext);
44
+ const [newCondition, setNewCondition] = useState(condition);
45
+ const onApplyClick = useCallback(() => {
46
+ onApply?.(newCondition);
47
+ dismiss();
48
+ }, [newCondition, onApply]);
49
+ const actions = (_jsx(Button, { variant: 'primary', onClick: onApplyClick, children: t('apply') }));
50
+ return (_jsxs(Modal, { heading: t('filters'), actions: actions, stretch: true, children: [_jsx(Flex, { container: { justify: 'end' }, children: _jsx(StyledClearAllButton, { variant: 'simple', onClick: () => {
51
+ setNewCondition(undefined);
52
+ }, children: t('clear_all') }) }), _jsx(PromotedFiltersContent, { filters: filters, condition: newCondition, onChange: setNewCondition, orientation: 'vertical' })] }));
53
+ };
54
+ export const PromotedFilters = forwardRef(({ filters, condition, onChange, orientation = 'horizontal' }, ref) => {
55
+ const t = useI18n();
56
+ const isSmallOrAbove = useBreakpoint('sm');
57
+ const { create } = useContext(ModalManagerContext);
58
+ const modalMethods = useRef();
59
+ // map of Conditions indexed by field name
60
+ const conditionsCount = condition ? splitConditionForBuilder(condition).rows.length : undefined;
61
+ useEffect(() => {
62
+ modalMethods.current?.update({
63
+ filters,
64
+ condition
65
+ });
66
+ }, [filters, condition]);
67
+ const openFiltersModal = () => {
68
+ modalMethods.current = create(FilterModal, {
69
+ filters,
70
+ condition,
71
+ onApply: onChange
72
+ });
73
+ };
74
+ return (_jsx(Flex, { as: StyledPromotedFilters, container: {
75
+ alignItems: orientation === 'horizontal' && isSmallOrAbove ? 'start' : undefined,
76
+ justify: 'between',
77
+ direction: !isSmallOrAbove || orientation === 'horizontal' ? 'row' : 'column',
78
+ pad: 2,
79
+ gap: 2
80
+ }, ref: ref, children: isSmallOrAbove ? (_jsxs(_Fragment, { children: [orientation === 'vertical' && (_jsxs(Flex, { container: {
81
+ justify: 'between',
82
+ alignItems: 'center',
83
+ pad: [0, 0, 1, 0]
84
+ }, children: [_jsx(StyledTextWithEllipsis, { variant: 'h3', children: t('filters') }), _jsx(Button, { variant: 'simple', onClick: () => {
85
+ onChange();
86
+ }, children: t('clear_all') })] })), _jsx(PromotedFiltersContent, { filters: filters, onChange: onChange, condition: condition, orientation: orientation, ref: ref }), orientation === 'horizontal' && (_jsx("div", { children: _jsx(StyledClearAllButton, { variant: 'simple', onClick: () => {
87
+ onChange();
88
+ }, children: t('promoted_filters_clear_all_button_label') }) }))] })) : (_jsxs(_Fragment, { children: [_jsx(Button, { type: 'button', variant: 'text', onClick: openFiltersModal, children: _jsxs(Flex, { container: { alignItems: 'center', gap: 0.5 }, forwardedAs: 'span', children: [_jsx(Icon, { name: 'filter' }), _jsxs("span", { children: [t('filters'), conditionsCount && `\u00a0(${conditionsCount})`] })] }) }), _jsx(Button, { variant: 'simple', onClick: () => {
46
89
  onChange();
47
- }, children: t('promoted_filters_clear_all_button_label') }) })] }));
90
+ }, children: t('clear_all') })] })) }));
48
91
  });
49
92
  export default PromotedFilters;
50
93
  //# sourceMappingURL=PromotedFilters.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PromotedFilters.js","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAsC,MAAM,OAAO,CAAC;AACvE,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,IAAI,EAAgB,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAGhG,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,cAAc,MAAM,mBAAmB,CAAC;AAI/C,MAAM,qBAAqB,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IACrD,OAAO,GAAG,CAAA;qBACS,KAAK,CAAC,UAAU,CAAC,IAAI,CAA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O,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EACtE,GAAG,EAAE,GAAG,aAER,KAAC,IAAI,IAAC,SAAS,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,YACtC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;oBACpB,OAAO,CACL,KAAC,cAAc,IAEb,SAAS,EAAE,MAAM,CAAC,SAAS,EAC3B,SAAS,EAAE,MAAM,CAAC,SAAS,EAC3B,IAAI,EAAE,MAAM,CAAC,IAAI,EACjB,UAAU,EAAE,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,SAAS,EACjD,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,SAAS,CAAC,EAC1C,QAAQ,EAAE,CAAC,YAA4B,EAAE,EAAE;4BACzC,QAAQ,CAAC,sBAAsB,CAAC,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC;wBACnE,CAAC,IARI,MAAM,CAAC,SAAS,CASrB,CACH,CAAC;gBACJ,CAAC,CAAC,GACG,EAEP,wBACE,KAAC,oBAAoB,IACnB,OAAO,EAAC,QAAQ,EAChB,OAAO,EAAE,GAAG,EAAE;wBACZ,QAAQ,EAAE,CAAC;oBACb,CAAC,YAEA,CAAC,CAAC,yCAAyC,CAAC,GACxB,GACnB,IACD,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { forwardRef, FunctionComponent, PropsWithoutRef } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport { Button, defaultThemeProp, Flex, ForwardProps, useI18n } from '@pega/cosmos-react-core';\n\nimport { Condition, LeafCondition } from '../ConditionBuilder/ConditionBuilder.types';\nimport { splitConditionForBuilder } from '../ConditionBuilder/core/utils';\nimport ConditionInput from '../ConditionInput';\n\nimport { PromotedFiltersProps } from './PromotedFilters.types';\n\nconst StyledPromotedFilters = styled.div(({ theme }) => {\n return css`\n border-radius: ${theme.components.card['border-radius']};\n background-color: ${theme.base.palette['secondary-background']};\n `;\n});\n\nStyledPromotedFilters.defaultProps = defaultThemeProp;\n\nconst StyledClearAllButton = styled(Button)`\n margin-top: 0.625rem;\n white-space: nowrap;\n`;\n\nStyledClearAllButton.defaultProps = defaultThemeProp;\n\nconst PromotedFilters: FunctionComponent<PromotedFiltersProps & ForwardProps> = forwardRef(\n (\n { filters, condition, onChange }: PropsWithoutRef<PromotedFiltersProps>,\n ref: PromotedFiltersProps['ref']\n ) => {\n const t = useI18n();\n\n // map of Conditions indexed by field name\n const conditionsMap = condition\n ? splitConditionForBuilder(condition).rows.reduce(\n (result: { [key: string]: LeafCondition }, item) => {\n result[item.lhs.field] = item;\n return result;\n },\n {}\n )\n : {};\n\n const createUpdatedCondition = (key: string, newCondition?: LeafCondition) => {\n if (newCondition) {\n conditionsMap[key] = newCondition;\n } else {\n delete conditionsMap[key];\n }\n\n return {\n AND: Object.values(conditionsMap).map(c => {\n return { condition: c } as Condition;\n })\n };\n };\n\n return (\n <Flex\n as={StyledPromotedFilters}\n container={{ alignItems: 'start', justify: 'between', pad: 2, gap: 2 }}\n ref={ref}\n >\n <Flex container={{ wrap: 'wrap', gap: 2 }}>\n {filters.map(filter => {\n return (\n <ConditionInput\n key={filter.fieldName}\n fieldName={filter.fieldName}\n fieldType={filter.fieldType}\n mode={filter.mode}\n fieldLabel={filter.fieldLabel ?? filter.fieldName}\n condition={conditionsMap[filter.fieldName]}\n onChange={(newCondition?: LeafCondition) => {\n onChange(createUpdatedCondition(filter.fieldName, newCondition));\n }}\n />\n );\n })}\n </Flex>\n\n <div>\n <StyledClearAllButton\n variant='simple'\n onClick={() => {\n onChange();\n }}\n >\n {t('promoted_filters_clear_all_button_label')}\n </StyledClearAllButton>\n </div>\n </Flex>\n );\n }\n);\n\nexport default PromotedFilters;\n"]}
1
+ {"version":3,"file":"PromotedFilters.js","sourceRoot":"","sources":["../../../src/components/PromotedF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gCACZ,QAAQ,EAAE,CAAC;4BACb,CAAC,YAEA,CAAC,CAAC,WAAW,CAAC,GACR,IACJ,CACR,EAED,KAAC,sBAAsB,IACrB,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,WAAW,EACxB,GAAG,EAAE,GAAG,GACR,EAED,WAAW,KAAK,YAAY,IAAI,CAC/B,wBACE,KAAC,oBAAoB,IACnB,OAAO,EAAC,QAAQ,EAChB,OAAO,EAAE,GAAG,EAAE;4BACZ,QAAQ,EAAE,CAAC;wBACb,CAAC,YAEA,CAAC,CAAC,yCAAyC,CAAC,GACxB,GACnB,CACP,IACA,CACJ,CAAC,CAAC,CAAC,CACF,8BACE,KAAC,MAAM,IAAC,IAAI,EAAC,QAAQ,EAAC,OAAO,EAAC,MAAM,EAAC,OAAO,EAAE,gBAAgB,YAC5D,MAAC,IAAI,IAAC,SAAS,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,WAAW,EAAC,MAAM,aACrE,KAAC,IAAI,IAAC,IAAI,EAAC,QAAQ,GAAG,EACtB,2BACG,CAAC,CAAC,SAAS,CAAC,EACZ,eAAe,IAAI,UAAU,eAAe,GAAG,IAC3C,IACF,GACA,EACT,KAAC,MAAM,IACL,OAAO,EAAC,QAAQ,EAChB,OAAO,EAAE,GAAG,EAAE;wBACZ,QAAQ,EAAE,CAAC;oBACb,CAAC,YAEA,CAAC,CAAC,WAAW,CAAC,GACR,IACR,CACJ,GACI,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import {\n forwardRef,\n FunctionComponent,\n PropsWithoutRef,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState\n} from 'react';\n\nimport {\n Button,\n Flex,\n ForwardProps,\n Icon,\n Modal,\n ModalMethods,\n useBreakpoint,\n useI18n\n} from '@pega/cosmos-react-core';\nimport {\n ModalContext,\n ModalManagerContext\n} from '@pega/cosmos-react-core/lib/components/Modal/Contexts';\n\nimport { Condition, LeafCondition } from '../ConditionBuilder/ConditionBuilder.types';\nimport { splitConditionForBuilder } from '../ConditionBuilder/core/utils';\nimport ConditionInput from '../ConditionInput';\n\nimport { PromotedFiltersProps } from './PromotedFilters.types';\nimport {\n StyledPromotedFilters,\n StyledClearAllButton,\n StyledTextWithEllipsis\n} from './PromotedFilters.styles';\n\nexport interface FilterModalProps extends Pick<PromotedFiltersProps, 'filters' | 'condition'> {\n /** Callback fired on apply of any of the filters */\n onApply?: (condition: Condition | undefined) => void;\n}\n\nconst PromotedFiltersContent: FunctionComponent<PromotedFiltersProps & ForwardProps> = forwardRef(\n (\n {\n filters,\n condition,\n onChange,\n orientation: orientationProp = 'horizontal'\n }: PropsWithoutRef<PromotedFiltersProps>,\n ref: PromotedFiltersProps['ref']\n ) => {\n const isSmallOrAbove = useBreakpoint('sm');\n const orientation =\n isSmallOrAbove && orientationProp === 'horizontal' ? 'horizontal' : 'vertical';\n\n // map of Conditions indexed by field name\n const conditionsMap = condition\n ? splitConditionForBuilder(condition).rows.reduce(\n (result: { [key: string]: LeafCondition }, item) => {\n result[item.lhs.field] = item;\n return result;\n },\n {}\n )\n : {};\n\n const createUpdatedCondition = (key: string, newCondition?: LeafCondition) => {\n if (newCondition) {\n conditionsMap[key] = newCondition;\n } else {\n delete conditionsMap[key];\n }\n\n return {\n AND: Object.values(conditionsMap).map(c => {\n return { condition: c } as Condition;\n })\n };\n };\n\n return (\n <Flex\n container={{\n gap: 2,\n direction: orientation === 'vertical' ? 'column' : 'row',\n wrap: 'wrap'\n }}\n ref={ref}\n >\n {filters.map(({ fieldName, fieldType, mode, fieldLabel }) => {\n return (\n <ConditionInput\n key={fieldName}\n fieldName={fieldName}\n fieldType={fieldType}\n mode={mode}\n fieldLabel={fieldLabel ?? fieldName}\n condition={conditionsMap[fieldName]}\n flat={orientation === 'vertical'}\n onChange={(newCondition?: LeafCondition) => {\n onChange(createUpdatedCondition(fieldName, newCondition));\n }}\n />\n );\n })}\n </Flex>\n );\n }\n);\n\nconst FilterModal = ({ filters, condition, onApply }: FilterModalProps) => {\n const t = useI18n();\n\n const { dismiss } = useContext(ModalContext);\n const [newCondition, setNewCondition] = useState<Condition | undefined>(condition);\n\n const onApplyClick = useCallback(() => {\n onApply?.(newCondition);\n dismiss();\n }, [newCondition, onApply]);\n\n const actions = (\n <Button variant='primary' onClick={onApplyClick}>\n {t('apply')}\n </Button>\n );\n\n return (\n <Modal heading={t('filters')} actions={actions} stretch>\n <Flex container={{ justify: 'end' }}>\n <StyledClearAllButton\n variant='simple'\n onClick={() => {\n setNewCondition(undefined);\n }}\n >\n {t('clear_all')}\n </StyledClearAllButton>\n </Flex>\n\n <PromotedFiltersContent\n filters={filters}\n condition={newCondition}\n onChange={setNewCondition}\n orientation='vertical'\n />\n </Modal>\n );\n};\n\nexport const PromotedFilters: FunctionComponent<PromotedFiltersProps & ForwardProps> = forwardRef(\n (\n {\n filters,\n condition,\n onChange,\n orientation = 'horizontal'\n }: PropsWithoutRef<PromotedFiltersProps>,\n ref: PromotedFiltersProps['ref']\n ) => {\n const t = useI18n();\n\n const isSmallOrAbove = useBreakpoint('sm');\n\n const { create } = useContext(ModalManagerContext);\n const modalMethods = useRef<ModalMethods<FilterModalProps>>();\n\n // map of Conditions indexed by field name\n const conditionsCount = condition ? splitConditionForBuilder(condition).rows.length : undefined;\n\n useEffect(() => {\n modalMethods.current?.update({\n filters,\n condition\n });\n }, [filters, condition]);\n\n const openFiltersModal = () => {\n modalMethods.current = create(FilterModal, {\n filters,\n condition,\n onApply: onChange\n });\n };\n\n return (\n <Flex\n as={StyledPromotedFilters}\n container={{\n alignItems: orientation === 'horizontal' && isSmallOrAbove ? 'start' : undefined,\n justify: 'between',\n direction: !isSmallOrAbove || orientation === 'horizontal' ? 'row' : 'column',\n pad: 2,\n gap: 2\n }}\n ref={ref}\n >\n {isSmallOrAbove ? (\n <>\n {orientation === 'vertical' && (\n <Flex\n container={{\n justify: 'between',\n alignItems: 'center',\n pad: [0, 0, 1, 0]\n }}\n >\n <StyledTextWithEllipsis variant='h3'>{t('filters')}</StyledTextWithEllipsis>\n <Button\n variant='simple'\n onClick={() => {\n onChange();\n }}\n >\n {t('clear_all')}\n </Button>\n </Flex>\n )}\n\n <PromotedFiltersContent\n filters={filters}\n onChange={onChange}\n condition={condition}\n orientation={orientation}\n ref={ref}\n />\n\n {orientation === 'horizontal' && (\n <div>\n <StyledClearAllButton\n variant='simple'\n onClick={() => {\n onChange();\n }}\n >\n {t('promoted_filters_clear_all_button_label')}\n </StyledClearAllButton>\n </div>\n )}\n </>\n ) : (\n <>\n <Button type='button' variant='text' onClick={openFiltersModal}>\n <Flex container={{ alignItems: 'center', gap: 0.5 }} forwardedAs='span'>\n <Icon name='filter' />\n <span>\n {t('filters')}\n {conditionsCount && `\\u00a0(${conditionsCount})`}\n </span>\n </Flex>\n </Button>\n <Button\n variant='simple'\n onClick={() => {\n onChange();\n }}\n >\n {t('clear_all')}\n </Button>\n </>\n )}\n </Flex>\n );\n }\n);\n\nexport default PromotedFilters;\n"]}
@@ -0,0 +1,4 @@
1
+ export declare const StyledPromotedFilters: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
2
+ export declare const StyledClearAllButton: import("styled-components").StyledComponent<import("react").FunctionComponent<import("@pega/cosmos-react-core").ButtonProps & import("@pega/cosmos-react-core").ForwardProps>, import("styled-components").DefaultTheme, {}, never>;
3
+ export declare const StyledTextWithEllipsis: import("styled-components").StyledComponent<import("react").FunctionComponent<import("@pega/cosmos-react-core").TextProps & import("@pega/cosmos-react-core").ForwardProps>, import("styled-components").DefaultTheme, {}, never>;
4
+ //# sourceMappingURL=PromotedFilters.styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PromotedFilters.styles.d.ts","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.styles.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,qBAAqB,yGAKhC,CAAC;AAIH,eAAO,MAAM,oBAAoB,qOAOhC,CAAC;AAIF,eAAO,MAAM,sBAAsB,mOAIlC,CAAC"}
@@ -0,0 +1,26 @@
1
+ import styled, { css } from 'styled-components';
2
+ import { defaultThemeProp, Button, Text } from '@pega/cosmos-react-core';
3
+ import { StyledModalChildrenWrap } from '@pega/cosmos-react-core/lib/components/Modal/Modal.styles';
4
+ export const StyledPromotedFilters = styled.div(({ theme }) => {
5
+ return css `
6
+ border-radius: ${theme.components.card['border-radius']};
7
+ background-color: ${theme.base.palette['secondary-background']};
8
+ `;
9
+ });
10
+ StyledPromotedFilters.defaultProps = defaultThemeProp;
11
+ export const StyledClearAllButton = styled(Button) `
12
+ margin: 1.125rem 0 0.625rem;
13
+ white-space: nowrap;
14
+
15
+ ${StyledModalChildrenWrap} & {
16
+ margin-top: 0;
17
+ }
18
+ `;
19
+ StyledClearAllButton.defaultProps = defaultThemeProp;
20
+ export const StyledTextWithEllipsis = styled(Text) `
21
+ overflow: hidden;
22
+ white-space: nowrap;
23
+ text-overflow: ellipsis;
24
+ `;
25
+ StyledTextWithEllipsis.defaultProps = defaultThemeProp;
26
+ //# sourceMappingURL=PromotedFilters.styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PromotedFilters.styles.js","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.styles.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2DAA2D,CAAC;AAEpG,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IAC5D,OAAO,GAAG,CAAA;qBACS,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,eAAe,CAAC;wBACnC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC;GAC/D,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,qBAAqB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAEtD,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;;;;IAI9C,uBAAuB;;;CAG1B,CAAC;AAEF,oBAAoB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAErD,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;;;;CAIjD,CAAC;AAEF,sBAAsB,CAAC,YAAY,GAAG,gBAAgB,CAAC","sourcesContent":["import styled, { css } from 'styled-components';\n\nimport { defaultThemeProp, Button, Text } from '@pega/cosmos-react-core';\nimport { StyledModalChildrenWrap } from '@pega/cosmos-react-core/lib/components/Modal/Modal.styles';\n\nexport const StyledPromotedFilters = styled.div(({ theme }) => {\n return css`\n border-radius: ${theme.components.card['border-radius']};\n background-color: ${theme.base.palette['secondary-background']};\n `;\n});\n\nStyledPromotedFilters.defaultProps = defaultThemeProp;\n\nexport const StyledClearAllButton = styled(Button)`\n margin: 1.125rem 0 0.625rem;\n white-space: nowrap;\n\n ${StyledModalChildrenWrap} & {\n margin-top: 0;\n }\n`;\n\nStyledClearAllButton.defaultProps = defaultThemeProp;\n\nexport const StyledTextWithEllipsis = styled(Text)`\n overflow: hidden;\n white-space: nowrap;\n text-overflow: ellipsis;\n`;\n\nStyledTextWithEllipsis.defaultProps = defaultThemeProp;\n"]}
@@ -1,5 +1,5 @@
1
1
  import { Ref } from 'react';
2
- import { BaseProps } from '@pega/cosmos-react-core';
2
+ import { BaseProps, NoChildrenProp } from '@pega/cosmos-react-core';
3
3
  import type { Condition } from '../ConditionBuilder/ConditionBuilder.types';
4
4
  import type { ConditionInputMode, ConditionFieldType } from '../ConditionInput/ConditionInput.types';
5
5
  export interface PromotedFilter {
@@ -12,11 +12,13 @@ export interface PromotedFilter {
12
12
  /** Label for the filter. */
13
13
  fieldLabel?: string;
14
14
  }
15
- export interface PromotedFiltersProps extends BaseProps {
15
+ export interface PromotedFiltersProps extends BaseProps, NoChildrenProp {
16
16
  /** Configuration of filters for every field that has been defined as promoted. */
17
17
  filters: PromotedFilter[];
18
18
  /** A value representing the current condition state. */
19
19
  condition?: Condition;
20
+ /** Orientation mode. The default is horizontal. */
21
+ orientation?: 'vertical' | 'horizontal';
20
22
  /** Callback fired on change of any of the filters. */
21
23
  onChange: (condition?: Condition) => void;
22
24
  /** Ref for the wrapping element. */
@@ -1 +1 @@
1
- {"version":3,"file":"PromotedFilters.types.d.ts","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4CAA4C,CAAC;AAC5E,OAAO,KAAK,EACV,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,wCAAwC,CAAC;AAEhD,MAAM,WAAW,cAAc;IAC7B,+BAA+B;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,yBAAyB;IACzB,SAAS,EAAE,kBAAkB,CAAC;IAC9B,oBAAoB;IACpB,IAAI,EAAE,kBAAkB,CAAC;IACzB,4BAA4B;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,oBAAqB,SAAQ,SAAS;IACrD,kFAAkF;IAClF,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,wDAAwD;IACxD,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,sDAAsD;IACtD,QAAQ,EAAE,CAAC,SAAS,CAAC,EAAE,SAAS,KAAK,IAAI,CAAC;IAC1C,oCAAoC;IACpC,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CAC3B"}
1
+ {"version":3,"file":"PromotedFilters.types.d.ts","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEpE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4CAA4C,CAAC;AAC5E,OAAO,KAAK,EACV,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,wCAAwC,CAAC;AAEhD,MAAM,WAAW,cAAc;IAC7B,+BAA+B;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,yBAAyB;IACzB,SAAS,EAAE,kBAAkB,CAAC;IAC9B,oBAAoB;IACpB,IAAI,EAAE,kBAAkB,CAAC;IACzB,4BAA4B;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,oBAAqB,SAAQ,SAAS,EAAE,cAAc;IACrE,kFAAkF;IAClF,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,wDAAwD;IACxD,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,mDAAmD;IACnD,WAAW,CAAC,EAAE,UAAU,GAAG,YAAY,CAAC;IACxC,sDAAsD;IACtD,QAAQ,EAAE,CAAC,SAAS,CAAC,EAAE,SAAS,KAAK,IAAI,CAAC;IAC1C,oCAAoC;IACpC,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CAC3B"}
@@ -1 +1 @@
1
- {"version":3,"file":"PromotedFilters.types.js","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.types.ts"],"names":[],"mappings":"","sourcesContent":["import { Ref } from 'react';\n\nimport { BaseProps } from '@pega/cosmos-react-core';\n\nimport type { Condition } from '../ConditionBuilder/ConditionBuilder.types';\nimport type {\n ConditionInputMode,\n ConditionFieldType\n} from '../ConditionInput/ConditionInput.types';\n\nexport interface PromotedFilter {\n /** Unique field identifier. */\n fieldName: string;\n /** Type of the field. */\n fieldType: ConditionFieldType;\n /** Display mode. */\n mode: ConditionInputMode;\n /** Label for the filter. */\n fieldLabel?: string;\n}\n\nexport interface PromotedFiltersProps extends BaseProps {\n /** Configuration of filters for every field that has been defined as promoted. */\n filters: PromotedFilter[];\n /** A value representing the current condition state. */\n condition?: Condition;\n /** Callback fired on change of any of the filters. */\n onChange: (condition?: Condition) => void;\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLDivElement>;\n}\n"]}
1
+ {"version":3,"file":"PromotedFilters.types.js","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.types.ts"],"names":[],"mappings":"","sourcesContent":["import { Ref } from 'react';\n\nimport { BaseProps, NoChildrenProp } from '@pega/cosmos-react-core';\n\nimport type { Condition } from '../ConditionBuilder/ConditionBuilder.types';\nimport type {\n ConditionInputMode,\n ConditionFieldType\n} from '../ConditionInput/ConditionInput.types';\n\nexport interface PromotedFilter {\n /** Unique field identifier. */\n fieldName: string;\n /** Type of the field. */\n fieldType: ConditionFieldType;\n /** Display mode. */\n mode: ConditionInputMode;\n /** Label for the filter. */\n fieldLabel?: string;\n}\n\nexport interface PromotedFiltersProps extends BaseProps, NoChildrenProp {\n /** Configuration of filters for every field that has been defined as promoted. */\n filters: PromotedFilter[];\n /** A value representing the current condition state. */\n condition?: Condition;\n /** Orientation mode. The default is horizontal. */\n orientation?: 'vertical' | 'horizontal';\n /** Callback fired on change of any of the filters. */\n onChange: (condition?: Condition) => void;\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLDivElement>;\n}\n"]}