Commit 660fd974 authored by Matija Obreza's avatar Matija Obreza
Browse files

Strongly-typed filtering

- Prevent mismatches with API
parent 863aa65b
...@@ -42,6 +42,8 @@ import AuditedInfo from 'ui/common/AuditedInfo'; ...@@ -42,6 +42,8 @@ import AuditedInfo from 'ui/common/AuditedInfo';
import Authorize from 'ui/common/authorized/Authorize'; import Authorize from 'ui/common/authorized/Authorize';
import BioClimateDisplay from 'accessions/ui/c/BioClimateDisplay'; import BioClimateDisplay from 'accessions/ui/c/BioClimateDisplay';
import PageTitle from 'ui/common/PageTitle'; import PageTitle from 'ui/common/PageTitle';
import AccessionFilter from 'model/accession/AccessionFilter';
import { IPageRequest } from 'model/Page';
const styles = (theme) => ({ const styles = (theme) => ({
pageSection: { pageSection: {
...@@ -71,7 +73,7 @@ interface IBrowsePageProps { ...@@ -71,7 +73,7 @@ interface IBrowsePageProps {
accessions: any; accessions: any;
addAccessionToMyList: any; addAccessionToMyList: any;
removeAccessionFromMyList: any; removeAccessionFromMyList: any;
applyFilters: any; applyFilters: (filters: string | AccessionFilter, page?: IPageRequest) => any;
navigateTo: (location: string) => void; navigateTo: (location: string) => void;
mapLayers: MapLayer[]; mapLayers: MapLayer[];
} }
......
...@@ -30,6 +30,8 @@ import Button from '@material-ui/core/Button'; ...@@ -30,6 +30,8 @@ import Button from '@material-ui/core/Button';
import BlurbText from 'cms/ui/c/BlurbText'; import BlurbText from 'cms/ui/c/BlurbText';
import ContentHeader from 'ui/common/heading/ContentHeader'; import ContentHeader from 'ui/common/heading/ContentHeader';
import Permissions from 'ui/common/permission/Permissions'; import Permissions from 'ui/common/permission/Permissions';
import AccessionFilter from 'model/accession/AccessionFilter';
import { IPageRequest } from 'model/Page';
/*tslint:disable*/ /*tslint:disable*/
const styles = (theme) => ({ const styles = (theme) => ({
...@@ -46,7 +48,7 @@ interface IDisplayPageProps extends React.ClassAttributes<any> { ...@@ -46,7 +48,7 @@ interface IDisplayPageProps extends React.ClassAttributes<any> {
shortName: string; shortName: string;
t: any; t: any;
classes?: any; classes?: any;
applyFilters: any; applyFilters: (filters: string | AccessionFilter, page?: IPageRequest) => any;
relinkAccessions: (shortName: string) => void; relinkAccessions: (shortName: string) => void;
} }
......
...@@ -24,13 +24,15 @@ import Number from 'ui/common/Number'; ...@@ -24,13 +24,15 @@ import Number from 'ui/common/Number';
import PageTitle from 'ui/common/PageTitle'; import PageTitle from 'ui/common/PageTitle';
import PieChartCard from 'ui/common/pie-chart/PieChartCard'; import PieChartCard from 'ui/common/pie-chart/PieChartCard';
import GridContainer from 'ui/layout/GridContainer'; import GridContainer from 'ui/layout/GridContainer';
import AccessionFilter from 'model/accession/AccessionFilter';
import { IPageRequest } from 'model/Page';
interface ICountryDisplayPageProps extends React.ClassAttributes<any> { interface ICountryDisplayPageProps extends React.ClassAttributes<any> {
details: CountryDetails; details: CountryDetails;
isoCode: string; isoCode: string;
t: any; t: any;
loadCountryDetails: (isoCode: string) => void; loadCountryDetails: (isoCode: string) => void;
applyFilters: any; applyFilters: (filters: string | AccessionFilter, page?: IPageRequest) => any;
mapLayers: MapLayer[]; mapLayers: MapLayer[];
} }
...@@ -72,7 +74,7 @@ class CountryDisplayPage extends React.Component<ICountryDisplayPageProps> { ...@@ -72,7 +74,7 @@ class CountryDisplayPage extends React.Component<ICountryDisplayPageProps> {
private applyCountryOfOriginFilter = (iso3Code: string) => { private applyCountryOfOriginFilter = (iso3Code: string) => {
const filter = { const filter = {
origin: {iso3: [ iso3Code ]}, countryOfOrigin: { code3: [iso3Code] },
}; };
this.props.applyFilters(filter); this.props.applyFilters(filter);
} }
......
...@@ -34,6 +34,8 @@ import ButtonBar from 'ui/common/buttons/ButtonBar'; ...@@ -34,6 +34,8 @@ import ButtonBar from 'ui/common/buttons/ButtonBar';
import DownloadDialog from 'ui/common/download-dialog'; import DownloadDialog from 'ui/common/download-dialog';
import PageTitle from 'ui/common/PageTitle'; import PageTitle from 'ui/common/PageTitle';
import BlurbText from 'cms/ui/c/BlurbText'; import BlurbText from 'cms/ui/c/BlurbText';
import AccessionFilter from 'model/accession/AccessionFilter';
import { IPageRequest } from 'model/Page';
/*tslint:disable*/ /*tslint:disable*/
const styles = (theme) => ({ const styles = (theme) => ({
...@@ -57,8 +59,8 @@ interface IDisplayPageProps extends React.ClassAttributes<any> { ...@@ -57,8 +59,8 @@ interface IDisplayPageProps extends React.ClassAttributes<any> {
error: any; error: any;
loading: boolean; loading: boolean;
loadInstitute: any; loadInstitute: any;
applyFilters: any; applyFilters: (filters: string | AccessionFilter, page?: IPageRequest) => any;
applyOverviewFilters: any; applyOverviewFilters: (filters: string | AccessionFilter) => any;
userRoles: string[]; userRoles: string[];
mapLayers: MapLayer[]; mapLayers: MapLayer[];
} }
...@@ -80,13 +82,13 @@ class DisplayPage extends React.Component<IDisplayPageProps, any> { ...@@ -80,13 +82,13 @@ class DisplayPage extends React.Component<IDisplayPageProps, any> {
private applyInstituteCodeFilter = () => { private applyInstituteCodeFilter = () => {
const { institute, applyFilters} = this.props; const { institute, applyFilters} = this.props;
const filter = {holder: {code: [ institute.details.code ]}}; const filter = { institute: { code: [institute.details.code] } };
applyFilters(filter); applyFilters(filter);
} }
private applyFilterForOverview = () => { private applyFilterForOverview = () => {
const { institute, applyOverviewFilters } = this.props; const { institute, applyOverviewFilters } = this.props;
const filter = {holder: {code: [ institute.details.code ]}}; const filter = { institute: { code: [institute.details.code] } };
applyOverviewFilters(filter); applyOverviewFilters(filter);
} }
...@@ -98,7 +100,7 @@ class DisplayPage extends React.Component<IDisplayPageProps, any> { ...@@ -98,7 +100,7 @@ class DisplayPage extends React.Component<IDisplayPageProps, any> {
endOfDay.setHours(23, 59, 59); endOfDay.setHours(23, 59, 59);
const filter = { const filter = {
holder: {code: [ institute.details.code ]}, institute: { code: [institute.details.code] },
lastModifiedDate: { lastModifiedDate: {
ge: startOfDay, ge: startOfDay,
le: endOfDay, le: endOfDay,
......
...@@ -5,23 +5,23 @@ import DateFilter from 'model/filter/DateFilter'; ...@@ -5,23 +5,23 @@ import DateFilter from 'model/filter/DateFilter';
import StringFilter from 'model/filter/StringFilter'; import StringFilter from 'model/filter/StringFilter';
class UserFilter { class UserFilter {
public NOT: UserFilter; public NOT?: UserFilter;
public NOTNULL: string[]; public NOTNULL?: string[];
public NULL: string[]; public NULL?: string[];
public active: boolean; public active?: boolean;
public createdBy: number[]; public createdBy?: number[];
public createdDate: DateFilter; public createdDate?: DateFilter;
public email: StringFilter; public email?: StringFilter;
public enabled: boolean; public enabled?: boolean;
public expired: boolean; public expired?: boolean;
public id: number[]; public id?: number[];
public lastModifiedBy: number[]; public lastModifiedBy?: number[];
public lastModifiedDate: DateFilter; public lastModifiedDate?: DateFilter;
public locked: boolean; public locked?: boolean;
public role: string[]; public role?: string[];
public uuid: string[]; public uuid?: string[];
public version: number[]; public version?: number[];
public lastLogin: DateFilter; public lastLogin?: DateFilter;
} }
export default UserFilter; export default UserFilter;
...@@ -11,29 +11,28 @@ import AccessionGeoFilter from './AccessionGeoFilter'; ...@@ -11,29 +11,28 @@ import AccessionGeoFilter from './AccessionGeoFilter';
*/ */
class AccessionFilter { class AccessionFilter {
public accessionNumber?: StringFilter; public accessionNumber?: StringFilter;
public aliases: StringFilter; public aliases?: StringFilter;
public active?: boolean; public active?: boolean;
public available?: boolean; public available?: boolean;
public createdBy?: number[]; public createdBy?: number[];
public countryOfOrigin: CountryFilter; public countryOfOrigin?: CountryFilter;
public createdDate?: DateFilter; public createdDate?: DateFilter;
public crop?: string[]; public crop?: string[];
public cropName?: string; public cropName?: string;
public doi?: string[]; public doi?: string[];
public elevation?: NumberFilter;
public geo?: AccessionGeoFilter; public geo?: AccessionGeoFilter;
public historic?: boolean; public historic?: boolean;
public images?: boolean; public images?: boolean;
public inTrust: boolean; public inTrust?: boolean;
public institute: InstituteFilter; public institute?: InstituteFilter;
public lists: string[]; public lists?: string[];
public id?: number[]; public id?: number[];
public lastModifiedBy?: number[]; public lastModifiedBy?: number[];
public lastModifiedDate?: DateFilter; public lastModifiedDate?: DateFilter;
public latitude?: NumberFilter; public latitude?: NumberFilter;
public longitude?: NumberFilter; public longitude?: NumberFilter;
public mlsStatus?: boolean; public mlsStatus?: boolean;
public pdci: NumberFilter; public pdci?: NumberFilter;
public sampStat?: number[]; public sampStat?: number[];
public seqNo?: NumberFilter; public seqNo?: NumberFilter;
public taxa?: TaxonomyFilter; public taxa?: TaxonomyFilter;
...@@ -41,7 +40,7 @@ class AccessionFilter { ...@@ -41,7 +40,7 @@ class AccessionFilter {
public version?: number[]; public version?: number[];
public sgsv?: boolean; public sgsv?: boolean;
public storage?: number[]; public storage?: number[];
public taxonomy: TaxonomyFilter; public taxonomy?: TaxonomyFilter;
public NOT?: AccessionFilter; public NOT?: AccessionFilter;
} }
......
...@@ -5,11 +5,11 @@ import NumberFilter from 'model/filter/NumberFilter'; ...@@ -5,11 +5,11 @@ import NumberFilter from 'model/filter/NumberFilter';
* Defined in Swagger as '#/definitions/AccessionGeoFilter' * Defined in Swagger as '#/definitions/AccessionGeoFilter'
*/ */
class AccessionGeoFilter { class AccessionGeoFilter {
public climate: ClimateFilter; public climate?: ClimateFilter;
public elevation: NumberFilter; public elevation?: NumberFilter;
public latitude: NumberFilter; public latitude?: NumberFilter;
public longitude: NumberFilter; public longitude?: NumberFilter;
public referenced: boolean; public referenced?: boolean;
} }
......
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
* Defined in OpenAPI as '#/definitions/StringFilter' * Defined in OpenAPI as '#/definitions/StringFilter'
*/ */
class StringFilter { class StringFilter {
public contains: string; public contains?: string;
public eq: string; public eq?: string;
public sw: string; public sw?: string;
} }
......
...@@ -5,10 +5,10 @@ import StringFilter from 'model/filter/StringFilter'; ...@@ -5,10 +5,10 @@ import StringFilter from 'model/filter/StringFilter';
* Defined in Swagger as '#/definitions/InstituteFilter' * Defined in Swagger as '#/definitions/InstituteFilter'
*/ */
class InstituteFilter { class InstituteFilter {
public code: string[]; public code?: string[];
public country: CountryFilter; public country?: CountryFilter;
public name: StringFilter; public name?: StringFilter;
public networks?: string[];
} }
......
...@@ -5,16 +5,15 @@ import StringFilter from 'model/filter/StringFilter'; ...@@ -5,16 +5,15 @@ import StringFilter from 'model/filter/StringFilter';
* Defined in Swagger as '#/definitions/TaxonomyFilter' * Defined in Swagger as '#/definitions/TaxonomyFilter'
*/ */
class TaxonomyFilter { class TaxonomyFilter {
public active: boolean; public createdBy?: number[];
public createdBy: number[]; public createdDate?: DateFilter;
public createdDate: DateFilter; public genus?: string[];
public genus: string[]; public id?: number[];
public id: number[]; public lastModifiedBy?: number[];
public lastModifiedBy: number[]; public lastModifiedDate?: DateFilter;
public lastModifiedDate: DateFilter; public species?: string[];
public species: string[]; public subtaxa?: StringFilter;
public subtaxa: StringFilter; public version?: number[];
public version: number[];
} }
......
...@@ -11,7 +11,7 @@ import { navigateTo } from 'actions/navigation'; ...@@ -11,7 +11,7 @@ import { navigateTo } from 'actions/navigation';
// model // model
import ApiCall from 'model/ApiCall'; import ApiCall from 'model/ApiCall';
import MapLayer from 'model/genesys/MapTileLayer'; import MapLayer from 'model/genesys/MapTileLayer';
import Page from 'model/Page'; import Page, { IPageRequest } from 'model/Page';
import FaoInstitute from 'model/genesys/FaoInstitute'; import FaoInstitute from 'model/genesys/FaoInstitute';
import PGRFANetwork from 'model/network/PGRFANetwork'; import PGRFANetwork from 'model/network/PGRFANetwork';
import PGRFANetworkDetails from 'model/network/PGRFANetworkDetails'; import PGRFANetworkDetails from 'model/network/PGRFANetworkDetails';
...@@ -32,6 +32,7 @@ import ButtonBar from 'ui/common/buttons/ButtonBar'; ...@@ -32,6 +32,7 @@ import ButtonBar from 'ui/common/buttons/ButtonBar';
import { Button } from '@material-ui/core'; import { Button } from '@material-ui/core';
import confirmAlert from 'utilities/confirmAlert'; import confirmAlert from 'utilities/confirmAlert';
import Authorize from 'ui/common/authorized/Authorize'; import Authorize from 'ui/common/authorized/Authorize';
import AccessionFilter from 'model/accession/AccessionFilter';
interface IDisplayPageProps extends React.ClassAttributes<any> { interface IDisplayPageProps extends React.ClassAttributes<any> {
networkCall: ApiCall<PGRFANetworkDetails>; networkCall: ApiCall<PGRFANetworkDetails>;
...@@ -39,8 +40,8 @@ interface IDisplayPageProps extends React.ClassAttributes<any> { ...@@ -39,8 +40,8 @@ interface IDisplayPageProps extends React.ClassAttributes<any> {
shortName: string; shortName: string;
loadNetwork: (shortName: string, lang: string) => void; loadNetwork: (shortName: string, lang: string) => void;
loadMoreNetworkInstitutes: (shortName: string, page: number) => void; loadMoreNetworkInstitutes: (shortName: string, page: number) => void;
applyFilters: any; applyFilters: (filters: string | AccessionFilter, page?: IPageRequest) => any;
applyOverviewFilters: any; applyOverviewFilters: (filters: string | AccessionFilter) => any;
deleteNetwork: (network: PGRFANetwork) => any; deleteNetwork: (network: PGRFANetwork) => any;
navigateTo: any; navigateTo: any;
t: any; t: any;
...@@ -81,13 +82,13 @@ class DisplayPage extends React.Component<IDisplayPageProps> { ...@@ -81,13 +82,13 @@ class DisplayPage extends React.Component<IDisplayPageProps> {
private applyNetworkFilter = () => { private applyNetworkFilter = () => {
const { networkCall: { data: networkDetails }, applyFilters} = this.props; const { networkCall: { data: networkDetails }, applyFilters} = this.props;
const filter = {holder: {networks: [ networkDetails.network.slug ]}}; const filter = { institute: { networks: [networkDetails.network.slug] } };
applyFilters(filter); applyFilters(filter);
} }
private applyNetworkOverviewFilter = () => { private applyNetworkOverviewFilter = () => {
const { networkCall: { data: networkDetails }, applyOverviewFilters} = this.props; const { networkCall: { data: networkDetails }, applyOverviewFilters} = this.props;
const filter = {holder: {networks: [ networkDetails.network.slug ]}}; const filter = { institute: { networks: [networkDetails.network.slug] } };
applyOverviewFilters(filter); applyOverviewFilters(filter);
} }
......
...@@ -11,7 +11,7 @@ import {loadMoreSubsets, applyFilters, createNewVersion} from 'subsets/actions/d ...@@ -11,7 +11,7 @@ import {loadMoreSubsets, applyFilters, createNewVersion} from 'subsets/actions/d
import FilteredPage from 'model/FilteredPage'; import FilteredPage from 'model/FilteredPage';
import Subset from 'model/subset/Subset'; import Subset from 'model/subset/Subset';
import SubsetFilter from 'model/subset/SubsetFilter'; import SubsetFilter from 'model/subset/SubsetFilter';
import {SortDirection} from 'model/Page'; import {SortDirection, IPageRequest} from 'model/Page';
// UI // UI
import SubsetFilters from './c/SubsetFilters'; import SubsetFilters from './c/SubsetFilters';
...@@ -32,7 +32,7 @@ interface IDashboardPageProps extends React.ClassAttributes<any> { ...@@ -32,7 +32,7 @@ interface IDashboardPageProps extends React.ClassAttributes<any> {
login: any; login: any;
t: any; t: any;
filterCode: string; filterCode: string;
applyFilters: any; applyFilters: (filters: string | SubsetFilter, page?: IPageRequest) => any;
dataClassName: string; dataClassName: string;
} }
......
...@@ -3,8 +3,9 @@ import * as _ from 'lodash'; ...@@ -3,8 +3,9 @@ import * as _ from 'lodash';
// Models // Models
import FilteredPage from 'model/FilteredPage'; import FilteredPage from 'model/FilteredPage';
import { SortDirection } from 'model/Page'; import { SortDirection, IPageRequest } from 'model/Page';
import ApiCall from 'model/ApiCall'; import ApiCall from 'model/ApiCall';
import UserFilter from 'model/UserFilter';
interface IBrowsePageProps<T> { interface IBrowsePageProps<T> {
t?: any; t?: any;
...@@ -12,7 +13,7 @@ interface IBrowsePageProps<T> { ...@@ -12,7 +13,7 @@ interface IBrowsePageProps<T> {
apiCall: ApiCall<FilteredPage<T>>; apiCall: ApiCall<FilteredPage<T>>;
renderItem: (s: T, index: number) => any; renderItem: (s: T, index: number) => any;
filterCode: string; filterCode: string;
applyFilters: any; applyFilters: (filters: string | UserFilter, page?: IPageRequest) => any;
loadMoreData: (paged?: FilteredPage<any>) => any; loadMoreData: (paged?: FilteredPage<any>) => any;
updateRoute: any; updateRoute: any;
currentTab: any; currentTab: any;
......
...@@ -10,12 +10,14 @@ import Dialog from '@material-ui/core/Dialog'; ...@@ -10,12 +10,14 @@ import Dialog from '@material-ui/core/Dialog';
import DialogContent from '@material-ui/core/DialogContent'; import DialogContent from '@material-ui/core/DialogContent';
import DialogTitle from '@material-ui/core/DialogTitle'; import DialogTitle from '@material-ui/core/DialogTitle';
import RegistrationForm from 'user/ui/c/RegistrationForm'; import RegistrationForm from 'user/ui/c/RegistrationForm';
import UserFilter from 'model/UserFilter';
import { IPageRequest } from 'model/Page';
interface ICreateUserDialogProps extends React.ClassAttributes<any> { interface ICreateUserDialogProps extends React.ClassAttributes<any> {
registrationRequest: (u, p, fN, c) => Promise<any>; registrationRequest: (u, p, fN, c) => Promise<any>;
toggleUserModal: (open: boolean) => void; toggleUserModal: (open: boolean) => void;
loadUser: (uuid: string) => void; loadUser: (uuid: string) => void;
applyFilters: any; applyFilters: (filters: string | UserFilter, page?: IPageRequest) => any;
isOpen: boolean; isOpen: boolean;
captchaClientKey: string; captchaClientKey: string;
t: any; t: any;
...@@ -36,7 +38,7 @@ class CreateUserDialog extends React.Component<ICreateUserDialogProps, any> { ...@@ -36,7 +38,7 @@ class CreateUserDialog extends React.Component<ICreateUserDialogProps, any> {
const {registrationRequest, applyFilters} = this.props; const {registrationRequest, applyFilters} = this.props;
return registrationRequest(email, password, fullName, captcha.captcha) return registrationRequest(email, password, fullName, captcha.captcha)
.then(() => { .then(() => {
applyFilters(); applyFilters({});
this.hide(); this.hide();
}) })
.catch((err) => { .catch((err) => {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment