Skip to content

Commit

Permalink
Refactor sidebar assignee&milestone&project selectors (#32465)
Browse files Browse the repository at this point in the history
Follow #32460

Now the code could be much clearer than before and easier to maintain. A
lot of legacy code is removed.

Manually tested.

This PR is large enough, that fine tunes could be deferred to the future if
there is no bug found or design problem.

Screenshots:

<details>

![image](https://github.com/user-attachments/assets/35f4ab7b-1bc0-4bad-a73c-a4569328303c)

</details>
  • Loading branch information
wxiaoguang authored Nov 10, 2024
1 parent 58c634b commit a928739
Show file tree
Hide file tree
Showing 23 changed files with 504 additions and 829 deletions.
3 changes: 3 additions & 0 deletions modules/base/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ func StringsToInt64s(strs []string) ([]int64, error) {
}
ints := make([]int64, 0, len(strs))
for _, s := range strs {
if s == "" {
continue
}
n, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions modules/base/tool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func TestStringsToInt64s(t *testing.T) {
}
testSuccess(nil, nil)
testSuccess([]string{}, []int64{})
testSuccess([]string{""}, []int64{})
testSuccess([]string{"-1234"}, []int64{-1234})
testSuccess([]string{"1", "4", "16", "64", "256"}, []int64{1, 4, 16, 64, 256})

Expand Down
4 changes: 2 additions & 2 deletions modules/container/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func (s Set[T]) AddMultiple(values ...T) {
}
}

// Contains determines whether a set contains the specified elements.
// Returns true if the set contains the specified element; otherwise, false.
// Contains determines whether a set contains all these elements.
// Returns true if the set contains all these elements; otherwise, false.
func (s Set[T]) Contains(values ...T) bool {
ret := true
for _, value := range values {
Expand Down
2 changes: 2 additions & 0 deletions modules/container/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ func TestSet(t *testing.T) {

assert.True(t, s.Contains("key1"))
assert.True(t, s.Contains("key2"))
assert.True(t, s.Contains("key1", "key2"))
assert.False(t, s.Contains("key3"))
assert.False(t, s.Contains("key1", "key3"))

assert.True(t, s.Remove("key2"))
assert.False(t, s.Contains("key2"))
Expand Down
1 change: 1 addition & 0 deletions modules/templates/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func NewFuncMap() template.FuncMap {
"ctx": func() any { return nil }, // template context function

"DumpVar": dumpVar,
"NIL": func() any { return nil },

// -----------------------------------------------------------------
// html/template related functions
Expand Down
12 changes: 2 additions & 10 deletions routers/web/repo/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -788,19 +788,11 @@ func CompareDiff(ctx *context.Context) {

if !nothingToCompare {
// Setup information for new form.
retrieveRepoMetasForIssueWriter(ctx, ctx.Repo.Repository, true)
pageMetaData := retrieveRepoIssueMetaData(ctx, ctx.Repo.Repository, nil, true)
if ctx.Written() {
return
}
labelsData := retrieveRepoLabels(ctx, ctx.Repo.Repository, 0, true)
if ctx.Written() {
return
}
RetrieveRepoReviewers(ctx, ctx.Repo.Repository, nil, true)
if ctx.Written() {
return
}
_, templateErrs := setTemplateIfExists(ctx, pullRequestTemplateKey, pullRequestTemplateCandidates, labelsData)
_, templateErrs := setTemplateIfExists(ctx, pullRequestTemplateKey, pullRequestTemplateCandidates, pageMetaData)
if len(templateErrs) > 0 {
ctx.Flash.Warning(renderErrorOfTemplates(ctx, templateErrs), true)
}
Expand Down
Loading

0 comments on commit a928739

Please sign in to comment.