Skip to content

Commit

Permalink
Adjusted according to review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenthoms committed Oct 16, 2023
1 parent c7820cc commit b6631d4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
12 changes: 4 additions & 8 deletions backend/src/services/graph_access/graph_access.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import base64
from typing import Mapping
from urllib.parse import urljoin

# Using the same http client as sumo
import httpx
Expand All @@ -8,6 +9,7 @@
class GraphApiAccess:
def __init__(self, access_token: str):
self._access_token = access_token
self.base_url = "https://graph.microsoft.com/v1.0/"

def _make_headers(self) -> Mapping[str, str]:
return {"Authorization": f"Bearer {self._access_token}"}
Expand All @@ -21,10 +23,7 @@ async def _request(self, url: str) -> httpx.Response:
return response

async def get_user_profile_photo(self, user_id: str) -> str | None:
request_url = f"https://graph.microsoft.com/v1.0/me/photo/$value"

if user_id != "me":
request_url = f"https://graph.microsoft.com/v1.0/users/{user_id}/photo/$value"
request_url = urljoin(self.base_url, "me/photo/$value" if user_id == "me" else f"users/{user_id}/photo/$value")

response = await self._request(request_url)

Expand All @@ -34,10 +33,7 @@ async def get_user_profile_photo(self, user_id: str) -> str | None:
return None

async def get_user_info(self, user_id: str) -> Mapping[str, str] | None:
request_url = f"https://graph.microsoft.com/v1.0/me"

if user_id != "me":
request_url = f"https://graph.microsoft.com/v1.0/users/{user_id}"
request_url = urljoin(self.base_url, "me" if user_id == "me" else f"users/{user_id}")

response = await self._request(request_url)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import { UseQueryResult, useQuery } from "@tanstack/react-query";
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> {
function useUserInfoQuery(userId: string): UseQueryResult<GraphUserPhoto_api> {
return useQuery({
queryKey: ["getUserInfo", userId],
queryFn: () => apiService.graph.userInfo(`${userId.toUpperCase()}@equinor.com`),
Expand All @@ -31,7 +29,7 @@ export const UserAvatar: React.FC<UserAvatarProps> = (props) => {
if (userInfo.isFetching) {
return <CircularProgress size="medium-small" className="mr-1" />;
}

if (userInfo.data?.avatar_b64str) {
return (
<img
Expand All @@ -42,5 +40,9 @@ export const UserAvatar: React.FC<UserAvatarProps> = (props) => {
/>
);
}
return <span title={props.userId}><AccountCircle className="w-5 h-5 mr-1" /></span>;
}
return (
<span title={props.userId}>
<AccountCircle className="w-5 h-5 mr-1" />
</span>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export const SelectEnsemblesDialog: React.FC<SelectEnsemblesDialogProps> = (prop
onChange={handleKeepCasesSwitchChange}
/>
</Label>
<Label position="right" text="My cases" title="Show only cases that I created">
<Label position="right" text="My cases" title="Show only my cases">
<Switch
checked={casesFilteringOptions.onlyMyCases}
onChange={handleCasesByMeChange}
Expand Down Expand Up @@ -311,7 +311,7 @@ export const SelectEnsemblesDialog: React.FC<SelectEnsemblesDialogProps> = (prop
</div>
<div className="flex flex-col flex-grow gap-4 p-4">
<Label text="Selected Ensembles">
<table className="w-full border border-collapse table-fixed text-sm">
<table className="w-full border border-collapse table-fixed text-sm">
<thead>
<tr>
<th className="min-w-1/2 text-left p-2 bg-slate-300">Case</th>
Expand Down

0 comments on commit b6631d4

Please sign in to comment.