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

Allow adding capability to display alert/announcement in the new UI #1232

Merged
merged 2 commits into from
Oct 2, 2023
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
3 changes: 3 additions & 0 deletions configs/app/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ const UI = Object.freeze({
indexingAlert: {
isHidden: getEnvValue(process.env.NEXT_PUBLIC_HIDE_INDEXING_ALERT),
},
maintenanceAlert: {
message: getEnvValue(process.env.NEXT_PUBLIC_MAINTENANCE_ALERT_MESSAGE),
},
explorers: {
items: parseEnvJson<Array<NetworkExplorer>>(getEnvValue(process.env.NEXT_PUBLIC_NETWORK_EXPLORERS)) || [],
},
Expand Down
1 change: 1 addition & 0 deletions configs/envs/.env.pw
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ NEXT_PUBLIC_FOOTER_LINKS=
NEXT_PUBLIC_VIEWS_BLOCK_HIDDEN_FIELDS=
## misc
NEXT_PUBLIC_NETWORK_EXPLORERS=[{'title':'Bitquery','baseUrl':'https://explorer.bitquery.io/','paths':{'tx':'/goerli/tx','address':'/goerli/address','token':'/goerli/token','block':'/goerli/block'}},{'title':'Etherscan','baseUrl':'https://goerli.etherscan.io/','paths':{'tx':'/tx','address':'/address','token':'/token','block':'/block'}}]
NEXT_PUBLIC_MAINTENANCE_ALERT_MESSAGE=

# app features
NEXT_PUBLIC_APP_ENV=testing
Expand Down
1 change: 1 addition & 0 deletions deploy/tools/envs-validator/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ const schema = yup
.json()
.of(networkExplorerSchema),
NEXT_PUBLIC_HIDE_INDEXING_ALERT: yup.boolean(),
NEXT_PUBLIC_MAINTENANCE_ALERT_MESSAGE: yup.string(),

// 5. Features configuration
NEXT_PUBLIC_API_SPEC_URL: yup.string().url(),
Expand Down
1 change: 1 addition & 0 deletions docs/ENVS.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ Settings for meta tags and OG tags
| --- | --- | --- | --- | --- | --- |
| NEXT_PUBLIC_NETWORK_EXPLORERS | `Array<NetworkExplorer>` where `NetworkExplorer` can have following [properties](#network-explorer-configuration-properties) | Used to build up links to transactions, blocks, addresses in other chain explorers. | - | - | `[{'title':'Anyblock','baseUrl':'https://explorer.anyblock.tools','paths':{'tx':'/ethereum/poa/core/tx'}}]` |
| NEXT_PUBLIC_HIDE_INDEXING_ALERT | `boolean` | Set to `true` to hide indexing alert, if the chain indexing isn't completed | - | `false` | `true` |
| 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! 🤪` |

#### Network explorer configuration properties

Expand Down
4 changes: 2 additions & 2 deletions ui/pages/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useRouter } from 'next/router';
import type { FormEvent } from 'react';
import React from 'react';

import IndexingAlertBlocks from 'ui/home/IndexingAlertBlocks';
import useMarketplaceApps from 'ui/marketplace/useMarketplaceApps';
import SearchResultListItem from 'ui/searchResults/SearchResultListItem';
import SearchResultsInput from 'ui/searchResults/SearchResultsInput';
Expand All @@ -17,6 +16,7 @@ import PageTitle from 'ui/shared/Page/PageTitle';
import Pagination from 'ui/shared/pagination/Pagination';
import Thead from 'ui/shared/TheadSticky';
import Header from 'ui/snippets/header/Header';
import HeaderAlert from 'ui/snippets/header/HeaderAlert';
import useSearchQuery from 'ui/snippets/searchBar/useSearchQuery';

const SearchResultsPageContent = () => {
Expand Down Expand Up @@ -181,7 +181,7 @@ const SearchResultsPageContent = () => {

return (
<>
<IndexingAlertBlocks/>
<HeaderAlert/>
<Header renderSearchBar={ renderSearchBar }/>
<AppErrorBoundary>
<Layout.Content>
Expand Down
13 changes: 12 additions & 1 deletion ui/shared/layout/Layout.pw.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import { test, expect } from '@playwright/experimental-ct-react';
import { test as base, expect } from '@playwright/experimental-ct-react';
import React from 'react';

import contextWithEnvs from 'playwright/fixtures/contextWithEnvs';
import TestApp from 'playwright/TestApp';
import buildApiUrl from 'playwright/utils/buildApiUrl';

import Layout from './Layout';

const API_URL = buildApiUrl('homepage_indexing_status');

const test = base.extend({
context: contextWithEnvs([
{
name: 'NEXT_PUBLIC_MAINTENANCE_ALERT_MESSAGE',
value: 'We are currently lacking pictures of <i>ducks</i>. Please <a href="mailto:[email protected]">send</a> us one.',
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
]) as any,
});

test('base view +@mobile', async({ mount, page }) => {
await page.route(API_URL, (route) => route.fulfill({
status: 200,
Expand Down
4 changes: 2 additions & 2 deletions ui/shared/layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React from 'react';

import type { Props } from './types';

import IndexingAlertBlocks from 'ui/home/IndexingAlertBlocks';
import AppErrorBoundary from 'ui/shared/AppError/AppErrorBoundary';
import Header from 'ui/snippets/header/Header';
import HeaderAlert from 'ui/snippets/header/HeaderAlert';

import * as Layout from './components';

Expand All @@ -14,7 +14,7 @@ const LayoutDefault = ({ children }: Props) => {
<Layout.MainArea>
<Layout.SideBar/>
<Layout.MainColumn>
<IndexingAlertBlocks/>
<HeaderAlert/>
<Header/>
<AppErrorBoundary>
<Layout.Content>
Expand Down
4 changes: 2 additions & 2 deletions ui/shared/layout/LayoutError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React from 'react';

import type { Props } from './types';

import IndexingAlertBlocks from 'ui/home/IndexingAlertBlocks';
import AppErrorBoundary from 'ui/shared/AppError/AppErrorBoundary';
import Header from 'ui/snippets/header/Header';
import HeaderAlert from 'ui/snippets/header/HeaderAlert';

import * as Layout from './components';

Expand All @@ -14,7 +14,7 @@ const LayoutError = ({ children }: Props) => {
<Layout.MainArea>
<Layout.SideBar/>
<Layout.MainColumn>
<IndexingAlertBlocks/>
<HeaderAlert/>
<Header/>
<AppErrorBoundary>
<main>
Expand Down
4 changes: 2 additions & 2 deletions ui/shared/layout/LayoutHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React from 'react';

import type { Props } from './types';

import IndexingAlertBlocks from 'ui/home/IndexingAlertBlocks';
import AppErrorBoundary from 'ui/shared/AppError/AppErrorBoundary';
import Header from 'ui/snippets/header/Header';
import HeaderAlert from 'ui/snippets/header/HeaderAlert';

import * as Layout from './components';

Expand All @@ -16,7 +16,7 @@ const LayoutHome = ({ children }: Props) => {
<Layout.MainColumn
paddingTop={{ base: '88px', lg: 9 }}
>
<IndexingAlertBlocks/>
<HeaderAlert/>
<Header isHomePage/>
<AppErrorBoundary>
{ children }
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions ui/snippets/footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import type { ResourceError } from 'lib/api/resources';
import useApiQuery from 'lib/api/useApiQuery';
import useFetch from 'lib/hooks/useFetch';
import useIssueUrl from 'lib/hooks/useIssueUrl';
import IndexingAlertIntTxs from 'ui/home/IndexingAlertIntTxs';
import NetworkAddToWallet from 'ui/shared/NetworkAddToWallet';

import ColorModeToggler from '../header/ColorModeToggler';
import FooterLinkItem from './FooterLinkItem';
import IntTxsIndexingStatus from './IntTxsIndexingStatus';
import getApiVersionUrl from './utils/getApiVersionUrl';

const MAX_LINKS_COLUMNS = 3;
Expand Down Expand Up @@ -109,7 +109,7 @@ const Footer = () => {
<Box flexGrow="1" mb={{ base: 8, lg: 0 }}>
<Flex flexWrap="wrap" columnGap={ 8 } rowGap={ 6 }>
<ColorModeToggler/>
{ !config.UI.indexingAlert.isHidden && <IndexingAlertIntTxs/> }
{ !config.UI.indexingAlert.isHidden && <IntTxsIndexingStatus/> }
<NetworkAddToWallet/>
</Flex>
<Box mt={{ base: 5, lg: '44px' }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { apos, nbsp, ndash } from 'lib/html-entities';
import useSocketChannel from 'lib/socket/useSocketChannel';
import useSocketMessage from 'lib/socket/useSocketMessage';

const IndexingAlertIntTxs = () => {
const IntTxsIndexingStatus = () => {

const { data, isError, isLoading } = useApiQuery('homepage_indexing_status');

Expand Down Expand Up @@ -98,4 +98,4 @@ const IndexingAlertIntTxs = () => {
);
};

export default IndexingAlertIntTxs;
export default IntTxsIndexingStatus;
16 changes: 16 additions & 0 deletions ui/snippets/header/HeaderAlert.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Flex } from '@chakra-ui/react';
import React from 'react';

import IndexingBlocksAlert from './alerts/IndexingBlocksAlert';
import MaintenanceAlert from './alerts/MaintenanceAlert';

const HeaderAlert = () => {
return (
<Flex flexDir="column" rowGap={ 3 } mb={ 6 } _empty={{ display: 'none' }}>
<MaintenanceAlert/>
<IndexingBlocksAlert/>
</Flex>
);
};

export default React.memo(HeaderAlert);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Alert, AlertIcon, AlertTitle, chakra, Skeleton } from '@chakra-ui/react';
import { Alert, AlertIcon, AlertTitle, Skeleton } from '@chakra-ui/react';
import { useQueryClient } from '@tanstack/react-query';
import React from 'react';

Expand All @@ -8,14 +8,11 @@ import type { IndexingStatus } from 'types/api/indexingStatus';
import useApiQuery, { getResourceKey } from 'lib/api/useApiQuery';
import { useAppContext } from 'lib/contexts/app';
import * as cookies from 'lib/cookies';
import useIsMobile from 'lib/hooks/useIsMobile';
import { nbsp, ndash } from 'lib/html-entities';
import useSocketChannel from 'lib/socket/useSocketChannel';
import useSocketMessage from 'lib/socket/useSocketMessage';

const IndexingAlertBlocks = ({ className }: { className?: string }) => {
const isMobile = useIsMobile();

const IndexingBlocksAlert = () => {
const appProps = useAppContext();
const cookiesString = appProps.cookies;
const [ hasAlertCookie ] = React.useState(cookies.get(cookies.NAMES.INDEXING_ALERT, cookiesString) === 'true');
Expand Down Expand Up @@ -57,16 +54,16 @@ const IndexingAlertBlocks = ({ className }: { className?: string }) => {
}

if (isLoading) {
return hasAlertCookie ? <Skeleton h={{ base: '96px', lg: '48px' }} mb={ 6 } w="100%" className={ className }/> : null;
return hasAlertCookie ? <Skeleton h={{ base: '96px', lg: '48px' }} mb={ 6 } w="100%"/> : null;
}

if (data.finished_indexing_blocks !== false) {
return null;
}

return (
<Alert status="info" colorScheme="gray" py={ 3 } borderRadius="12px" mb={ 6 } className={ className }>
{ !isMobile && <AlertIcon/> }
<Alert status="info" colorScheme="gray" py={ 3 } borderRadius="md">
<AlertIcon display={{ base: 'none', lg: 'flex' }}/>
<AlertTitle>
{ `${ data.indexed_blocks_ratio && `${ Math.floor(Number(data.indexed_blocks_ratio) * 100) }% Blocks Indexed${ nbsp }${ ndash } ` }
We're indexing this chain right now. Some of the counts may be inaccurate.` }
Expand All @@ -75,4 +72,4 @@ const IndexingAlertBlocks = ({ className }: { className?: string }) => {
);
};

export default chakra(IndexingAlertBlocks);
export default React.memo(IndexingBlocksAlert);
29 changes: 29 additions & 0 deletions ui/snippets/header/alerts/MaintenanceAlert.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Alert, AlertIcon, AlertTitle } from '@chakra-ui/react';
import React from 'react';

import config from 'configs/app';

const MaintenanceAlert = () => {
if (!config.UI.maintenanceAlert.message) {
return null;
}

return (
<Alert status="info" colorScheme="gray" py={ 3 } borderRadius="md">
<AlertIcon display={{ base: 'none', lg: 'flex' }}/>
<AlertTitle
dangerouslySetInnerHTML={{ __html: config.UI.maintenanceAlert.message }}
sx={{
'& a': {
color: 'link',
_hover: {
color: 'link_hovered',
},
},
}}
/>
</Alert>
);
};

export default MaintenanceAlert;
Loading