Skip to content

Commit

Permalink
reintegrate changes from case name templating #647
Browse files Browse the repository at this point in the history
  • Loading branch information
Pascal-Delange committed Jan 10, 2025
1 parent 010bb2d commit 992d34d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
8 changes: 6 additions & 2 deletions packages/app-builder/src/models/astNode/builder-ast-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import { isIsMultipleOf, type IsMultipleOfAstNode } from './multiple-of';
import {
type FuzzyMatchComparatorAstNode,
isFuzzyMatchComparator,
isStringTemplateAstNode,
type StringTemplateAstNode,
} from './strings';
import {
isTimeAdd,
Expand All @@ -38,7 +40,8 @@ export type EditableAstNode =
| AggregationAstNode
| TimeAddAstNode
| FuzzyMatchComparatorAstNode
| IsMultipleOfAstNode;
| IsMultipleOfAstNode
| StringTemplateAstNode;

/**
* Check if the node is editable in a dedicated modal
Expand All @@ -51,7 +54,8 @@ export function isEditableAstNode(node: AstNode): node is EditableAstNode {
isTimeAdd(node) ||
isFuzzyMatchComparator(node) ||
isTimestampExtract(node) ||
isIsMultipleOf(node)
isIsMultipleOf(node) ||
isStringTemplateAstNode(node)
);
}

Expand Down
10 changes: 9 additions & 1 deletion packages/app-builder/src/models/astNode/data-accessor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type AstNode } from './ast-node';
import { type ConstantAstNode } from './constant';
import { type ConstantAstNode, NewConstantAstNode } from './constant';

export const databaseAccessAstNodeName = 'DatabaseAccess';
export interface DatabaseAccessAstNode {
Expand All @@ -25,6 +25,14 @@ export interface PayloadAstNode {
namedChildren: Record<string, never>;
}

export function NewPayloadAstNode(field: string): PayloadAstNode {
return {
name: payloadAstNodeName,
children: [NewConstantAstNode({ constant: field })],
namedChildren: {},
};
}

export function isPayload(node: AstNode): node is PayloadAstNode {
return node.name === payloadAstNodeName;
}
Expand Down
34 changes: 34 additions & 0 deletions packages/app-builder/src/models/astNode/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {
import { type AstNode, NewUndefinedAstNode } from './ast-node';
import { type ConstantAstNode, NewConstantAstNode } from './constant';

////////////////////////
// Fuzzy string matching
////////////////////////

export const fuzzyMatchAstNodeName = 'FuzzyMatch';
export interface FuzzyMatchAstNode {
name: typeof fuzzyMatchAstNodeName;
Expand Down Expand Up @@ -133,3 +137,33 @@ export function isFuzzyMatchComparator(
}
return isFuzzyMatch(firstChild) || isFuzzyMatchAnyOf(firstChild);
}

////////////////////////
// String templating ///
////////////////////////

export const stringTemplateAstNodeName = 'StringTemplate';
export interface StringTemplateAstNode {
name: typeof stringTemplateAstNodeName;
constant?: undefined;
children: ConstantAstNode<string>[];
namedChildren: Record<string, AstNode>;
}

export function NewStringTemplateAstNode(
template: string = '',
variables: Record<string, AstNode> = {},
): StringTemplateAstNode {
return {
name: stringTemplateAstNodeName,
constant: undefined,
children: [NewConstantAstNode({ constant: template })],
namedChildren: variables,
};
}

export function isStringTemplateAstNode(
node: AstNode,
): node is StringTemplateAstNode {
return node.name === stringTemplateAstNodeName;
}

0 comments on commit 992d34d

Please sign in to comment.