-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add priority to protected branch #32286
base: main
Are you sure you want to change the base?
Conversation
as its an object we can add stuff later on
vid-20241021-211051.mp4 |
const newOrder = Array.from(protectedBranchesList.children, (item) => { | ||
const id = item.getAttribute('data-id'); | ||
return id ? parseInt(id) : NaN; | ||
}).filter((id) => !Number.isNaN(id)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the filter is needed? If an item doesn't have data-id
, isn't it just a bug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not needed but I added it just as savety guard as it does not hurt -> defensive programming (e.g. I expect users to mess up there custom templates)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that's not defensive programming, that's unclear logic.
You can't do use protectedBranchesList.children
directly here, but need to query correct items first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
queryElemChildren(protectedBranchesList, '.item[data-id]')
(or use .flex-item[data-id]
)
Then no need the filter
or isNaN
trick
@@ -125,3 +128,8 @@ type EditBranchProtectionOption struct { | |||
UnprotectedFilePatterns *string `json:"unprotected_file_patterns"` | |||
BlockAdminMergeOverride *bool `json:"block_admin_merge_override"` | |||
} | |||
|
|||
// UpdateBranchProtectionPriories a list to update the branch protection rule priorities | |||
type UpdateBranchProtectionPriories []struct { |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
ids := make([]int64, len(*form)) | ||
for i, v := range *form { | ||
ids[i] = v.ID | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a proper form struct then no need this trick.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the API i want to use a proper struct so we can extend it later on if we want ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... as for the web route, If I can figure it out how to just send an []int64{} directly, I will do so - oh already did so :)
createSortable(protectedBranchesList, { | ||
handle: '.drag-handle', | ||
animation: 150, | ||
onEnd: async () => { // eslint-disable-line @typescript-eslint/no-misused-promises |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is misused
and why ignored?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no idea
I just reused that code
gitea/web_src/js/features/repo-issue-list.ts
Line 199 in f2a6df0
onEnd: pinMoveEnd, // eslint-disable-line @typescript-eslint/no-misused-promises |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PS: if I remove that the linter fails - but the code works ... so no idea whats going on
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The definition is in export interface SortableOptions {
, onEnd
doesn't accept async
.
The proper change is:
onEnd: () => {
(async () => {
await ....
})();
}
But I won't block it if you don't want to make further change.
@@ -125,3 +128,8 @@ type EditBranchProtectionOption struct { | |||
UnprotectedFilePatterns *string `json:"unprotected_file_patterns"` | |||
BlockAdminMergeOverride *bool `json:"block_admin_merge_override"` | |||
} | |||
|
|||
// UpdateBranchProtectionPriories a list to update the branch protection rule priorities | |||
type UpdateBranchProtectionPriories []struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, here we need a proper struct, instead of the naked array.
<div class="ui basic primary label">{{.RuleName}}</div> | ||
<div data-id="{{.ID}}"> | ||
<div class="flex-item tw-items-center"> | ||
<div class="drag-handle tw-cursor-grab"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be as simple as
<div class="flex-item tw-items-center item" data-id="{{.ID}} >
</div>
(I do not understand why it's worth to add the extra wrapper)
Solves
Currently for rules to re-order them you have to alter the creation date. so you basicly have to delete and recreate them in the right order. This is more than just inconvinient ...
Solution
Add a new col for prioritization
TODOs:
Demo WebUI Video
vid-20241021-211051.mp4
Sponsored by Kithara Software GmbH