Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: case name templating #647

Merged
merged 4 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ const adaptStringTemplateEditState = ({
initialNode: StringTemplateAstNode;
initialErrors: AstNodeErrors | undefined;
}) => {
const template = initialNode.children[0]?.constant ?? '';
// const templateErrors = initialErrors.children[0]?.errors ?? [];

return { template, variables: initialNode.namedChildren };
return {
template: initialNode.children[0]?.constant ?? '',
variables: initialNode.namedChildren,
};
};

export const useStringTemplateEditState = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,6 @@ export const useDefaultCaseName = (triggerObjectType: string) => {
});
}, [defaultCaseTemplate]);

// const isDefaultCaseName = (astNode: StringTemplateAstNode) => {
// return R.isDeepEqual(astNode, defaultCaseNameNode);
// // if (astNode.children[0]?.constant !== defaultCaseTemplate) {
// // return false;
// // }
// // const objectIdVariable = astNode.namedChildren['object_id'];

// // return (
// // objectIdVariable &&
// // isPayload(objectIdVariable) &&
// // objectIdVariable.children[0]?.constant === 'object_id'
// // );
// };

return {
defaultCaseNameNode,
};
Expand Down
2 changes: 2 additions & 0 deletions packages/app-builder/src/models/node-evaluation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export type ReturnValue =
isOmitted: true;
};

export type ReturnValueType = 'string' | 'int' | 'float' | 'bool' | 'datetime';

export type NonOmittedReturnValue = { value: ConstantType; isOmitted: false };

export function hasReturnValue(
Expand Down
7 changes: 4 additions & 3 deletions packages/app-builder/src/repositories/ScenarioRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import {
adaptNodeEvaluation,
type NodeEvaluation,
type ReturnValueType,
} from '@app-builder/models/node-evaluation';
import {
adaptSnoozesOfIteration,
Expand Down Expand Up @@ -76,7 +77,7 @@ export interface ScenarioRepository {
}): Promise<ScenarioValidation['rules']['ruleItems'][number]>;
validateAst(
scenarioId: string,
payload: { node: AstNode; returnType?: string },
payload: { node: AstNode; expectedReturnType?: ReturnValueType },
): Promise<NodeEvaluation>;
commitScenarioIteration(args: {
iterationId: string;
Expand Down Expand Up @@ -174,12 +175,12 @@ export function makeGetScenarioRepository() {
ruleId,
);
},
validateAst: async (scenarioId, { node, returnType }) => {
validateAst: async (scenarioId, { node, expectedReturnType }) => {
const { ast_validation } = await marbleCoreApiClient.validateAstNode(
scenarioId,
{
node: adaptNodeDto(node),
return_type: returnType,
expected_return_type: expectedReturnType,
},
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type AstNode } from '@app-builder/models';
import { type ReturnValueType } from '@app-builder/models/node-evaluation';
import { serverServices } from '@app-builder/services/init.server';
import { getRoute } from '@app-builder/utils/routes';
import { fromParams, fromUUID } from '@app-builder/utils/short-uuid';
Expand All @@ -8,7 +9,7 @@ import { useCallback } from 'react';

type AstValidationPayload = {
node: AstNode;
returnType?: string;
expectedReturnType?: ReturnValueType;
};

export async function action({ request, params }: ActionFunctionArgs) {
Expand All @@ -22,7 +23,7 @@ export async function action({ request, params }: ActionFunctionArgs) {

const res = await scenario.validateAst(scenarioId, {
node: body.node,
returnType: body.returnType,
expectedReturnType: body.expectedReturnType,
});

console.dir(res, { depth: null });
Expand All @@ -34,10 +35,10 @@ export function useAstValidationFetcher(scenarioId: string) {
const { submit, data } = useFetcher<typeof action>();

const validate = useCallback(
(ast: AstNode, returnType?: string) => {
(ast: AstNode, expectedReturnType?: ReturnValueType) => {
const args: AstValidationPayload = {
node: ast,
returnType,
expectedReturnType,
};
submit(args, {
method: 'POST',
Expand Down
3 changes: 2 additions & 1 deletion packages/marble-api/openapis/marblecore-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4838,8 +4838,9 @@ components:
type: object
allOf:
- $ref: '#/components/schemas/NodeDto'
return_type:
expected_return_type:
type: string
enum: ['string', 'int', 'float', 'bool', 'datetime']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a comment: I prefer "timestamp" to "datetime" here because that is what is actually manipulated in the backend, but this is in no way blocking for this feature so feel free to not make the change now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'll remove it from the enum list as for now we do not use it, changing it to timestamp would mean changing the backend and I already merged the PR on this side.

ScenarioUpdateInputDto:
type: object
properties:
Expand Down
2 changes: 1 addition & 1 deletion packages/marble-api/src/generated/marblecore-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ export type ScenarioUpdateInputDto = {
};
export type ScenarioAstValidateInputDto = {
node?: NodeDto;
return_type?: string;
expected_return_type?: "string" | "int" | "float" | "bool" | "datetime";
};
export type ScenarioIterationDto = {
id: string;
Expand Down
Loading