2018-11-04 11:01:31 +05:30
|
|
|
|
import React from 'react';
|
|
|
|
|
import { restoreScroll } from 'components/ui/scroll/scroll';
|
|
|
|
|
import { FormattedMessage as Message } from 'react-intl';
|
|
|
|
|
import { LinkButton } from 'components/ui/form';
|
|
|
|
|
import { COLOR_GREEN } from 'components/ui';
|
2019-12-07 16:58:52 +05:30
|
|
|
|
import { OauthAppResponse } from 'services/api/oauth';
|
2018-11-04 11:01:31 +05:30
|
|
|
|
|
|
|
|
|
import messages from '../ApplicationsIndex.intl.json';
|
|
|
|
|
import styles from '../applicationsIndex.scss';
|
|
|
|
|
import ApplicationItem from './ApplicationItem';
|
|
|
|
|
|
|
|
|
|
type Props = {
|
2019-12-07 16:58:52 +05:30
|
|
|
|
applications: OauthAppResponse[];
|
|
|
|
|
deleteApp: (clientId: string) => Promise<any>;
|
|
|
|
|
resetApp: (clientId: string, resetClientSecret: boolean) => Promise<any>;
|
|
|
|
|
resetClientId: () => void;
|
|
|
|
|
clientId: string | null;
|
2018-11-04 11:01:31 +05:30
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type State = {
|
2019-12-07 16:58:52 +05:30
|
|
|
|
expandedApp: string | null;
|
2018-11-04 11:01:31 +05:30
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default class ApplicationsList extends React.Component<Props, State> {
|
2019-11-27 14:33:32 +05:30
|
|
|
|
state = {
|
|
|
|
|
expandedApp: null,
|
|
|
|
|
};
|
2018-11-04 11:01:31 +05:30
|
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
|
appsRefs: { [key: string]: HTMLDivElement | null } = {};
|
2018-11-04 11:01:31 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
componentDidMount() {
|
|
|
|
|
this.checkForActiveApp();
|
|
|
|
|
}
|
2018-11-04 11:01:31 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
componentDidUpdate() {
|
|
|
|
|
this.checkForActiveApp();
|
|
|
|
|
}
|
2018-11-04 11:01:31 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
render() {
|
|
|
|
|
const { applications, resetApp, deleteApp } = this.props;
|
|
|
|
|
const { expandedApp } = this.state;
|
2018-11-04 11:01:31 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<div className={styles.appsListTitleContainer}>
|
|
|
|
|
<div className={styles.appsListTitle}>
|
|
|
|
|
<Message {...messages.yourApplications} />
|
|
|
|
|
</div>
|
|
|
|
|
<LinkButton
|
|
|
|
|
to="/dev/applications/new"
|
|
|
|
|
data-e2e="newApp"
|
|
|
|
|
label={messages.addNew}
|
|
|
|
|
color={COLOR_GREEN}
|
|
|
|
|
className={styles.appsListAddNewAppBtn}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className={styles.appsListContainer}>
|
|
|
|
|
{applications.map(app => (
|
|
|
|
|
<div
|
|
|
|
|
key={app.clientId}
|
|
|
|
|
ref={elem => {
|
|
|
|
|
this.appsRefs[app.clientId] = elem;
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<ApplicationItem
|
|
|
|
|
application={app}
|
|
|
|
|
expand={app.clientId === expandedApp}
|
|
|
|
|
onTileClick={this.onTileClick}
|
|
|
|
|
onResetSubmit={resetApp}
|
|
|
|
|
onDeleteSubmit={deleteApp}
|
|
|
|
|
/>
|
2018-11-04 11:01:31 +05:30
|
|
|
|
</div>
|
2019-11-27 14:33:32 +05:30
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2018-11-04 11:01:31 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
checkForActiveApp() {
|
|
|
|
|
const { applications, clientId } = this.props;
|
|
|
|
|
const { expandedApp } = this.state;
|
2018-11-04 11:01:31 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
if (
|
|
|
|
|
clientId &&
|
|
|
|
|
expandedApp !== clientId &&
|
|
|
|
|
applications.some(app => app.clientId === clientId)
|
|
|
|
|
) {
|
|
|
|
|
requestAnimationFrame(() =>
|
|
|
|
|
this.onTileClick(clientId, { noReset: true }),
|
|
|
|
|
);
|
2018-11-04 11:01:31 +05:30
|
|
|
|
}
|
2019-11-27 14:33:32 +05:30
|
|
|
|
}
|
2018-11-04 11:01:31 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
onTileClick = (
|
|
|
|
|
clientId: string,
|
|
|
|
|
{ noReset = false }: { noReset?: boolean } = {},
|
|
|
|
|
) => {
|
|
|
|
|
const { clientId: initialClientId, resetClientId } = this.props;
|
|
|
|
|
const expandedApp = this.state.expandedApp === clientId ? null : clientId;
|
2018-11-04 11:01:31 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
if (initialClientId && noReset !== true) {
|
|
|
|
|
resetClientId();
|
|
|
|
|
}
|
2018-11-04 11:52:04 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
this.setState({ expandedApp }, () => {
|
|
|
|
|
if (expandedApp !== null) {
|
|
|
|
|
// TODO: @SleepWalker: мб у тебя есть идея, как это сделать более правильно и менее дёргано?
|
|
|
|
|
setTimeout(() => restoreScroll(this.appsRefs[clientId]), 150);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
2018-11-04 11:01:31 +05:30
|
|
|
|
}
|