Skip to content

Commit

Permalink
Merge branch 'master' into feat/category-progress-bar
Browse files Browse the repository at this point in the history
  • Loading branch information
esmeetewinkel authored Feb 2, 2024
2 parents 19ecb86 + 1f55fd3 commit be2dbbf
Show file tree
Hide file tree
Showing 19 changed files with 99 additions and 48 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "frontend",
"version": "0.16.23",
"version": "0.16.24",
"author": "IDEMS International",
"license": "See LICENSE",
"homepage": "https://idems.international/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,33 @@ describe("data_pipe Parser", () => {
});
expect(deferred).toEqual(["data_pipe.test_pipe_defer"]);
});

// QA - https://github.com/IDEMSInternational/parenting-app-ui/issues/2184
// NOTE - test case more explicitly handled by jsEvaluator.spec
it("Supports text with line break characters", async () => {
const parser = new DataPipeParser({
processedFlowHashmap: {
data_list: {
test_data_list: [{ id: 1, text: "normal" }, { id: 2, text: "line\nbreak" }, { id: 3 }],
},
},
} as any);
const ops: IDataPipeOperation[] = [
{
input_source: "test_data_list",
operation: "filter",
args_list: "id < 3" as any, // will be parsed during process
output_target: "test_output",
},
];
const output = parser.run({
flow_name: "test_line_breaks",
flow_type: "data_pipe",
rows: ops,
});
expect(output._generated.data_list.test_output.rows).toEqual([
{ id: 1, text: "normal" },
{ id: 2, text: "line\nbreak" },
]);
});
});
17 changes: 16 additions & 1 deletion packages/scripts/src/commands/version.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from "fs-extra";
import { Command } from "commander";
import inquirer from "inquirer";
import { APP_BUILD_GRADLE_PATH, MAIN_PACKAGE_PATH } from "../paths";
import { APP_BUILD_GRADLE_PATH, MAIN_PACKAGE_PATH, ANDROID_BUILD_ACTION_PATH } from "../paths";

/***************************************************************************************
* CLI
Expand All @@ -26,6 +26,7 @@ async function version(options: IProgramOptions) {
const newVersion = await promptNewVersion(oldVersion);
updatePackageJson(newVersion);
updateGradleBuild(newVersion);
updateAndroidBuildAction(newVersion);
}

function updateGradleBuild(newVersionName: string) {
Expand All @@ -47,6 +48,20 @@ async function updatePackageJson(newVersion: string) {
fs.writeJSONSync(MAIN_PACKAGE_PATH, packageJson, { spaces: 2 });
}

function updateAndroidBuildAction(newVersionName) {
let androidBuildAction = fs.readFileSync(ANDROID_BUILD_ACTION_PATH, { encoding: "utf-8" });
const newVersionCode = _generateVersionCode(newVersionName);
androidBuildAction = androidBuildAction.replace(
/[0-9]+\/\$VERSION_CODE\//g,
`${newVersionCode}/$VERSION_CODE/`
);
androidBuildAction = androidBuildAction.replace(
/[0-9]+\.[0-9]+\.[0-9]+\/\$VERSION\//g,
`${newVersionName}/$VERSION/`
);
fs.writeFileSync(ANDROID_BUILD_ACTION_PATH, androidBuildAction, { encoding: "utf-8" });
}

async function promptNewVersion(currentVersion: string) {
const { version } = await inquirer.prompt([
{
Expand Down
39 changes: 29 additions & 10 deletions packages/shared/src/models/jsEvaluator/jsEvaluator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { JSEvaluator } from "./jsEvaluator";

const constants = {
a: 1,
b: 2,
nestedConstant: { array: [1] },
};
const functions = {
isEven: (n) => n % 2 === 0,
};

describe("JS Evaluator", () => {
const constants = {
a: 1,
b: 2,
nestedConstant: { array: [1] },
};
const functions = {
isEven: (n) => n % 2 === 0,
};
const evaluator = new JSEvaluator();
evaluator.setGlobalContext({ constants, functions });
let evaluator: JSEvaluator;
beforeEach(() => {
evaluator = new JSEvaluator();
evaluator.setGlobalContext({ constants, functions });
});

it("expression: Math.min(5,7)", () => {
expect(evaluator.evaluate("Math.min(5,7)")).toEqual(5);
});
Expand All @@ -35,4 +40,18 @@ describe("JS Evaluator", () => {
evaluator.setGlobalContext({ constants: { ...invalidConstants, ...constants } });
expect(() => evaluator.evaluate("Math.min(a,b)")).toThrowError("Unexpected token 'default'");
});
it("handles escape characters", () => {
// Case 1 - evaluation string with linebreak
expect(evaluator.evaluate("'Hello\n'+this.name", { name: "Ada" })).toEqual("Hello\nAda");
// Case 2 - this context with linebreak
expect(evaluator.evaluate("'Hello'+this.name", { name: "\nAda" })).toEqual("Hello\nAda");
// Case 3 - global constant with linebreak
evaluator.setGlobalContext({ constants: { name: "\nAda" } });
expect(evaluator.evaluate("'Hello'+name", { name: "\nAda" })).toEqual("Hello\nAda");
});
it("handles special characters", () => {
// Case 1 - single quotation (used to wrap string values in evaluator)
evaluator.setGlobalContext({ constants: { name: "Ada'" } });
expect(evaluator.evaluate("'Hello '+name")).toEqual("Hello Ada'");
});
});
14 changes: 12 additions & 2 deletions packages/shared/src/models/jsEvaluator/jsEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ export class JSEvaluator {
*/
evaluate(expression: string, executionContext = {}) {
const funcString = `${this.evaluationContextBase} (${expression});`;
const cleanedFuncString = this.cleanFunctionString(funcString);
try {
const func = new Function(funcString);
const func = new Function(cleanedFuncString);
const evaluated = func.apply(executionContext);
return evaluated;
} catch (error) {
Expand All @@ -85,10 +86,19 @@ export class JSEvaluator {
private parseContextValue(value: any) {
if (value) {
if (typeof value === "object") value = JSON.stringify(value);
if (typeof value === "string") return `'${value}'`;
if (typeof value === "string") {
// when returning a string value escape single quote which would otherwise conflict with return
const escapedValue = value.replace(/'/g, "\\'");
return `'${escapedValue}'`;
}
}
return value;
}

private cleanFunctionString(str: string) {
// Linebreak characters will break JS evaluator so add additional escape
return str.replace(/(?:\r)/g, "\\r").replace(/(?:\n)/g, "\\n");
}
}

/** Generic object containing list of functions */
Expand Down
4 changes: 4 additions & 0 deletions packages/shared/src/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ export const RESOURCE_FOLDER_PATH = path.join(ROOT_DIR, "resources");

export const ANDROID_RES_PATH = path.join(ROOT_DIR, "android/app/src/main/res");
export const APP_BUILD_GRADLE_PATH = path.join(ROOT_DIR, "android/app/build.gradle");
export const ANDROID_BUILD_ACTION_PATH = path.join(
ROOT_DIR,
".github/workflows/reusable-android-build.yml"
);
7 changes: 7 additions & 0 deletions packages/workflows/src/deployment.workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ const workflows: IDeploymentWorkflows = {
],
},
set: {
options: [
{
flags: "--skip-refresh",
description: "Skip remote content refresh",
},
],
label: "Set active deployment",
steps: [
{
Expand All @@ -94,6 +100,7 @@ const workflows: IDeploymentWorkflows = {
},
{
name: "refresh_remote_content",
condition: async ({ options }) => !options.skipRefresh,
function: async ({ tasks, config }) => {
if (config.git?.content_repo) {
await tasks.git().refreshRemoteRepo();
Expand Down
2 changes: 1 addition & 1 deletion packages/workflows/src/sync.workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ const workflows: IDeploymentWorkflows = {
{
name: "authorize",
function: async ({ tasks }) => {
tasks.gdrive.authorize();
await tasks.gdrive.authorize();
process.exit(0);
},
},
Expand Down
3 changes: 0 additions & 3 deletions src/assets/icon/shared/start.svg

This file was deleted.

3 changes: 0 additions & 3 deletions src/assets/images/github.png

This file was deleted.

3 changes: 0 additions & 3 deletions src/assets/images/splash-screen/0.svg

This file was deleted.

3 changes: 0 additions & 3 deletions src/assets/images/splash-screen/1.svg

This file was deleted.

3 changes: 0 additions & 3 deletions src/assets/images/splash-screen/2.svg

This file was deleted.

3 changes: 0 additions & 3 deletions src/assets/images/star.svg

This file was deleted.

3 changes: 0 additions & 3 deletions src/assets/images/sync.svg

This file was deleted.

3 changes: 0 additions & 3 deletions src/assets/logos/PLH.svg

This file was deleted.

3 changes: 0 additions & 3 deletions src/assets/logos/Unicef.svg

This file was deleted.

3 changes: 0 additions & 3 deletions src/assets/logos/WHO.svg

This file was deleted.

3 changes: 0 additions & 3 deletions src/assets/shapes.svg

This file was deleted.

0 comments on commit be2dbbf

Please sign in to comment.