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

Fix analysis.R loading from gist, again #222

Merged
merged 1 commit into from
Oct 7, 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
5 changes: 4 additions & 1 deletion gui/src/app/Project/FileMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ export const mapFileContentsToModel = (

fields.forEach((f) => {
// Don't do anything for unrecognized filenames
if (!isFileName(f)) return;
if (!isFileName(f)) {
console.warn(`Unrecognized filename: ${f}`);
return;
}

switch (f) {
case FileNames.META: {
Expand Down
3 changes: 2 additions & 1 deletion gui/src/app/Project/ProjectQueryLoading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export const fetchRemoteProject = async (query: QueryParams) => {
false,
);
data.meta.title = contentLoadedFromGist.description;
return persistStateToEphemera(data);
} else {
// right now we only support loading from a gist
console.error("Unsupported project URI", projectUri);
Expand All @@ -105,7 +106,7 @@ export const fetchRemoteProject = async (query: QueryParams) => {
: Promise.resolve(data.analysisPyFileContent);
const analysisRFilePromise = query["analysis_r"]
? tryFetch(query["analysis_r"])
: Promise.resolve(data.analysisPyFileContent);
: Promise.resolve(data.analysisRFileContent);
const dataPyFilePromise = query["data_py"]
? tryFetch(query["data_py"])
: Promise.resolve(data.dataPyFileContent);
Expand Down
3 changes: 1 addition & 2 deletions gui/src/app/Project/ProjectSerialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,8 @@ const loadFileFromString = (
data: ProjectDataModel,
field: ProjectKnownFiles,
contents: string,
replaceProject: boolean = false,
): ProjectDataModel => {
const newData = replaceProject ? { ...initialDataModel } : { ...data };
const newData = { ...data };
newData[field] = contents;
return newData;
};
Expand Down
26 changes: 26 additions & 0 deletions gui/test/app/Project/ProjectQueryLoading.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ const hoistedMocks = vi.hoisted(() => {
description: "gist discription",
files: {
"main.stan": "gist stan code",
"data.json": '{"data": "gist data"}',
"analysis.py": "gist analysis.py",
"analysis.R": "gist analysis.R",
"data.py": "gist data.py",
"data.R": "gist data.R",
"sampling_opts.json": JSON.stringify(mockedSamplingOpts),
"extra.txt": "gist extra",
},
};

Expand Down Expand Up @@ -297,6 +304,25 @@ describe("Query fetching", () => {
expect(project.stanFileContent).toEqual("gist stan code");
expect(project.ephemera.stanFileContent).toEqual("gist stan code");
expect(project.meta.title).toEqual("gist discription");

expect(project.dataFileContent).toEqual('{"data": "gist data"}');
expect(project.ephemera.dataFileContent).toEqual('{"data": "gist data"}');

expect(project.analysisPyFileContent).toEqual("gist analysis.py");
expect(project.ephemera.analysisPyFileContent).toEqual(
"gist analysis.py",
);

expect(project.analysisRFileContent).toEqual("gist analysis.R");
expect(project.ephemera.analysisRFileContent).toEqual("gist analysis.R");

expect(project.dataPyFileContent).toEqual("gist data.py");
expect(project.ephemera.dataPyFileContent).toEqual("gist data.py");

expect(project.dataRFileContent).toEqual("gist data.R");
expect(project.ephemera.dataRFileContent).toEqual("gist data.R");

expect(project.samplingOpts).toEqual(hoistedMocks.mockedSamplingOpts);
});
});
});