diff --git a/core/block/editor.go b/core/block/editor.go index 6209a0c4a..b430ac4f7 100644 --- a/core/block/editor.go +++ b/core/block/editor.go @@ -176,7 +176,7 @@ func (s *Service) GetAggregatedRelations( func (s *Service) UpdateDataviewView(ctx *session.Context, req pb.RpcBlockDataviewViewUpdateRequest) error { return s.DoDataview(req.ContextId, func(b dataview.Dataview) error { - return b.UpdateView(ctx, req.BlockId, req.ViewId, *req.View, true) + return b.UpdateView(ctx, req.BlockId, req.ViewId, req.View, true) }) } diff --git a/core/block/editor/dataview/dataview.go b/core/block/editor/dataview/dataview.go index 27532342d..ea50cf18b 100644 --- a/core/block/editor/dataview/dataview.go +++ b/core/block/editor/dataview/dataview.go @@ -59,7 +59,7 @@ type Dataview interface { SetViewPosition(ctx *session.Context, blockId string, viewId string, position uint32) error AddRelations(ctx *session.Context, blockId string, relationIds []string, showEvent bool) error DeleteRelations(ctx *session.Context, blockId string, relationIds []string, showEvent bool) error - UpdateView(ctx *session.Context, blockId string, viewId string, view model.BlockContentDataviewView, showEvent bool) error + UpdateView(ctx *session.Context, blockId string, viewId string, view *model.BlockContentDataviewView, showEvent bool) error UpdateViewGroupOrder(ctx *session.Context, blockId string, order *model.BlockContentDataviewGroupOrder) error UpdateViewObjectOrder(ctx *session.Context, blockId string, orders []*model.BlockContentDataviewObjectOrder) error @@ -209,14 +209,14 @@ func (d *sdataview) DeleteView(ctx *session.Context, blockId string, viewId stri return d.Apply(s, smartblock.NoEvent) } -func (d *sdataview) UpdateView(ctx *session.Context, blockId string, viewId string, view model.BlockContentDataviewView, showEvent bool) error { +func (d *sdataview) UpdateView(ctx *session.Context, blockId string, viewId string, view *model.BlockContentDataviewView, showEvent bool) error { s := d.NewStateCtx(ctx) dvBlock, err := getDataviewBlock(s, blockId) if err != nil { return err } - if err = dvBlock.SetView(viewId, view); err != nil { + if err = dvBlock.SetViewFields(viewId, view); err != nil { return err } diff --git a/core/block/simple/dataview/dataview.go b/core/block/simple/dataview/dataview.go index 17e5c2101..d4a2af999 100644 --- a/core/block/simple/dataview/dataview.go +++ b/core/block/simple/dataview/dataview.go @@ -44,6 +44,7 @@ type Block interface { simple.Block GetView(viewID string) (*model.BlockContentDataviewView, error) SetView(viewID string, view model.BlockContentDataviewView) error + SetViewFields(viewID string, view *model.BlockContentDataviewView) error AddView(view model.BlockContentDataviewView) DeleteView(viewID string) error SetViewOrder(ids []string) @@ -330,36 +331,47 @@ func (s *Dataview) DeleteView(viewID string) error { } func (s *Dataview) SetView(viewID string, view model.BlockContentDataviewView) error { - var found bool - for _, v := range s.content.Views { - if v.Id == viewID { - found = true + v, err := s.GetView(viewID) + if err != nil { + return nil + } - v.Relations = view.Relations - v.Sorts = view.Sorts - v.Filters = view.Filters - for _, f := range v.Filters { - if f.Id == "" { - f.Id = bson.NewObjectId().Hex() - } - } - v.Name = view.Name - v.Type = view.Type - v.CoverRelationKey = view.CoverRelationKey - v.HideIcon = view.HideIcon - v.CoverFit = view.CoverFit - v.CardSize = view.CardSize - v.GroupRelationKey = view.GroupRelationKey - v.GroupBackgroundColors = view.GroupBackgroundColors - - break + v.Relations = view.Relations + v.Sorts = view.Sorts + v.Filters = view.Filters + for _, f := range v.Filters { + if f.Id == "" { + f.Id = bson.NewObjectId().Hex() } } + v.Name = view.Name + v.Type = view.Type + v.CoverRelationKey = view.CoverRelationKey + v.HideIcon = view.HideIcon + v.CoverFit = view.CoverFit + v.CardSize = view.CardSize + v.GroupRelationKey = view.GroupRelationKey + v.GroupBackgroundColors = view.GroupBackgroundColors - if !found { - return ErrViewNotFound + return nil +} + +// SetViewFields updates only simple fields of a view. It doesn't update filters, relations, sorts. +func (s *Dataview) SetViewFields(viewID string, view *model.BlockContentDataviewView) error { + v, err := s.GetView(viewID) + if err != nil { + return err } + v.Name = view.Name + v.Type = view.Type + v.CoverRelationKey = view.CoverRelationKey + v.HideIcon = view.HideIcon + v.CoverFit = view.CoverFit + v.CardSize = view.CardSize + v.GroupRelationKey = view.GroupRelationKey + v.GroupBackgroundColors = view.GroupBackgroundColors + return nil }