2022-02-08 05:35:15 -06:00
|
|
|
import React, { useEffect } from 'react';
|
2022-01-19 10:03:45 -06:00
|
|
|
import { connect, ConnectedProps } from 'react-redux';
|
|
|
|
import { getNavModel } from 'app/core/selectors/navModel';
|
|
|
|
import Page from 'app/core/components/Page/Page';
|
|
|
|
import { ServiceAccountProfile } from './ServiceAccountProfile';
|
2022-02-08 05:35:15 -06:00
|
|
|
import { StoreState, ServiceAccountDTO, ApiKey } from 'app/types';
|
2022-01-19 10:03:45 -06:00
|
|
|
import { GrafanaRouteComponentProps } from 'app/core/navigation/types';
|
2022-02-08 05:35:15 -06:00
|
|
|
import { deleteServiceAccountToken, loadServiceAccount, loadServiceAccountTokens } from './state/actions';
|
|
|
|
import { ServiceAccountTokensTable } from './ServiceAccountTokensTable';
|
|
|
|
import { getTimeZone, NavModel } from '@grafana/data';
|
2022-01-19 10:03:45 -06:00
|
|
|
|
|
|
|
interface OwnProps extends GrafanaRouteComponentProps<{ id: string }> {
|
|
|
|
navModel: NavModel;
|
|
|
|
serviceAccount?: ServiceAccountDTO;
|
2022-02-08 05:35:15 -06:00
|
|
|
tokens: ApiKey[];
|
2022-01-19 10:03:45 -06:00
|
|
|
isLoading: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapStateToProps(state: StoreState) {
|
|
|
|
return {
|
|
|
|
navModel: getNavModel(state.navIndex, 'serviceaccounts'),
|
|
|
|
serviceAccount: state.serviceAccountProfile.serviceAccount,
|
2022-02-08 05:35:15 -06:00
|
|
|
tokens: state.serviceAccountProfile.tokens,
|
2022-01-19 10:03:45 -06:00
|
|
|
isLoading: state.serviceAccountProfile.isLoading,
|
2022-02-08 05:35:15 -06:00
|
|
|
timezone: getTimeZone(state.user),
|
2022-01-19 10:03:45 -06:00
|
|
|
};
|
|
|
|
}
|
|
|
|
const mapDispatchToProps = {
|
|
|
|
loadServiceAccount,
|
2022-02-08 05:35:15 -06:00
|
|
|
loadServiceAccountTokens,
|
|
|
|
deleteServiceAccountToken,
|
2022-01-19 10:03:45 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
const connector = connect(mapStateToProps, mapDispatchToProps);
|
|
|
|
type Props = OwnProps & ConnectedProps<typeof connector>;
|
2022-02-08 05:35:15 -06:00
|
|
|
|
|
|
|
const ServiceAccountPageUnconnected = ({
|
|
|
|
navModel,
|
|
|
|
match,
|
|
|
|
serviceAccount,
|
|
|
|
tokens,
|
|
|
|
timezone,
|
|
|
|
isLoading,
|
|
|
|
loadServiceAccount,
|
|
|
|
loadServiceAccountTokens,
|
|
|
|
deleteServiceAccountToken,
|
|
|
|
}: Props) => {
|
|
|
|
useEffect(() => {
|
|
|
|
const serviceAccountId = parseInt(match.params.id, 10);
|
|
|
|
loadServiceAccount(serviceAccountId);
|
|
|
|
loadServiceAccountTokens(serviceAccountId);
|
|
|
|
}, [match, loadServiceAccount, loadServiceAccountTokens]);
|
|
|
|
|
|
|
|
const onDeleteServiceAccountToken = (key: ApiKey) => {
|
|
|
|
deleteServiceAccountToken(parseInt(match.params.id, 10), key.id!);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Page navModel={navModel}>
|
|
|
|
<Page.Contents isLoading={isLoading}>
|
|
|
|
{serviceAccount && (
|
|
|
|
<>
|
|
|
|
<ServiceAccountProfile
|
|
|
|
serviceaccount={serviceAccount}
|
|
|
|
onServiceAccountDelete={() => {
|
|
|
|
console.log(`not implemented`);
|
|
|
|
}}
|
|
|
|
onServiceAccountUpdate={() => {
|
|
|
|
console.log(`not implemented`);
|
|
|
|
}}
|
|
|
|
onServiceAccountDisable={() => {
|
|
|
|
console.log(`not implemented`);
|
|
|
|
}}
|
|
|
|
onServiceAccountEnable={() => {
|
|
|
|
console.log(`not implemented`);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
<h3 className="page-heading">Tokens</h3>
|
|
|
|
{tokens && (
|
|
|
|
<ServiceAccountTokensTable tokens={tokens} timeZone={timezone} onDelete={onDeleteServiceAccountToken} />
|
|
|
|
)}
|
|
|
|
</Page.Contents>
|
|
|
|
</Page>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const ServiceAccountPage = connector(ServiceAccountPageUnconnected);
|