Skip to content
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

Fix elipsis button not working if the last commit loading is deferred #29544

Merged
merged 9 commits into from
Mar 2, 2024
24 changes: 8 additions & 16 deletions routers/web/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"code.gitea.io/gitea/modules/actions"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/charset"
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/highlight"
"code.gitea.io/gitea/modules/lfs"
Expand Down Expand Up @@ -859,25 +858,18 @@ func renderDirectoryFiles(ctx *context.Context, timeout time.Duration) git.Entri
defer cancel()
}

selected := make(container.Set[string])
selected.AddMultiple(ctx.FormStrings("f[]")...)

entries := allEntries
if len(selected) > 0 {
entries = make(git.Entries, 0, len(selected))
for _, entry := range allEntries {
if selected.Contains(entry.Name()) {
entries = append(entries, entry)
}
}
}

var latestCommit *git.Commit
ctx.Data["Files"], latestCommit, err = entries.GetCommitsInfo(commitInfoCtx, ctx.Repo.Commit, ctx.Repo.TreePath)
files, latestCommit, err := allEntries.GetCommitsInfo(commitInfoCtx, ctx.Repo.Commit, ctx.Repo.TreePath)
if err != nil {
ctx.ServerError("GetCommitsInfo", err)
return nil
}
ctx.Data["Files"] = files
for _, f := range files {
if f.Commit == nil {
ctx.Data["HasFilesWithoutLatestCommit"] = true
break
}
}

if !loadLatestCommitData(ctx, latestCommit) {
return nil
Expand Down
4 changes: 2 additions & 2 deletions templates/repo/view_list.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<table id="repo-files-table" class="ui single line table gt-mt-0" data-last-commit-loader-url="{{.LastCommitLoaderURL}}">
<table id="repo-files-table" class="ui single line table gt-mt-0" {{if .HasFilesWithoutLatestCommit}}hx-indicator="tr.notready td.message span" hx-trigger="load" hx-swap="morph" hx-post="{{.LastCommitLoaderURL}}"{{end}}>
<thead>
wxiaoguang marked this conversation as resolved.
Show resolved Hide resolved
<tr class="commit-list">
<th colspan="2" {{if not .LatestCommit}}class="notready"{{end}}>
<th colspan="2">
{{template "repo/latest_commit" .}}
</th>
<th class="text grey right age">{{if .LatestCommit}}{{if .LatestCommit.Committer}}{{TimeSince .LatestCommit.Committer.When ctx.Locale}}{{end}}{{end}}</th>
Expand Down
43 changes: 0 additions & 43 deletions web_src/js/features/repo-commit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {createTippy} from '../modules/tippy.js';
import {toggleElem} from '../utils/dom.js';
import {parseDom} from '../utils.js';
import {POST} from '../modules/fetch.js';

export function initRepoEllipsisButton() {
for (const button of document.querySelectorAll('.js-toggle-commit-body')) {
Expand All @@ -14,47 +12,6 @@ export function initRepoEllipsisButton() {
}
}

export async function initRepoCommitLastCommitLoader() {
const entryMap = {};

const entries = Array.from(document.querySelectorAll('table#repo-files-table tr.notready'), (el) => {
const entryName = el.getAttribute('data-entryname');
entryMap[entryName] = el;
return entryName;
});

if (entries.length === 0) {
return;
}

const lastCommitLoaderURL = document.querySelector('table#repo-files-table').getAttribute('data-last-commit-loader-url');

if (entries.length > 200) {
// For more than 200 entries, replace the entire table
const response = await POST(lastCommitLoaderURL);
const data = await response.text();
document.querySelector('table#repo-files-table').outerHTML = data;
return;
}

// For fewer entries, update individual rows
const response = await POST(lastCommitLoaderURL, {data: {'f': entries}});
const data = await response.text();
const doc = parseDom(data, 'text/html');
for (const row of doc.querySelectorAll('tr')) {
if (row.className === 'commit-list') {
document.querySelector('table#repo-files-table .commit-list')?.replaceWith(row);
continue;
}
// there are other <tr> rows in response (eg: <tr class="has-parent">)
// at the moment only the "data-entryname" rows should be processed
const entryName = row.getAttribute('data-entryname');
if (entryName) {
entryMap[entryName]?.replaceWith(row);
}
}
}

export function initCommitStatuses() {
for (const element of document.querySelectorAll('[data-tippy="commit-statuses"]')) {
const top = document.querySelector('.repository.file.list') || document.querySelector('.repository.diff');
Expand Down
7 changes: 1 addition & 6 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ import {
initRepoPullRequestAllowMaintainerEdit,
initRepoPullRequestReview, initRepoIssueSidebarList, initArchivedLabelHandler,
} from './features/repo-issue.js';
import {
initRepoEllipsisButton,
initRepoCommitLastCommitLoader,
initCommitStatuses,
} from './features/repo-commit.js';
import {initRepoEllipsisButton, initCommitStatuses} from './features/repo-commit.js';
import {
initFootLanguageMenu,
initGlobalButtonClickOnEnter,
Expand Down Expand Up @@ -148,7 +144,6 @@ onDomReady(() => {
initRepoCommentForm();
initRepoEllipsisButton();
initRepoDiffCommitBranchesAndTags();
initRepoCommitLastCommitLoader();
initRepoEditor();
initRepoGraphGit();
initRepoIssueContentHistory();
Expand Down