2018-03-26 00:46:45 +05:30
|
|
|
|
// @flow
|
2018-05-14 01:02:53 +05:30
|
|
|
|
import type { OauthAppResponse } from 'services/api/oauth';
|
2018-03-26 00:46:45 +05:30
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
import { FormattedMessage as Message } from 'react-intl';
|
|
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
|
import classNames from 'classnames';
|
|
|
|
|
import { SKIN_LIGHT, COLOR_BLACK, COLOR_RED } from 'components/ui';
|
|
|
|
|
import { Input, Button } from 'components/ui/form';
|
|
|
|
|
import Collapse from 'components/ui/collapse';
|
|
|
|
|
|
2018-11-04 11:01:31 +05:30
|
|
|
|
import styles from '../applicationsIndex.scss';
|
|
|
|
|
import messages from '../ApplicationsIndex.intl.json';
|
2018-03-26 00:46:45 +05:30
|
|
|
|
|
|
|
|
|
const ACTION_REVOKE_TOKENS = 'revoke-tokens';
|
|
|
|
|
const ACTION_RESET_SECRET = 'reset-secret';
|
|
|
|
|
const ACTION_DELETE = 'delete';
|
2018-11-04 11:01:31 +05:30
|
|
|
|
const actionButtons = [
|
|
|
|
|
{
|
|
|
|
|
type: ACTION_REVOKE_TOKENS,
|
|
|
|
|
label: messages.revokeAllTokens
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: ACTION_RESET_SECRET,
|
|
|
|
|
label: messages.resetClientSecret
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: ACTION_DELETE,
|
|
|
|
|
label: messages.delete
|
|
|
|
|
}
|
|
|
|
|
];
|
2018-03-26 00:46:45 +05:30
|
|
|
|
|
2018-11-04 11:01:31 +05:30
|
|
|
|
export default class ApplicationItem extends Component<
|
|
|
|
|
{
|
|
|
|
|
application: OauthAppResponse,
|
|
|
|
|
expand: bool,
|
|
|
|
|
onTileClick: string => void,
|
|
|
|
|
onResetSubmit: (string, bool) => Promise<*>,
|
|
|
|
|
onDeleteSubmit: string => Promise<*>
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
selectedAction: ?string,
|
|
|
|
|
isActionPerforming: bool,
|
2018-11-04 11:37:04 +05:30
|
|
|
|
detailsHeight: number,
|
|
|
|
|
translateY: number
|
2018-11-04 11:01:31 +05:30
|
|
|
|
}
|
|
|
|
|
> {
|
2018-03-26 00:46:45 +05:30
|
|
|
|
state = {
|
|
|
|
|
selectedAction: null,
|
|
|
|
|
isActionPerforming: false,
|
2018-11-04 11:37:04 +05:30
|
|
|
|
translateY: 0,
|
2018-11-04 11:01:31 +05:30
|
|
|
|
detailsHeight: 0
|
2018-03-26 00:46:45 +05:30
|
|
|
|
};
|
|
|
|
|
|
2018-11-04 11:37:04 +05:30
|
|
|
|
actionContainer: ?HTMLDivElement;
|
|
|
|
|
|
2018-03-26 00:46:45 +05:30
|
|
|
|
render() {
|
|
|
|
|
const { application: app, expand } = this.props;
|
2018-11-04 11:37:04 +05:30
|
|
|
|
const { selectedAction, translateY } = this.state;
|
2018-11-04 11:01:31 +05:30
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
className={classNames(styles.appItemContainer, {
|
|
|
|
|
[styles.appExpanded]: expand
|
|
|
|
|
})}
|
2018-11-10 14:33:47 +05:30
|
|
|
|
data-e2e="appItem"
|
2019-06-30 19:02:50 +05:30
|
|
|
|
data-e2e-app-name={app.name}
|
2018-11-04 11:01:31 +05:30
|
|
|
|
>
|
|
|
|
|
<div className={styles.appItemTile} onClick={this.onTileToggle}>
|
|
|
|
|
<div className={styles.appTileTitle}>
|
|
|
|
|
<div className={styles.appName}>{app.name}</div>
|
|
|
|
|
<div className={styles.appStats}>
|
|
|
|
|
Client ID: {app.clientId}
|
|
|
|
|
{typeof app.countUsers !== 'undefined' && (
|
|
|
|
|
<span>
|
|
|
|
|
{' | '}
|
|
|
|
|
<Message
|
|
|
|
|
{...messages.countUsers}
|
|
|
|
|
values={{
|
|
|
|
|
count: app.countUsers
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className={styles.appItemToggle}>
|
|
|
|
|
<div className={styles.appItemToggleIcon} />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<Collapse isOpened={expand} onRest={this.onCollapseRest}>
|
2018-11-04 11:37:04 +05:30
|
|
|
|
<div
|
|
|
|
|
className={styles.appDetailsContainer}
|
|
|
|
|
style={{ transform: `translateY(-${translateY}px)` }}
|
|
|
|
|
>
|
2018-11-04 11:01:31 +05:30
|
|
|
|
<div className={styles.appDetailsInfoField}>
|
|
|
|
|
<Link
|
|
|
|
|
to={`/dev/applications/${app.clientId}`}
|
|
|
|
|
className={styles.editAppLink}
|
|
|
|
|
>
|
|
|
|
|
<Message
|
|
|
|
|
{...messages.editDescription}
|
|
|
|
|
values={{
|
|
|
|
|
icon: (
|
|
|
|
|
<div
|
|
|
|
|
className={styles.pencilIcon}
|
|
|
|
|
/>
|
|
|
|
|
)
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</Link>
|
|
|
|
|
<Input
|
|
|
|
|
label="Client ID:"
|
|
|
|
|
skin={SKIN_LIGHT}
|
|
|
|
|
disabled
|
|
|
|
|
value={app.clientId}
|
|
|
|
|
copy
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className={styles.appDetailsInfoField}>
|
|
|
|
|
<Input
|
|
|
|
|
label="Client Secret:"
|
|
|
|
|
skin={SKIN_LIGHT}
|
|
|
|
|
disabled
|
|
|
|
|
value={app.clientSecret}
|
|
|
|
|
copy
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className={styles.appDetailsDescription}>
|
|
|
|
|
<Message
|
|
|
|
|
{...messages.ifYouSuspectingThatSecretHasBeenCompromised}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2018-03-26 00:46:45 +05:30
|
|
|
|
|
2018-11-04 11:01:31 +05:30
|
|
|
|
<div className={styles.appActionsButtons}>
|
|
|
|
|
{actionButtons.map(({ type, label }) => (
|
|
|
|
|
<Button
|
|
|
|
|
key={type}
|
|
|
|
|
label={label}
|
|
|
|
|
color={COLOR_BLACK}
|
|
|
|
|
className={styles.appActionButton}
|
|
|
|
|
disabled={
|
|
|
|
|
selectedAction
|
|
|
|
|
&& selectedAction !== type
|
|
|
|
|
}
|
|
|
|
|
onClick={this.onActionButtonClick(type)}
|
|
|
|
|
small
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
|
2018-11-04 11:37:04 +05:30
|
|
|
|
<div
|
|
|
|
|
className={styles.appActionContainer}
|
|
|
|
|
ref={(el) => {
|
|
|
|
|
this.actionContainer = el;
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{this.getActionContent()}
|
|
|
|
|
</div>
|
2018-11-04 11:01:31 +05:30
|
|
|
|
</div>
|
|
|
|
|
</Collapse>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getActionContent() {
|
|
|
|
|
const { selectedAction, isActionPerforming } = this.state;
|
2018-05-14 01:02:53 +05:30
|
|
|
|
|
2018-03-26 00:46:45 +05:30
|
|
|
|
switch (selectedAction) {
|
|
|
|
|
case ACTION_REVOKE_TOKENS:
|
|
|
|
|
case ACTION_RESET_SECRET:
|
2018-11-04 11:01:31 +05:30
|
|
|
|
return (
|
2018-03-26 00:46:45 +05:30
|
|
|
|
<div>
|
|
|
|
|
<div className={styles.appActionDescription}>
|
2018-11-04 11:01:31 +05:30
|
|
|
|
<Message
|
|
|
|
|
{...messages.allRefreshTokensWillBecomeInvalid}
|
|
|
|
|
/>{' '}
|
|
|
|
|
<Message
|
|
|
|
|
{...messages.takeCareAccessTokensInvalidation}
|
|
|
|
|
/>
|
2018-03-26 00:46:45 +05:30
|
|
|
|
</div>
|
|
|
|
|
<div className={styles.appActionsButtons}>
|
|
|
|
|
<Button
|
|
|
|
|
label={messages.cancel}
|
|
|
|
|
color={COLOR_BLACK}
|
|
|
|
|
className={styles.appActionButton}
|
|
|
|
|
onClick={this.onActionButtonClick(null)}
|
|
|
|
|
small
|
|
|
|
|
/>
|
|
|
|
|
<div className={styles.continueActionButtonWrapper}>
|
|
|
|
|
{isActionPerforming ? (
|
|
|
|
|
<div className={styles.performingAction}>
|
|
|
|
|
<Message {...messages.performing} />
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<div
|
|
|
|
|
className={styles.continueActionLink}
|
2018-11-04 11:01:31 +05:30
|
|
|
|
onClick={this.onResetSubmit(
|
|
|
|
|
selectedAction
|
|
|
|
|
=== ACTION_RESET_SECRET
|
|
|
|
|
)}
|
2018-03-26 00:46:45 +05:30
|
|
|
|
>
|
|
|
|
|
<Message {...messages.continue} />
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2018-11-04 11:01:31 +05:30
|
|
|
|
|
2018-03-26 00:46:45 +05:30
|
|
|
|
case ACTION_DELETE:
|
2018-11-04 11:01:31 +05:30
|
|
|
|
return (
|
2018-03-26 00:46:45 +05:30
|
|
|
|
<div>
|
|
|
|
|
<div className={styles.appActionDescription}>
|
2018-11-04 11:01:31 +05:30
|
|
|
|
<Message
|
|
|
|
|
{...messages.appAndAllTokenWillBeDeleted}
|
|
|
|
|
/>{' '}
|
|
|
|
|
<Message
|
|
|
|
|
{...messages.takeCareAccessTokensInvalidation}
|
|
|
|
|
/>
|
2018-03-26 00:46:45 +05:30
|
|
|
|
</div>
|
|
|
|
|
<div className={styles.appActionsButtons}>
|
|
|
|
|
<Button
|
|
|
|
|
label={messages.cancel}
|
|
|
|
|
color={COLOR_BLACK}
|
|
|
|
|
className={styles.appActionButton}
|
|
|
|
|
onClick={this.onActionButtonClick(null)}
|
|
|
|
|
small
|
|
|
|
|
/>
|
|
|
|
|
<div className={styles.continueActionButtonWrapper}>
|
|
|
|
|
{isActionPerforming ? (
|
|
|
|
|
<div className={styles.performingAction}>
|
|
|
|
|
<Message {...messages.performing} />
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<Button
|
|
|
|
|
label={messages.delete}
|
|
|
|
|
color={COLOR_RED}
|
|
|
|
|
className={styles.appActionButton}
|
|
|
|
|
onClick={this.onSubmitDelete}
|
|
|
|
|
small
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2018-11-04 11:01:31 +05:30
|
|
|
|
|
2018-05-14 01:02:53 +05:30
|
|
|
|
default:
|
2018-11-04 11:01:31 +05:30
|
|
|
|
return null;
|
2018-03-26 00:46:45 +05:30
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-04 11:37:04 +05:30
|
|
|
|
setActiveAction = (type: ?string) => {
|
|
|
|
|
const { actionContainer } = this;
|
|
|
|
|
|
|
|
|
|
if (!actionContainer) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.setState(
|
|
|
|
|
{
|
|
|
|
|
selectedAction: type
|
|
|
|
|
},
|
|
|
|
|
() => {
|
|
|
|
|
const translateY = actionContainer.offsetHeight;
|
|
|
|
|
|
|
|
|
|
this.setState({ translateY });
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2018-03-26 00:46:45 +05:30
|
|
|
|
onTileToggle = () => {
|
|
|
|
|
const { onTileClick, application } = this.props;
|
2018-11-04 11:37:04 +05:30
|
|
|
|
|
2018-03-26 00:46:45 +05:30
|
|
|
|
onTileClick(application.clientId);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onCollapseRest = () => {
|
|
|
|
|
if (!this.props.expand && this.state.selectedAction) {
|
2018-11-04 11:37:04 +05:30
|
|
|
|
this.setActiveAction(null);
|
2018-03-26 00:46:45 +05:30
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onActionButtonClick = (type: ?string) => () => {
|
2018-11-04 11:37:04 +05:30
|
|
|
|
this.setActiveAction(type === this.state.selectedAction ? null : type);
|
2018-03-26 00:46:45 +05:30
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onResetSubmit = (resetClientSecret: bool) => async () => {
|
|
|
|
|
const { onResetSubmit, application } = this.props;
|
2018-11-04 11:37:04 +05:30
|
|
|
|
|
2018-03-26 00:46:45 +05:30
|
|
|
|
this.setState({
|
2018-11-04 11:01:31 +05:30
|
|
|
|
isActionPerforming: true
|
2018-03-26 00:46:45 +05:30
|
|
|
|
});
|
2018-11-04 11:37:04 +05:30
|
|
|
|
|
2018-03-26 00:46:45 +05:30
|
|
|
|
await onResetSubmit(application.clientId, resetClientSecret);
|
2018-11-04 11:37:04 +05:30
|
|
|
|
|
2018-03-26 00:46:45 +05:30
|
|
|
|
this.setState({
|
2018-11-04 11:37:04 +05:30
|
|
|
|
isActionPerforming: false
|
2018-03-26 00:46:45 +05:30
|
|
|
|
});
|
2018-11-04 11:37:04 +05:30
|
|
|
|
this.setActiveAction(null);
|
2018-03-26 00:46:45 +05:30
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onSubmitDelete = () => {
|
|
|
|
|
const { onDeleteSubmit, application } = this.props;
|
2018-11-04 11:37:04 +05:30
|
|
|
|
|
2018-03-26 00:46:45 +05:30
|
|
|
|
this.setState({
|
2018-11-04 11:01:31 +05:30
|
|
|
|
isActionPerforming: true
|
2018-03-26 00:46:45 +05:30
|
|
|
|
});
|
2018-11-04 11:37:04 +05:30
|
|
|
|
|
2018-03-26 00:46:45 +05:30
|
|
|
|
onDeleteSubmit(application.clientId);
|
|
|
|
|
};
|
|
|
|
|
}
|