From 5e57cec391c4e1a5a762aeaa770b1fe09656cfa5 Mon Sep 17 00:00:00 2001 From: Mikhail Iudin Date: Tue, 25 Apr 2023 18:17:59 +0200 Subject: [PATCH] PROD-605 Change default sort --- core/block/editor/dataview/dataview.go | 29 +++++++++++++------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/core/block/editor/dataview/dataview.go b/core/block/editor/dataview/dataview.go index 82a65f78d..815f3a3e5 100644 --- a/core/block/editor/dataview/dataview.go +++ b/core/block/editor/dataview/dataview.go @@ -301,11 +301,7 @@ func (d *sdataview) CreateView(ctx *session.Context, id string, if len(view.Sorts) == 0 { // todo: set depends on the view type - view.Sorts = []*model.BlockContentDataviewSort{{ - Id: bson.NewObjectId().Hex(), - RelationKey: bundle.RelationKeyLastModifiedDate.String(), - Type: model.BlockContentDataviewSort_Desc, - }} + view.Sorts = defaultLastModifiedDateSort() } sbType, err := d.sbtProvider.Type(d.Id()) @@ -327,6 +323,16 @@ func (d *sdataview) CreateView(ctx *session.Context, id string, return &view, d.Apply(s) } +func defaultLastModifiedDateSort() []*model.BlockContentDataviewSort { + return []*model.BlockContentDataviewSort{ + { + Id: bson.NewObjectId().Hex(), + RelationKey: bundle.RelationKeyLastModifiedDate.String(), + Type: model.BlockContentDataviewSort_Desc, + }, + } +} + func (d *sdataview) UpdateViewGroupOrder(ctx *session.Context, blockId string, order *model.BlockContentDataviewGroupOrder) error { st := d.NewStateCtx(ctx) dvBlock, err := getDataviewBlock(st, blockId) @@ -630,15 +636,10 @@ func DataviewBlockBySource(sbtProvider typeprovider.SmartBlockTypeProvider, stor RelationLinks: relations, Views: []*model.BlockContentDataviewView{ { - Id: bson.NewObjectId().Hex(), - Type: model.BlockContentDataviewView_Table, - Name: "All", - Sorts: []*model.BlockContentDataviewSort{ - { - RelationKey: "name", - Type: model.BlockContentDataviewSort_Asc, - }, - }, + Id: bson.NewObjectId().Hex(), + Type: model.BlockContentDataviewView_Table, + Name: "All", + Sorts: defaultLastModifiedDateSort(), Filters: nil, Relations: viewRelations, },