Skip to content

Commit f39c03f

Browse files
committed
[FIX] website: use website systray + remove dead code
1 parent e3d220e commit f39c03f

17 files changed

+68
-856
lines changed

addons/website/static/src/client_actions/website_preview/edit_website_systray_item.xml

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,45 @@
22
<templates xml:space="preserve">
33

44
<t t-name="html_builder.EditWebsiteSystrayItem">
5-
<button t-if="!translatable and !this.websiteService.is404"
6-
class="o-website-btn-custo-primary btn d-flex align-items-center rounded-0 border-0 px-3"
7-
t-on-click="this.onClickEditPage"
8-
accesskey="a">
9-
<span t-if="websiteContext.edition" role="img" aria-label="Loading" class="fa fa-circle-o-notch fa-spin"/>
10-
<t t-else="">Edit</t>
11-
</button>
12-
<Dropdown t-else="">
13-
<button class="o-website-btn-custo-primary o-dropdown-toggle-custo btn rounded-0 border-0 px-3" accesskey="a">
5+
<div class="o_menu_systray_item o_edit_website_container d-none d-md-flex">
6+
<button t-if="!translatable and !this.websiteService.is404"
7+
class="o-website-btn-custo-primary btn d-flex align-items-center rounded-0 border-0 px-3"
8+
t-on-click="this.onClickEditPage"
9+
accesskey="a">
1410
<span t-if="websiteContext.edition" role="img" aria-label="Loading" class="fa fa-circle-o-notch fa-spin"/>
1511
<t t-else="">Edit</t>
1612
</button>
17-
<t t-set-slot="content">
18-
<t t-if="this.websiteService.is404">
19-
<t t-if="translatable">
13+
<Dropdown t-else="">
14+
<button class="o-website-btn-custo-primary o-dropdown-toggle-custo btn rounded-0 border-0 px-3" accesskey="a">
15+
<span t-if="websiteContext.edition" role="img" aria-label="Loading" class="fa fa-circle-o-notch fa-spin"/>
16+
<t t-else="">Edit</t>
17+
</button>
18+
<t t-set-slot="content">
19+
<t t-if="this.websiteService.is404">
20+
<t t-if="translatable">
21+
<DropdownItem onSelected.bind="() => this.attemptStartTranslate()" class="'o_translate_website_dropdown_item'">
22+
Translate 404 page<t t-translation="off"> - <span class="text-muted" t-out="this.currentWebsiteInfo.langName"/></t>
23+
</DropdownItem>
24+
</t>
25+
<DropdownItem onSelected.bind="() => this.translatable ? this.editFromTranslate() : this.onClickEditPage()" class="'o_edit_website_dropdown_item'">
26+
Edit 404 page<t t-if="translatable" t-translation="off"> - <span class="text-muted" t-out="this.currentWebsiteInfo.defaultLangName"/></t>
27+
</DropdownItem>
28+
<DropdownItem onSelected.bind="() => this.props.onNewPage(true)" class="'o_edit_website_dropdown_item'">
29+
<t t-set="url" t-value="this.websiteService.currentLocation"/>
30+
Create <span class="text-muted" t-out="url"/> page
31+
</DropdownItem>
32+
</t>
33+
<t t-else=""><!-- In this case, this is translatable -->
2034
<DropdownItem onSelected.bind="() => this.attemptStartTranslate()" class="'o_translate_website_dropdown_item'">
21-
Translate 404 page<t t-translation="off"> - <span class="text-muted" t-out="this.currentWebsiteInfo.langName"/></t>
35+
Translate<t t-translation="off"> - <span class="text-muted" t-out="this.currentWebsiteInfo.langName"/></t>
36+
</DropdownItem>
37+
<DropdownItem onSelected.bind="() => this.editFromTranslate()" class="'o_edit_website_dropdown_item'">
38+
Edit<t t-translation="off"> - <span class="text-muted" t-out="this.currentWebsiteInfo.defaultLangName"/></t>
2239
</DropdownItem>
2340
</t>
24-
<DropdownItem onSelected.bind="() => this.translatable ? this.editFromTranslate() : this.onClickEditPage()" class="'o_edit_website_dropdown_item'">
25-
Edit 404 page<t t-if="translatable" t-translation="off"> - <span class="text-muted" t-out="this.currentWebsiteInfo.defaultLangName"/></t>
26-
</DropdownItem>
27-
<DropdownItem onSelected.bind="() => this.props.onNewPage(true)" class="'o_edit_website_dropdown_item'">
28-
<t t-set="url" t-value="this.websiteService.currentLocation"/>
29-
Create <span class="text-muted" t-out="url"/> page
30-
</DropdownItem>
31-
</t>
32-
<t t-else=""><!-- In this case, this is translatable -->
33-
<DropdownItem onSelected.bind="() => this.attemptStartTranslate()" class="'o_translate_website_dropdown_item'">
34-
Translate<t t-translation="off"> - <span class="text-muted" t-out="this.currentWebsiteInfo.langName"/></t>
35-
</DropdownItem>
36-
<DropdownItem onSelected.bind="() => this.editFromTranslate()" class="'o_edit_website_dropdown_item'">
37-
Edit<t t-translation="off"> - <span class="text-muted" t-out="this.currentWebsiteInfo.defaultLangName"/></t>
38-
</DropdownItem>
3941
</t>
40-
</t>
41-
</Dropdown>
42+
</Dropdown>
43+
</div>
4244
</t>
4345

4446
</templates>

addons/website/static/src/client_actions/website_preview/website_builder_action.js

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import { isHTTPSorNakedDomainRedirection } from "./utils";
2929
import { WebsiteSystrayItem } from "./website_systray_item";
3030
import { renderToElement } from "@web/core/utils/render";
3131

32+
const websiteSystrayRegistry = registry.category("website_systray");
33+
3234
export class WebsiteBuilder extends Component {
3335
static template = "html_builder.WebsiteBuilder";
3436
static components = { LazyComponent, LocalOverlayContainer, ResizablePanel, ResourceEditor };
@@ -71,9 +73,6 @@ export class WebsiteBuilder extends Component {
7173
[this.websiteContext]
7274
);
7375
});
74-
// TODO: to remove: this is only needed to not use the website systray
75-
// when using the "website preview" app.
76-
this.websiteService.useMysterious = true;
7776
this.translation = !!this.props.action.context.params?.edit_translations;
7877

7978
this.overlayRef = useChildRef();
@@ -124,9 +123,9 @@ export class WebsiteBuilder extends Component {
124123
});
125124
this.publicRootReady = new Deferred();
126125
this.setIframeLoaded();
126+
this.addSystrayItems();
127127
onWillDestroy(() => {
128-
registry.category("systray").remove("website.WebsiteSystrayItem");
129-
this.websiteService.useMysterious = false;
128+
websiteSystrayRegistry.remove("website.WebsiteSystrayItem");
130129
this.websiteService.currentWebsiteId = null;
131130
});
132131

@@ -144,7 +143,8 @@ export class WebsiteBuilder extends Component {
144143
document.querySelector("body").classList.toggle("o_builder_open", isEditing);
145144
if (isEditing) {
146145
setTimeout(() => {
147-
registry.category("systray").remove("website.WebsiteSystrayItem");
146+
websiteSystrayRegistry.remove("website.WebsiteSystrayItem");
147+
websiteSystrayRegistry.trigger("EDIT-WEBSITE");
148148
}, 200);
149149
}
150150
},
@@ -181,15 +181,30 @@ export class WebsiteBuilder extends Component {
181181
};
182182
}
183183

184+
isSystrayDisplayed() {
185+
// TODO: improve this. These are the minimal requirements for at least
186+
// one systray item to be displayed, but it duplicates logic from the
187+
// WebsiteSystrayItem component.
188+
const websiteMetadata = this.websiteService.currentWebsite.metadata;
189+
return (
190+
this.websiteService.websites.length > 1 ||
191+
this.websiteService.isRestrictedEditor ||
192+
(this.websiteService.currentWebsite &&
193+
(websiteMetadata.canPublish || websiteMetadata.editableInBackend))
194+
);
195+
}
196+
184197
addSystrayItems() {
185-
if (!registry.category("systray").contains("website.WebsiteSystrayItem")) {
186-
registry
187-
.category("systray")
188-
.add(
189-
"website.WebsiteSystrayItem",
190-
{ Component: WebsiteSystrayItem, props: this.systrayProps },
191-
{ sequence: -100 }
192-
);
198+
if (!websiteSystrayRegistry.contains("website.WebsiteSystrayItem")) {
199+
websiteSystrayRegistry.add(
200+
"website.WebsiteSystrayItem",
201+
{
202+
Component: WebsiteSystrayItem,
203+
props: this.systrayProps,
204+
isDisplayed: this.isSystrayDisplayed(),
205+
},
206+
{ sequence: -100 }
207+
);
193208
}
194209
}
195210

@@ -389,6 +404,7 @@ export class WebsiteBuilder extends Component {
389404
async reloadIframeAndCloseEditor() {
390405
const isEditing = false;
391406
this.state.isEditing = isEditing;
407+
this.addSystrayItems();
392408
await this.reloadIframe(isEditing);
393409
}
394410

addons/website/static/src/client_actions/website_preview/website_systray_item.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class WebsiteSystrayItem extends Component {
3131
}
3232

3333
get hasMultiWebsites() {
34-
return this.website.hasMultiWebsites;
34+
return this.website.websites.length > 1;
3535
}
3636

3737
get canPublish() {

addons/website/static/src/components/navbar/navbar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ patch(NavBar.prototype, {
4545
},
4646

4747
get shouldDisplayWebsiteSystray() {
48-
return this.websiteService.currentWebsite && this.websiteService.isRestrictedEditor && !this.websiteService.useMysterious;
48+
return this.websiteService.currentWebsite && this.websiteService.isRestrictedEditor;
4949
},
5050

5151
// Somehow a setter is needed in `patch()` to avoid an owl error.
@@ -55,7 +55,7 @@ patch(NavBar.prototype, {
5555
* @override
5656
*/
5757
get systrayItems() {
58-
if (this.shouldDisplayWebsiteSystray) {
58+
if (this.websiteService.currentWebsite) {
5959
const websiteItems = websiteSystrayRegistry
6060
.getEntries()
6161
.map(([key, value], index) => ({ key, ...value, index }))

addons/website/static/src/services/website_service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ export const websiteService = {
245245
invalidateSnippetCache = value;
246246
},
247247

248-
goToWebsite({ websiteId, path, edition, translation, lang, htmlBuilder=false } = {}) {
248+
goToWebsite({ websiteId, path, edition, translation, lang } = {}) {
249249
this.websiteRootInstance = undefined;
250250
if (lang) {
251251
invalidateSnippetCache = true;

addons/website/static/src/systray_items/edit_in_backend.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

addons/website/static/src/systray_items/edit_in_backend.xml

Lines changed: 0 additions & 12 deletions
This file was deleted.

addons/website/static/src/systray_items/edit_website.js

Lines changed: 0 additions & 120 deletions
This file was deleted.

0 commit comments

Comments
 (0)