Skip to content

Commit d1f5d33

Browse files
Merge pull request #389 from AllenInstitute/feature/derive_local_path
feature/derive_local_path
2 parents 89df078 + e7592a7 commit d1f5d33

File tree

19 files changed

+411
-288
lines changed

19 files changed

+411
-288
lines changed

packages/core/components/FileDetails/FileAnnotationList.tsx

+4-14
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,11 @@ export default function FileAnnotationList(props: FileAnnotationListProps) {
3333
let active = true;
3434

3535
async function formatPathForHost() {
36-
if (!fileDetails) {
37-
return;
38-
}
36+
if (!fileDetails || !active) return;
37+
38+
const localPath = fileDetails.localPath;
39+
const path = localPath ? await executionEnvService.formatPathForHost(localPath) : null;
3940

40-
let path;
41-
if (fileDetails.localPath === null) {
42-
// The Local File Path annotation is not defined because the file is not available
43-
// on-premises
44-
path = fileDetails.localPath;
45-
} else {
46-
path = await executionEnvService.formatPathForHost(fileDetails.localPath);
47-
}
48-
if (!active) {
49-
return;
50-
}
5141
setLocalPath(path);
5242
}
5343

packages/core/components/FileDetails/test/FileAnnotationList.test.tsx

+40-43
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import FileAnnotationList from "../FileAnnotationList";
88
import FileDetail from "../../../entity/FileDetail";
99
import ExecutionEnvServiceNoop from "../../../services/ExecutionEnvService/ExecutionEnvServiceNoop";
1010
import { initialState } from "../../../state";
11-
import { TOP_LEVEL_FILE_ANNOTATIONS } from "../../../constants";
12-
import Annotation from "../../../entity/Annotation";
13-
import { AnnotationType } from "../../../entity/AnnotationFormatter";
11+
import { Environment, TOP_LEVEL_FILE_ANNOTATIONS } from "../../../constants";
1412

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

2119
class FakeExecutionEnvService extends ExecutionEnvServiceNoop {
2220
public formatPathForHost(posixPath: string): Promise<string> {
23-
return Promise.resolve(posixPath.replace("/allen", hostMountPoint));
21+
return Promise.resolve(posixPath.replace("/test", hostMountPoint));
2422
}
2523
}
2624

2725
const { store } = configureMockStore({
2826
state: mergeState(initialState, {
2927
metadata: {
30-
annotations: [
31-
...TOP_LEVEL_FILE_ANNOTATIONS,
32-
new Annotation({
33-
annotationName: "Local File Path",
34-
annotationDisplayName: "File Path (Local VAST)",
35-
description: "Path to file in on-premises storage.",
36-
type: AnnotationType.STRING,
37-
}),
38-
],
28+
annotations: [...TOP_LEVEL_FILE_ANNOTATIONS],
3929
},
4030
interaction: {
4131
platformDependentServices: {
@@ -45,18 +35,19 @@ describe("<FileAnnotationList />", () => {
4535
}),
4636
});
4737

48-
const filePathInsideAllenDrive = "path/to/MyFile.txt";
49-
const filePath = `production.files.allencell.org/${filePathInsideAllenDrive}`;
50-
const fileDetails = new FileDetail({
51-
file_path: filePath,
52-
file_id: "abc123",
53-
file_name: "MyFile.txt",
54-
file_size: 7,
55-
uploaded: "01/01/01",
56-
annotations: [
57-
{ name: "Local File Path", values: [`/allen/${filePathInsideAllenDrive}`] },
58-
],
59-
});
38+
const relativePath = "MyFile.txt";
39+
const filePath = `test.files.allencell.org/${relativePath}`;
40+
const fileDetails = new FileDetail(
41+
{
42+
file_path: filePath,
43+
file_id: "c32e3eed66e4416d9532d369ffe1636f",
44+
file_name: "MyFile.txt",
45+
file_size: 7,
46+
uploaded: "01/01/01",
47+
annotations: [{ name: "Cache Eviction Date", values: ["SOME DATE"] }],
48+
},
49+
Environment.TEST
50+
);
6051

6152
// Act
6253
const { findByText } = render(
@@ -70,7 +61,7 @@ describe("<FileAnnotationList />", () => {
7061
"File Path (Cloud)",
7162
`https://s3.us-west-2.amazonaws.com/${filePath}`,
7263
"File Path (Local VAST)",
73-
`${hostMountPoint}/${filePathInsideAllenDrive}`,
64+
`${hostMountPoint}/${relativePath}`,
7465
]) {
7566
expect(await findByText(cellText)).to.not.be.undefined;
7667
}
@@ -98,15 +89,18 @@ describe("<FileAnnotationList />", () => {
9889
});
9990

10091
const filePathInsideAllenDrive = "path/to/MyFile.txt";
101-
const filePath = `production.files.allencell.org/${filePathInsideAllenDrive}`;
102-
const fileDetails = new FileDetail({
103-
file_path: filePath,
104-
file_id: "abc123",
105-
file_name: "MyFile.txt",
106-
file_size: 7,
107-
uploaded: "01/01/01",
108-
annotations: [],
109-
});
92+
const filePath = `test.files.allencell.org/${filePathInsideAllenDrive}`;
93+
const fileDetails = new FileDetail(
94+
{
95+
file_path: filePath,
96+
file_id: "abc123",
97+
file_name: "MyFile.txt",
98+
file_size: 7,
99+
uploaded: "01/01/01",
100+
annotations: [],
101+
},
102+
Environment.TEST
103+
);
110104

111105
// Act
112106
const { getByText } = render(
@@ -144,14 +138,17 @@ describe("<FileAnnotationList />", () => {
144138
}),
145139
});
146140

147-
const fileDetails = new FileDetail({
148-
file_path: "path/to/file",
149-
file_id: "abc123",
150-
file_name: "MyFile.txt",
151-
file_size: 7,
152-
uploaded: "01/01/01",
153-
annotations: [{ name: "shouldBeInLocal", values: [true] }],
154-
});
141+
const fileDetails = new FileDetail(
142+
{
143+
file_path: "path/to/file",
144+
file_id: "abc123",
145+
file_name: "MyFile.txt",
146+
file_size: 7,
147+
uploaded: "01/01/01",
148+
annotations: [{ name: "shouldBeInLocal", values: [true] }],
149+
},
150+
Environment.TEST
151+
);
155152

156153
// Act
157154
const { findByText } = render(

packages/core/components/FileList/test/LazilyRenderedRow.test.tsx

+18-14
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import FileSet from "../../../entity/FileSet";
1111
import { initialState } from "../../../state";
1212

1313
import LazilyRenderedRow from "../LazilyRenderedRow";
14+
import { Environment } from "../../../constants";
1415

1516
describe("<LazilyRenderedRow />", () => {
1617
const fileNameAnnotation = new Annotation({
@@ -24,20 +25,23 @@ describe("<LazilyRenderedRow />", () => {
2425
const fileSet = new FileSet();
2526
sinon.stub(fileSet, "getFileByIndex").callsFake((index) => {
2627
if (index === 3) {
27-
return new FileDetail({
28-
annotations: [
29-
{
30-
name: "someDateAnnotation",
31-
values: ["2019-05-17T07:43:55.205Z"],
32-
},
33-
],
34-
file_id: "abc123",
35-
file_name: "my_image.czi",
36-
file_path: "some/path/to/my_image.czi",
37-
file_size: 1,
38-
thumbnail: "",
39-
uploaded: new Date().toISOString(),
40-
});
28+
return new FileDetail(
29+
{
30+
annotations: [
31+
{
32+
name: "someDateAnnotation",
33+
values: ["2019-05-17T07:43:55.205Z"],
34+
},
35+
],
36+
file_id: "abc123",
37+
file_name: "my_image.czi",
38+
file_path: "some/path/to/my_image.czi",
39+
file_size: 1,
40+
thumbnail: "",
41+
uploaded: new Date().toISOString(),
42+
},
43+
Environment.TEST
44+
);
4145
}
4246
});
4347

packages/core/components/FileList/test/LazilyRenderedThumbnail.test.tsx

+35-25
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,51 @@ import { initialState } from "../../../state";
1010
import FileSet from "../../../entity/FileSet";
1111
import FileDetail from "../../../entity/FileDetail";
1212
import { FileView } from "../../../entity/FileExplorerURL";
13+
import { Environment } from "../../../constants";
1314

1415
describe("<LazilyRenderedThumbnail />", () => {
1516
function makeItemData() {
1617
const fileSet = new FileSet();
1718
sinon.stub(fileSet, "getFileByIndex").callsFake((index) => {
1819
if (index === 0) {
19-
return new FileDetail({
20-
annotations: [],
21-
file_id: "abc1230",
22-
file_name: "my_image0.czi",
23-
file_path: "some/path/to/my_image0.czi",
24-
file_size: 1,
25-
thumbnail: "some/path/to/my_image0.jpg",
26-
uploaded: new Date().toISOString(),
27-
});
20+
return new FileDetail(
21+
{
22+
annotations: [],
23+
file_id: "abc1230",
24+
file_name: "my_image0.czi",
25+
file_path: "some/path/to/my_image0.czi",
26+
file_size: 1,
27+
thumbnail: "some/path/to/my_image0.jpg",
28+
uploaded: new Date().toISOString(),
29+
},
30+
Environment.TEST
31+
);
2832
}
2933
if (index === 9) {
30-
return new FileDetail({
31-
annotations: [],
32-
file_id: "abc1239",
33-
file_name: "my_image9.jpg",
34-
file_path: "some/path/to/my_image9.jpg",
35-
file_size: 1,
36-
uploaded: new Date().toISOString(),
37-
});
34+
return new FileDetail(
35+
{
36+
annotations: [],
37+
file_id: "abc1239",
38+
file_name: "my_image9.jpg",
39+
file_path: "some/path/to/my_image9.jpg",
40+
file_size: 1,
41+
uploaded: new Date().toISOString(),
42+
},
43+
Environment.TEST
44+
);
3845
}
3946
if (index === 25) {
40-
return new FileDetail({
41-
annotations: [],
42-
file_id: "abc12325",
43-
file_name: "my_image25.czi",
44-
file_path: "some/path/to/my_image25.czi",
45-
file_size: 1,
46-
uploaded: new Date().toISOString(),
47-
});
47+
return new FileDetail(
48+
{
49+
annotations: [],
50+
file_id: "abc12325",
51+
file_name: "my_image25.czi",
52+
file_path: "some/path/to/my_image25.czi",
53+
file_size: 1,
54+
uploaded: new Date().toISOString(),
55+
},
56+
Environment.TEST
57+
);
4858
}
4959
});
5060

packages/core/constants/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ export const TOP_LEVEL_FILE_ANNOTATIONS = [
3131
description: "Path to file in the cloud.",
3232
type: AnnotationType.STRING,
3333
}),
34+
new Annotation({
35+
annotationDisplayName: "File Path (Local VAST)",
36+
annotationName: AnnotationName.LOCAL_FILE_PATH,
37+
description: "Path to file in local storage.",
38+
type: AnnotationType.STRING,
39+
}),
3440
new Annotation({
3541
annotationDisplayName: "Size",
3642
annotationName: AnnotationName.FILE_SIZE,

packages/core/entity/Annotation/AnnotationName.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
FILE_NAME: "file_name", // a file attribute (top-level prop on file documents in MongoDb)
77
FILE_SIZE: "file_size", // a file attribute (top-level prop on file documents in MongoDb)
88
FILE_PATH: "file_path", // a file attribute (top-level prop on file documents in MongoDb)
9-
LOCAL_FILE_PATH: "Local File Path", // (optional) annotation for FMS files on the local NAS
9+
LOCAL_FILE_PATH: "File Path (Local VAST)", // (optional) annotation for FMS files on the local NAS
1010
PLATE_BARCODE: "Plate Barcode",
1111
SHOULD_BE_IN_LOCAL: "Should Be in Local Cache",
1212
THUMBNAIL_PATH: "thumbnail", // (optional) file attribute (top-level prop on the file documents in MongoDb)

0 commit comments

Comments
 (0)