-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements to ensemble selector (#427)
- Loading branch information
1 parent
d5cb21f
commit 5bb5155
Showing
20 changed files
with
571 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import logging | ||
|
||
import httpx | ||
from fastapi import APIRouter, Depends, Query | ||
|
||
from src.backend.auth.auth_helper import AuthHelper | ||
from src.services.utils.authenticated_user import AuthenticatedUser | ||
from src.services.graph_access.graph_access import GraphApiAccess | ||
|
||
from .schemas import GraphUserPhoto | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("/user_photo/") | ||
async def user_info( | ||
# fmt:off | ||
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user), | ||
user_id: str = Query(description="User id"), | ||
# fmt:on | ||
) -> GraphUserPhoto: | ||
"""Get username, display name and avatar from Microsoft Graph API for a given user id""" | ||
|
||
user_photo = GraphUserPhoto( | ||
avatar_b64str=None, | ||
) | ||
|
||
if authenticated_user.has_graph_access_token(): | ||
graph_api_access = GraphApiAccess(authenticated_user.get_graph_access_token()) | ||
try: | ||
avatar_b64str = await graph_api_access.get_user_profile_photo(user_id) | ||
|
||
user_photo.avatar_b64str = avatar_b64str | ||
except httpx.HTTPError as exc: | ||
print("Error while fetching user avatar and info from Microsoft Graph API (HTTP error):\n", exc) | ||
except httpx.InvalidURL as exc: | ||
print("Error while fetching user avatar and info from Microsoft Graph API (Invalid URL):\n", exc) | ||
|
||
# Return 404 if no user info was found? | ||
return user_photo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from pydantic import BaseModel | ||
|
||
|
||
class GraphUserPhoto(BaseModel): | ||
avatar_b64str: str | None = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,7 @@ | |
export type CaseInfo = { | ||
uuid: string; | ||
name: string; | ||
status: string; | ||
user: string; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* istanbul ignore file */ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
|
||
export type GraphUserPhoto = { | ||
avatar_b64str: (string | null); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* istanbul ignore file */ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
import type { GraphUserPhoto } from '../models/GraphUserPhoto'; | ||
|
||
import type { CancelablePromise } from '../core/CancelablePromise'; | ||
import type { BaseHttpRequest } from '../core/BaseHttpRequest'; | ||
|
||
export class GraphService { | ||
|
||
constructor(public readonly httpRequest: BaseHttpRequest) {} | ||
|
||
/** | ||
* User Info | ||
* Get username, display name and avatar from Microsoft Graph API for a given user id | ||
* @param userId User id | ||
* @returns GraphUserPhoto Successful Response | ||
* @throws ApiError | ||
*/ | ||
public userInfo( | ||
userId: string, | ||
): CancelablePromise<GraphUserPhoto> { | ||
return this.httpRequest.request({ | ||
method: 'GET', | ||
url: '/graph/user_photo/', | ||
query: { | ||
'user_id': userId, | ||
}, | ||
errors: { | ||
422: `Validation Error`, | ||
}, | ||
}); | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
...src/framework/internal/components/SelectEnsemblesDialog/private-components/userAvatar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from "react"; | ||
|
||
import { GraphUserPhoto_api } from "@api"; | ||
import { apiService } from "@framework/ApiService"; | ||
import { CircularProgress } from "@lib/components/CircularProgress"; | ||
import { AccountCircle } from "@mui/icons-material"; | ||
import { UseQueryResult, useQuery } from "@tanstack/react-query"; | ||
|
||
export type UserAvatarProps = { | ||
userId: string; | ||
}; | ||
|
||
const STALE_TIME = 60 * 1000; | ||
const CACHE_TIME = 60 * 1000; | ||
|
||
function useUserInfoQuery(userId: string): UseQueryResult<GraphUserPhoto_api> { | ||
return useQuery({ | ||
queryKey: ["getUserInfo", userId], | ||
queryFn: () => apiService.graph.userInfo(`${userId.toUpperCase()}@equinor.com`), | ||
staleTime: STALE_TIME, | ||
cacheTime: CACHE_TIME, | ||
enabled: userId !== "", | ||
}); | ||
} | ||
|
||
export const UserAvatar: React.FC<UserAvatarProps> = (props) => { | ||
const userInfo = useUserInfoQuery(props.userId); | ||
|
||
if (userInfo.isFetching) { | ||
return <CircularProgress size="medium-small" className="mr-1" />; | ||
} | ||
|
||
if (userInfo.data?.avatar_b64str) { | ||
return ( | ||
<img | ||
src={`data:image/png;base64,${userInfo.data.avatar_b64str}`} | ||
alt="Avatar" | ||
className="w-5 h-5 rounded-full mr-1" | ||
title={props.userId} | ||
/> | ||
); | ||
} | ||
return ( | ||
<span title={props.userId}> | ||
<AccountCircle className="w-5 h-5 mr-1" /> | ||
</span> | ||
); | ||
}; |
Oops, something went wrong.