2019-10-19 16:38:07 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
import { History } from 'history';
|
|
|
|
|
import { withRouter } from 'react-router-dom';
|
|
|
|
|
import classNames from 'classnames';
|
|
|
|
|
import { Button, urls } from './index';
|
|
|
|
|
import { FilterInput } from './forms';
|
2019-04-19 13:18:49 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
2019-10-19 16:38:07 +02:00
|
|
|
showCreateButton: boolean;
|
|
|
|
|
link: string;
|
|
|
|
|
label?: string;
|
2019-04-19 13:18:49 +02:00
|
|
|
|
|
|
|
|
// context props
|
2019-10-19 16:38:07 +02:00
|
|
|
history: History;
|
|
|
|
|
location: any;
|
2019-04-19 13:18:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class OverviewPageActions extends React.Component<Props> {
|
|
|
|
|
render() {
|
|
|
|
|
const { history, location, link } = this.props;
|
|
|
|
|
return (
|
2019-04-24 09:46:22 +02:00
|
|
|
<>
|
2019-04-19 13:18:49 +02:00
|
|
|
<FilterInput
|
|
|
|
|
value={urls.getQueryStringFromLocation(location)}
|
|
|
|
|
filter={filter => {
|
2019-04-24 09:59:29 +02:00
|
|
|
history.push(`/${link}/?q=${filter}`);
|
2019-04-19 13:18:49 +02:00
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
{this.renderCreateButton()}
|
2019-04-24 09:46:22 +02:00
|
|
|
</>
|
2019-04-19 13:18:49 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderCreateButton() {
|
2019-10-08 16:42:08 +02:00
|
|
|
const { showCreateButton, link, label } = this.props;
|
2019-04-19 13:18:49 +02:00
|
|
|
if (showCreateButton) {
|
|
|
|
|
return (
|
2019-10-19 16:38:07 +02:00
|
|
|
<div className={classNames('input-button', 'control')}>
|
2019-04-24 09:59:29 +02:00
|
|
|
<Button label={label} link={`/${link}/create`} color="primary" />
|
2019-04-19 13:18:49 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-08 16:42:08 +02:00
|
|
|
export default withRouter(OverviewPageActions);
|