Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #11224 from qmonmert/feature/react-hooks-calls
Fix issue #11222 : react in a few scenarios, the entity list page can invoke up to 4 calls to the backend API #11222
  • Loading branch information
pascalgrimaud committed Feb 11, 2020
2 parents 9c4276e + 2a29b06 commit 00e3a65
Showing 1 changed file with 4 additions and 14 deletions.
Expand Up @@ -98,17 +98,17 @@ export const <%= entityReactName %> = (props: I<%= entityReactName %>Props) => {
};
<%_ } _%>

<%_ if (pagination === 'no' || pagination === 'infinite-scroll') { _%>
useEffect(() => {
<%_ if (pagination !== 'no') { _%>
<%_ if (pagination === 'infinite-scroll') { _%>
resetAll();
<%_ } else { _%>
getAllEntities();
<%_ } _%>
<%_ } else { _%>
props.getEntities();
<%_ } _%>
}, []);
}, [<%_ if (searchEngine === 'elasticsearch' && pagination === 'no') { _%>search<%_ } _%>]);
<%_ } _%>

<%_ if (pagination === 'infinite-scroll') { _%>
useEffect(() => {
Expand All @@ -119,12 +119,6 @@ export const <%= entityReactName %> = (props: I<%= entityReactName %>Props) => {
<%_ } _%>

<%_ if (searchEngine === 'elasticsearch') { _%>
<%_ if (pagination !== 'no') { _%>
useEffect(() => {
props.getSearchEntities(search, paginationState.activePage - 1, paginationState.itemsPerPage, `${paginationState.sort},${paginationState.order}`);
}, [paginationState.activePage]);

<%_ } _%>
const startSearching = () => {
if (search) {
<%_ if (pagination === 'infinite-scroll') { _%>
Expand All @@ -141,10 +135,6 @@ export const <%= entityReactName %> = (props: I<%= entityReactName %>Props) => {
}
};

useEffect(() => {
props.getEntities()
}, [<%_ if (pagination !== 'no') { _%>paginationState.activePage, <%_ } _%>search]);

const clear = () => {
<%_ if (pagination === 'infinite-scroll') { _%>
props.reset();
Expand Down Expand Up @@ -194,7 +184,7 @@ export const <%= entityReactName %> = (props: I<%= entityReactName %>Props) => {
<% } else { %>
sortEntities();
<% } %>
}, [<% if (pagination === 'infinite-scroll') { %>sorting<% } else { %>paginationState.activePage, paginationState.order, paginationState.sort<% } %>]);
}, [<% if (pagination === 'infinite-scroll') { %>sorting<% } else { %>paginationState.activePage, paginationState.order, paginationState.sort<% } %><%_ if (searchEngine === 'elasticsearch') { _%>, search<% } %>]);

const sort = p => () => {
<% if (pagination === 'infinite-scroll') { %>
Expand Down

0 comments on commit 00e3a65

Please sign in to comment.