Skip to content

Commit

Permalink
feat: tokenized filter option (#112)
Browse files Browse the repository at this point in the history
* feat: add tokenized filter to verify page

* feat: add tokenized filter to captures page

* chore: use common tokenizationStates

* chore: simplify tokenization dropdown logic
  • Loading branch information
VLuisa authored Jun 12, 2021
1 parent 707e428 commit 17742b2
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/common/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ export const verificationStates = {
AWAITING: 'Awaiting Verification',
REJECTED: 'Rejected',
};
export const tokenizationStates = {
TOKENIZED: 'Tokenized',
NOT_TOKENIZED: 'Not Tokenized',
};
23 changes: 22 additions & 1 deletion src/components/Filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
convertDateToDefaultSqlDate,
} from '../common/locale';

import { verificationStates } from '../common/variables';
import { verificationStates, tokenizationStates } from '../common/variables';

export const FILTER_WIDTH = 330;

Expand Down Expand Up @@ -72,6 +72,7 @@ function Filter(props) {
filter.dateStart || dateStartDefault,
);
const [dateEnd, setDateEnd] = useState(filter.dateEnd || dateEndDefault);
const [tokenId, setTokenId] = useState(filterOptionAll);

const handleDateStartChange = (date) => {
setDateStart(date);
Expand All @@ -96,6 +97,7 @@ function Filter(props) {
setDateEnd(dateEndDefault);
setApproved();
setActive();
setTokenId(filterOptionAll);
props.onSubmit && props.onSubmit(filter);
}

Expand All @@ -110,6 +112,7 @@ function Filter(props) {
filter.dateEnd = dateEnd ? formatDate(dateEnd) : undefined;
filter.approved = approved;
filter.active = active;
filter.tokenId = tokenId;
props.onSubmit && props.onSubmit(filter);
}

Expand Down Expand Up @@ -251,6 +254,24 @@ function Filter(props) {
</MenuItem>
))}
</TextField>
<GSInputLabel text="Token Status" />
<TextField
select
value={tokenId}
onChange={(e) => {
setTokenId(e.target.value);
}}
>
{[
filterOptionAll,
tokenizationStates.NOT_TOKENIZED,
tokenizationStates.TOKENIZED,
].map((name) => (
<MenuItem key={name} value={name}>
{name}
</MenuItem>
))}
</TextField>
<GSInputLabel text="Time created" />
<MuiPickersUtilsProvider
utils={DateFnsUtils}
Expand Down
23 changes: 22 additions & 1 deletion src/components/FilterTop.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
convertDateToDefaultSqlDate,
} from '../common/locale';
import { getOrganization } from '../api/apiUtils';
import { verificationStates } from '../common/variables';
import { verificationStates, tokenizationStates } from '../common/variables';

export const FILTER_WIDTH = 330;

Expand Down Expand Up @@ -92,6 +92,7 @@ function Filter(props) {
filter.organizationId || ALL_ORGANIZATIONS,
);
const [userHasOrg, setUserHasOrg] = useState(false);
const [tokenId, setTokenId] = useState(filterOptionAll);

useEffect(() => {
props.tagsDispatch.getTags(tagSearchString);
Expand Down Expand Up @@ -132,6 +133,7 @@ function Filter(props) {
filter.speciesId = speciesId;
filter.tagId = tag ? tag.id : 0;
filter.organizationId = organizationId;
filter.tokenId = tokenId;
props.onSubmit && props.onSubmit(filter);
}

Expand All @@ -147,6 +149,7 @@ function Filter(props) {
setOrganizationId(ALL_ORGANIZATIONS);
setTag(null);
setTagSearchString('');
setTokenId(filterOptionAll);

const filter = new FilterModel();
filter.approved = approved; // keeps last value set
Expand Down Expand Up @@ -198,6 +201,24 @@ function Filter(props) {
</MenuItem>
))}
</TextField>
<TextField
select
label="Token Status"
value={tokenId}
onChange={(e) => {
setTokenId(e.target.value);
}}
>
{[
filterOptionAll,
tokenizationStates.NOT_TOKENIZED,
tokenizationStates.TOKENIZED,
].map((name) => (
<MenuItem key={name} value={name}>
{name}
</MenuItem>
))}
</TextField>
<MuiPickersUtilsProvider
utils={DateFnsUtils}
locale={getDatePickerLocale()}
Expand Down
8 changes: 8 additions & 0 deletions src/models/Filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const SPECIES_NOT_SET = 'SPECIES_NOT_SET';
export const ALL_ORGANIZATIONS = 'ALL_ORGANIZATIONS';
export const ORGANIZATION_NOT_SET = 'ORGANIZATION_NOT_SET';
export const TAG_NOT_SET = 'TAG_NOT_SET';
import { tokenizationStates } from '../common/variables';

export default class Filter {
captureId;
Expand All @@ -21,6 +22,7 @@ export default class Filter {
speciesId;
tagId;
organizationId;
tokenId;

constructor(options) {
Object.assign(this, options);
Expand Down Expand Up @@ -96,6 +98,12 @@ export default class Filter {
where.organizationId = this.organizationId;
}

if (this.tokenId === tokenizationStates.TOKENIZED) {
where.tokenId = { neq: null };
} else if (this.tokenId === tokenizationStates.NOT_TOKENIZED) {
where.tokenId = { eq: null };
}

return where;
//}}}
}
Expand Down

0 comments on commit 17742b2

Please sign in to comment.