Skip to content

Commit

Permalink
Fix analysis.R loading from gist, again
Browse files Browse the repository at this point in the history
  • Loading branch information
WardBrian committed Oct 7, 2024
1 parent 0d0047f commit 8d1090e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
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);
});
});
});

0 comments on commit 8d1090e

Please sign in to comment.