/* * Copyright 2018 Red Hat, Inc. and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import * as React from 'react'; import { DataList, DataListItem, DataListItemRow, DataListCell, DataListToggle, DataListContent, DataListItemCells, Grid, GridItem, Button, } from '@patternfly/react-core'; import { InfoAltIcon, CheckIcon, BuilderImageIcon, ExternalLinkAltIcon } from '@patternfly/react-icons'; import { ContentPage } from '../ContentPage'; import { ContinueCancelModal } from '../../widgets/ContinueCancelModal'; import { HttpResponse } from '../../account-service/account.service'; import { AccountServiceContext } from '../../account-service/AccountServiceContext'; import { Msg } from '../../widgets/Msg'; declare const locale: string; export interface ApplicationsPageProps { } export interface ApplicationsPageState { isRowOpen: boolean[]; applications: Application[]; } export interface GrantedScope { displayTest: string; id: string; name: string; } export interface Consent { createDate: number; grantedScopes: GrantedScope[]; lastUpdatedDate: number; } interface Application { effectiveUrl: string; clientId: string; clientName: string; consent: Consent; description: string; inUse: boolean; offlineAccess: boolean; userConsentRequired: boolean; scope: string[]; } export class ApplicationsPage extends React.Component { static contextType = AccountServiceContext; context: React.ContextType; public constructor(props: ApplicationsPageProps, context: React.ContextType) { super(props); this.context = context; this.state = { isRowOpen: [], applications: [] }; this.fetchApplications(); } private removeConsent = (clientId: string) => { this.context!.doDelete("/applications/" + clientId + "/consent") .then(() => { this.fetchApplications(); }); } private onToggle = (row: number): void => { const newIsRowOpen: boolean[] = this.state.isRowOpen; newIsRowOpen[row] = !newIsRowOpen[row]; this.setState({ isRowOpen: newIsRowOpen }); }; private fetchApplications(): void { this.context!.doGet("/applications") .then((response: HttpResponse) => { const applications = response.data || []; this.setState({ isRowOpen: new Array(applications.length).fill(false), applications: applications }); }); } private elementId(item: string, application: Application): string { return `application-${item}-${application.clientId}`; } public render(): React.ReactNode { return ( // invisible toggle allows headings to line up properly , , , ]} /> {this.state.applications.map((application: Application, appIndex: number) => { return ( this.onToggle(appIndex)} isExpanded={this.state.isRowOpen[appIndex]} id={this.elementId('toggle', application)} aria-controls={this.elementId("expandable", application)} /> , {application.userConsentRequired ? Msg.localize('thirdPartyApp') : Msg.localize('internalApp')} {application.offlineAccess ? ', ' + Msg.localize('offlineAccess') : ''} , {application.inUse ? Msg.localize('inUse') : Msg.localize('notInUse')} ]} />
{Msg.localize('client') + ': '} {application.clientId} {application.description && {Msg.localize('description') + ': '} {application.description} } URL: {application.effectiveUrl.split('"')} {application.consent && Has access to: {application.consent.grantedScopes.map((scope: GrantedScope, scopeIndex: number) => { return ( {scope.name} ) })} {Msg.localize('accessGrantedOn') + ': '} {new Intl.DateTimeFormat(locale, { year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric' }).format(application.consent.createDate)} }
{(application.consent || application.offlineAccess) &&
this.removeConsent(application.clientId)} // required /> {Msg.localize('infoMessage')}
}
) })}
); } };