2018-02-28 06:41:12 +00:00
|
|
|
|
// @flow
|
2020-11-09 06:33:52 +00:00
|
|
|
|
import { observable } from "mobx";
|
|
|
|
|
import { inject, observer } from "mobx-react";
|
|
|
|
|
import queryString from "query-string";
|
2020-08-09 05:53:59 +00:00
|
|
|
|
import * as React from "react";
|
2020-11-30 04:04:58 +00:00
|
|
|
|
import { withTranslation, type TFunction } from "react-i18next";
|
2020-11-09 06:33:52 +00:00
|
|
|
|
import { type RouterHistory } from "react-router-dom";
|
|
|
|
|
import styled from "styled-components";
|
2020-08-09 05:53:59 +00:00
|
|
|
|
import DocumentsStore from "stores/DocumentsStore";
|
2020-11-09 06:33:52 +00:00
|
|
|
|
import CollectionFilter from "scenes/Search/components/CollectionFilter";
|
|
|
|
|
import DateFilter from "scenes/Search/components/DateFilter";
|
|
|
|
|
|
2020-08-09 05:53:59 +00:00
|
|
|
|
import Actions, { Action } from "components/Actions";
|
2020-06-20 20:59:15 +00:00
|
|
|
|
import CenteredContent from "components/CenteredContent";
|
|
|
|
|
import Empty from "components/Empty";
|
2020-11-09 06:33:52 +00:00
|
|
|
|
import Flex from "components/Flex";
|
2020-08-09 05:53:59 +00:00
|
|
|
|
import Heading from "components/Heading";
|
|
|
|
|
import InputSearch from "components/InputSearch";
|
2020-06-20 20:59:15 +00:00
|
|
|
|
import PageTitle from "components/PageTitle";
|
|
|
|
|
import PaginatedDocumentList from "components/PaginatedDocumentList";
|
|
|
|
|
import Subheading from "components/Subheading";
|
|
|
|
|
import NewDocumentMenu from "menus/NewDocumentMenu";
|
2020-11-09 06:33:52 +00:00
|
|
|
|
import { type LocationWithState } from "types";
|
2018-02-28 06:41:12 +00:00
|
|
|
|
|
2020-11-09 06:33:52 +00:00
|
|
|
|
type Props = {|
|
2018-05-05 23:16:08 +00:00
|
|
|
|
documents: DocumentsStore,
|
2020-11-09 06:33:52 +00:00
|
|
|
|
history: RouterHistory,
|
|
|
|
|
location: LocationWithState,
|
2020-11-30 04:04:58 +00:00
|
|
|
|
t: TFunction,
|
2020-11-09 06:33:52 +00:00
|
|
|
|
|};
|
2018-02-28 06:41:12 +00:00
|
|
|
|
|
2018-05-05 23:16:08 +00:00
|
|
|
|
@observer
|
|
|
|
|
class Drafts extends React.Component<Props> {
|
2020-11-09 06:33:52 +00:00
|
|
|
|
@observable params: URLSearchParams = new URLSearchParams(
|
|
|
|
|
this.props.location.search
|
|
|
|
|
);
|
|
|
|
|
|
2020-11-30 04:04:58 +00:00
|
|
|
|
componentDidUpdate(prevProps: Props) {
|
2020-11-09 06:33:52 +00:00
|
|
|
|
if (prevProps.location.search !== this.props.location.search) {
|
|
|
|
|
this.handleQueryChange();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleQueryChange = () => {
|
|
|
|
|
this.params = new URLSearchParams(this.props.location.search);
|
|
|
|
|
};
|
|
|
|
|
|
2020-11-30 04:04:58 +00:00
|
|
|
|
handleFilterChange = (search: {
|
|
|
|
|
dateFilter?: ?string,
|
|
|
|
|
collectionId?: ?string,
|
|
|
|
|
}) => {
|
2020-11-09 06:33:52 +00:00
|
|
|
|
this.props.history.replace({
|
|
|
|
|
pathname: this.props.location.pathname,
|
|
|
|
|
search: queryString.stringify({
|
|
|
|
|
...queryString.parse(this.props.location.search),
|
|
|
|
|
...search,
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
get collectionId() {
|
|
|
|
|
const id = this.params.get("collectionId");
|
|
|
|
|
return id ? id : undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get dateFilter() {
|
|
|
|
|
const id = this.params.get("dateFilter");
|
|
|
|
|
return id ? id : undefined;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-28 06:41:12 +00:00
|
|
|
|
render() {
|
2020-11-30 04:04:58 +00:00
|
|
|
|
const { t } = this.props;
|
2020-11-09 06:33:52 +00:00
|
|
|
|
const { drafts, fetchDrafts } = this.props.documents;
|
|
|
|
|
const isFiltered = this.collectionId || this.dateFilter;
|
|
|
|
|
const options = {
|
|
|
|
|
dateFilter: this.dateFilter,
|
|
|
|
|
collectionId: this.collectionId,
|
|
|
|
|
};
|
2018-02-28 06:41:12 +00:00
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<CenteredContent column auto>
|
2020-11-30 04:04:58 +00:00
|
|
|
|
<PageTitle title={t("Drafts")} />
|
|
|
|
|
<Heading>{t("Drafts")}</Heading>
|
2020-11-09 06:33:52 +00:00
|
|
|
|
<Subheading>
|
2020-11-30 04:04:58 +00:00
|
|
|
|
{t("Documents")}
|
2020-11-09 06:33:52 +00:00
|
|
|
|
<Filters>
|
|
|
|
|
<CollectionFilter
|
|
|
|
|
collectionId={this.collectionId}
|
|
|
|
|
onSelect={(collectionId) =>
|
|
|
|
|
this.handleFilterChange({ collectionId })
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
<DateFilter
|
|
|
|
|
dateFilter={this.dateFilter}
|
|
|
|
|
onSelect={(dateFilter) => this.handleFilterChange({ dateFilter })}
|
|
|
|
|
/>
|
|
|
|
|
</Filters>
|
|
|
|
|
</Subheading>
|
|
|
|
|
|
2020-01-14 02:17:56 +00:00
|
|
|
|
<PaginatedDocumentList
|
2020-11-09 06:33:52 +00:00
|
|
|
|
empty={
|
|
|
|
|
<Empty>
|
|
|
|
|
{isFiltered
|
2020-11-30 04:04:58 +00:00
|
|
|
|
? t("No documents found for your filters.")
|
|
|
|
|
: t("You’ve not got any drafts at the moment.")}
|
2020-11-09 06:33:52 +00:00
|
|
|
|
</Empty>
|
|
|
|
|
}
|
2020-01-14 02:17:56 +00:00
|
|
|
|
fetch={fetchDrafts}
|
2020-11-09 06:33:52 +00:00
|
|
|
|
documents={drafts(options)}
|
|
|
|
|
options={options}
|
2020-01-14 02:17:56 +00:00
|
|
|
|
showCollection
|
|
|
|
|
/>
|
|
|
|
|
|
2018-08-07 05:49:41 +00:00
|
|
|
|
<Actions align="center" justify="flex-end">
|
2020-01-10 03:14:34 +00:00
|
|
|
|
<Action>
|
2020-09-25 04:56:37 +00:00
|
|
|
|
<InputSearch source="drafts" />
|
2020-01-10 03:14:34 +00:00
|
|
|
|
</Action>
|
2018-08-07 05:49:41 +00:00
|
|
|
|
<Action>
|
2019-07-13 17:15:38 +00:00
|
|
|
|
<NewDocumentMenu />
|
2018-08-07 05:49:41 +00:00
|
|
|
|
</Action>
|
|
|
|
|
</Actions>
|
2018-02-28 06:41:12 +00:00
|
|
|
|
</CenteredContent>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-09 06:33:52 +00:00
|
|
|
|
const Filters = styled(Flex)`
|
|
|
|
|
opacity: 0.85;
|
|
|
|
|
transition: opacity 100ms ease-in-out;
|
|
|
|
|
position: absolute;
|
|
|
|
|
right: -8px;
|
|
|
|
|
bottom: 0;
|
|
|
|
|
padding: 0 0 6px;
|
|
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
|
opacity: 1;
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
2020-11-30 04:04:58 +00:00
|
|
|
|
export default withTranslation()<Drafts>(inject("documents")(Drafts));
|