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

feature/refactor-environment #339

Merged
Show file tree
Hide file tree
Changes from 3 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
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?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the enum as the type value here (Environment)

Suggested change
environment?: string;
environment?: Environment;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved in 07a2715

}

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 @@ -38,7 +38,7 @@ describe("<AnnotationFilterForm />", () => {
};
const mockHttpClient = createMockHttpClient(responseStub);
const annotationService = new HttpAnnotationService({
baseUrl: "test",
fileExplorerServiceBaseUrl: "test",
httpClient: mockHttpClient,
});
sandbox.stub(interaction.selectors, "getAnnotationService").returns(annotationService);
Expand Down Expand Up @@ -75,7 +75,7 @@ describe("<AnnotationFilterForm />", () => {
};
const mockHttpClient = createMockHttpClient(responseStub);
const annotationService = new HttpAnnotationService({
baseUrl: "test",
fileExplorerServiceBaseUrl: "test",
httpClient: mockHttpClient,
});
sandbox.stub(interaction.selectors, "getAnnotationService").returns(annotationService);
Expand Down Expand Up @@ -131,7 +131,7 @@ describe("<AnnotationFilterForm />", () => {
};
const mockHttpClient = createMockHttpClient(responseStub);
const annotationService = new HttpAnnotationService({
baseUrl: "test",
fileExplorerServiceBaseUrl: "test",
httpClient: mockHttpClient,
});
sandbox.stub(interaction.selectors, "getAnnotationService").returns(annotationService);
Expand Down Expand Up @@ -179,7 +179,7 @@ describe("<AnnotationFilterForm />", () => {
};
const mockHttpClient = createMockHttpClient(responseStub);
const annotationService = new HttpAnnotationService({
baseUrl: "test",
fileExplorerServiceBaseUrl: "test",
httpClient: mockHttpClient,
});

Expand Down Expand Up @@ -286,7 +286,7 @@ describe("<AnnotationFilterForm />", () => {
};
const mockHttpClient = createMockHttpClient(responseStub);
const annotationService = new HttpAnnotationService({
baseUrl: "test",
fileExplorerServiceBaseUrl: "test",
httpClient: mockHttpClient,
});
sandbox.stub(interaction.selectors, "getAnnotationService").returns(annotationService);
Expand Down Expand Up @@ -341,7 +341,7 @@ describe("<AnnotationFilterForm />", () => {
};
const mockHttpClient = createMockHttpClient(responseStub);
const annotationService = new HttpAnnotationService({
baseUrl: "test",
fileExplorerServiceBaseUrl: "test",
httpClient: mockHttpClient,
});
sandbox.stub(interaction.selectors, "getAnnotationService").returns(annotationService);
Expand Down
Original file line number Diff line number Diff line change
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 = "http://test.int.allencell.org";
const annotationService = new HttpAnnotationService({
fileExplorerServiceBaseUrl: fileExplorerServiceBaseUrl,
httpClient: mockHttpClient,
});
const fileService = new HttpFileService({
baseUrl,
fileExplorerServiceBaseUrl: fileExplorerServiceBaseUrl,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you want to be extra javascripty, this and line 189 could just be fileExplorerServiceBaseUrl,

Copy link
Contributor Author

@BrianWhitneyAI BrianWhitneyAI Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it bad to say I don't want to be? I kept moving around variables and stuff broke.

Copy link
Contributor

@aswallace aswallace Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough! just noted since elsewhere in file sometimes (or used to?) use this pattern

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 @@ -19,10 +19,11 @@ import HttpFileService from "../../../../services/FileService/HttpFileService";
import FileDownloadServiceNoop from "../../../../services/FileDownloadService/FileDownloadServiceNoop";

describe("<MetadataManifest />", () => {
const baseUrl = "test";
const fileExplorerServiceBaseUrl = "TEST";
const environment = "TEST";
const visibleDialogState = mergeState(initialState, {
interaction: {
fileExplorerServiceBaseUrl: baseUrl,
environment: environment,
visibleModal: ModalType.MetadataManifest,
},
});
Expand All @@ -35,7 +36,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
38 changes: 27 additions & 11 deletions packages/core/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@ 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 const Environment = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be better as an enum

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved in 07a2715

LOCALHOST: "LOCALHOST",
STAGING: "STAGING",
PRODUCTION: "PRODUCTION",
TEST: "TEST",
} as const;

export const TOP_LEVEL_FILE_ANNOTATIONS = [
new Annotation({
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 const FESBaseUrlMap = {
LOCALHOST: "http://localhost:9081",
STAGING: "https://staging.int.allencell.org",
PRODUCTION: "https://production.int.allencell.org",
TEST: "http://test.int.allencell.org",
};

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

export const LoadBalancerBaseUrlMap = {
BrianWhitneyAI marked this conversation as resolved.
Show resolved Hide resolved
LOCALHOST: "http://localhost:8080",
STAGING: "http://stg-aics.corp.alleninstitute.org",
PRODUCTION: "http://aics.corp.alleninstitute.org",
TEST: "http://test-aics.corp.alleninstitute.org",
};
8 changes: 5 additions & 3 deletions packages/core/entity/FileSelection/test/FileSelection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ describe("FileSelection", () => {
describe("fetchAllDetails", () => {
it("returns file details for each selected item", async () => {
// Arrange
const baseUrl = "test";
const fileExplorerServiceBaseUrl = "test";
const queryResult = [];
for (let i = 0; i < 31; i++) {
queryResult.push(i);
Expand All @@ -354,13 +354,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
18 changes: 9 additions & 9 deletions packages/core/entity/FileSet/test/FileSet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,40 +148,40 @@ describe("FileSet", () => {
});

it("turns indicies for requested data into a properly formed pagination query", async () => {
const baseUrl = "test";
const fileExplorerServiceBaseUrl = "test";
const spec = [
{
expectedUrl: `${baseUrl}/${HttpFileService.BASE_FILES_URL}?from=1&limit=28`,
expectedUrl: `${fileExplorerServiceBaseUrl}/${HttpFileService.BASE_FILES_URL}?from=1&limit=28`,
start: 35,
end: 55,
},
{
expectedUrl: `${baseUrl}/${HttpFileService.BASE_FILES_URL}?from=11&limit=23`,
expectedUrl: `${fileExplorerServiceBaseUrl}/${HttpFileService.BASE_FILES_URL}?from=11&limit=23`,
start: 256,
end: 274,
},
{
expectedUrl: `${baseUrl}/${HttpFileService.BASE_FILES_URL}?from=0&limit=6`,
expectedUrl: `${fileExplorerServiceBaseUrl}/${HttpFileService.BASE_FILES_URL}?from=0&limit=6`,
start: 0,
end: 5,
},
{
expectedUrl: `${baseUrl}/${HttpFileService.BASE_FILES_URL}?from=1&limit=11`,
expectedUrl: `${fileExplorerServiceBaseUrl}/${HttpFileService.BASE_FILES_URL}?from=1&limit=11`,
start: 14,
end: 21,
},
{
expectedUrl: `${baseUrl}/${HttpFileService.BASE_FILES_URL}?from=0&limit=6`,
expectedUrl: `${fileExplorerServiceBaseUrl}/${HttpFileService.BASE_FILES_URL}?from=0&limit=6`,
start: 2,
end: 5,
},
{
expectedUrl: `${baseUrl}/${HttpFileService.BASE_FILES_URL}?from=3&limit=4`,
expectedUrl: `${fileExplorerServiceBaseUrl}/${HttpFileService.BASE_FILES_URL}?from=3&limit=4`,
start: 12,
end: 15,
},
{
expectedUrl: `${baseUrl}/${HttpFileService.BASE_FILES_URL}?from=0&limit=301`,
expectedUrl: `${fileExplorerServiceBaseUrl}/${HttpFileService.BASE_FILES_URL}?from=0&limit=301`,
start: 2,
end: 300,
},
Expand All @@ -203,7 +203,7 @@ describe("FileSet", () => {
const fileSet = new FileSet({
fileService: new HttpFileService({
httpClient,
baseUrl,
fileExplorerServiceBaseUrl,
downloadService: new FileDownloadServiceNoop(),
}),
});
Expand Down
4 changes: 2 additions & 2 deletions packages/core/hooks/useOpenWithMenuItems/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ export default (fileDetails?: FileDetail, filters?: FileFilter[]): IContextualMe
const annotationNameToAnnotationMap = useSelector(
metadata.selectors.getAnnotationNameToAnnotationMap
);
const aicsLoadBalancerBaseUrl = useSelector(interaction.selectors.getAicsLoadBalancerBaseUrl);
const loadBalancerBaseUrl = useSelector(interaction.selectors.getLoadBalancerBaseUrl);

const plateLink = fileDetails?.getLinkToPlateUI(aicsLoadBalancerBaseUrl);
const plateLink = fileDetails?.getLinkToPlateUI(loadBalancerBaseUrl);
const annotationNameToLinkMap = React.useMemo(
() =>
fileDetails?.annotations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class HttpAnnotationService extends HttpServiceBase implements An
* Fetch all annotations.
*/
public async fetchAnnotations(): Promise<Annotation[]> {
const requestUrl = `${this.baseUrl}/${HttpAnnotationService.BASE_ANNOTATION_URL}${this.pathSuffix}`;
const requestUrl = `${this.fileExplorerServiceBaseUrl}/${HttpAnnotationService.BASE_ANNOTATION_URL}${this.pathSuffix}`;

const response = await this.get<AnnotationResponse>(requestUrl);
return [
Expand All @@ -45,7 +45,7 @@ export default class HttpAnnotationService extends HttpServiceBase implements An
public async fetchValues(annotation: string): Promise<AnnotationValue[]> {
// Encode any special characters in the annotation as necessary
const encodedAnnotation = HttpServiceBase.encodeURISection(annotation);
const requestUrl = `${this.baseUrl}/${HttpAnnotationService.BASE_ANNOTATION_URL}/${encodedAnnotation}/values${this.pathSuffix}`;
const requestUrl = `${this.fileExplorerServiceBaseUrl}/${HttpAnnotationService.BASE_ANNOTATION_URL}/${encodedAnnotation}/values${this.pathSuffix}`;

const response = await this.get<AnnotationValue>(requestUrl);
return response.data;
Expand All @@ -70,7 +70,7 @@ export default class HttpAnnotationService extends HttpServiceBase implements An
.filter((param) => !!param)
.join("&");

const requestUrl = `${this.baseUrl}/${HttpAnnotationService.BASE_ANNOTATION_HIERARCHY_ROOT_URL}${this.pathSuffix}?${queryParams}`;
const requestUrl = `${this.fileExplorerServiceBaseUrl}/${HttpAnnotationService.BASE_ANNOTATION_HIERARCHY_ROOT_URL}${this.pathSuffix}?${queryParams}`;

const response = await this.get<string>(requestUrl);
return response.data;
Expand All @@ -91,7 +91,7 @@ export default class HttpAnnotationService extends HttpServiceBase implements An
]
.filter((param) => !!param)
.join("&");
const requestUrl = `${this.baseUrl}/${HttpAnnotationService.BASE_ANNOTATION_HIERARCHY_UNDER_PATH_URL}${this.pathSuffix}?${queryParams}`;
const requestUrl = `${this.fileExplorerServiceBaseUrl}/${HttpAnnotationService.BASE_ANNOTATION_HIERARCHY_UNDER_PATH_URL}${this.pathSuffix}?${queryParams}`;

const response = await this.get<string>(requestUrl);
return response.data;
Expand All @@ -103,7 +103,7 @@ export default class HttpAnnotationService extends HttpServiceBase implements An
*/
public async fetchAvailableAnnotationsForHierarchy(annotations: string[]): Promise<string[]> {
const queryParams = this.buildQueryParams(QueryParam.HIERARCHY, [...annotations].sort());
const requestUrl = `${this.baseUrl}/${HttpAnnotationService.BASE_AVAILABLE_ANNOTATIONS_UNDER_HIERARCHY}${this.pathSuffix}?${queryParams}`;
const requestUrl = `${this.fileExplorerServiceBaseUrl}/${HttpAnnotationService.BASE_AVAILABLE_ANNOTATIONS_UNDER_HIERARCHY}${this.pathSuffix}?${queryParams}`;

const response = await this.get<string>(requestUrl);
if (!response.data) {
Expand Down
Loading
Loading