-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(editor): Rework banners framework and add email confirmation ban…
…ner (#7205) This PR introduces banner framework overhaul: First version of the banner framework was built to allow multiple banners to be shown at the same time. Since that proven to be the case we don't need and it turned out to be pretty messy keeping only one banner visible in such setup, this PR reworks it so it renders only one banner at a time, based on [this priority list](https://www.notion.so/n8n/Banner-stack-60948c4167c743718fde80d6745258d5?pvs=4#6afd052ec8d146a1b0fab8884a19add7) that is assembled together with our product & design team. ### How to test banner stack: 1. Available banners and their priorities are registered [here](https://github.com/n8n-io/n8n/blob/f9f122d46d26565a4cc5dcf63060e7ed9f359e53/packages/editor-ui/src/components/banners/BannerStack.vue#L14) 2. Banners are pushed to stack using `pushBannerToStack` action, for example: ``` useUIStore().pushBannerToStack('TRIAL'); ``` 4. Try pushing different banners to stack and check if only the one with highest priorities is showing up ### How to test the _Email confirmation_ banner: 1. Comment out [this line](https://github.com/n8n-io/n8n/blob/b80d2e3bec59a9abe141a4c808ea2b7f5d9fecce/packages/editor-ui/src/stores/cloudPlan.store.ts#L59), so cloud data is always fetched 2. Create an [override](https://chrome.google.com/webstore/detail/resource-override/pkoacgokdfckfpndoffpifphamojphii) (URL -> File) that will serve user data that triggers this banner: - **URL**: `*/rest/cloud/proxy/admin/user/me` - **File**: ``` { "confirmed": false, "id": 1, "email": "test@test.com", "username": "test" } ``` 3. Run n8n
- Loading branch information
1 parent
2491ccf
commit b0e98b5
Showing
18 changed files
with
424 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 35 additions & 14 deletions
49
packages/editor-ui/src/components/banners/BannerStack.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,59 @@ | ||
<script setup lang="ts"> | ||
<script lang="ts"> | ||
import NonProductionLicenseBanner from '@/components/banners/NonProductionLicenseBanner.vue'; | ||
import TrialOverBanner from '@/components/banners/TrialOverBanner.vue'; | ||
import TrialBanner from '@/components/banners/TrialBanner.vue'; | ||
import V1Banner from '@/components/banners/V1Banner.vue'; | ||
import EmailConfirmationBanner from '@/components/banners/EmailConfirmationBanner.vue'; | ||
import type { Component } from 'vue'; | ||
import type { N8nBanners } from '@/Interface'; | ||
// All banners that can be shown in the app should be registered here. | ||
// This component renders the banner with the highest priority from the banner stack, located in the UI store. | ||
// When registering a new banner, please consult this document to determine it's priority: | ||
// https://www.notion.so/n8n/Banner-stack-60948c4167c743718fde80d6745258d5 | ||
export const N8N_BANNERS: N8nBanners = { | ||
V1: { priority: 350, component: V1Banner as Component }, | ||
TRIAL_OVER: { priority: 260, component: TrialOverBanner as Component }, | ||
EMAIL_CONFIRMATION: { priority: 250, component: EmailConfirmationBanner as Component }, | ||
TRIAL: { priority: 150, component: TrialBanner as Component }, | ||
NON_PRODUCTION_LICENSE: { priority: 140, component: NonProductionLicenseBanner as Component }, | ||
}; | ||
</script> | ||
|
||
<script setup lang="ts"> | ||
import { useUIStore } from '@/stores/ui.store'; | ||
import { onMounted, watch } from 'vue'; | ||
import { computed, onMounted } from 'vue'; | ||
import { getBannerRowHeight } from '@/utils'; | ||
import type { BannerName } from 'n8n-workflow'; | ||
const uiStore = useUIStore(); | ||
function shouldShowBanner(bannerName: BannerName) { | ||
return uiStore.banners[bannerName].dismissed === false; | ||
} | ||
async function updateCurrentBannerHeight() { | ||
const bannerHeight = await getBannerRowHeight(); | ||
uiStore.updateBannersHeight(bannerHeight); | ||
} | ||
onMounted(async () => { | ||
await updateCurrentBannerHeight(); | ||
const currentlyShownBanner = computed(() => { | ||
void updateCurrentBannerHeight(); | ||
if (uiStore.bannerStack.length === 0) return null; | ||
// Find the banner with the highest priority | ||
let banner = N8N_BANNERS[uiStore.bannerStack[0]]; | ||
uiStore.bannerStack.forEach((bannerName, index) => { | ||
if (index === 0) return; | ||
const bannerToCompare = N8N_BANNERS[bannerName]; | ||
if (bannerToCompare.priority > banner.priority) { | ||
banner = bannerToCompare; | ||
} | ||
}); | ||
return banner.component; | ||
}); | ||
watch(uiStore.banners, async () => { | ||
onMounted(async () => { | ||
await updateCurrentBannerHeight(); | ||
}); | ||
</script> | ||
|
||
<template> | ||
<div data-test-id="banner-stack"> | ||
<trial-over-banner v-if="shouldShowBanner('TRIAL_OVER')" /> | ||
<trial-banner v-if="shouldShowBanner('TRIAL')" /> | ||
<v1-banner v-if="shouldShowBanner('V1')" /> | ||
<non-production-license-banner v-if="shouldShowBanner('NON_PRODUCTION_LICENSE')" /> | ||
<component :is="currentlyShownBanner" /> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.