Skip to content

Commit

Permalink
Merge pull request #389 from AllenInstitute/feature/derive_local_path
Browse files Browse the repository at this point in the history
feature/derive_local_path
  • Loading branch information
BrianWhitneyAI authored Jan 17, 2025
2 parents 89df078 + e7592a7 commit d1f5d33
Show file tree
Hide file tree
Showing 19 changed files with 411 additions and 288 deletions.
18 changes: 4 additions & 14 deletions packages/core/components/FileDetails/FileAnnotationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,11 @@ export default function FileAnnotationList(props: FileAnnotationListProps) {
let active = true;

async function formatPathForHost() {
if (!fileDetails) {
return;
}
if (!fileDetails || !active) return;

const localPath = fileDetails.localPath;
const path = localPath ? await executionEnvService.formatPathForHost(localPath) : null;

let path;
if (fileDetails.localPath === null) {
// The Local File Path annotation is not defined because the file is not available
// on-premises
path = fileDetails.localPath;
} else {
path = await executionEnvService.formatPathForHost(fileDetails.localPath);
}
if (!active) {
return;
}
setLocalPath(path);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import FileAnnotationList from "../FileAnnotationList";
import FileDetail from "../../../entity/FileDetail";
import ExecutionEnvServiceNoop from "../../../services/ExecutionEnvService/ExecutionEnvServiceNoop";
import { initialState } from "../../../state";
import { TOP_LEVEL_FILE_ANNOTATIONS } from "../../../constants";
import Annotation from "../../../entity/Annotation";
import { AnnotationType } from "../../../entity/AnnotationFormatter";
import { Environment, TOP_LEVEL_FILE_ANNOTATIONS } from "../../../constants";

describe("<FileAnnotationList />", () => {
describe("file path representation", () => {
Expand All @@ -20,22 +18,14 @@ describe("<FileAnnotationList />", () => {

class FakeExecutionEnvService extends ExecutionEnvServiceNoop {
public formatPathForHost(posixPath: string): Promise<string> {
return Promise.resolve(posixPath.replace("/allen", hostMountPoint));
return Promise.resolve(posixPath.replace("/test", hostMountPoint));
}
}

const { store } = configureMockStore({
state: mergeState(initialState, {
metadata: {
annotations: [
...TOP_LEVEL_FILE_ANNOTATIONS,
new Annotation({
annotationName: "Local File Path",
annotationDisplayName: "File Path (Local VAST)",
description: "Path to file in on-premises storage.",
type: AnnotationType.STRING,
}),
],
annotations: [...TOP_LEVEL_FILE_ANNOTATIONS],
},
interaction: {
platformDependentServices: {
Expand All @@ -45,18 +35,19 @@ describe("<FileAnnotationList />", () => {
}),
});

const filePathInsideAllenDrive = "path/to/MyFile.txt";
const filePath = `production.files.allencell.org/${filePathInsideAllenDrive}`;
const fileDetails = new FileDetail({
file_path: filePath,
file_id: "abc123",
file_name: "MyFile.txt",
file_size: 7,
uploaded: "01/01/01",
annotations: [
{ name: "Local File Path", values: [`/allen/${filePathInsideAllenDrive}`] },
],
});
const relativePath = "MyFile.txt";
const filePath = `test.files.allencell.org/${relativePath}`;
const fileDetails = new FileDetail(
{
file_path: filePath,
file_id: "c32e3eed66e4416d9532d369ffe1636f",
file_name: "MyFile.txt",
file_size: 7,
uploaded: "01/01/01",
annotations: [{ name: "Cache Eviction Date", values: ["SOME DATE"] }],
},
Environment.TEST
);

// Act
const { findByText } = render(
Expand All @@ -70,7 +61,7 @@ describe("<FileAnnotationList />", () => {
"File Path (Cloud)",
`https://s3.us-west-2.amazonaws.com/${filePath}`,
"File Path (Local VAST)",
`${hostMountPoint}/${filePathInsideAllenDrive}`,
`${hostMountPoint}/${relativePath}`,
]) {
expect(await findByText(cellText)).to.not.be.undefined;
}
Expand Down Expand Up @@ -98,15 +89,18 @@ describe("<FileAnnotationList />", () => {
});

const filePathInsideAllenDrive = "path/to/MyFile.txt";
const filePath = `production.files.allencell.org/${filePathInsideAllenDrive}`;
const fileDetails = new FileDetail({
file_path: filePath,
file_id: "abc123",
file_name: "MyFile.txt",
file_size: 7,
uploaded: "01/01/01",
annotations: [],
});
const filePath = `test.files.allencell.org/${filePathInsideAllenDrive}`;
const fileDetails = new FileDetail(
{
file_path: filePath,
file_id: "abc123",
file_name: "MyFile.txt",
file_size: 7,
uploaded: "01/01/01",
annotations: [],
},
Environment.TEST
);

// Act
const { getByText } = render(
Expand Down Expand Up @@ -144,14 +138,17 @@ describe("<FileAnnotationList />", () => {
}),
});

const fileDetails = new FileDetail({
file_path: "path/to/file",
file_id: "abc123",
file_name: "MyFile.txt",
file_size: 7,
uploaded: "01/01/01",
annotations: [{ name: "shouldBeInLocal", values: [true] }],
});
const fileDetails = new FileDetail(
{
file_path: "path/to/file",
file_id: "abc123",
file_name: "MyFile.txt",
file_size: 7,
uploaded: "01/01/01",
annotations: [{ name: "shouldBeInLocal", values: [true] }],
},
Environment.TEST
);

// Act
const { findByText } = render(
Expand Down
32 changes: 18 additions & 14 deletions packages/core/components/FileList/test/LazilyRenderedRow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import FileSet from "../../../entity/FileSet";
import { initialState } from "../../../state";

import LazilyRenderedRow from "../LazilyRenderedRow";
import { Environment } from "../../../constants";

describe("<LazilyRenderedRow />", () => {
const fileNameAnnotation = new Annotation({
Expand All @@ -24,20 +25,23 @@ describe("<LazilyRenderedRow />", () => {
const fileSet = new FileSet();
sinon.stub(fileSet, "getFileByIndex").callsFake((index) => {
if (index === 3) {
return new FileDetail({
annotations: [
{
name: "someDateAnnotation",
values: ["2019-05-17T07:43:55.205Z"],
},
],
file_id: "abc123",
file_name: "my_image.czi",
file_path: "some/path/to/my_image.czi",
file_size: 1,
thumbnail: "",
uploaded: new Date().toISOString(),
});
return new FileDetail(
{
annotations: [
{
name: "someDateAnnotation",
values: ["2019-05-17T07:43:55.205Z"],
},
],
file_id: "abc123",
file_name: "my_image.czi",
file_path: "some/path/to/my_image.czi",
file_size: 1,
thumbnail: "",
uploaded: new Date().toISOString(),
},
Environment.TEST
);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,51 @@ import { initialState } from "../../../state";
import FileSet from "../../../entity/FileSet";
import FileDetail from "../../../entity/FileDetail";
import { FileView } from "../../../entity/FileExplorerURL";
import { Environment } from "../../../constants";

describe("<LazilyRenderedThumbnail />", () => {
function makeItemData() {
const fileSet = new FileSet();
sinon.stub(fileSet, "getFileByIndex").callsFake((index) => {
if (index === 0) {
return new FileDetail({
annotations: [],
file_id: "abc1230",
file_name: "my_image0.czi",
file_path: "some/path/to/my_image0.czi",
file_size: 1,
thumbnail: "some/path/to/my_image0.jpg",
uploaded: new Date().toISOString(),
});
return new FileDetail(
{
annotations: [],
file_id: "abc1230",
file_name: "my_image0.czi",
file_path: "some/path/to/my_image0.czi",
file_size: 1,
thumbnail: "some/path/to/my_image0.jpg",
uploaded: new Date().toISOString(),
},
Environment.TEST
);
}
if (index === 9) {
return new FileDetail({
annotations: [],
file_id: "abc1239",
file_name: "my_image9.jpg",
file_path: "some/path/to/my_image9.jpg",
file_size: 1,
uploaded: new Date().toISOString(),
});
return new FileDetail(
{
annotations: [],
file_id: "abc1239",
file_name: "my_image9.jpg",
file_path: "some/path/to/my_image9.jpg",
file_size: 1,
uploaded: new Date().toISOString(),
},
Environment.TEST
);
}
if (index === 25) {
return new FileDetail({
annotations: [],
file_id: "abc12325",
file_name: "my_image25.czi",
file_path: "some/path/to/my_image25.czi",
file_size: 1,
uploaded: new Date().toISOString(),
});
return new FileDetail(
{
annotations: [],
file_id: "abc12325",
file_name: "my_image25.czi",
file_path: "some/path/to/my_image25.czi",
file_size: 1,
uploaded: new Date().toISOString(),
},
Environment.TEST
);
}
});

Expand Down
6 changes: 6 additions & 0 deletions packages/core/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export const TOP_LEVEL_FILE_ANNOTATIONS = [
description: "Path to file in the cloud.",
type: AnnotationType.STRING,
}),
new Annotation({
annotationDisplayName: "File Path (Local VAST)",
annotationName: AnnotationName.LOCAL_FILE_PATH,
description: "Path to file in local storage.",
type: AnnotationType.STRING,
}),
new Annotation({
annotationDisplayName: "Size",
annotationName: AnnotationName.FILE_SIZE,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/entity/Annotation/AnnotationName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
FILE_NAME: "file_name", // a file attribute (top-level prop on file documents in MongoDb)
FILE_SIZE: "file_size", // a file attribute (top-level prop on file documents in MongoDb)
FILE_PATH: "file_path", // a file attribute (top-level prop on file documents in MongoDb)
LOCAL_FILE_PATH: "Local File Path", // (optional) annotation for FMS files on the local NAS
LOCAL_FILE_PATH: "File Path (Local VAST)", // (optional) annotation for FMS files on the local NAS
PLATE_BARCODE: "Plate Barcode",
SHOULD_BE_IN_LOCAL: "Should Be in Local Cache",
THUMBNAIL_PATH: "thumbnail", // (optional) file attribute (top-level prop on the file documents in MongoDb)
Expand Down
Loading

0 comments on commit d1f5d33

Please sign in to comment.