Skip to content

Commit

Permalink
feat: add session filter to captures page'
Browse files Browse the repository at this point in the history
  • Loading branch information
gwynndp committed Jan 10, 2024
1 parent 6cd4e3c commit 312f3da
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 29 deletions.
12 changes: 0 additions & 12 deletions src/api/treeTrackerApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,18 +526,6 @@ export default {
getSessions() {
try {
const query = `${FIELD_DATA_API}/session`;
// Will want to limit results to the orgs/user's sessions only...
// Which is best field to query by?
// orgList &&...
// device_configuration_id
// originating_wallet_registration_id
// target_wallet
// organization
// organization_id
// device_identifier
// grower_account_id

log.debug('GET SESSIONS -----', query);

return fetch(query, {
method: 'GET',
Expand Down
13 changes: 13 additions & 0 deletions src/components/CaptureFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import TextField from '@material-ui/core/TextField';
import MenuItem from '@material-ui/core/MenuItem';
import Autocomplete from '@material-ui/lab/Autocomplete';
import SelectOrg from './common/SelectOrg';
import SelectSession from './common/SelectSession';
import FilterModel, {
ALL_SPECIES,
ALL_SESSIONS,
SPECIES_ANY_SET,
SPECIES_NOT_SET,
ALL_ORGANIZATIONS,
Expand Down Expand Up @@ -94,6 +96,9 @@ function Filter(props) {
const [tag, setTag] = useState(null);
const [tagSearchString, setTagSearchString] = useState('');
const [organizationId, setOrganizationId] = useState(ALL_ORGANIZATIONS);
const [sessionId, setSessionId] = useState(
filter?.session_id || ALL_SESSIONS
);
const [tokenId, setTokenId] = useState(filter?.tokenId || filterOptionAll);

const handleStartDateChange = (date) => {
Expand Down Expand Up @@ -123,6 +128,7 @@ function Filter(props) {
species_id: speciesId,
tag_id: tag ? tag.id : undefined,
organization_id: organizationId,
session_id: sessionId,
tokenId: tokenId.trim(),
};
const filter = new FilterModel(test);
Expand All @@ -144,6 +150,7 @@ function Filter(props) {
setTag(null);
setTagSearchString('');
setOrganizationId(ALL_ORGANIZATIONS);
setSessionId(ALL_SESSIONS);
setTokenId(filterOptionAll);
const filter = new FilterModel();
props.onSubmit && props.onSubmit(filter);
Expand Down Expand Up @@ -338,6 +345,12 @@ function Filter(props) {
setOrganizationId(org.stakeholder_uuid);
}}
/>
<SelectSession
sessionId={sessionId}
handleSelection={(session) => {
setSessionId(session.id);
}}
/>
</Grid>
<Grid className={classes.inputContainer}>
<Button
Expand Down
1 change: 0 additions & 1 deletion src/components/FilterTop.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import FilterModel, {
TAG_NOT_SET,
ANY_TAG_SET,
ALL_SESSIONS,
// SESSION_NOT_SET,
} from '../models/Filter';
import DateFnsUtils from '@date-io/date-fns';
import {
Expand Down
12 changes: 7 additions & 5 deletions src/components/common/SelectSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ function SelectSession({ sessionId, defaultSessions, handleSelection }) {
// format the session data for the dropdown
const sesh = sessionList.map((s) => ({
id: s.id,
name: `${getDateTimeStringLocale(s.created_at)} : ${s.wallet} : ${
s.organization
}`,
org: s.organization,
name: `${s.wallet} ${s.organization ? ` / ${s.organization} ` : ''}`,
date: getDateTimeStringLocale(s.created_at),
value: s.id,
}));
setSessions((s) => [...s, ...sesh]);

setSessions(() => [...defaultList, ...sesh]);
}, [sessionList]);

const handleChange = (e) => {
Expand All @@ -51,7 +52,8 @@ function SelectSession({ sessionId, defaultSessions, handleSelection }) {
key={session.id}
value={session.id}
>
{session.name}
{session.date} -- {session.name}{' '}
{session.organization ? ` / ${session.organization}` : ''}
</MenuItem>
))}
</TextField>
Expand Down
11 changes: 0 additions & 11 deletions src/context/AppContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ export const AppProvider = (props) => {
const [orgList, setOrgList] = useState([]);
const [sessionList, setSessionList] = useState([]);
const [orgId, setOrgId] = useState(undefined);
const [sessionList, setSessionList] = useState([]);

// TODO: The below `selectedFilters` state would be better placed under a
// separate FilterContext in the future iterations when the need to share
Expand Down Expand Up @@ -318,16 +317,6 @@ export const AppProvider = (props) => {
}

async function loadSessions() {
// Will want to limit results to the orgs/user's sessions only...
// Which is best field to query by?
// orgList &&...
// device_configuration_id
// originating_wallet_registration_id
// target_wallet
// organization
// organization_id
// device_identifier
// grower_account_id
const { sessions } = await api.getSessions();
setSessionList(sessions);
}
Expand Down

0 comments on commit 312f3da

Please sign in to comment.