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 .locale.Tr function not found in delete modal #23468

Merged
merged 8 commits into from
Mar 21, 2023

Conversation

delvh
Copy link
Member

@delvh delvh commented Mar 14, 2023

Caught by @wxiaoguang in #23337 (comment).

Additionally, there were three instances that have the same content as templates/base/deletion_modal_actions.tmpl, but that are not intended to delete something.
Instead of renaming the template above, these instances were simply re-hard-coded again.
Renaming/improving the template above is left for future PRs.

@delvh delvh added type/bug topic/ui Change the appearance of the Gitea UI labels Mar 14, 2023
@delvh delvh added this to the 1.20.0 milestone Mar 14, 2023
@wxiaoguang
Copy link
Contributor

I guess this change equals before. Because in this template, .xx is $.xx

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 14, 2023
@wxiaoguang
Copy link
Contributor

Just have a try, I see the error message:

template: base/delete_modal_actions:4:5: executing "base/delete_modal_actions" at <$.locale.Tr>: can't evaluate field locale in type string,

it's $.locale.Tr now 😂

@delvh
Copy link
Member Author

delvh commented Mar 14, 2023

As far as I've understood Go templates (please correct me if I misunderstood something):
.something is the attribute x.something when you use {{template "<another>" x}}.
$.something is the global value set with ctx.Data["something"].
Is that correct, or is there yet another thing I have to learn about the templates?

@delvh delvh marked this pull request as draft March 14, 2023 10:05
@delvh delvh changed the title Fix .locale.Tr function not found in delete modal WIP: Fix .locale.Tr function not found in delete modal Mar 14, 2023
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Mar 14, 2023

In a template, $.xx is accessing the root/top scope. .xx is accessing current range/with scope.

So, if we write $.xx or .xx in root/top scope , they are the same.

I guess the problem is caused by that this sub-template is called inside a range scope by {{template "actions" .}}. Actually, it needs to access top scope to get the locale: try to use {{template "actions" $}}?

@delvh
Copy link
Member Author

delvh commented Mar 14, 2023

@wxiaoguang unfortunately, I was never able to see the dialogue, not even during #23337.
So, could you please tell me if it now works?

@wxiaoguang
Copy link
Contributor

I just navigated to the page http://localhost:3000/user/settings/repos , let me see ....

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Mar 14, 2023

I guess the fix could be like this:

diff --git a/templates/user/settings/repos.tmpl b/templates/user/settings/repos.tmpl
index 2e107ca7f..d1cb60225 100644
--- a/templates/user/settings/repos.tmpl
+++ b/templates/user/settings/repos.tmpl
@@ -50,7 +50,7 @@
                                                                                                                {{$.CsrfTokenHtml}}
                                                                                                                <input type="hidden" name="id" value="{{$dir}}">
                                                                                                                <input type="hidden" name="action" value="adopt">
-                                                                                                               {{template "base/delete_modal_actions" .}}
+                                                                                                               {{template "base/delete_modal_actions" $}}
                                                                                                        </form>
                                                                                                </div>
                                                                                        {{end}}
@@ -68,7 +68,7 @@
                                                                                                                {{$.CsrfTokenHtml}}
                                                                                                                <input type="hidden" name="id" value="{{$dir}}">
                                                                                                                <input type="hidden" name="action" value="delete">
-                                                                                                               {{template "base/delete_modal_actions" .}}
+                                                                                                               {{template "base/delete_modal_actions" $}}
                                                                                                        </form>
                                                                                                </div>
                                                                                        {{end}}

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Mar 14, 2023

Hmm , I think I know your question now .... some pages are for special usage, for example, adopt repositories, adopt lfs files, etc. You need to have some unadopted repositories to make Gitea render that UI.

I did a global search, I can find there are also similar problems in templates/admin/repo/unadopted.tmpl : {{range}} => {{template "actions" .}}.

So I guess there are 4 lines need to be changed: 2 lines in unadopted.tmpl, 2 lines in templates/user/settings/repos.tmpl


And I find one more possible problem, the template name delete_modal_actions is not accurate, for example, in the unadopted.tmpl, these yes/no buttons are also used to confirm to adopt, but not to delete.

@delvh
Copy link
Member Author

delvh commented Mar 14, 2023

Yep, and I agree that all three other times, delete is not the correct method, so I de-converted these instances now.
(Another approach would be to rename the dialogue, but I would leave that for another PR of its own)

@delvh delvh changed the title WIP: Fix .locale.Tr function not found in delete modal Fix .locale.Tr function not found in delete modal Mar 14, 2023
@delvh delvh marked this pull request as ready for review March 14, 2023 17:29
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Mar 14, 2023
{{svg "octicon-check" 16 "gt-mr-2"}}
{{$.locale.Tr "modal.yes"}}
</button>
</div>
Copy link
Member

@silverwind silverwind Mar 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not make another subtemplate with the trash icon? 3 repetitions is already worthy of a subtemplate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just need a rename.

Rename the delete_modal_actions to modal_actions_yes_no

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to postpone this for a future PR, but yeah, we can of course do it in this one too…

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either is fine, fix bugs first 😁

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 19, 2023
@delvh delvh added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Mar 19, 2023
@delvh delvh enabled auto-merge (squash) March 20, 2023 21:32
@jolheiser
Copy link
Member

🎺 (for merge queue)

@delvh delvh merged commit 6250fe1 into go-gitea:main Mar 21, 2023
@jolheiser jolheiser removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Mar 21, 2023
zjjhot added a commit to zjjhot/gitea that referenced this pull request Mar 21, 2023
* upstream/main:
  Replace a few fontawesome icons with svg (go-gitea#23602)
  Fix pagination on `/notifications/watching` (go-gitea#23564)
  Fix `.locale.Tr` function not found in delete modal (go-gitea#23468)
  fix submodule is nil panic (go-gitea#23588)
  `Publish Review` buttons should indicate why they are disabled (go-gitea#23598)
  Improve template error reporting (go-gitea#23396)
  Polyfill the window.customElements (go-gitea#23592)
  Add CHANGELOG for 1.19.0 (go-gitea#23583)
@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
@delvh delvh deleted the bugfix/500-on-delete-modal branch June 25, 2023 21:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. topic/ui Change the appearance of the Gitea UI type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants