Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust code to implement constructed url feature. #1033

Open
wants to merge 1 commit into
base: 1.0.1-ccdihub.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/facet-filter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"access": "public"
},
"dependencies": {
"@bento-core/util": "1.0.1-ccdihub.1",
"lodash": "^4.17.20"
},
"peerDependencies": {
Expand All @@ -24,7 +25,8 @@
"clsx": "^1.2.1",
"react": "^17.0.2",
"react-dom": "^17.0.0",
"react-redux": "^7.2.1"
"react-redux": "^7.2.1",
"react-router-dom": "^5.1.2"
},
"author": "CTOS Bento Team",
"license": "ISC",
Expand Down
1 change: 1 addition & 0 deletions packages/facet-filter/src/FacetFilterController.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const FacetFilterController = (props) => {
data,
facetsConfig,
facetSectionConfig,
queryParams,
} = props;

const filterState = {};
Expand Down
2 changes: 2 additions & 0 deletions packages/facet-filter/src/FacetFilterView.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const BentoFacetFilter = ({
sideBarSections,
CustomFacetSection,
CustomFacetView,
queryParams,
}) => {
return (
<>
Expand All @@ -32,6 +33,7 @@ const BentoFacetFilter = ({
{section.items.map((facet) => (
<FacetView
facet={facet}
queryParams={queryParams}
CustomView={CustomFacetView}
>
<List className={`List_${facet.label}`}>
Expand Down
3 changes: 3 additions & 0 deletions packages/facet-filter/src/components/facet/FacetView.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const FacetView = ({
onClearFacetSection,
onClearSliderSection,
CustomView,
queryParams,
}) => {
const [expand, setExpand] = useState(false);
const onExpandFacet = () => setExpand(!expand);
Expand Down Expand Up @@ -152,6 +153,7 @@ const FacetView = ({
}
<FilterItems
facet={facet}
queryParams={queryParams}
sortBy={sortBy}
/>
</Accordion>
Expand All @@ -161,6 +163,7 @@ const FacetView = ({
<List id="filter_Items">
<FilterItems
facet={displayFacet}
queryParams={queryParams}
/>
</List>
</>
Expand Down
4 changes: 3 additions & 1 deletion packages/facet-filter/src/components/inputs/FilterItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { sortBySection } from '../../utils/Sort';

const FilterItems = ({
facet,
queryParams,
sortBy,
}) => {
const { type, datafield, section } = facet;
Expand All @@ -21,10 +22,11 @@ const FilterItems = ({
checkboxItem={{ ...item, index, section }}
datafield={datafield}
facet={facet}
queryParams={queryParams}
/>
));
case InputTypes.SLIDER:
return (<ReduxSlider facet={facet} />);
return (<ReduxSlider facet={facet} queryParams={queryParams} />);
default:
return (<></>);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
/* eslint-disable object-shorthand */
/* eslint-disable react/jsx-one-expression-per-line */
import React from 'react';
import {
useLocation,
useNavigate,
} from 'react-router-dom';
import { generateQueryStr } from '@bento-core/util';
import { withStyles } from '@material-ui/core/styles';
import {
Checkbox,
Expand Down Expand Up @@ -33,6 +38,7 @@ const CheckBoxView = ({
datafield,
onToggle,
facet,
queryParams,
}) => {
const {
name,
Expand All @@ -43,6 +49,10 @@ const CheckBoxView = ({
tooltip,
label,
} = checkboxItem;

const query = new URLSearchParams(useLocation().search);
const navigate = useNavigate();

const indexType = index % 2 === 0 ? 'Even' : 'Odd';
const checkedSection = `${section}`.toLowerCase().replace(' ', '_');

Expand All @@ -54,6 +64,28 @@ const CheckBoxView = ({
datafield: datafield,
isChecked: !isChecked,
};
const checkedValues = query.get(datafield);
const paramValue = {};
if (toggleCheckBoxItem.isChecked) {
if (checkedValues) {
const newValues = checkedValues.split('|');
newValues.push(name);
paramValue[datafield] = newValues.join('|');
} else {
paramValue[datafield] = name;
}
} else if (checkedValues) {
const newValues = checkedValues.split('|');
const idx = newValues.indexOf(name);
if (idx > -1) {
newValues.splice(idx, 1);
}
paramValue[datafield] = newValues.length > 0 ? newValues.join('|') : '';
} else {
paramValue[datafield] = '';
}
const queryStr = generateQueryStr(query, queryParams, paramValue);
navigate(`/explore${queryStr}`);
onToggle(toggleCheckBoxItem);
};

Expand Down
13 changes: 13 additions & 0 deletions packages/facet-filter/src/components/inputs/slider/SliderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
/* eslint-disable react/jsx-indent */
/* eslint-disable object-curly-newline */
import React, { useEffect, useState } from 'react';
import {
useLocation,
useNavigate,
} from 'react-router-dom';
import { generateQueryStr } from '@bento-core/util';
import { withStyles, Slider, Typography, Box } from '@material-ui/core';
// import styles from './SliderStyle';
import { silderTypes } from '../Types';
Expand All @@ -13,11 +18,15 @@ const SliderView = ({
facet,
onSliderToggle,
filterState,
queryParams,
}) => {
const { minLowerBound, maxUpperBound, quantifier, datafield, facetValues } = facet;
const lowerBoundValue = facetValues[0];
const upperBoundValue = facetValues[1];

const query = new URLSearchParams(useLocation().search);
const navigate = useNavigate();

// Determines whether the lower bound and upper bound values are valid
const isValid = () => {
const checks = [
Expand All @@ -30,6 +39,10 @@ const SliderView = ({
};
const handleChangeCommittedSlider = (value) => {
if (!value.includes('')) {
const paramValue = {};
paramValue[datafield] = value;
const queryStr = generateQueryStr(query, queryParams, paramValue);
navigate(`/explore${queryStr}`);
onSliderToggle({ sliderValue: value, ...facet });
}
};
Expand Down
1 change: 1 addition & 0 deletions packages/facet-filter/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export {
clearFacetSection,
clearSliderSection,
clearAllAndSelectFacet,
updateFilterState,
} from './store/actions/Actions';
export {
generateFacetSectionView,
Expand Down
1 change: 1 addition & 0 deletions packages/facet-filter/src/store/actions/ActionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const sideBarActionTypes = {
CLEAR_FACET_SECTION: 'CLEAR_FACET_SECTION',
CLEAR_SLIDER_SECTION: 'CLEAR_SLIDER_SECTION',
CLEAR_AND_SELECT_FACET_VALUE: 'CLEAR_AND_SELECT_FACET_VALUE',
UPDATE_FILTER_STATE: 'UPDATE_FILTER_STATE',
};

export const Actions = '';
5 changes: 5 additions & 0 deletions packages/facet-filter/src/store/actions/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ export const clearAllAndSelectFacet = (facetValue) => ({
type: sideBarActionTypes.CLEAR_AND_SELECT_FACET_VALUE,
payload: facetValue,
});

export const updateFilterState = (filterState) => ({
type: sideBarActionTypes.UPDATE_FILTER_STATE,
payload: filterState,
});
4 changes: 4 additions & 0 deletions packages/facet-filter/src/store/reducers/SideBarReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ export function sideBarReducerGenerator() {
return {
filterState: payload,
};
case sideBarActionTypes.UPDATE_FILTER_STATE:
return {
filterState: payload,
};
default:
return state;
}
Expand Down
4 changes: 3 additions & 1 deletion packages/local-find/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
"clsx": "^1.2.1",
"react": "^17.0.2",
"react-dom": "^17.0.0",
"react-redux": "^7.2.1"
"react-redux": "^7.2.1",
"react-router-dom": "^5.1.2"
},
"dependencies": {
"@bento-core/tool-tip": "^1.0.0",
"@bento-core/util": "1.0.1-ccdihub.1",
"lodash": "^4.17.20"
},
"author": "CTOS Bento Team",
Expand Down
12 changes: 12 additions & 0 deletions packages/local-find/src/SearchBox/SearchBoxGenerator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React, { useEffect, useRef, useState } from 'react';
import { connect } from 'react-redux';
import {
useLocation,
useNavigate,
} from 'react-router-dom';
import { withStyles } from '@material-ui/core';
import Autocomplete, { createFilterOptions } from '@material-ui/lab/Autocomplete';
import { isEqual } from 'lodash';
Expand All @@ -25,6 +29,10 @@ export const SearchBoxGenerator = (uiConfig = DEFAULT_CONFIG) => {
? functions.onChange
: DEFAULT_CONFIG.functions.onChange;

const updateBrowserUrl = functions && typeof functions.updateBrowserUrl === 'function'
? functions.updateBrowserUrl
: DEFAULT_CONFIG.functions.updateBrowserUrl;

const getSuggestions = functions && typeof functions.getSuggestions === 'function'
? functions.getSuggestions
: DEFAULT_CONFIG.functions.getSuggestions;
Expand Down Expand Up @@ -57,6 +65,9 @@ export const SearchBoxGenerator = (uiConfig = DEFAULT_CONFIG) => {
classes, autocomplete, applySearch,
} = props;

const query = new URLSearchParams(useLocation().search);
const navigate = useNavigate();

const [open, setOpen] = useState(false);
const [value, setValue] = useState(autocomplete || []);
const [options, setOptions] = useState([]);
Expand Down Expand Up @@ -100,6 +111,7 @@ export const SearchBoxGenerator = (uiConfig = DEFAULT_CONFIG) => {
// Call the onChange function if the selection has changed
if (!isEqual(newUniqueValue, value)) {
onChange(newUniqueValue, reason, deleted);
updateBrowserUrl(query, navigate, newUniqueValue);
applySearch(newUniqueValue);
setValue(newUniqueValue);
}
Expand Down
8 changes: 8 additions & 0 deletions packages/local-find/src/SearchBox/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ export const DEFAULT_CONFIG_SEARCHBAR = {
*/
onChange: (newValue = [], reason, deleted) => {},

/**
* A function that is called when the autocomplete selection changes
*
* @param void
* @return void
*/
updateBrowserUrl: () => {},

/**
* Perform autocomplete search on the API
*
Expand Down
24 changes: 22 additions & 2 deletions packages/local-find/src/SearchView.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import React, { useState } from 'react';
import { connect } from 'react-redux';
import {
useLocation,
useNavigate,
} from 'react-router-dom';
import { generateQueryStr } from '@bento-core/util';
import { Button } from '@material-ui/core';
import SearchList from './SearchBox/components/SearchList';
import { resetUploadData } from './store/actions/Actions';
Expand All @@ -21,9 +26,12 @@ import { resetUploadData } from './store/actions/Actions';
const SearchView = (props) => {
const {
classes, hidden, state, resetUpload,
UploadModal, SearchBox, config,
UploadModal, SearchBox, config, queryParams,
} = props;

const query = new URLSearchParams(useLocation().search);
const navigate = useNavigate();

const [showCasesModal, setShowCasesModal] = useState(false);
const matchedFiles = state && state.upload ? state.upload : [];

Expand All @@ -36,6 +44,18 @@ const SearchView = (props) => {
? config.searchLabel
: null;

/**
* Handles the deletion of upload set
*/
const onDelete = () => {
const paramValue = {
participant_upload: '',
};
const queryStr = generateQueryStr(query, queryParams, paramValue);
navigate(`/explore${queryStr}`);
resetUpload();
};

return (
<div
className={classes.searchContainer}
Expand All @@ -56,7 +76,7 @@ const SearchView = (props) => {
classes={{ divider: classes.customDivider, listPadding: classes.customListPadding }}
items={['INPUT SET']}
id="localFindCaseUploadSet"
onDelete={resetUpload}
onDelete={onDelete}
/>
) : null}
<SearchBox classes={classes} />
Expand Down
12 changes: 12 additions & 0 deletions packages/local-find/src/UploadModal/UploadModalGenerator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React, { useState } from 'react';
import { connect } from 'react-redux';
import {
useLocation,
useNavigate,
} from 'react-router-dom';
import {
Modal, Button, Typography,
TextareaAutosize, IconButton, withStyles,
Expand Down Expand Up @@ -52,6 +56,10 @@ export const UploadModalGenerator = (uiConfig = DEFAULT_CONFIG) => {
? functions.modalClosed
: DEFAULT_CONFIG.functions.modalClosed;

const updateBrowserUrl = functions && typeof functions.updateBrowserUrl === 'function'
? functions.updateBrowserUrl
: DEFAULT_CONFIG.functions.updateBrowserUrl;

const searchMatches = functions && typeof functions.searchMatches === 'function'
? functions.searchMatches
: DEFAULT_CONFIG.functions.searchMatches;
Expand Down Expand Up @@ -98,6 +106,9 @@ export const UploadModalGenerator = (uiConfig = DEFAULT_CONFIG) => {
onApplySearch, updateMetadata,
} = props;

const query = new URLSearchParams(useLocation().search);
const navigate = useNavigate();

const {
FileUploader: uploaderClasses,
// SummaryTable: summaryClasses,
Expand Down Expand Up @@ -127,6 +138,7 @@ export const UploadModalGenerator = (uiConfig = DEFAULT_CONFIG) => {
};

const applySearchWrapper = () => {
updateBrowserUrl(query, navigate, filename, fileContent, matchIds, unmatchedIds);
onApplySearch(matchIds);
updateMetadata({
filename,
Expand Down
8 changes: 8 additions & 0 deletions packages/local-find/src/UploadModal/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ export const DEFAULT_CONFIG_UPLOADMODAL = {

// Helper functions used by the component
functions: {
/**
* Callback function called when the submit button is clicked.
*
* @param void
* @return void
*/
updateBrowserUrl: () => {},

/**
* Callback function called when the modal is closed.
*
Expand Down