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