Skip to content

Commit

Permalink
Merge branch 'main' into remove-tmp-folders
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyCBakerPhD authored Sep 25, 2023
2 parents a3ee993 + f775bab commit b24c9f2
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 59 deletions.
21 changes: 3 additions & 18 deletions src/renderer/src/progress/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { merge } from "../stories/pages/utils.js";
import { updateAppProgress, updateFile } from "./update.js";
import { updateURLParams } from "../../utils/url.js";

import * as operations from "./operations";

export * from "./update";

class GlobalAppConfig {
Expand Down Expand Up @@ -122,24 +124,7 @@ export const remove = async (name) => {
focusCancel: true,
});

if (result.isConfirmed) {
//Get the path of the progress file to delete
const progressFilePathToDelete = joinPath(guidedProgressFilePath, name + ".json");

//delete the progress file
if (fs) fs.unlinkSync(progressFilePathToDelete);
else localStorage.removeItem(progressFilePathToDelete);

if (fs) {
// delete default stub location
fs.rmSync(joinPath(stubSaveFolderPath, name), { recursive: true, force: true });

// delete default conversion location
fs.rmSync(joinPath(conversionSaveFolderPath, name), { recursive: true, force: true });
}

return true;
}
if (result.isConfirmed) return operations.remove(name);

return false;
};
Expand Down
22 changes: 22 additions & 0 deletions src/renderer/src/progress/operations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { joinPath } from "../globals";
import { conversionSaveFolderPath, guidedProgressFilePath, stubSaveFolderPath } from "../dependencies/simple";
import { fs } from "../electron";

export const remove = (name) => {
//Get the path of the progress file to delete
const progressFilePathToDelete = joinPath(guidedProgressFilePath, name + ".json");

//delete the progress file
if (fs) fs.unlinkSync(progressFilePathToDelete);
else localStorage.removeItem(progressFilePathToDelete);

if (fs) {
// delete default stub location
fs.rmSync(joinPath(stubSaveFolderPath, name), { recursive: true, force: true });

// delete default conversion location
fs.rmSync(joinPath(conversionSaveFolderPath, name), { recursive: true, force: true });
}

return true;
};
10 changes: 4 additions & 6 deletions src/renderer/src/progress/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { updateURLParams } from "../../utils/url.js";
import { guidedProgressFilePath } from "../dependencies/simple.js";
import { fs } from "../electron/index.js";
import { joinPath } from "../globals.js";
import { get } from "./index.js";
import { get, hasEntry } from "./index.js";

export const rename = (newDatasetName, previousDatasetName) => {
//If updating the dataset, update the old banner image path with a new one
if (previousDatasetName) {
if (previousDatasetName === newDatasetName) return "No changes made to dataset name";
if (previousDatasetName === newDatasetName) return;

if (hasEntry(newDatasetName))
throw new Error("An existing progress file already exists with that name. Please choose a different name.");
throw new Error("An existing project already exists with that name. Please choose a different name.");

// update old progress file with new dataset name
const oldProgressFilePath = `${guidedProgressFilePath}/${previousDatasetName}.json`;
Expand All @@ -20,9 +20,7 @@ export const rename = (newDatasetName, previousDatasetName) => {
localStorage.setItem(newProgressFilePath, localStorage.getItem(oldProgressFilePath));
localStorage.removeItem(oldProgressFilePath);
}

return "Dataset name updated";
} else throw new Error("No previous dataset name provided");
} else throw new Error("No previous project name provided");
};

export const updateAppProgress = (
Expand Down
6 changes: 1 addition & 5 deletions src/renderer/src/stories/FileSystemSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,7 @@ export class FilesystemSelector extends LitElement {
isUpdated = resolved !== this.value;
}

if (isUpdated) {
this.value = resolved;
this.#handleFiles(this.value); // Notify of the change to the separators
return;
}
if (isUpdated) this.#handleFiles(resolved); // Notify of the change to the separators

const resolvedValueDisplay = isArray
? len > 1
Expand Down
14 changes: 7 additions & 7 deletions src/renderer/src/stories/JSONSchemaForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export class JSONSchemaForm extends LitElement {
this.identifier = props.identifier;
this.mode = props.mode ?? "default";
this.schema = props.schema ?? {};
this.results = props.results ?? {};
this.results = (props.base ? structuredClone(props.results) : props.results) ?? {}; // Deep clone results in nested forms
this.globals = props.globals ?? {};

this.ignore = props.ignore ?? [];
Expand Down Expand Up @@ -254,10 +254,10 @@ export class JSONSchemaForm extends LitElement {

// NOTE: Forms with nested forms will handle their own state updates
if (!value) {
if (fullPath.length === 1) delete resultParent[name];
delete resultParent[name];
delete resolvedParent[name];
} else {
if (fullPath.length === 1) resultParent[name] = value;
resultParent[name] = value;
resolvedParent[name] = value;
}

Expand Down Expand Up @@ -297,9 +297,9 @@ export class JSONSchemaForm extends LitElement {
throw new Error(message);
};

validate = async () => {
validate = async (resolved) => {
// Check if any required inputs are missing
const invalidInputs = await this.#validateRequirements(); // get missing required paths
const invalidInputs = await this.#validateRequirements(resolved); // get missing required paths
const isValid = !invalidInputs.length;

// Print out a detailed error message if any inputs are missing
Expand All @@ -316,9 +316,9 @@ export class JSONSchemaForm extends LitElement {

if (message) this.throw(message);

for (let key in this.#nestedForms) await this.#nestedForms[key].validate(); // Validate nested forms too
for (let key in this.#nestedForms) await this.#nestedForms[key].validate(resolved ? resolved[key] : undefined); // Validate nested forms too
try {
for (let key in this.tables) await this.tables[key].validate(); // Validate nested tables too
for (let key in this.tables) await this.tables[key].validate(resolved ? resolved[key] : undefined); // Validate nested tables too
} catch (e) {
this.throw(e.message);
}
Expand Down
7 changes: 6 additions & 1 deletion src/renderer/src/stories/pages/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ export class Page extends LitElement {
this.beforeTransition();

// Otherwise note unsaved updates if present
if (this.unsavedUpdates || ("states" in this.info && !this.info.states.saved)) {
if (
this.unsavedUpdates ||
("states" in this.info &&
transition === 1 && // Only ensure save for standard forward progression
!this.info.states.saved)
) {
if (transition === 1) await this.save(); // Save before a single forward transition
else {
Swal.fire({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { html } from "lit";

import Swal from "sweetalert2";
import { isStorybook } from "../../../../dependencies/globals.js";
import { JSONSchemaForm } from "../../../JSONSchemaForm.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class GuidedNewDatasetPage extends Page {
const has = await hasEntry(name);
if (has) {
this.notify(
"An existing progress file already exists with that name. Please choose a different name.",
"An existing project already exists with that name. Please choose a different name.",
"error"
);
return;
Expand Down
18 changes: 11 additions & 7 deletions tests/metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ test('inter-table updates are triggered', async () => {
test('changes are resolved correctly', async () => {

const results = {}

const schema = {
properties: {
v0: {
Expand All @@ -148,11 +147,16 @@ test('changes are resolved correctly', async () => {
l2: {
type: "object",
properties: {
v2: {
type: 'string'
}
l3: {
type: "object",
properties: {
v2: {
type: 'string'
}
},
required: ['v2']
},
},
required: ['v2']
},
v1: {
type: 'string'
Expand Down Expand Up @@ -181,13 +185,13 @@ test('changes are resolved correctly', async () => {

const input1 = form.getInput(['v0'])
const input2 = form.getInput(['l1', 'v1'])
const input3 = form.getInput(['l1', 'l2', 'v2'])
const input3 = form.getInput(['l1', 'l2', 'l3', 'v2'])

input1.updateData('test')
input2.updateData('test')
input3.updateData('test')

// Validate that the new structure is correct
await form.validate().then(res => errors = false).catch(e => errors = true)
await form.validate(form.results).then(res => errors = false).catch(e => errors = true)
expect(errors).toBe(false) // Is valid
})
27 changes: 25 additions & 2 deletions tests/progress.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
import { test } from 'vitest'
import { updateAppProgress } from '../src/renderer/src/progress/update'
import { expect, test } from 'vitest'
import { updateAppProgress, updateFile, rename } from '../src/renderer/src/progress/update'
import { get } from '../src/renderer/src/progress'
import { remove } from '../src/renderer/src/progress/operations'

test('updates to app progress do not fail', () => updateAppProgress('/', {}))

const initialName = '.progressTestPipelineName'
const renameName = initialName + 2
const info = { random: Math.random() }

// Remove before tests
remove(initialName)
remove(renameName)

// create pipeline
test('pipeline creation works', () => {
updateFile(initialName, () => info)
const result = get(initialName)
expect(result.random).toEqual(info.random) // NOTE: Result has an extra lastModified field
})

// rename pipeline
test('pipeline renaming works', () => rename(renameName, initialName))

// delete pipeline
test('pipeline deletion works', () => remove(renameName))
22 changes: 12 additions & 10 deletions tests/testPyinstallerExecutable.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,25 @@ handleProcess(proc2, "spawn");

let now = Date.now();

let outputCollection = "";
const regex = /.+Error: .+/i; // Check for error messages (without case sensitivity)

const regex = /.+Error: .+/;
function onMessage(data, id) {
const message = data.toString();
if (!cmds.forever && regex.test(message)) throw new Error(message);
else console.error(`[${id}] ${message}`);
}

function handleProcess(proc, id = "process") {
if (proc != null) {
// Listen for errors from Python process
proc.stderr.on("data", function (data) {
const message = data.toString();
console.error(`[${id}] Error: ${data}`);
outputCollection += message;
if (regex.test(message)) throw new Error(outputCollection);
});
proc.stderr.on("data", (data) => onMessage(data, id));

proc.stdout.on("data", function (data) {
console.log(`Time to Start: ${(Date.now() - now).toFixed(2)}ms`);
if (!cmds.forever) process.exit();
if (cmds.forever) onMessage(data, id);
else {
console.log(`Time to Start: ${(Date.now() - now).toFixed(2)}ms`);
process.exit();
}
});

const error = () => () => {
Expand Down

0 comments on commit b24c9f2

Please sign in to comment.