Skip to content

Commit

Permalink
Fix PR feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
ChibiBlasphem committed Jan 7, 2025
1 parent 10591f9 commit ae4f548
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 27 deletions.
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']
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

0 comments on commit ae4f548

Please sign in to comment.