Skip to content

Commit

Permalink
Fix lint issues & remove duplicate var
Browse files Browse the repository at this point in the history
  • Loading branch information
Janelle Law committed Sep 7, 2021
1 parent c7bd7be commit 1880d06
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 27 deletions.
4 changes: 1 addition & 3 deletions src/app/AppLayout/AppLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ const AppLayout: React.FunctionComponent<IAppLayout> = ({children}) => {
const userInfoItems = [
<DropdownGroup key={0}>
<DropdownItem onClick={handleLogout}>Logout</DropdownItem>
</DropdownGroup>,
</DropdownGroup>
];

const UserInfoToggle = (
Expand Down Expand Up @@ -214,7 +214,6 @@ const AppLayout: React.FunctionComponent<IAppLayout> = ({children}) => {
</PageHeaderToolsItem>
<PageHeaderToolsItem visibility={{default: showUserIcon ? 'visible' : 'hidden'}} >
<Dropdown
position="right"
isPlain={true}
isOpen={showUserInfoDropdown}
toggle={UserInfoToggle}
Expand Down Expand Up @@ -329,7 +328,6 @@ const AppLayout: React.FunctionComponent<IAppLayout> = ({children}) => {
</SkipToContent>
);
const NotificationDrawer = React.useMemo(() => (<NotificationCenter onClose={handleCloseNotificationCenter} />), []);

return (<>
<AlertGroup isToast>
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/Login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const Login = () => {
let tok = token;

if (authMethod === 'Basic') {
tok = Base64.encodeURL(tok);
tok = Base64.encodeURL(token);
} // else this is Bearer auth and the token is sent as-is
addSubscription(
serviceContext.login.checkAuth(tok, authMethod)
Expand Down
15 changes: 4 additions & 11 deletions src/app/Shared/Services/Api.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,12 @@ export class ApiService {
private readonly cryostatVersionSubject = new ReplaySubject<string>(1);
private readonly grafanaDatasourceUrlSubject = new ReplaySubject<string>(1);
private readonly grafanaDashboardUrlSubject = new ReplaySubject<string>(1);
readonly authority: string;

constructor(
private readonly target: TargetService,
private readonly notifications: Notifications,
private readonly login: LoginService
) {
let apiAuthority = process.env.CRYOSTAT_AUTHORITY;
if (!apiAuthority) {
apiAuthority = '';
}
window.console.log(`Using API authority ${apiAuthority}`);
this.authority = apiAuthority;

if(login.isAuthenticated()) {
this.doGet('recordings').subscribe(() => {
Expand All @@ -88,12 +81,12 @@ export class ApiService {
});
}

const getDatasourceURL = fromFetch(`${apiAuthority}/api/v1/grafana_datasource_url`)
const getDatasourceURL = fromFetch(`${this.login.authority}/api/v1/grafana_datasource_url`)
.pipe(concatMap(resp => from(resp.json())));
const getDashboardURL = fromFetch(`${apiAuthority}/api/v1/grafana_dashboard_url`)
const getDashboardURL = fromFetch(`${this.login.authority}/api/v1/grafana_dashboard_url`)
.pipe(concatMap(resp => from(resp.json())));

fromFetch(`${apiAuthority}/health`)
fromFetch(`${this.login.authority}/health`)
.pipe(
concatMap(resp => from(resp.json())),
concatMap((jsonResp: any) => {
Expand Down Expand Up @@ -460,7 +453,7 @@ export class ApiService {
private sendRequest(apiVersion: ApiVersion, path: string, config?: RequestInit): Observable<Response> {
const req = () => this.getHeaders().pipe(
concatMap(headers =>
fromFetch(`${this.authority}/api/${apiVersion}/${path}`, {
fromFetch(`${this.login.authority}/api/${apiVersion}/${path}`, {
credentials: 'include',
mode: 'cors',
headers,
Expand Down
4 changes: 2 additions & 2 deletions src/app/Shared/Services/Login.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import { Observable, ObservableInput, of, ReplaySubject, Subject} from 'rxjs';
import { Observable, ObservableInput, of, ReplaySubject } from 'rxjs';
import { fromFetch } from 'rxjs/fetch';
import { catchError, first, map, tap } from 'rxjs/operators';

Expand All @@ -44,7 +44,7 @@ export class LoginService {
private readonly token = new ReplaySubject<string>(1);
private readonly authMethod = new ReplaySubject<string>(1);
private readonly login = new ReplaySubject<boolean>(1);
readonly authority: string; //how to prevent duplication?
readonly authority: string;

constructor() {
let apiAuthority = process.env.CRYOSTAT_AUTHORITY;
Expand Down
6 changes: 2 additions & 4 deletions src/app/Shared/Services/NotificationChannel.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ import { Notifications } from '@app/Notifications/Notifications';
import { BehaviorSubject, combineLatest, from, Observable, Subject } from 'rxjs';
import { fromFetch } from 'rxjs/fetch';
import { webSocket, WebSocketSubject } from 'rxjs/webSocket';
import { concatMap, filter, first, map } from 'rxjs/operators';
import { concatMap, filter, map } from 'rxjs/operators';
import { Base64 } from 'js-base64';
import { ApiService } from './Api.service';
import { LoginService } from './Login.service';

const NOTIFICATION_CATEGORY = 'WS_CLIENT_ACTIVITY';
Expand All @@ -53,7 +52,6 @@ export class NotificationChannel {
private readonly _ready = new BehaviorSubject<boolean>(false);

constructor(
private readonly apiSvc: ApiService,
private readonly notifications: Notifications,
private readonly login: LoginService
) {
Expand All @@ -63,7 +61,7 @@ export class NotificationChannel {
notifications.info('WebSocket Client Activity', `Client at ${addr} ${status}`);
});

const notificationsUrl = fromFetch(`${this.apiSvc.authority}/api/v1/notifications_url`)
const notificationsUrl = fromFetch(`${this.login.authority}/api/v1/notifications_url`)
.pipe(
concatMap(resp => from(resp.json())),
map((url: any): string => url.notificationsUrl)
Expand Down
2 changes: 1 addition & 1 deletion src/app/Shared/Services/Services.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export interface Services {

const login = new LoginService();
const api = new ApiService(TargetInstance, NotificationsInstance, login);
const notificationChannel = new NotificationChannel(api, NotificationsInstance, login);
const notificationChannel = new NotificationChannel(NotificationsInstance, login);
const reports = new ReportService(api, NotificationsInstance);
const settings = new SettingsService();
const targets = new TargetsService(api, NotificationsInstance, login, notificationChannel);
Expand Down
9 changes: 4 additions & 5 deletions src/app/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,18 @@ const AppRoutes = () => {
const [authenticated, setAuthenticated] = React.useState(context.login.isAuthenticated());

React.useEffect(() => {
const sub =
combineLatest(context.login.loggedIn(), context.notificationChannel.isReady())
const sub = combineLatest(context.login.loggedIn(), context.notificationChannel.isReady())
.pipe(debounceTime(500))
.subscribe(parts => {
.subscribe((parts) => {
const loggedIn = parts[0];
const connected = parts[1];

if(loggedIn && connected) {
if (loggedIn && connected) {
setAuthenticated(true);
} else {
setAuthenticated(false);
}
});
});
return () => sub.unsubscribe();
}, [context, context.login, setAuthenticated]);

Expand Down

0 comments on commit 1880d06

Please sign in to comment.