-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementa a busca utilizando o endpoint de querystring-search
- Loading branch information
Showing
10 changed files
with
283 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 26 additions & 4 deletions
30
frontend/packages/portalbrasil-intranet/src/components/Blocks/Calendario/View.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,34 @@ | ||
import React from 'react'; | ||
import { withBlockExtensions } from '@plone/volto/helpers'; | ||
import CalendarioView from './DefaultView'; | ||
import { parseDate } from '@internationalized/date'; | ||
import withQuerystringResults from './withQuerystringResults'; | ||
|
||
const CalendarioBlockView = (props) => { | ||
const { data, isEditMode, className } = props; | ||
const groupByDate = (items) => { | ||
return items.reduce((map, obj) => { | ||
const key = obj.start ? parseDate(obj.start.slice(0, 10)).toString() : null; | ||
if (key) { | ||
if (map[key] === undefined) { | ||
map[key] = []; | ||
} | ||
map[key].push(obj); | ||
} | ||
return map; | ||
}, {}); | ||
}; | ||
|
||
const CalendarioBlockView = withQuerystringResults((props) => { | ||
const { data, isEditMode, path, pathname, className, listingItems } = props; | ||
const items = listingItems ? groupByDate(listingItems) : {}; | ||
return ( | ||
<CalendarioView {...data} isEditMode={isEditMode} className={className} /> | ||
<CalendarioView | ||
data={data} | ||
path={path ?? pathname} | ||
isEditMode={isEditMode} | ||
className={className} | ||
items={items} | ||
/> | ||
); | ||
}; | ||
}); | ||
|
||
export default withBlockExtensions(CalendarioBlockView); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
...ackages/portalbrasil-intranet/src/components/Blocks/Calendario/withQuerystringResults.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import React, { useRef } from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import hoistNonReactStatics from 'hoist-non-react-statics'; | ||
import useDeepCompareEffect from 'use-deep-compare-effect'; | ||
|
||
import { getQueryStringResults } from '@plone/volto/actions'; | ||
import { usePagination, getBaseUrl } from '@plone/volto/helpers'; | ||
|
||
import config from '@plone/volto/registry'; | ||
|
||
function getDisplayName(WrappedComponent) { | ||
return WrappedComponent.displayName || WrappedComponent.name || 'Component'; | ||
} | ||
|
||
export default function withQuerystringResults(WrappedComponent) { | ||
function WithQuerystringResults(props) { | ||
const { | ||
data = {}, | ||
id = data.block, | ||
properties: content, | ||
path, | ||
variation, | ||
} = props; | ||
const { settings } = config; | ||
const querystring = data.querystring || {}; | ||
const subrequestID = content?.UID ? `${content?.UID}-${id}` : id; | ||
const { b_size = settings.defaultPageSize } = querystring; // batchsize | ||
|
||
// save the path so it won't trigger dispatch on eager router location change | ||
const [initialPath] = React.useState(getBaseUrl(path)); | ||
|
||
const copyFields = ['limit', 'query', 'sort_on', 'sort_order', 'depth']; | ||
const { currentPage, setCurrentPage } = usePagination(id, 1); | ||
const adaptedQuery = Object.assign( | ||
variation?.fullobjects ? { fullobjects: 1 } : { metadata_fields: '_all' }, | ||
{ | ||
b_size: b_size, | ||
}, | ||
...copyFields.map((name) => | ||
Object.keys(querystring).includes(name) | ||
? { [name]: querystring[name] } | ||
: {}, | ||
), | ||
); | ||
const adaptedQueryRef = useRef(adaptedQuery); | ||
const currentPageRef = useRef(currentPage); | ||
|
||
const querystringResults = useSelector( | ||
(state) => state.querystringsearch.subrequests, | ||
); | ||
const dispatch = useDispatch(); | ||
|
||
const hasQuery = querystring?.query?.length > 0; | ||
const hasLoaded = hasQuery | ||
? querystringResults?.[subrequestID]?.loaded | ||
: true; | ||
|
||
const listingItems = | ||
hasQuery && (querystringResults?.[subrequestID]?.items || []); | ||
|
||
const showAsQueryListing = | ||
hasQuery && querystringResults?.[subrequestID]?.total > b_size; | ||
|
||
const totalPages = showAsQueryListing | ||
? Math.ceil(querystringResults[subrequestID].total / b_size) | ||
: 0; | ||
|
||
const prevBatch = showAsQueryListing | ||
? querystringResults[subrequestID].batching?.prev | ||
: null; | ||
const nextBatch = showAsQueryListing | ||
? querystringResults[subrequestID].batching?.next | ||
: null; | ||
|
||
useDeepCompareEffect(() => { | ||
if (hasQuery) { | ||
dispatch( | ||
getQueryStringResults( | ||
initialPath, | ||
adaptedQuery, | ||
subrequestID, | ||
currentPage, | ||
), | ||
); | ||
} | ||
adaptedQueryRef.current = adaptedQuery; | ||
currentPageRef.current = currentPage; | ||
}, [ | ||
subrequestID, | ||
adaptedQuery, | ||
hasQuery, | ||
initialPath, | ||
dispatch, | ||
currentPage, | ||
]); | ||
|
||
return ( | ||
<WrappedComponent | ||
{...props} | ||
onPaginationChange={(e, { activePage }) => setCurrentPage(activePage)} | ||
total={querystringResults?.[subrequestID]?.total} | ||
batch_size={b_size} | ||
currentPage={currentPage} | ||
totalPages={totalPages} | ||
prevBatch={prevBatch} | ||
nextBatch={nextBatch} | ||
listingItems={listingItems} | ||
hasLoaded={hasLoaded} | ||
/> | ||
); | ||
} | ||
|
||
WithQuerystringResults.displayName = `WithQuerystringResults(${getDisplayName( | ||
WrappedComponent, | ||
)})`; | ||
|
||
return hoistNonReactStatics(WithQuerystringResults, WrappedComponent); | ||
} |
34 changes: 34 additions & 0 deletions
34
...end/packages/portalbrasil-intranet/src/components/CalendarioEventos/CalendarioEventos.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { | ||
Calendar as RACCalendar, | ||
CalendarCell, | ||
CalendarGrid, | ||
Heading, | ||
} from 'react-aria-components'; | ||
|
||
const CalendarioEventos = (props) => { | ||
const { items } = props; | ||
const hasEvents = Object.keys(items); | ||
return ( | ||
<div className={'calendarioEventos'}> | ||
<RACCalendar {...props}> | ||
<header> | ||
<Heading /> | ||
</header> | ||
<CalendarGrid> | ||
{(date) => { | ||
const className = | ||
hasEvents.indexOf(date.toString()) > -1 ? 'hasEvents' : ''; | ||
return ( | ||
<CalendarCell | ||
date={date} | ||
className={`${className} react-aria-CalendarCell`} | ||
/> | ||
); | ||
}} | ||
</CalendarGrid> | ||
</RACCalendar> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CalendarioEventos; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
frontend/packages/portalbrasil-intranet/src/theme/blocks/_calendario.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,29 @@ | ||
// Estilos do bloco de calendário | ||
.block.calendarioBlock { | ||
padding: $spacing-small; | ||
.wrapper { | ||
display: flex; | ||
width: 100%; | ||
flex-direction: row; | ||
flex-wrap: wrap; | ||
.column { | ||
display: flex; | ||
max-height: 310px; | ||
flex: 1; | ||
flex-direction: column; | ||
} | ||
.calendario { | ||
h2:last-child { | ||
margin: unset; | ||
} | ||
} | ||
.eventos { | ||
display: flex; | ||
flex: 3; | ||
overflow-y: auto; | ||
.eventos-lista { | ||
display: block; | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
frontend/packages/portalbrasil-intranet/src/theme/components/_calendarioeventos.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.calendarioEventos { | ||
.react-aria-Calendar { | ||
.react-aria-CalendarGridBody { | ||
.react-aria-CalendarCell { | ||
&.hasEvents { | ||
text-decoration: underline; | ||
} | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.