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

fixes LUNA-218 add path to tauri project metadata #377

Merged
merged 5 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
66 changes: 38 additions & 28 deletions packages/app/src/hooks/useSaveProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,23 @@ export function useSaveProject() {
saving = toast.info('Saving project');
}, 500);

await ioProvider.saveProjectDataNoPrompt(newProject, { testSuites }, loadedProject.path);
try {
await ioProvider.saveProjectDataNoPrompt(newProject, { testSuites }, loadedProject.path);

if (saving != null) {
toast.dismiss(saving);
}
clearTimeout(savingTimeout);
if (saving != null) {
toast.dismiss(saving);
}
clearTimeout(savingTimeout);

toast.success('Project saved');
setLoadedProject({
loaded: true,
path: loadedProject.path,
});
toast.success('Project saved');
setLoadedProject({
loaded: true,
path: loadedProject.path,
});
} catch (cause) {
clearTimeout(savingTimeout);
toast.error('Failed to save project');
}
}

async function saveProjectAs() {
Expand All @@ -57,26 +62,31 @@ export function useSaveProject() {
saving = toast.info('Saving project');
}, 500);

const filePath = await ioProvider.saveProjectData(newProject, { testSuites });
try {
const filePath = await ioProvider.saveProjectData(newProject, { testSuites });

if (saving != null) {
toast.dismiss(saving);
}
clearTimeout(savingTimeout);
if (saving != null) {
toast.dismiss(saving);
}
clearTimeout(savingTimeout);

if (filePath) {
toast.success('Project saved');
setLoadedProject({
loaded: true,
path: filePath,
});
setOpenedProjects((projects) => ({
...projects,
[project.metadata.id]: {
project,
fsPath: filePath,
},
}));
if (filePath) {
toast.success('Project saved');
setLoadedProject({
loaded: true,
path: filePath,
});
setOpenedProjects((projects) => ({
...projects,
[project.metadata.id]: {
project,
fsPath: filePath,
},
}));
}
} catch (cause) {
clearTimeout(savingTimeout);
toast.error('Failed to save project');
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/io/TauriIOProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class TauriIOProvider implements IOProvider {

async loadProjectDataNoPrompt(path: string): Promise<{ project: Project; testData: TrivetData }> {
const data = await readTextFile(path);
const [projectData, attachedData] = deserializeProject(data);
const [projectData, attachedData] = deserializeProject(data, path);

const trivetData = attachedData.trivet
? deserializeTrivetData(attachedData.trivet as SerializedTrivetData)
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/model/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type Project = {
title: string;
description: string;
mainGraphId?: GraphId;
path?: string;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is going to serialize the path of the project in the project itself, which I'd like to avoid :/

Can you change the project metadata serialization to ignore this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pushed a change!

};

plugins?: PluginLoadSpec[];
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/utils/serialization/serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ export function serializeProject(project: Project, attachedData?: AttachedData):
return projectV4Serializer(project, attachedData);
}

export function deserializeProject(serializedProject: unknown): [Project, AttachedData] {
export function deserializeProject(serializedProject: unknown, path: string | null = null): [Project, AttachedData] {
try {
return projectV4Deserializer(serializedProject);
const result = projectV4Deserializer(serializedProject);
if (path !== null)
result[0].metadata.path = path;
return result;
} catch (err) {
if (err instanceof yaml.YAMLError) {
yamlProblem(err);
Expand Down
10 changes: 9 additions & 1 deletion packages/core/src/utils/serialization/serialization_v4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,16 @@ export function graphV4Deserializer(data: unknown): NodeGraph {
}

export function projectV4Serializer(project: Project, attachedData?: AttachedData): unknown {
const filteredProject = {
...project,
metadata: {
...project.metadata,
path: undefined,
}
}

// Make sure all data is ordered deterministically first
const stabilized = JSON.parse(stableStringify(toSerializedProject(project, attachedData)));
const stabilized = JSON.parse(stableStringify(toSerializedProject(filteredProject, attachedData)));

const serialized = yaml.stringify(
{
Expand Down
6 changes: 3 additions & 3 deletions packages/core/test/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export async function loadTestGraphInProcessor(graphName: string) {

export async function loadProjectFromFile(path: string): Promise<Project> {
const content = await readFile(path, { encoding: 'utf8' });
return loadProjectFromString(content);
return loadProjectFromString(content, path);
}

export function loadProjectFromString(content: string): Project {
const [project] = deserializeProject(content);
export function loadProjectFromString(content: string, path: string | null = null): Project {
const [project] = deserializeProject(content, path);
return project;
}

Expand Down
Loading