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

chore: Remove dev tools notification code #19557

Merged
merged 4 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ public int handle(NavigationEvent event) {
// on the UI.
if (preserveOnRefreshTarget) {
setPreservedChain(chain, event);
warnAboutPreserveOnRefreshAndLiveReloadCombo(ui);
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -1040,14 +1039,4 @@ public static void purgeInactiveUIPreservedChainCache(UI inactiveUI) {
}
}

private static void warnAboutPreserveOnRefreshAndLiveReloadCombo(UI ui) {
// Show a warning that live-reload may work counter-intuitively
DeploymentConfiguration configuration = ui.getSession()
.getConfiguration();
if (configuration.getMode() == Mode.DEVELOPMENT_FRONTEND_LIVERELOAD
&& configuration.isDevModeLiveReloadEnabled()) {
ui.getPage().executeJs(
"Vaadin.devTools.showNotification('warning', '@PreserveOnRefresh enabled', 'When refreshing the page in the browser, the server-side Java view instance is reused rather than being recreated.', null, 'preserveOnRefreshWarning')");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@
@NotThreadSafe
public class PreserveOnRefreshLiveReloadIT extends AbstractLiveReloadIT {

@Test
public void notificationShownWhenLoadingPreserveOnRefreshView() {
open();

DevToolsElement liveReload = $(DevToolsElement.class).waitForFirst();
WebElement messageDetails = liveReload.$("*")
.attributeContains("class", "warning").first();
Assert.assertTrue(
messageDetails.getText().contains("@PreserveOnRefresh"));
}

@Test
public void viewIsPreservedOnLiveReload() {
open();
Expand Down
130 changes: 0 additions & 130 deletions vaadin-dev-server/src/main/frontend/vaadin-dev-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,17 +589,9 @@ export class VaadinDevTools extends LitElement {
return active === null || active !== 'false';
}

static notificationDismissed(persistentId: string) {
const shown = window.localStorage.getItem(VaadinDevTools.DISMISSED_NOTIFICATIONS_IN_LOCAL_STORAGE);
return shown !== null && shown.includes(persistentId);
}

@property({ type: String, attribute: false })
splashMessage?: string;

@property({ type: Array, attribute: false })
notifications: Message[] = [];

@property({ type: String, attribute: false })
frontendStatus: ConnectionStatus = ConnectionStatus.UNAVAILABLE;

Expand Down Expand Up @@ -831,137 +823,15 @@ export class VaadinDevTools extends LitElement {
}
}

showNotification(
type: MessageType,
message: string,
details?: string,
link?: string,
persistentId?: string,
dontShowAgainMessage?: string
) {
if (persistentId === undefined || !VaadinDevTools.notificationDismissed(persistentId!)) {
// Do not open persistent message if another is already visible with the same persistentId
const matchingVisibleNotifications = this.notifications
.filter((notification) => notification.persistentId === persistentId)
.filter((notification) => !notification.deleted);
if (matchingVisibleNotifications.length > 0) {
return;
}
const id = this.nextMessageId;
this.nextMessageId += 1;
this.notifications.push({
id,
type,
message,
details,
link,
persistentId,
dontShowAgain: false,
dontShowAgainMessage,
deleted: false
});
// automatically move notification to message tray after a certain amount of time unless it contains a link
if (link === undefined) {
setTimeout(() => {
this.dismissNotification(id);
}, VaadinDevTools.AUTO_DEMOTE_NOTIFICATION_DELAY);
}
this.requestUpdate();
}
}

dismissNotification(id: number) {
const index = this.findNotificationIndex(id);
if (index !== -1 && !this.notifications[index].deleted) {
const notification = this.notifications[index];

// user is explicitly dismissing a notification---after that we won't bug them with it
if (
notification.dontShowAgain &&
notification.persistentId &&
!VaadinDevTools.notificationDismissed(notification.persistentId)
) {
let dismissed = window.localStorage.getItem(VaadinDevTools.DISMISSED_NOTIFICATIONS_IN_LOCAL_STORAGE);
dismissed = dismissed === null ? notification.persistentId : `${dismissed},${notification.persistentId}`;
window.localStorage.setItem(VaadinDevTools.DISMISSED_NOTIFICATIONS_IN_LOCAL_STORAGE, dismissed);
}

notification.deleted = true;

// give some time for the animation
setTimeout(() => {
const idx = this.findNotificationIndex(id);
if (idx !== -1) {
this.notifications.splice(idx, 1);
this.requestUpdate();
}
}, this.transitionDuration);
}
}

findNotificationIndex(id: number): number {
let index = -1;
this.notifications.some((notification, idx) => {
if (notification.id === id) {
index = idx;
return true;
} else {
return false;
}
});
return index;
}

toggleDontShowAgain(id: number) {
const index = this.findNotificationIndex(id);
if (index !== -1 && !this.notifications[index].deleted) {
const notification = this.notifications[index];
notification.dontShowAgain = !notification.dontShowAgain;
this.requestUpdate();
}
}

setActive(yes: boolean) {
this.frontendConnection?.setActive(yes);
this.javaConnection?.setActive(yes);
window.sessionStorage.setItem(VaadinDevTools.ACTIVE_KEY_IN_SESSION_STORAGE, yes ? 'true' : 'false');
}

/* eslint-disable lit/no-template-arrow */
renderMessage(messageObject: Message) {
return html`
<div
class="message ${messageObject.type} ${messageObject.deleted ? 'animate-out' : ''} ${messageObject.details ||
messageObject.link
? 'has-details'
: ''}"
>
<div class="message-content">
<div class="message-heading">${messageObject.message}</div>
<div class="message-details" ?hidden="${!messageObject.details && !messageObject.link}">
${messageObject.details ? html`<p>${messageObject.details}</p>` : ''}
${messageObject.link
? html`<a class="ahreflike" href="${messageObject.link}" target="_blank">Learn more</a>`
: ''}
</div>
${messageObject.persistentId
? html`<div
class="persist ${messageObject.dontShowAgain ? 'on' : 'off'}"
@click=${() => this.toggleDontShowAgain(messageObject.id)}
>
${messageObject.dontShowAgainMessage || 'Don’t show again'}
</div>`
: ''}
</div>
<div class="dismiss-message" @click=${() => this.dismissNotification(messageObject.id)}>Dismiss</div>
</div>
`;
}

/* eslint-disable lit/no-template-map */
render() {
return html`
<div class="notification-tray">${this.notifications.map((msg) => this.renderMessage(msg))}</div>
<div
style="display: none"
class="dev-tools ${this.splashMessage ? 'active' : ''}"
Expand Down
Loading