Skip to content

Commit c10916e

Browse files
authored
Maintenance banner - allow rotation (#3322)
Resolves #3313
1 parent 4a50251 commit c10916e

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

configs/app/ui.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,23 @@ const navigationPromoBanner = (() => {
4242
return envValue || undefined;
4343
})();
4444

45+
const maintenanceAlertMessage = (() => {
46+
const envValue = getEnvValue('NEXT_PUBLIC_MAINTENANCE_ALERT_MESSAGE');
47+
const parsedValue = envValue ? parseEnvJson<Array<string>>(envValue) : undefined;
48+
49+
if (!parsedValue || !Array.isArray(parsedValue)) {
50+
return envValue;
51+
}
52+
53+
if (parsedValue.length < 2) {
54+
return parsedValue[0];
55+
}
56+
57+
const index = Math.floor(Math.random() * parsedValue.length);
58+
59+
return parsedValue[index];
60+
})();
61+
4562
const UI = Object.freeze({
4663
navigation: {
4764
logo: {
@@ -83,7 +100,7 @@ const UI = Object.freeze({
83100
},
84101
},
85102
maintenanceAlert: {
86-
message: getEnvValue('NEXT_PUBLIC_MAINTENANCE_ALERT_MESSAGE'),
103+
message: maintenanceAlertMessage,
87104
},
88105
apiKeysAlert: {
89106
message: getEnvValue('NEXT_PUBLIC_API_KEYS_ALERT_MESSAGE'),

configs/envs/.env.main

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ NEXT_PUBLIC_API_WEBSOCKET_PROTOCOL=ws
1111

1212
NEXT_PUBLIC_HOMEPAGE_HIGHLIGHTS_CONFIG=https://raw.githubusercontent.com/blockscout/frontend-configs/main/configs/homepage-highlights/test.json
1313
# NEXT_PUBLIC_ACCOUNT_AUTH_PROVIDER=dynamic
14+
NEXT_PUBLIC_MAINTENANCE_ALERT_MESSAGE=['<p>Launch your own fully functioning blockchain explorer in minutes. <a href=\\"https://deploy.blockscout.com/?utm_source=blockscout_ad\\">Deploy now</a></p>', '<p>The <b>super</b> duck!</p>']
1415

1516
# Instance ENVs
1617
NEXT_PUBLIC_AD_BANNER_ENABLE_SPECIFY=true

deploy/tools/envs-validator/schemas/ui.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,21 @@ export const miscSchema = yup.object({
211211
NEXT_PUBLIC_HIDE_INDEXING_ALERT_BLOCKS: yup.boolean(),
212212
NEXT_PUBLIC_HIDE_INDEXING_ALERT_INT_TXS: yup.boolean(),
213213
NEXT_PUBLIC_HIDE_NATIVE_COIN_PRICE: yup.boolean(),
214-
NEXT_PUBLIC_MAINTENANCE_ALERT_MESSAGE: yup.string(),
214+
NEXT_PUBLIC_MAINTENANCE_ALERT_MESSAGE: yup
215+
.mixed()
216+
.test(
217+
'shape',
218+
'Invalid schema were provided for NEXT_PUBLIC_MAINTENANCE_ALERT_MESSAGE, it should be either an array of strings or a string',
219+
(data) => {
220+
const isStringSchema = yup.string();
221+
const isArrayOfStringsSchema = yup
222+
.array()
223+
.transform(replaceQuotes)
224+
.json()
225+
.of(yup.string());
226+
227+
return isStringSchema.isValidSync(data) || isArrayOfStringsSchema.isValidSync(data);
228+
}),
215229
NEXT_PUBLIC_COLOR_THEME_DEFAULT: yup.string().oneOf(COLOR_THEME_IDS),
216230
NEXT_PUBLIC_COLOR_THEME_OVERRIDES: yup.object().transform(replaceQuotes).json(),
217231
NEXT_PUBLIC_FONT_FAMILY_HEADING: yup

deploy/tools/envs-validator/test/.env.alt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ NEXT_PUBLIC_NAVIGATION_PROMO_BANNER_CONFIG={'img_url': {'small': 'https://exampl
1313
NEXT_PUBLIC_IS_ACCOUNT_SUPPORTED=true
1414
NEXT_PUBLIC_ACCOUNT_API_KEYS_BUTTON=https://example.com
1515
NEXT_PUBLIC_ACCOUNT_AUTH_PROVIDER=dynamic
16-
NEXT_PUBLIC_ACCOUNT_DYNAMIC_ENVIRONMENT_ID=xxx
16+
NEXT_PUBLIC_ACCOUNT_DYNAMIC_ENVIRONMENT_ID=xxx
17+
NEXT_PUBLIC_MAINTENANCE_ALERT_MESSAGE=['<a href=\"https://example.com\">Hello</a>','Duck me']

docs/ENVS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ Settings for meta tags, OG tags and SEO
378378
| NEXT_PUBLIC_HIDE_INDEXING_ALERT_BLOCKS | `boolean` | Set to `true` to hide indexing alert in the page header about indexing chain's blocks | - | `false` | `true` | v1.17.0+ |
379379
| NEXT_PUBLIC_HIDE_INDEXING_ALERT_INT_TXS | `boolean` | Set to `true` to hide indexing alert in the page footer about indexing block's internal transactions | - | `false` | `true` | v1.17.0+ |
380380
| NEXT_PUBLIC_HIDE_NATIVE_COIN_PRICE | `boolean` | Set to `true` to hide the native coin price in the top bar | - | `false` | `true` | v2.4.0+ |
381-
| NEXT_PUBLIC_MAINTENANCE_ALERT_MESSAGE | `string` | Used for displaying custom announcements or alerts in the header of the site. Could be a regular string or a HTML code. | - | - | `Hello world! 🤪` | v1.13.0+ |
381+
| NEXT_PUBLIC_MAINTENANCE_ALERT_MESSAGE | `string \| Array<string>` | Used to display custom announcements or alerts in the site's header, this feature can handle a single instance or an array of regular strings or HTML code. If an array of instances is provided, the banners will rotate randomly each time the user reloads the page. In this case, please ensure that you properly escape the values of HTML attributes or other special symbols (for example, `<a href=\\"https://example.com\\">Link!</a>`). | - | - | `Hello world! 🤪` | v1.13.0+ |
382382
| NEXT_PUBLIC_API_KEYS_ALERT_MESSAGE | `string` | Used for displaying custom alerts on the API keys page. Could be a regular string or a HTML code. | - | - | `Hello world! 🤪` | v2.7.0+ |
383383
| NEXT_PUBLIC_COLOR_THEME_DEFAULT | `'light' \| 'dim' \| 'midnight' \| 'dark'` | Preferred color theme of the app | - | - | `midnight` | v1.30.0+ |
384384
| NEXT_PUBLIC_COLOR_THEME_OVERRIDES | `string` | Color overrides for the default theme; pass a JSON-like string that represents a subset of the `DEFAULT_THEME_COLORS` object (see `toolkit/theme/foundations/colors.ts`) to customize the app's main colors. See [here](https://www.figma.com/design/4In0X8UADoZaTfZ34HaZ3K/Blockscout-design-system?node-id=29124-23813&t=XOv4ahHUSsTDlNkN-4) the Figma worksheet with description of available color tokens. | - | - | `{'text':{'primary':{'_light':{'value':'rgba(16,17,18,0.80)'},'_dark':{'value':'rgba(222,217,217)'}}}}` | v2.3.0+ |

0 commit comments

Comments
 (0)