--- /dev/null
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
+REACT_APP_ARVADOS_API_HOST=https://qr1hi.arvadosapi.com
\ No newline at end of file
yarn build
</pre>
+### Configuration
+You can customize project global variables using env variables. Default values are placed in the `.env` file.
+
+Example:
+```
+REACT_APP_ARVADOS_API_HOST=localhost:8000 yarn start
+```
+
### Licensing
Arvados is Free Software. See COPYING for information about Arvados Free
import MockAdapter from "axios-mock-adapter";
describe("CommonResourceService", () => {
-
- const axiosMock = new MockAdapter(axios);
+ const axiosInstance = axios.create();
+ const axiosMock = new MockAdapter(axiosInstance);
beforeEach(() => {
axiosMock.reset();
});
+ it("#create", async () => {
+ axiosMock
+ .onPost("/resource/")
+ .reply(200, { owner_uuid: "ownerUuidValue" });
+
+ const commonResourceService = new CommonResourceService(axiosInstance, "resource");
+ const resource = await commonResourceService.create({ ownerUuid: "ownerUuidValue" });
+ expect(resource).toEqual({ ownerUuid: "ownerUuidValue" });
+ });
+
+ it("#create maps request params to snake case", async () => {
+ axiosInstance.post = jest.fn(() => Promise.resolve({data: {}}));
+ const commonResourceService = new CommonResourceService(axiosInstance, "resource");
+ await commonResourceService.create({ ownerUuid: "ownerUuidValue" });
+ expect(axiosInstance.post).toHaveBeenCalledWith("/resource/", {owner_uuid: "ownerUuidValue"});
+ });
+
it("#delete", async () => {
axiosMock
.onDelete("/resource/uuid")
.reply(200, { deleted_at: "now" });
- const commonResourceService = new CommonResourceService(axios, "resource");
+ const commonResourceService = new CommonResourceService(axiosInstance, "resource");
const resource = await commonResourceService.delete("uuid");
expect(resource).toEqual({ deletedAt: "now" });
});
.onGet("/resource/uuid")
.reply(200, { modified_at: "now" });
- const commonResourceService = new CommonResourceService(axios, "resource");
+ const commonResourceService = new CommonResourceService(axiosInstance, "resource");
const resource = await commonResourceService.get("uuid");
expect(resource).toEqual({ modifiedAt: "now" });
});
items_available: 20
});
- const commonResourceService = new CommonResourceService(axios, "resource");
+ const commonResourceService = new CommonResourceService(axiosInstance, "resource");
const resource = await commonResourceService.list({ limit: 10, offset: 1 });
expect(resource).toEqual({
kind: "kind",
create(data: Partial<T>) {
return this.serverApi
- .post<T>(this.resourceType, data)
+ .post<T>(this.resourceType, CommonResourceService.mapKeys(_.snakeCase)(data))
.then(CommonResourceService.mapResponseKeys);
}
import Axios, { AxiosInstance } from "axios";
-export const API_HOST = 'https://qr1hi.arvadosapi.com';
+export const API_HOST = process.env.REACT_APP_ARVADOS_API_HOST;
export const serverApi: AxiosInstance = Axios.create({
baseURL: API_HOST + '/arvados/v1'
open={!!anchorEl}
onClose={onClose}
transformOrigin={DefaultTransformOrigin}
- anchorOrigin={DefaultTransformOrigin}>
+ anchorOrigin={DefaultTransformOrigin}
+ onContextMenu={this.handleContextMenu}>
<List dense>
{actions.map((group, groupIndex) =>
<React.Fragment key={groupIndex}>
</List>
</Popover>;
}
+
+ handleContextMenu = (event: React.MouseEvent<HTMLElement>) => {
+ event.preventDefault();
+ this.props.onClose();
+ }
}
const store = configureStore(history);
store.dispatch(authActions.INIT());
-const rootUuid = authService.getRootUuid();
-store.dispatch<any>(getProjectList(rootUuid));
+store.dispatch<any>(getProjectList(authService.getUuid()));
const App = () =>
<MuiThemeProvider theme={CustomTheme}>
<Provider store={store}>
<ConnectedRouter history={history}>
<div>
- <Route path="/" component={Workbench}/>
- <Route path="/token" component={ApiToken}/>
+ <Route path="/" component={Workbench} />
+ <Route path="/token" component={ApiToken} />
</div>
</ConnectedRouter>
</Provider>
</MuiThemeProvider>;
ReactDOM.render(
- <App/>,
+ <App />,
document.getElementById('root') as HTMLElement
);
export interface GroupResource extends Resource {
kind: ResourceKind.Group;
name: string;
- groupClass: string;
+ groupClass: GroupClass | null;
description: string;
properties: string;
writeableBy: string[];
trashAt: string;
deleteAt: string;
isTrashed: boolean;
+}
+
+export enum GroupClass {
+ Project = "project"
}
\ No newline at end of file
// SPDX-License-Identifier: AGPL-3.0
import { Resource as R } from "./resource";
-import { GroupResource } from "./group";
+import { GroupResource, GroupClass } from "./group";
export interface Project extends R {
}
export interface ProjectResource extends GroupResource {
- groupClass: "project";
+ groupClass: GroupClass.Project;
}
import { ProjectResource } from "../../models/project";
import { ProcessResource } from "../../models/process";
-interface ContensArguments {
+export interface ContentsArguments {
limit?: number;
offset?: number;
order?: OrderBuilder;
ProjectResource |
ProcessResource;
-export default class GroupsService extends CommonResourceService<GroupResource> {
+export default class GroupsService<T extends GroupResource = GroupResource> extends CommonResourceService<T> {
constructor(serverApi: AxiosInstance) {
super(serverApi, "groups");
}
- contents(uuid: string, args: ContensArguments = {}): Promise<ListResults<GroupContentsResource>> {
+ contents(uuid: string, args: ContentsArguments = {}): Promise<ListResults<GroupContentsResource>> {
const { filters, order, ...other } = args;
const params = {
...other,
--- /dev/null
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import axios from "axios";
+import MockAdapter from "axios-mock-adapter";
+import ProjectService from "./project-service";
+import FilterBuilder from "../../common/api/filter-builder";
+import { ProjectResource } from "../../models/project";
+
+describe("CommonResourceService", () => {
+ const axiosInstance = axios.create();
+
+ it(`#create has groupClass set to "project"`, async () => {
+ axiosInstance.post = jest.fn(() => Promise.resolve({ data: {} }));
+ const projectService = new ProjectService(axiosInstance);
+ const resource = await projectService.create({ name: "nameValue" });
+ expect(axiosInstance.post).toHaveBeenCalledWith("/groups/", {
+ name: "nameValue",
+ group_class: "project"
+ });
+ });
+
+
+ it("#list has groupClass filter set by default", async () => {
+ axiosInstance.get = jest.fn(() => Promise.resolve({ data: {} }));
+ const projectService = new ProjectService(axiosInstance);
+ const resource = await projectService.list();
+ expect(axiosInstance.get).toHaveBeenCalledWith("/groups/", {
+ params: {
+ filters: FilterBuilder
+ .create<ProjectResource>()
+ .addEqual("groupClass", "project")
+ .serialize()
+ }
+ });
+ });
+
+});
--- /dev/null
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import GroupsService, { ContentsArguments } from "../groups-service/groups-service";
+import { ProjectResource } from "../../models/project";
+import { GroupClass } from "../../models/group";
+import { ListArguments } from "../../common/api/common-resource-service";
+import FilterBuilder from "../../common/api/filter-builder";
+
+export default class ProjectService extends GroupsService<ProjectResource> {
+
+ create(data: Partial<ProjectResource>) {
+ const projectData = { ...data, groupClass: GroupClass.Project };
+ return super.create(projectData);
+ }
+
+ list(args: ListArguments = {}) {
+ return super.list({
+ ...args,
+ filters: this.addProjectFilter(args.filters)
+ });
+ }
+
+ private addProjectFilter(filters?: FilterBuilder) {
+ return FilterBuilder
+ .create()
+ .concat(filters
+ ? filters
+ : FilterBuilder.create())
+ .concat(FilterBuilder
+ .create<ProjectResource>()
+ .addEqual("groupClass", GroupClass.Project));
+ }
+
+}
\ No newline at end of file
import CollectionService from "./collection-service/collection-service";
import GroupsService from "./groups-service/groups-service";
import { serverApi } from "../common/api/server-api";
+import ProjectService from "./project-service/project-service";
export const authService = new AuthService();
export const collectionService = new CollectionService();
export const groupsService = new GroupsService(serverApi);
+export const projectService = new ProjectService(serverApi);
// SPDX-License-Identifier: AGPL-3.0
import { default as unionize, ofType, UnionOf } from "unionize";
-import { Project } from "../../models/project";
-import { groupsService } from "../../services/services";
+import { Project, ProjectResource } from "../../models/project";
+import { projectService } from "../../services/services";
import { Dispatch } from "redux";
import { getResourceKind } from "../../models/resource";
+import FilterBuilder from "../../common/api/filter-builder";
const actions = unionize({
CREATE_PROJECT: ofType<Project>(),
tag: 'type',
value: 'payload'
});
-
+
export const getProjectList = (parentUuid: string = '') => (dispatch: Dispatch) => {
- dispatch(actions.PROJECTS_REQUEST(parentUuid));
- return groupsService.list().then(listResults => {
- const projects = listResults.items.map(item => ({
- ...item,
- kind: getResourceKind(item.kind)
- }));
- dispatch(actions.PROJECTS_SUCCESS({ projects, parentItemId: parentUuid }));
- return projects;
- });
+ dispatch(actions.PROJECTS_REQUEST(parentUuid));
+ return projectService.list({
+ filters: FilterBuilder
+ .create<ProjectResource>()
+ .addEqual("ownerUuid", parentUuid)
+ }).then(listResults => {
+ const projects = listResults.items.map(item => ({
+ ...item,
+ kind: getResourceKind(item.kind)
+ }));
+ dispatch(actions.PROJECTS_SUCCESS({ projects, parentItemId: parentUuid }));
+ return projects;
+ });
};
export type ProjectAction = UnionOf<typeof actions>;