Skip to content

Commit

Permalink
Merge pull request #339 from AllenInstitute/feature/refactor-environment
Browse files Browse the repository at this point in the history
feature/refactor-environment
  • Loading branch information
BrianWhitneyAI authored Nov 22, 2024
2 parents f697ebd + ccca39f commit 390a804
Show file tree
Hide file tree
Showing 29 changed files with 300 additions and 281 deletions.
15 changes: 5 additions & 10 deletions packages/core/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import GlobalActionButtonRow from "./components/GlobalActionButtonRow";
import StatusMessage from "./components/StatusMessage";
import TutorialTooltip from "./components/TutorialTooltip";
import QuerySidebar from "./components/QuerySidebar";
import { AicsLoadBalancerBaseUrl, FileExplorerServiceBaseUrl } from "./constants";
import { Environment } from "./constants";
import { interaction, selection } from "./state";
import useLayoutMeasurements from "./hooks/useLayoutMeasurements";

Expand All @@ -39,15 +39,11 @@ interface AppProps {
// Localhost: "https://localhost:9081"
// Stage: "http://stg-aics-api.corp.alleninstitute.org"
// From the web (behind load balancer): "/"
aicsLoadBalancerBaseUrl?: string;
fileExplorerServiceBaseUrl?: string;
environment?: Environment;
}

export default function App(props: AppProps) {
const {
aicsLoadBalancerBaseUrl = AicsLoadBalancerBaseUrl.PRODUCTION,
fileExplorerServiceBaseUrl = FileExplorerServiceBaseUrl.PRODUCTION,
} = props;
const { environment = Environment.PRODUCTION } = props;

const dispatch = useDispatch();
const hasQuerySelected = useSelector(selection.selectors.hasQuerySelected);
Expand Down Expand Up @@ -86,11 +82,10 @@ export default function App(props: AppProps) {
React.useEffect(() => {
dispatch(
interaction.actions.initializeApp({
aicsLoadBalancerBaseUrl,
fileExplorerServiceBaseUrl,
environment,
})
);
}, [dispatch, aicsLoadBalancerBaseUrl, fileExplorerServiceBaseUrl]);
}, [dispatch, environment]);

// Respond to screen size changes
React.useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Annotation from "../../../entity/Annotation";
import FileFilter from "../../../entity/FileFilter";
import { initialState, reducer, reduxLogics, interaction, selection } from "../../../state";
import HttpAnnotationService from "../../../services/AnnotationService/HttpAnnotationService";
import { FESBaseUrl } from "../../../constants";

describe("<AnnotationFilterForm />", () => {
const LISTROW_TESTID_PREFIX = "default-button-";
Expand All @@ -31,14 +32,14 @@ describe("<AnnotationFilterForm />", () => {
it("shows all values as unchecked at first", async () => {
// arrange
const responseStub = {
when: `test/file-explorer-service/1.0/annotations/${fooAnnotation.name}/values`,
when: `${FESBaseUrl.TEST}/file-explorer-service/1.0/annotations/${fooAnnotation.name}/values`,
respondWith: {
data: { data: ["a", "b", "c", "d"] },
},
};
const mockHttpClient = createMockHttpClient(responseStub);
const annotationService = new HttpAnnotationService({
baseUrl: "test",
fileExplorerServiceBaseUrl: FESBaseUrl.TEST,
httpClient: mockHttpClient,
});
sandbox.stub(interaction.selectors, "getAnnotationService").returns(annotationService);
Expand Down Expand Up @@ -68,14 +69,14 @@ describe("<AnnotationFilterForm />", () => {
it("deselects and selects a value", async () => {
// arrange
const responseStub = {
when: `test/file-explorer-service/1.0/annotations/${fooAnnotation.name}/values`,
when: `${FESBaseUrl.TEST}/file-explorer-service/1.0/annotations/${fooAnnotation.name}/values`,
respondWith: {
data: { data: ["a", "b", "c", "d"] },
},
};
const mockHttpClient = createMockHttpClient(responseStub);
const annotationService = new HttpAnnotationService({
baseUrl: "test",
fileExplorerServiceBaseUrl: FESBaseUrl.TEST,
httpClient: mockHttpClient,
});
sandbox.stub(interaction.selectors, "getAnnotationService").returns(annotationService);
Expand Down Expand Up @@ -124,14 +125,14 @@ describe("<AnnotationFilterForm />", () => {
it("naturally sorts values", async () => {
// arrange
const responseStub = {
when: `test/file-explorer-service/1.0/annotations/${fooAnnotation.name}/values`,
when: `${FESBaseUrl.TEST}/file-explorer-service/1.0/annotations/${fooAnnotation.name}/values`,
respondWith: {
data: { data: ["AICS-24", "AICS-0", "aics-32", "aICs-2"] },
},
};
const mockHttpClient = createMockHttpClient(responseStub);
const annotationService = new HttpAnnotationService({
baseUrl: "test",
fileExplorerServiceBaseUrl: FESBaseUrl.TEST,
httpClient: mockHttpClient,
});
sandbox.stub(interaction.selectors, "getAnnotationService").returns(annotationService);
Expand Down Expand Up @@ -172,14 +173,14 @@ describe("<AnnotationFilterForm />", () => {
});

const responseStub = {
when: `test/file-explorer-service/1.0/annotations/${fooAnnotation.name}/values`,
when: `${FESBaseUrl.TEST}/file-explorer-service/1.0/annotations/${fooAnnotation.name}/values`,
respondWith: {
data: { data: [true, false] },
},
};
const mockHttpClient = createMockHttpClient(responseStub);
const annotationService = new HttpAnnotationService({
baseUrl: "test",
fileExplorerServiceBaseUrl: FESBaseUrl.TEST,
httpClient: mockHttpClient,
});

Expand Down Expand Up @@ -279,14 +280,14 @@ describe("<AnnotationFilterForm />", () => {
it("naturally sorts values", async () => {
// arrange
const responseStub = {
when: `test/file-explorer-service/1.0/annotations/${fooAnnotation.name}/values`,
when: `${FESBaseUrl.TEST}/file-explorer-service/1.0/annotations/${fooAnnotation.name}/values`,
respondWith: {
data: { data: [5, 8, 6.3, -12, 10000000000, 0] },
},
};
const mockHttpClient = createMockHttpClient(responseStub);
const annotationService = new HttpAnnotationService({
baseUrl: "test",
fileExplorerServiceBaseUrl: FESBaseUrl.TEST,
httpClient: mockHttpClient,
});
sandbox.stub(interaction.selectors, "getAnnotationService").returns(annotationService);
Expand Down Expand Up @@ -334,14 +335,14 @@ describe("<AnnotationFilterForm />", () => {
it("naturally sorts values", async () => {
// arrange
const responseStub = {
when: `test/file-explorer-service/1.0/annotations/${fooAnnotation.name}/values`,
when: `${FESBaseUrl.TEST}/file-explorer-service/1.0/annotations/${fooAnnotation.name}/values`,
respondWith: {
data: { data: [446582220, 125, 10845000, 86400000] },
},
};
const mockHttpClient = createMockHttpClient(responseStub);
const annotationService = new HttpAnnotationService({
baseUrl: "test",
fileExplorerServiceBaseUrl: FESBaseUrl.TEST,
httpClient: mockHttpClient,
});
sandbox.stub(interaction.selectors, "getAnnotationService").returns(annotationService);
Expand Down
17 changes: 7 additions & 10 deletions packages/core/components/DirectoryTree/test/DirectoryTree.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { Provider } from "react-redux";
import { createSandbox } from "sinon";

import { TOP_LEVEL_FILE_ANNOTATIONS } from "../../../constants";
import { FESBaseUrl, TOP_LEVEL_FILE_ANNOTATIONS } from "../../../constants";
import Annotation from "../../../entity/Annotation";
import AnnotationName from "../../../entity/Annotation/AnnotationName";
import { FmsFileAnnotation } from "../../../services/FileService";
Expand Down Expand Up @@ -53,14 +53,10 @@ describe("<DirectoryTree />", () => {
type: "Text",
});

const baseUrl = "http://test-aics.corp.alleninstitute.org";
const baseDisplayAnnotations = TOP_LEVEL_FILE_ANNOTATIONS.filter(
(a) => a.name === AnnotationName.FILE_NAME
);
const state = mergeState(initialState, {
interaction: {
fileExplorerServiceBaseUrl: baseUrl,
},
selection: {
annotationHierarchy: [fooAnnotation.name, barAnnotation.name],
displayAnnotations: [...baseDisplayAnnotations, fooAnnotation, barAnnotation],
Expand Down Expand Up @@ -188,9 +184,13 @@ describe("<DirectoryTree />", () => {
},
];
const mockHttpClient = createMockHttpClient(responseStubs);
const annotationService = new HttpAnnotationService({ baseUrl, httpClient: mockHttpClient });
const fileExplorerServiceBaseUrl = FESBaseUrl.TEST;
const annotationService = new HttpAnnotationService({
fileExplorerServiceBaseUrl: fileExplorerServiceBaseUrl,
httpClient: mockHttpClient,
});
const fileService = new HttpFileService({
baseUrl,
fileExplorerServiceBaseUrl: fileExplorerServiceBaseUrl,
httpClient: mockHttpClient,
downloadService: new FileDownloadServiceNoop(),
});
Expand Down Expand Up @@ -353,9 +353,6 @@ describe("<DirectoryTree />", () => {

it("only includes one filter value per annotation for an annotation within the hierarchy", async () => {
const oneAnnotationDeepState = mergeState(initialState, {
interaction: {
fileExplorerServiceBaseUrl: baseUrl,
},
selection: {
annotationHierarchy: [fooAnnotation.name],
displayAnnotations: [...baseDisplayAnnotations, fooAnnotation, barAnnotation],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@ import { Provider } from "react-redux";
import { createSandbox } from "sinon";

import Modal, { ModalType } from "../..";
import { FESBaseUrl } from "../../../../constants";
import Annotation from "../../../../entity/Annotation";
import FileFilter from "../../../../entity/FileFilter";
import { initialState, interaction, reduxLogics } from "../../../../state";
import HttpFileService from "../../../../services/FileService/HttpFileService";
import FileDownloadServiceNoop from "../../../../services/FileDownloadService/FileDownloadServiceNoop";

describe("<MetadataManifest />", () => {
const baseUrl = "test";
const fileExplorerServiceBaseUrl = FESBaseUrl.TEST;
const environment = "TEST";
const visibleDialogState = mergeState(initialState, {
interaction: {
fileExplorerServiceBaseUrl: baseUrl,
environment: environment,
visibleModal: ModalType.MetadataManifest,
},
});
Expand All @@ -35,7 +37,7 @@ describe("<MetadataManifest />", () => {
};
const mockHttpClient = createMockHttpClient(responseStub);
const fileService = new HttpFileService({
baseUrl,
fileExplorerServiceBaseUrl,
httpClient: mockHttpClient,
downloadService: new FileDownloadServiceNoop(),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import Modal, { ModalType } from "../..";
import { initialState, interaction, reduxLogics } from "../../../../state";

describe("<SmallScreenWarning />", () => {
const baseUrl = "test";
const visibleDialogState = mergeState(initialState, {
interaction: {
fileExplorerServiceBaseUrl: baseUrl,
visibleModal: ModalType.SmallScreenWarning,
},
});
Expand Down
36 changes: 26 additions & 10 deletions packages/core/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@ import { AnnotationType } from "../entity/AnnotationFormatter";
export const APP_ID = "fms-file-explorer-core";

// Refer to packages/fms-file-explorer-electron/src/main/menu
export enum FileExplorerServiceBaseUrl {
LOCALHOST = "http://localhost:9081",
STAGING = "https://staging.int.allencell.org",
PRODUCTION = "https://production.int.allencell.org",
}

export enum AicsLoadBalancerBaseUrl {
LOCALHOST = "http://localhost:8080",
STAGING = "http://stg-aics.corp.alleninstitute.org",
PRODUCTION = "http://aics.corp.alleninstitute.org",
export enum Environment {
LOCALHOST = "LOCALHOST",
STAGING = "STAGING",
PRODUCTION = "PRODUCTION",
TEST = "TEST",
}

export const TOP_LEVEL_FILE_ANNOTATIONS = [
Expand Down Expand Up @@ -65,3 +60,24 @@ export const THUMBNAIL_SIZE_TO_NUM_COLUMNS = {
};

export const AICS_FMS_DATA_SOURCE_NAME = "AICS FMS";

export enum FESBaseUrl {
LOCALHOST = "http://localhost:9081",
STAGING = "https://staging.int.allencell.org",
PRODUCTION = "https://production.int.allencell.org",
TEST = "http://test.int.allencell.org",
}

export enum MMSBaseUrl {
LOCALHOST = "http://localhost:9060",
STAGING = "http://stg-aics-api",
PRODUCTION = "http://prod-aics-api",
TEST = "http://test-aics-api",
}

export enum LoadBalancerBaseUrl {
LOCALHOST = "http://localhost:8080",
STAGING = "http://stg-aics.corp.alleninstitute.org",
PRODUCTION = "http://aics.corp.alleninstitute.org",
TEST = "http://test-aics.corp.alleninstitute.org",
}
9 changes: 6 additions & 3 deletions packages/core/entity/FileSelection/test/FileSelection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import FileSet from "../../FileSet";
import NumericRange from "../../NumericRange";

import FileSelection, { FocusDirective } from "..";
import { FESBaseUrl } from "../../../constants";
import FileDetail from "../../FileDetail";
import FileFilter from "../../FileFilter";
import FuzzyFilter from "../../FileFilter/FuzzyFilter";
Expand Down Expand Up @@ -344,7 +345,7 @@ describe("FileSelection", () => {
describe("fetchAllDetails", () => {
it("returns file details for each selected item", async () => {
// Arrange
const baseUrl = "test";
const fileExplorerServiceBaseUrl = FESBaseUrl.TEST;
const queryResult = [];
for (let i = 0; i < 31; i++) {
queryResult.push(i);
Expand All @@ -354,13 +355,15 @@ describe("FileSelection", () => {
.slice(1, 31)
.map((detail) => new FileDetail(detail as any));
const httpClient = createMockHttpClient({
when: `${baseUrl}/${HttpFileService.BASE_FILES_URL}?from=${0}&limit=${31}`,
when: `${fileExplorerServiceBaseUrl}/${
HttpFileService.BASE_FILES_URL
}?from=${0}&limit=${31}`,
respondWith: {
data: { data: queryResult },
},
});
const fileService = new HttpFileService({
baseUrl,
fileExplorerServiceBaseUrl,
httpClient,
downloadService: new FileDownloadServiceNoop(),
});
Expand Down
4 changes: 2 additions & 2 deletions packages/core/entity/FileSet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default class FileSet {
* by using this as the component's `key` attribute.
*/
public get hash() {
return `${this.toQueryString()}:${this.fileService.baseUrl}`;
return `${this.toQueryString()}:${this.fileService.fileExplorerServiceBaseUrl}`;
}

public async fetchTotalCount() {
Expand Down Expand Up @@ -210,7 +210,7 @@ export default class FileSet {
public toJSON() {
return {
queryString: this.toQueryString(),
baseUrl: this.fileService.baseUrl,
fileExplorerServiceBaseUrl: this.fileService.fileExplorerServiceBaseUrl,
};
}

Expand Down
Loading

0 comments on commit 390a804

Please sign in to comment.