refactor(dbfs): share navigator Capabilities skeleton via baseNavigatorProps

Four navigators built the same NavigatorProps literal with only the
capability set and search-option narrowing differing. baseNavigatorProps
holds the shared shape; each navigator adjusts search options on top.

Authored By: TDvorak <info@tdvorak.dev>

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
pull/3582/head
Tomas Dvorak 2 weeks ago
parent 053274afef
commit 501c872191

@ -134,12 +134,7 @@ func (n *myNavigator) walkNext(ctx context.Context, root *File, next string, isL
} }
func (n *myNavigator) Capabilities(isSearching bool) *fs.NavigatorProps { func (n *myNavigator) Capabilities(isSearching bool) *fs.NavigatorProps {
res := &fs.NavigatorProps{ res := baseNavigatorProps(myNavigatorCapability, n.config.MaxPageSize)
Capability: myNavigatorCapability,
OrderDirectionOptions: fullOrderDirectionOption,
OrderByOptions: fullOrderByOption,
MaxPageSize: n.config.MaxPageSize,
}
if isSearching { if isSearching {
res.OrderByOptions = nil res.OrderByOptions = nil
res.OrderDirectionOptions = nil res.OrderDirectionOptions = nil

@ -58,6 +58,17 @@ var (
fullOrderDirectionOption = []string{"asc", "desc"} fullOrderDirectionOption = []string{"asc", "desc"}
) )
// baseNavigatorProps builds the shared NavigatorProps skeleton; navigators
// adjust search options on top.
func baseNavigatorProps(capability *boolset.BooleanSet, maxPageSize int) *fs.NavigatorProps {
return &fs.NavigatorProps{
Capability: capability,
OrderDirectionOptions: fullOrderDirectionOption,
OrderByOptions: fullOrderByOption,
MaxPageSize: maxPageSize,
}
}
type ( type (
// Navigator is a navigator for database file system. // Navigator is a navigator for database file system.
Navigator interface { Navigator interface {

@ -278,12 +278,7 @@ func (n *shareNavigator) latestSharedSingleFile(ctx context.Context) (*File, err
} }
func (n *shareNavigator) Capabilities(isSearching bool) *fs.NavigatorProps { func (n *shareNavigator) Capabilities(isSearching bool) *fs.NavigatorProps {
res := &fs.NavigatorProps{ res := baseNavigatorProps(shareNavigatorCapability, n.config.MaxPageSize)
Capability: shareNavigatorCapability,
OrderDirectionOptions: fullOrderDirectionOption,
OrderByOptions: fullOrderByOption,
MaxPageSize: n.config.MaxPageSize,
}
// Once the share is resolved, narrow capabilities to what its props grant. // Once the share is resolved, narrow capabilities to what its props grant.
// This set is stamped onto resolved files and consulted by writePermitted. // This set is stamped onto resolved files and consulted by writePermitted.

@ -101,13 +101,7 @@ func (t *sharedWithMeNavigator) Children(ctx context.Context, parent *File, args
} }
func (t *sharedWithMeNavigator) Capabilities(isSearching bool) *fs.NavigatorProps { func (t *sharedWithMeNavigator) Capabilities(isSearching bool) *fs.NavigatorProps {
res := &fs.NavigatorProps{ res := baseNavigatorProps(sharedWithMeNavigatorCapability, t.config.MaxPageSize)
Capability: sharedWithMeNavigatorCapability,
OrderDirectionOptions: fullOrderDirectionOption,
OrderByOptions: fullOrderByOption,
MaxPageSize: t.config.MaxPageSize,
}
if isSearching { if isSearching {
res.OrderByOptions = searchLimitedOrderByOption res.OrderByOptions = searchLimitedOrderByOption
} }

@ -116,13 +116,7 @@ func (t *trashNavigator) Children(ctx context.Context, parent *File, args *ListA
} }
func (t *trashNavigator) Capabilities(isSearching bool) *fs.NavigatorProps { func (t *trashNavigator) Capabilities(isSearching bool) *fs.NavigatorProps {
res := &fs.NavigatorProps{ res := baseNavigatorProps(trashNavigatorCapability, t.config.MaxPageSize)
Capability: trashNavigatorCapability,
OrderDirectionOptions: fullOrderDirectionOption,
OrderByOptions: fullOrderByOption,
MaxPageSize: t.config.MaxPageSize,
}
if isSearching { if isSearching {
res.OrderByOptions = searchLimitedOrderByOption res.OrderByOptions = searchLimitedOrderByOption
} }

Loading…
Cancel
Save