Fixed some small paper-cuts
- Fixed a bug that was pushing duplicate view entries to the backstack - The appended column will now be selected once added
This commit is contained in:
parent
b51c13dfb1
commit
bfd0943c4f
14 changed files with 155 additions and 46 deletions
|
|
@ -1,4 +1,4 @@
|
|||
package workspaces
|
||||
package viewsnapshot
|
||||
|
||||
import "github.com/lmika/audax/internal/dynamo-browse/models/serialisable"
|
||||
|
||||
|
|
@ -8,6 +8,7 @@ type ViewSnapshotStore interface {
|
|||
CurrentlyViewedSnapshot() (*serialisable.ViewSnapshot, error)
|
||||
SetCurrentlyViewedSnapshot(resultSetId int64) error
|
||||
Find(resultSetID int64) (*serialisable.ViewSnapshot, error)
|
||||
Len() (int, error)
|
||||
Head() (*serialisable.ViewSnapshot, error)
|
||||
Remove(resultSetId int64) error
|
||||
Dehead(fromNode *serialisable.ViewSnapshot) error
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
package workspaces
|
||||
package viewsnapshot
|
||||
|
||||
import (
|
||||
"github.com/lmika/audax/internal/dynamo-browse/models"
|
||||
"github.com/lmika/audax/internal/dynamo-browse/models/serialisable"
|
||||
"github.com/pkg/errors"
|
||||
"time"
|
||||
|
|
@ -17,21 +16,22 @@ func NewService(store ViewSnapshotStore) *ViewSnapshotService {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *ViewSnapshotService) PushSnapshot(rs *models.ResultSet, filter string) error {
|
||||
func (s *ViewSnapshotService) PushSnapshot(details serialisable.ViewSnapshotDetails) error {
|
||||
newSnapshot := &serialisable.ViewSnapshot{
|
||||
Time: time.Now(),
|
||||
TableName: rs.TableInfo.Name,
|
||||
Time: time.Now(),
|
||||
Details: details,
|
||||
}
|
||||
if q := rs.Query; q != nil {
|
||||
newSnapshot.Query = q.String()
|
||||
}
|
||||
newSnapshot.Filter = filter
|
||||
|
||||
oldHead, err := s.store.CurrentlyViewedSnapshot()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "cannot get snapshot head")
|
||||
}
|
||||
|
||||
if oldHead != nil && oldHead.Details == details {
|
||||
// Attempting to push a duplicate
|
||||
return nil
|
||||
}
|
||||
|
||||
if oldHead != nil {
|
||||
newSnapshot.BackLink = oldHead.ID
|
||||
|
||||
|
|
@ -62,6 +62,10 @@ func (s *ViewSnapshotService) PushSnapshot(rs *models.ResultSet, filter string)
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *ViewSnapshotService) Len() (int, error) {
|
||||
return s.store.Len()
|
||||
}
|
||||
|
||||
func (s *ViewSnapshotService) ViewRestore() (*serialisable.ViewSnapshot, error) {
|
||||
vs, err := s.store.CurrentlyViewedSnapshot()
|
||||
if err != nil {
|
||||
53
internal/dynamo-browse/services/viewsnapshot/service_test.go
Normal file
53
internal/dynamo-browse/services/viewsnapshot/service_test.go
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
package viewsnapshot_test
|
||||
|
||||
import (
|
||||
"github.com/lmika/audax/internal/dynamo-browse/models/serialisable"
|
||||
"github.com/lmika/audax/internal/dynamo-browse/providers/workspacestore"
|
||||
"github.com/lmika/audax/internal/dynamo-browse/services/viewsnapshot"
|
||||
"github.com/lmika/audax/test/testworkspace"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestViewSnapshotService_PushSnapshot(t *testing.T) {
|
||||
t.Run("should not push duplicate snapshots", func(t *testing.T) {
|
||||
ws := testworkspace.New(t)
|
||||
|
||||
service := viewsnapshot.NewService(workspacestore.NewResultSetSnapshotStore(ws))
|
||||
|
||||
// Push some snapshots
|
||||
err := service.PushSnapshot(serialisable.ViewSnapshotDetails{
|
||||
TableName: "normal-table",
|
||||
Query: "pk = 'abc'",
|
||||
Filter: "",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
cnt, err := service.Len()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 1, cnt)
|
||||
|
||||
err = service.PushSnapshot(serialisable.ViewSnapshotDetails{
|
||||
TableName: "abnormal-table",
|
||||
Query: "pk = 'abc'",
|
||||
Filter: "fla",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
cnt, err = service.Len()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 2, cnt)
|
||||
|
||||
// Push a duplicate
|
||||
err = service.PushSnapshot(serialisable.ViewSnapshotDetails{
|
||||
TableName: "abnormal-table",
|
||||
Query: "pk = 'abc'",
|
||||
Filter: "fla",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
cnt, err = service.Len()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 2, cnt)
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue