8000 Add toggle for remove keyword search feature by sunfmin · Pull Request #266 · qor5/admin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add toggle for remove keyword search feature #266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion docs/docsrc/examples/examples_presets/listing.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,24 @@ func PresetsHelloWorld(b *presets.Builder, db *gorm.DB) (

b.DataOperator(gorm2op.DataOperator(db))
mb = b.Model(&Customer{})

cl = mb.Listing()
ce = mb.Editing()
return
}

// @snippet_end

func PresetsKeywordSearchOff(b *presets.Builder, db *gorm.DB) (
mb *presets.ModelBuilder,
cl *presets.ListingBuilder,
ce *presets.EditingBuilder,
dp *presets.DetailingBuilder,
) {
mb, cl, ce, dp = PresetsHelloWorld(b, db)
cl.KeywordSearchOff(true)
return
}

// @snippet_begin(PresetsListingCustomizationFieldsSample)

type Company struct {
Expand Down
32 changes: 32 additions & 0 deletions docs/docsrc/examples/examples_presets/listing_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package examples_presets

import (
"net/http"
"net/http/httptest"
"testing"

"github.com/qor5/admin/v3/presets"
"github.com/qor5/admin/v3/presets/gorm2op"
"github.com/qor5/web/v3/multipartestutils"
)

func TestPresetsListingKeywordSearchOff(t *testing.T) {
pb := presets.New().DataOperator(gorm2op.DataOperator(TestDB))
PresetsKeywordSearchOff(pb, TestDB)
cases := []multipartestutils.TestCase{
{
Name: "Index Page with keyword",
Debug: true,
ReqFunc: func() *http.Request {
return httptest.NewRequest("GET", "/customers?keyword=thisismykeyword", nil)
},
ExpectPageBodyNotContains: []string{"thisismykeyword"},
},
}

for _, c := range cases {
t.Run(c.Name, func(t *testing.T) {
multipartestutils.RunCase(t, c, pb)
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
dp *presets.DetailingBuilder,
) {
mb, cl, ce, dp = PresetsHelloWorld(b, db)
mb.LayoutConfig(&presets.LayoutConfig{SearchBoxInvisible: true})
mb.LayoutConfig(&presets.LayoutConfig{})

Check warning on line 23 in docs/docsrc/examples/examples_presets/model-builder-extensions.go

View check run for this annotation

Codecov / codecov/patch

docs/docsrc/examples/examples_presets/model-builder-extensions.go#L23

Added line #L23 was not covered by tests

eb := mb.Editing("Actions", "Name").ActionsFunc(func(obj interface{}, ctx *web.EventContext) h.HTMLComponent {
return h.Components(
Expand Down
1 change: 1 addition & 0 deletions docs/docsrc/examples/examples_presets/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
func SamplesHandler(mux examples.Muxer, prefix string) {
db := examples.ExampleDB()
addExample(mux, db, PresetsHelloWorld)
addExample(mux, db, PresetsKeywordSearchOff)

Check warning on line 14 in docs/docsrc/examples/examples_presets/mux.go

View check run for this annotation

Codecov / codecov/patch

docs/docsrc/examples/examples_presets/mux.go#L14

Added line #L14 was not covered by tests
addExample(mux, db, PresetsListingCustomizationFields)
addExample(mux, db, PresetsListingCustomizationFilters)
addExample(mux, db, PresetsListingCustomizationTabs)
Expand Down
10000
1 change: 0 additions & 1 deletion example/admin/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,6 @@ func configBrand(b *presets.Builder, db *gorm.DB) {
return
}).
NotFoundPageLayoutConfig(&presets.LayoutConfig{
SearchBoxInvisible: true,
NotificationCenterInvisible: true,
})
}
Expand Down
67 changes: 41 additions & 26 deletions presets/listing.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type ListingBuilder struct {
conditions []*SQLCondition
dialogWidth string
dialogHeight string
keywordSearchOff bool
FieldsBuilder
}

Expand Down Expand Up @@ -115,6 +116,11 @@ func (b *ListingBuilder) Title(title string) (r *ListingBuilder) {
return b
}

func (b *ListingBuilder) KeywordSearchOff(v bool) (r *ListingBuilder) {
b.keywordSearchOff = v
return b
}

func (b *ListingBuilder) SearchColumns(vs ...string) (r *ListingBuilder) {
b.searchColumns = vs
return b
Expand Down Expand Up @@ -233,31 +239,35 @@ func (b *ListingBuilder) listingComponent(
fd.SetByQueryString(ctx.R.URL.RawQuery)
filterBar = b.filterBar(ctx, msgr, fd, inDialog)
}
searchBoxDefault := VResponsive(
web.Scope(
VTextField(
web.Slot(VIcon("mdi-magnify")).Name("append-inner"),
).Density(DensityCompact).
Variant(FieldVariantOutlined).
Label(msgr.Search).
Flat(true).
Clearable(true).
HideDetails(true).
SingleLine(true).
ModelValue(ctx.R.URL.Query().Get("keyword")).
Attr("@keyup.enter", web.Plaid().
ClearMergeQuery("page").
Query("keyword", web.Var("[$event.target.value]")).
MergeQuery(true).
PushState(true).
Go()).
Attr("@click:clear", web.Plaid().
Query("keyword", "").
PushState(true).
Go()).
Class("mr-4"),
).VSlot("{ locals }").Init(`{isFocus: false}`),
).MaxWidth(200).MinWidth(200)
var searchBoxDefault h.HTMLComponent

if !b.keywordSearchOff {
searchBoxDefault = VResponsive(
web.Scope(
VTextField(
web.Slot(VIcon("mdi-magnify")).Name("append-inner"),
).Density(DensityCompact).
Variant(FieldVariantOutlined).
Label(msgr.Search).
Flat(true).
Clearable(true).
HideDetails(true).
SingleLine(true).
ModelValue(ctx.R.URL.Query().Get("keyword")).
Attr("@keyup.enter", web.Plaid().
ClearMergeQuery("page").
Query("keyword", web.Var("[$event.target.value]")).
MergeQuery(true).
PushState(true).
Go()).
Attr("@click:clear", web.Plaid().
Query("keyword", "").
PushState(true).
Go()).
Class("mr-4"),
).VSlot("{ locals }").Init(`{isFocus: false}`),
).MaxWidth(200).MinWidth(200)
}
dataTable, dataTableAdditions := b.getTableComponents(ctx, inDialog)

var (
Expand All @@ -277,7 +287,7 @@ func (b *ListingBuilder) listingComponent(
if title == "" {
title = msgr.ListingObjectTitle(i18n.T(ctx.R, ModelsI18nModuleKey, b.mb.label))
}
if b.mb.layoutConfig == nil || !b.mb.layoutConfig.SearchBoxInvisible {
if !b.keywordSearchOff {
searchBoxDefault = VResponsive(
web.Scope(
VTextField(
Expand Down Expand Up @@ -1179,6 +1189,11 @@ func (b *ListingBuilder) getTableComponents(
SQLConditions: b.conditions,
}

if b.keywordSearchOff {
searchParams.KeywordColumns = nil
searchParams.Keyword = ""
}

searchParams.Page, _ = strconv.ParseInt(qs.Get("page"), 10, 64)
if searchParams.Page == 0 {
searchParams.Page = 1
Expand Down
5 changes: 1 addition & 4 deletions presets/presets.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ func New() *Builder {
brandTitle: "Admin",
rightDrawerWidth: "600",
verifier: perm.NewVerifier(PermModule, nil),
homePageLayoutConfig: &LayoutConfig{SearchBoxInvisible: true},
homePageLayoutConfig: &LayoutConfig{},
notFoundPageLayoutConfig: &LayoutConfig{
SearchBoxInvisible: true,
NotificationCenterInvisible: true,
},
wrapHandlers: make(map[string]func(in http.Handler) (out http.Handler)),
Expand Down Expand Up @@ -862,7 +861,6 @@ func (b *Builder) dialog(r *web.EventResponse, comp h.HTMLComponent, width strin
}

type LayoutConfig struct {
SearchBoxInvisible bool
NotificationCenterInvisible bool
}

Expand Down Expand Up @@ -1266,7 +1264,6 @@ func (b *Builder) initMux() {
if m.layoutConfig == nil {
m.layoutConfig = &LayoutConfig{}
}
m.layoutConfig.SearchBoxInvisible = true
}
mux.Handle(
routePath,
Expand Down
1 change: 0 additions & 1 deletion seo/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func (b *Builder) Install(pb *presets.Builder) error {
Label("SEO").
RightDrawerWidth("1000").
LayoutConfig(&presets.LayoutConfig{
SearchBoxInvisible: true,
NotificationCenterInvisible: true,
})

Expand Down
Loading
0