Skip to content

Commit

Permalink
decrease the amount of data loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
tsubik committed Nov 13, 2024
1 parent 2990dcc commit e6282dd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 29 deletions.
2 changes: 1 addition & 1 deletion modules/documents-database.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export function getDocumentsDatabase(options = { reload: false }) {
'page[size]': pageSize,
include: includes.join(','),
'fields[fmus]': 'name,forest-type',
'fields[operator]': 'name',
'fields[operators]': 'name',
...Object.keys(filters).reduce((acc, key) => {
if (isEmpty(filters[key])) return acc;
return {
Expand Down
22 changes: 9 additions & 13 deletions modules/observations.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,7 @@ const initialState = {
},
cluster: {},
filters: {
data: {
observation_type: [],
country_id: [],
fmu_id: [],
years: [],
observer_id: [],
category_id: [],
subcategory_id: [],
severity_level: [],
validation_status: [],
hidden: []
},
data: {},
options: {},
loading: false,
error: false
Expand Down Expand Up @@ -132,7 +121,14 @@ export function getObservations() {
'page[size]': OBS_MAX_SIZE,
include: includes.join(','),
'fields[fmus]': 'name',
'fields[operator]': 'name',
'fields[operators]': 'name,operator-type',
'fields[severities]': 'details,level',
'fields[subcategories]': 'name,category',
'fields[categories]': 'name',
'fields[countries]': 'iso,name',
'fields[observers]': 'name,observer-type',
'fields[observation-reports]': 'attachment,title,publication-date',
'fields[observation-documents]': 'attachment,name',
...Object.keys(filters).reduce((acc, key) => {
if (isEmpty(filters[key])) return acc;
return {
Expand Down
16 changes: 2 additions & 14 deletions pages/observations.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ class ObservationsPage extends React.Component {

this.state = {
tab: 'observations-list',
popup: null,
page: 1,
popup: null
};

this.triggerChangeTab = this.triggerChangeTab.bind(this);
Expand Down Expand Up @@ -127,17 +126,6 @@ class ObservationsPage extends React.Component {
}
}

getPageSize() {
const { observations } = this.props;

if (observations.data && observations.data.length) {
// What if the page only have 5 results...
return observations.data.length > 50 ? 50 : observations.data.length;
}

return 1;
}

onCustomAttribute = (e) => {
e.preventDefault();
modal.toggleModal(true, {
Expand Down Expand Up @@ -397,7 +385,7 @@ class ObservationsPage extends React.Component {
columns: columnHeaders.filter((header) =>
observations.columns.includes(header.accessor)
),
pageSize: this.getPageSize(),
pageSize: 50,
pagination: true,
previousText: '<',
nextText: '>',
Expand Down
2 changes: 1 addition & 1 deletion pages/sitemap.xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function generateSiteMap(operators, countries) {

export async function getServerSideProps({ res }) {
const { data: operators } = await API
.get('operators', { locale: 'en', 'page[size]': 3000, 'fields[operator]': 'slug' })
.get('operators', { locale: 'en', 'page[size]': 3000, 'fields[operators]': 'slug' })

let countries = [];
if (process.env.FEATURE_COUNTRY_PAGES) {
Expand Down

0 comments on commit e6282dd

Please sign in to comment.