closes #13544 "Merge branch '13544-make-packages'".
[arvados.git] / src / services / project-service / project-service.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { serverApi } from "../../common/server-api";
6 import { Dispatch } from "redux";
7 import actions from "../../store/project/project-action";
8 import { Project } from "../../models/project";
9
10 interface GroupsResponse {
11     offset: number;
12     limit: number;
13     items: Array<{
14         href: string;
15         kind: string;
16         etag: string;
17         uuid: string;
18         owner_uuid: string;
19         created_at: string;
20         modified_by_client_uuid: string;
21         modified_by_user_uuid: string;
22         modified_at: string;
23         name: string;
24         group_class: string;
25         description: string;
26         writable_by: string[];
27         delete_at: string;
28         trash_at: string;
29         is_trashed: boolean;
30     }>;
31 }
32
33 export default class ProjectService {
34     public getTopProjectList = () => (dispatch: Dispatch) => {
35         dispatch(actions.TOP_PROJECTS_REQUEST());
36         serverApi.get<GroupsResponse>('/groups').then(groups => {
37             const projects = groups.data.items.map(g => ({
38                 name: g.name,
39                 createdAt: g.created_at,
40                 modifiedAt: g.modified_at,
41                 href: g.href,
42                 uuid: g.uuid,
43                 ownerUuid: g.owner_uuid
44             } as Project));
45             dispatch(actions.TOP_PROJECTS_SUCCESS(projects));
46         });
47     }
48 }