Skip to content

Commit

Permalink
Merge pull request Marklogic-retired#213 in PROD/explorer-ui from ~SV…
Browse files Browse the repository at this point in the history
…ISHAKA/explorer-ui:DHFPROD-4278 to develop

* commit 'b07797dbf976a2967d3fbcf3f18ff68ad7386930':
  Date picker fix
  • Loading branch information
Bruce An authored and Bruce An committed Feb 3, 2020
2 parents b4ecaa4 + b07797d commit 93deac4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/components/selected-facets/selected-facets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const SelectedFacets: React.FC<Props> = (props) => {
}
{ props.selectedFacets.map((item, index) => {
if (item.constraint === 'createdOnRange') {
let dateValues:any = [];
dateValues.push(item.facet.lowerBound,item.facet.upperBound);
return (
<MlButton
size="small"
Expand All @@ -44,7 +46,7 @@ const SelectedFacets: React.FC<Props> = (props) => {
data-cy='clear-date-facet'
>
<Icon type='close'/>
{item.facet.join(' ~ ')}
{ dateValues.join(' ~ ') }
</MlButton>
)
} else if (item.rangeValues) {
Expand Down
16 changes: 11 additions & 5 deletions src/components/sidebar/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const Sidebar: React.FC<Props> = (props) => {
for (let constraint in searchOptions.searchFacets) {
// TODO fix the date picker
if (constraint === 'createdOnRange') {
selectedFacets.push({ constraint, facet: searchOptions.searchFacets[constraint]['rangeValues'] })
selectedFacets.push({ constraint, facet: searchOptions.searchFacets[constraint]['rangeValues']});
} else {
let datatype = searchOptions.searchFacets[constraint].dataType;
if (datatype === 'xs:string') {
Expand Down Expand Up @@ -89,20 +89,25 @@ const Sidebar: React.FC<Props> = (props) => {
}, [props.selectedEntities, props.facets]);

const onDateChange = (dateVal, dateArray) => {
let updateFacets = { ...allSelectedFacets };
let updateFacets = {...allSelectedFacets};
if (dateVal.length > 1) {
toggleApply(true);
updateFacets = { ...updateFacets, createdOnRange: dateArray }
updateFacets = {
...updateFacets, createdOnRange:
{
dataType: 'date',
rangeValues: {lowerBound: dateArray[0], upperBound: dateArray[1]}
}
}
setDatePickerValue([moment(dateArray[0]), moment(dateArray[1])]);
} else {
toggleApply(false);
delete updateFacets.createdOnRange
delete updateFacets.createdOnRange;
setDatePickerValue([null, null]);
}
setAllSelectedFacets(updateFacets);
}


const updateSelectedFacets = (constraint: string, vals: string[], datatype: string) => {
let facets = { ...allSelectedFacets };
let type = '';
Expand Down Expand Up @@ -151,6 +156,7 @@ const Sidebar: React.FC<Props> = (props) => {
let newAllSelectedfacets = { ...allSelectedFacets };
let valueKey = 'stringValues';
// TODO add support for non string facets

if (dataType === 'xs:string') {
valueKey = 'stringValues';
}
Expand Down
9 changes: 4 additions & 5 deletions src/util/search-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ interface ISearchContextInterface {
setLatestJobFacet: (vals: string, option: string) => void;
clearFacet: (constraint: string, val: string) => void;
clearAllFacets: () => void;
setDateFacet: (dates: string[]) => void;
clearDateFacet: () => void;
clearRangeFacet: (range: string) => void;
resetSearchOptions: () => void;
Expand All @@ -55,7 +54,6 @@ export const SearchContext = React.createContext<ISearchContextInterface>({
setLatestJobFacet: () => { },
clearFacet: () => { },
clearAllFacets: () => { },
setDateFacet: () => { },
clearDateFacet: () => { },
clearRangeFacet: () => { },
resetSearchOptions: () => { },
Expand Down Expand Up @@ -195,8 +193,9 @@ const SearchProvider: React.FC<{ children: any }> = ({ children }) => {
});
}

const setDateFacet = (dates: string[]) => {
setSearchOptions({
/*
const setDateFacet = (dates) => {
setSearchOptions({
...searchOptions,
start: 1,
pageNumber: 1,
Expand All @@ -207,6 +206,7 @@ const SearchProvider: React.FC<{ children: any }> = ({ children }) => {
}
});
}
*/

const clearDateFacet = () => {
let facets = searchOptions.searchFacets;
Expand Down Expand Up @@ -273,7 +273,6 @@ const SearchProvider: React.FC<{ children: any }> = ({ children }) => {
clearFacet,
clearAllFacets,
setLatestJobFacet,
setDateFacet,
clearDateFacet,
clearRangeFacet,
resetSearchOptions,
Expand Down

0 comments on commit 93deac4

Please sign in to comment.