openfoodfoundation / openfoodnetwork

Connect suppliers, distributors and consumers to trade local produce.
https://www.openfoodnetwork.org
GNU Affero General Public License v3.0
1.12k stars 723 forks source link

Admin: Remove `#!#` anchor from enterprise preferences page #10541

Closed jibees closed 1 year ago

jibees commented 1 year ago

Context: Can't use reflex on page that contains #!# in URL as it is a non-valid URI. https://github.com/openfoodfoundation/openfoodnetwork/pull/9729

In this PR, I wanted to use reflex to invite a manager (instead of using controller, and having a stimulusjs controller that does the request ...) ; this seems to be impossible since the url of the page which is requested the reflex is not a correct URI and then stimulus_reflex (tested both 3.5.0.pre9 and 3.5.0.pre10) throw an error:

Reflex InviteManager#invite failed: bad URI(is not URI?): "http://localhost:3000/admin/enterprises/fred-s-farm/edit#!#users_panel" [http://localhost:3000/admin/enterprises/fred-s-farm/edit#!#users_panel]
Users/jibees/.rbenv/versions/3.0.3/lib/ruby/3.0.0/uri/common.rb:171:in `parse'
/Users/jibees/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/stimulus_reflex-3.5.0.pre10/lib/stimulus_reflex/reflex_data.rb:63:in `url_params'
/Users/jibees/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/stimulus_reflex-3.5.0.pre10/lib/stimulus_reflex/reflex_data.rb:55:in `params'
irb(main):001:0> URI.parse("http://localhost:3000/admin/enterprises/fred-s-farm/edit#!#users_panel")
/Users/jibees/.rbenv/versions/3.0.3/lib/ruby/3.0.0/uri/rfc3986_parser.rb:67:in `split': bad URI(is not URI?): "http://localhost:3000/admin/enterprises/fred-s-farm/edit#!#users_panel" (URI::InvalidURIError)                             
irb(main):002:0> URI.parse("http://localhost:3000/admin/enterprises/fred-s-farm/edit##users_panel")
/Users/jibees/.rbenv/versions/3.0.3/lib/ruby/3.0.0/uri/rfc3986_parser.rb:67:in `split': bad URI(is not URI?): "http://localhost:3000/admin/enterprises/fred-s-farm/edit##users_panel" (URI::InvalidURIError)                              
irb(main):003:0> URI.parse("http://localhost:3000/admin/enterprises/fred-s-farm/edit#users_panel")
=> #<URI::HTTP http://localhost:3000/admin/enterprises/fred-s-farm/edit#users_panel>
irb(main):004:0> 

Blocks #9729

jibees commented 1 year ago

Those two lines should be added to enable this:

$locationProvider.hashPrefix('')
$locationProvider.html5Mode({enabled: true, requireBase: false})

probably to file app/assets/javascripts/admin/admin_ofn.js.coffee

Actually, it seems that, on page /admin/enterprises/* this file doesn't run the #config() method (something I don't understand). I've tested then by adding those two lines into /admin/utils/utils.js.coffee#config() file and it works on pages /admin/enterprises/* which is the purpose of this issue.

jibees commented 1 year ago

Closed via https://github.com/openfoodfoundation/openfoodnetwork/pull/10575