Remove CTA when CTA-action is clicked instead of a /new route #13471

This commit is contained in:
Johannes Schill 2018-10-11 11:56:32 +02:00
parent b121700103
commit dc9e822cc7
4 changed files with 41 additions and 20 deletions

View File

@ -1,15 +1,20 @@
import React from 'react'; import React from 'react';
import Transition from 'react-transition-group/Transition'; import Transition from 'react-transition-group/Transition';
interface Style {
transition?: string;
overflow?: string;
}
const defaultMaxHeight = '200px'; // When animating using max-height we need to use a static value. const defaultMaxHeight = '200px'; // When animating using max-height we need to use a static value.
// If this is not enough, pass in <SlideDown maxHeight=".... // If this is not enough, pass in <SlideDown maxHeight="....
const defaultDuration = 200; const defaultDuration = 200;
const defaultStyle = { export const defaultStyle: Style = {
transition: `max-height ${defaultDuration}ms ease-in-out`, transition: `max-height ${defaultDuration}ms ease-in-out`,
overflow: 'hidden', overflow: 'hidden',
}; };
export default ({ children, in: inProp, maxHeight = defaultMaxHeight }) => { export default ({ children, in: inProp, maxHeight = defaultMaxHeight, style = defaultStyle }) => {
// There are 4 main states a Transition can be in: // There are 4 main states a Transition can be in:
// ENTERING, ENTERED, EXITING, EXITED // ENTERING, ENTERED, EXITING, EXITED
// https://reactcommunity.org/react-transition-group/ // https://reactcommunity.org/react-transition-group/
@ -25,7 +30,7 @@ export default ({ children, in: inProp, maxHeight = defaultMaxHeight }) => {
{state => ( {state => (
<div <div
style={{ style={{
...defaultStyle, ...style,
...transitionStyles[state], ...transitionStyles[state],
}} }}
> >

View File

@ -38,7 +38,7 @@ describe('Render', () => {
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });
it('should render CTA if theres are no API keys', () => { it('should render CTA if there are no API keys', () => {
const { wrapper } = setup({ const { wrapper } = setup({
apiKeys: getMultipleMockKeys(0), apiKeys: getMultipleMockKeys(0),
apiKeysCount: 0, apiKeysCount: 0,

View File

@ -7,8 +7,8 @@ import { getNavModel } from 'app/core/selectors/navModel';
import { getApiKeys, getApiKeysCount } from './state/selectors'; import { getApiKeys, getApiKeysCount } from './state/selectors';
import { loadApiKeys, deleteApiKey, setSearchQuery, addApiKey } from './state/actions'; import { loadApiKeys, deleteApiKey, setSearchQuery, addApiKey } from './state/actions';
import PageHeader from 'app/core/components/PageHeader/PageHeader'; import PageHeader from 'app/core/components/PageHeader/PageHeader';
import SlideDown from 'app/core/components/Animations/SlideDown';
import PageLoader from 'app/core/components/PageLoader/PageLoader'; import PageLoader from 'app/core/components/PageLoader/PageLoader';
import SlideDown, { defaultStyle as slideDownDefaultStyle } from 'app/core/components/Animations/SlideDown';
import ApiKeysAddedModal from './ApiKeysAddedModal'; import ApiKeysAddedModal from './ApiKeysAddedModal';
import config from 'app/core/config'; import config from 'app/core/config';
import appEvents from 'app/core/app_events'; import appEvents from 'app/core/app_events';
@ -105,21 +105,24 @@ export class ApiKeysPage extends PureComponent<Props, any> {
}; };
renderEmptyList() { renderEmptyList() {
const { isAdding } = this.state;
return ( return (
<div className="page-container page-body"> <div className="page-container page-body">
<EmptyListCTA {!isAdding && (
model={{ <EmptyListCTA
title: "You haven't added any API Keys yet.", model={{
buttonIcon: 'fa fa-plus', title: "You haven't added any API Keys yet.",
buttonLink: '#', buttonIcon: 'fa fa-plus',
onClick: this.onToggleAdding, buttonLink: '#',
buttonTitle: ' New API Key', onClick: this.onToggleAdding,
proTip: 'Remember you can provide view-only API access to other applications.', buttonTitle: ' New API Key',
proTipLink: '', proTip: 'Remember you can provide view-only API access to other applications.',
proTipLinkTitle: '', proTipLink: '',
proTipTarget: '_blank', proTipLinkTitle: '',
}} proTipTarget: '_blank',
/> }}
/>
)}
{this.renderAddApiKeyForm()} {this.renderAddApiKeyForm()}
</div> </div>
); );
@ -127,9 +130,10 @@ export class ApiKeysPage extends PureComponent<Props, any> {
renderAddApiKeyForm() { renderAddApiKeyForm() {
const { newApiKey, isAdding } = this.state; const { newApiKey, isAdding } = this.state;
const slideDownStyle = isAdding ? slideDownDefaultStyle : { ...slideDownDefaultStyle, transition: 'unset' };
return ( return (
<SlideDown in={isAdding}> <SlideDown in={isAdding} style={slideDownStyle}>
<div className="cta-form"> <div className="cta-form">
<button className="cta-form__close btn btn-transparent" onClick={this.onToggleAdding}> <button className="cta-form__close btn btn-transparent" onClick={this.onToggleAdding}>
<i className="fa fa-close" /> <i className="fa fa-close" />

View File

@ -45,6 +45,12 @@ exports[`Render should render API keys table if there are any keys 1`] = `
</div> </div>
<Component <Component
in={false} in={false}
style={
Object {
"overflow": "hidden",
"transition": "unset",
}
}
> >
<div <div
className="cta-form" className="cta-form"
@ -245,7 +251,7 @@ exports[`Render should render API keys table if there are any keys 1`] = `
</div> </div>
`; `;
exports[`Render should render CTA if theres are no API keys 1`] = ` exports[`Render should render CTA if there are no API keys 1`] = `
<div> <div>
<PageHeader <PageHeader
model={Object {}} model={Object {}}
@ -270,6 +276,12 @@ exports[`Render should render CTA if theres are no API keys 1`] = `
/> />
<Component <Component
in={false} in={false}
style={
Object {
"overflow": "hidden",
"transition": "unset",
}
}
> >
<div <div
className="cta-form" className="cta-form"