Skip to content

Commit 73434b9

Browse files
authored
Merge branch 'master' into feature/group-invite-link
2 parents 6adbe5d + cc1f3a9 commit 73434b9

31 files changed

+957
-789
lines changed

mwdb/web/src/__tests__/hooks/useCheckCapabilities.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { renderHook } from "@testing-library/react";
22
import { useCheckCapabilities } from "@mwdb-web/commons/hooks";
3-
import { AuthContextValues, Capability } from "@mwdb-web/types/types";
3+
import { Capability } from "@mwdb-web/types/types";
44
import { AuthContext } from "@mwdb-web/commons/auth";
55
import { AuthProviderProps } from "@mwdb-web/types/props";
6+
import { AuthContextValues } from "@mwdb-web/types/context";
67

78
describe("useCheckCapabilities", () => {
89
const authContextValue = {

mwdb/web/src/commons/api/index.tsx

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ import {
5656
GetUserProfileResponse,
5757
GetUserResponse,
5858
GetUsersResponse,
59+
OauthGetIdentitiesResponse,
60+
OauthGetLogoutLinkResponse,
61+
OauthGetProvidersResponse,
62+
OauthGetSingleProviderResponse,
63+
OauthRemoveSingleProviderResponse,
64+
OauthUpdateSingleProviderResponse,
5965
PullObjectRemoteResponse,
6066
PushObjectRemoteResponse,
6167
RegisterGroupResponse,
@@ -87,7 +93,8 @@ import {
8793
UploadFileResponse,
8894
UserRequestPasswordChangeResponse,
8995
} from "@mwdb-web/types/api";
90-
import { Attribute, ObjectType } from "@mwdb-web/types/types";
96+
import { Attribute, Capability, ObjectType } from "@mwdb-web/types/types";
97+
import { APIProviderProps } from "@mwdb-web/types/props";
9198

9299
function getApiForEnvironment() {
93100
// Default API endpoint
@@ -203,35 +210,42 @@ function oauthRegisterProvider(
203210
});
204211
}
205212

206-
function oauthGetProviders() {
213+
function oauthGetProviders(): OauthGetProvidersResponse {
207214
return axios.get("/oauth");
208215
}
209216

210-
function oauthGetSingleProvider(provider_name: string) {
217+
function oauthGetSingleProvider(
218+
provider_name: string
219+
): OauthGetSingleProviderResponse {
211220
return axios.get(`/oauth/${provider_name}`);
212221
}
213222

214-
function oauthUpdateSingleProvider(name: string, value: string) {
223+
function oauthUpdateSingleProvider(
224+
name: string,
225+
value: string
226+
): OauthUpdateSingleProviderResponse {
215227
return axios.put(`/oauth/${name}`, value);
216228
}
217229

218-
function oauthRemoveSingleProvider(name: string) {
230+
function oauthRemoveSingleProvider(
231+
name: string
232+
): OauthRemoveSingleProviderResponse {
219233
return axios.delete(`/oauth/${name}`);
220234
}
221235

222-
function oauthGetIdentities() {
236+
function oauthGetIdentities(): OauthGetIdentitiesResponse {
223237
return axios.get("/oauth/identities");
224238
}
225239

226-
function oauthGetLogoutLink(provider: string) {
240+
function oauthGetLogoutLink(provider: string): OauthGetLogoutLinkResponse {
227241
return axios.get(`/oauth/${provider}/logout`);
228242
}
229243

230244
function apiKeyAdd(login: string, name: string): ApiKeyAddResponse {
231245
return axios.post(`/user/${login}/api_key`, { name });
232246
}
233247

234-
function apiKeyRemove(key_id: number): ApiKeyRemoveResponse {
248+
function apiKeyRemove(key_id: number | string): ApiKeyRemoveResponse {
235249
return axios.delete(`/api_key/${key_id}`);
236250
}
237251

@@ -385,7 +399,10 @@ function registerGroup(name: string): RegisterGroupResponse {
385399
return axios.post(`/group/${name}`, { name });
386400
}
387401

388-
function updateGroup(name: string, value: string): UpdateGroupResponse {
402+
function updateGroup(
403+
name: string,
404+
value: { capabilities: Capability[] }
405+
): UpdateGroupResponse {
389406
return axios.put(`/group/${name}`, value);
390407
}
391408

@@ -875,10 +892,7 @@ export const api = {
875892
enableSharing3rdParty,
876893
};
877894

878-
type APIProviderProps = {
879-
children: React.ReactNode;
880-
};
881-
895+
// TODO: api context is not needed, remove it when all components will rewrite to TypeScript
882896
export const APIContext = React.createContext({});
883897
export function APIProvider(props: APIProviderProps) {
884898
return (

mwdb/web/src/commons/auth/context.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { AuthContextValues } from "@mwdb-web/types/types";
21
import React from "react";
2+
import { AuthContextValues } from "@mwdb-web/types/context";
33

44
export const AuthContext = React.createContext<AuthContextValues>(
55
{} as AuthContextValues

mwdb/web/src/commons/auth/provider.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { api } from "../api";
55

66
import { omit, isEqual, isNil } from "lodash";
77
import { AuthContext } from "./context";
8-
import { AuthContextValues, Capability, User } from "@mwdb-web/types/types";
8+
import { Capability, User } from "@mwdb-web/types/types";
99
import { AuthProviderProps } from "@mwdb-web/types/props";
10+
import { AuthContextValues } from "@mwdb-web/types/context";
1011

1112
export const localStorageAuthKey = "user";
1213

mwdb/web/src/commons/config/context.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ConfigContextValues } from "@mwdb-web/types/types";
1+
import { ConfigContextValues } from "@mwdb-web/types/context";
22
import React from "react";
33

44
export const ConfigContext = React.createContext<ConfigContextValues>(

mwdb/web/src/commons/config/provider.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import { isEqual } from "lodash";
1010
import { api } from "../api";
1111
import { ConfigContext } from "./context";
1212
import { AuthContext } from "../auth";
13-
import { ConfigContextValues, ServerInfo, User } from "@mwdb-web/types/types";
13+
import { ServerInfo, User } from "@mwdb-web/types/types";
14+
import { ConfigContextValues } from "@mwdb-web/types/context";
1415

1516
const configUpdate = Symbol("configUpdate");
1617
const configError = Symbol("configError");

mwdb/web/src/commons/ui/DateString.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
type Props = {
2-
date: string;
2+
date?: string | Date;
33
};
44

55
export default function DateString(props: Props) {
6+
if (!props.date) {
7+
return <></>;
8+
}
69
const date = props.date;
710
const d = new Date(date);
811
return <span>{date != null ? d.toUTCString() : "(never)"}</span>;

mwdb/web/src/commons/ui/ObjectTab.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { IconProp } from "@fortawesome/fontawesome-svg-core";
44

55
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
66
import { capitalize } from "../helpers";
7-
import { TabContextValues } from "@mwdb-web/types/types";
7+
import { TabContextValues } from "@mwdb-web/types/context";
88

99
export const TabContext = React.createContext<TabContextValues>(
1010
{} as TabContextValues

mwdb/web/src/commons/ui/ShowIf.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
type Props = {
22
condition: boolean;
3-
children: React.ReactNode;
3+
children: JSX.Element;
44
};
55

66
export function ShowIf({ condition, children }: Props) {
7-
return condition ? children : [];
7+
return condition ? children : <></>;
88
}

mwdb/web/src/components/Profile/ProfileView.jsx renamed to mwdb/web/src/components/Profile/ProfileView.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useContext, useEffect, useState } from "react";
1+
import { useContext, useEffect, useState } from "react";
22
import { NavLink, useParams, Outlet } from "react-router-dom";
33

44
import { faUserCog } from "@fortawesome/free-solid-svg-icons";
@@ -10,6 +10,7 @@ import { ConfigContext } from "@mwdb-web/commons/config";
1010
import { View } from "@mwdb-web/commons/ui";
1111
import { useViewAlert } from "@mwdb-web/commons/hooks";
1212
import DeleteCapabilityModal from "../Settings/Views/DeleteCapabilityModal";
13+
import { Capability, User } from "@mwdb-web/types/types";
1314

1415
function ProfileNav() {
1516
const config = useContext(ConfigContext);
@@ -32,12 +33,10 @@ function ProfileNav() {
3233
<NavLink end to="/profile/api-keys" className="nav-link">
3334
API keys
3435
</NavLink>
35-
{config.config["is_oidc_enabled"] ? (
36+
{config.config["is_oidc_enabled"] && (
3637
<NavLink end to="/profile/oauth" className="nav-link">
3738
OpenID Connect
3839
</NavLink>
39-
) : (
40-
[]
4140
)}
4241
</div>
4342
<hr />
@@ -48,15 +47,18 @@ function ProfileNav() {
4847
export default function ProfileView() {
4948
const auth = useContext(AuthContext);
5049
const { redirectToAlert, setAlert } = useViewAlert();
51-
const user = useParams().user || auth.user.login;
52-
const [profile, setProfile] = useState({});
50+
const userLogin = useParams().user || auth.user.login;
51+
const [profile, setProfile] = useState<User>({} as User);
5352
const [capabilitiesToDelete, setCapabilitiesToDelete] = useState("");
5453

5554
useEffect(() => {
5655
getProfile();
57-
}, [user]);
56+
}, [userLogin]);
5857

59-
async function changeCapabilities(capability, callback) {
58+
async function changeCapabilities(
59+
capability: Capability,
60+
callback: Function
61+
) {
6062
try {
6163
const capabilities = profile.capabilities.filter(
6264
(item) => item !== capability
@@ -71,7 +73,7 @@ export default function ProfileView() {
7173

7274
async function getProfile() {
7375
try {
74-
const response = await api.getUserProfile(user);
76+
const response = await api.getUserProfile(userLogin);
7577
setProfile(response.data);
7678
} catch (error) {
7779
redirectToAlert({
@@ -81,7 +83,7 @@ export default function ProfileView() {
8183
}
8284
}
8385

84-
if (profile.login !== user) return <></>;
86+
if (profile.login !== userLogin) return <></>;
8587

8688
return (
8789
<View ident="profile" fluid>
@@ -103,7 +105,7 @@ export default function ProfileView() {
103105
changeCapabilities={changeCapabilities}
104106
capabilitiesToDelete={capabilitiesToDelete}
105107
setCapabilitiesToDelete={setCapabilitiesToDelete}
106-
successMessage={`Capabilities for ${user} successfully changed`}
108+
successMessage={`Capabilities for ${userLogin} successfully changed`}
107109
/>
108110
</View>
109111
);

0 commit comments

Comments
 (0)