3
0

Pagination/sorting fixes & improvements

This commit is contained in:
Denis Arh
2020-11-13 16:17:39 +01:00
parent fc0ed924de
commit 11ea5df303
15 changed files with 27 additions and 17 deletions

View File

@@ -199,7 +199,7 @@ func (s Store) {{ unexport "fetchFullPageOf" $.Types.Plural }} (
// if limit is not set or we've already collected enough items
// we can break the loop right away
if limit == 0 || fetched == 0 || fetched < limit {
if limit == 0 || fetched == 0 || fetched <= limit {
break
}

View File

@@ -186,13 +186,12 @@ func (p *PagingCursor) Sort(sort SortExprSet) (SortExprSet, error) {
}
// check compatibility
ss := sort.Columns()
if len(p.keys) != len(ss) {
if len(p.keys) != len(sort) {
return nil, fmt.Errorf("incompatible sort")
}
for k := range p.keys {
if p.keys[k] != ss[k] {
if p.keys[k] != sort[k].Column {
return nil, fmt.Errorf("incompatible sort")
}
}

View File

@@ -1,6 +1,7 @@
package filter
import (
"encoding/json"
"fmt"
"github.com/cortezaproject/corteza-server/pkg/slice"
"regexp"
@@ -70,13 +71,18 @@ func parseSort(in string) (set SortExprSet, err error) {
return set, nil
}
// UnmarshalJSON parses stringified sort expression when passed inside JSON
// UnmarshalJSON parses sort expression when passed inside JSON
func (set *SortExprSet) UnmarshalJSON(in []byte) error {
tmp, err := parseSort(string(in))
*set = tmp
return err
}
// UnmarshalJSON parses sort expression when passed inside JSON
func (set SortExprSet) MarshalJSON() ([]byte, error) {
return json.Marshal(set.String())
}
// UnmarshalJSON parses stringified sort expression when passed inside JSON
func (set *SortExprSet) Set(in string) error {
tmp, err := parseSort(in)

View File

@@ -148,7 +148,7 @@ func (s Store) fetchFullPageOfActionlogs(
// if limit is not set or we've already collected enough items
// we can break the loop right away
if limit == 0 || fetched == 0 || fetched < limit {
if limit == 0 || fetched == 0 || fetched <= limit {
break
}

View File

@@ -148,7 +148,7 @@ func (s Store) fetchFullPageOfApplications(
// if limit is not set or we've already collected enough items
// we can break the loop right away
if limit == 0 || fetched == 0 || fetched < limit {
if limit == 0 || fetched == 0 || fetched <= limit {
break
}

View File

@@ -148,7 +148,7 @@ func (s Store) fetchFullPageOfComposeCharts(
// if limit is not set or we've already collected enough items
// we can break the loop right away
if limit == 0 || fetched == 0 || fetched < limit {
if limit == 0 || fetched == 0 || fetched <= limit {
break
}

View File

@@ -148,7 +148,7 @@ func (s Store) fetchFullPageOfComposeModules(
// if limit is not set or we've already collected enough items
// we can break the loop right away
if limit == 0 || fetched == 0 || fetched < limit {
if limit == 0 || fetched == 0 || fetched <= limit {
break
}

View File

@@ -148,7 +148,7 @@ func (s Store) fetchFullPageOfComposeNamespaces(
// if limit is not set or we've already collected enough items
// we can break the loop right away
if limit == 0 || fetched == 0 || fetched < limit {
if limit == 0 || fetched == 0 || fetched <= limit {
break
}

View File

@@ -148,7 +148,7 @@ func (s Store) fetchFullPageOfComposePages(
// if limit is not set or we've already collected enough items
// we can break the loop right away
if limit == 0 || fetched == 0 || fetched < limit {
if limit == 0 || fetched == 0 || fetched <= limit {
break
}

View File

@@ -90,7 +90,7 @@ func (s Store) fetchFullPageOfComposeRecords(
// if limit is not set or we've already collected enough items
// we can break the loop right away
if limit == 0 || fetched == 0 || fetched < limit {
if limit == 0 || fetched == 0 || fetched <= limit {
break
}

View File

@@ -148,7 +148,7 @@ func (s Store) fetchFullPageOfMessagingChannels(
// if limit is not set or we've already collected enough items
// we can break the loop right away
if limit == 0 || fetched == 0 || fetched < limit {
if limit == 0 || fetched == 0 || fetched <= limit {
break
}

View File

@@ -148,7 +148,7 @@ func (s Store) fetchFullPageOfReminders(
// if limit is not set or we've already collected enough items
// we can break the loop right away
if limit == 0 || fetched == 0 || fetched < limit {
if limit == 0 || fetched == 0 || fetched <= limit {
break
}

View File

@@ -148,7 +148,7 @@ func (s Store) fetchFullPageOfRoles(
// if limit is not set or we've already collected enough items
// we can break the loop right away
if limit == 0 || fetched == 0 || fetched < limit {
if limit == 0 || fetched == 0 || fetched <= limit {
break
}

View File

@@ -148,7 +148,7 @@ func (s Store) fetchFullPageOfUsers(
// if limit is not set or we've already collected enough items
// we can break the loop right away
if limit == 0 || fetched == 0 || fetched < limit {
if limit == 0 || fetched == 0 || fetched <= limit {
break
}

View File

@@ -320,8 +320,13 @@ func testUsers(t *testing.T, s store.Users) {
f := types.UserFilter{}
f.Sort = filter.SortExprSet{&filter.SortExpr{Column: "email", Descending: true}, &filter.SortExpr{Column: "handle", Descending: true}}
f.Limit = 1
f.Limit = uint(len(set))
set, f, err := store.SearchUsers(ctx, s, f)
req.Len(set, int(f.Limit))
req.NoError(err)
f.Limit = 1
set, f, err = store.SearchUsers(ctx, s, f)
req.NoError(err)
// go to next page with different sorting