Skip to content

Commit 8f6da32

Browse files
authored
Merge pull request #3502 from beahackman/test2
Guidance Update Feature
2 parents 3eaf327 + 402d3df commit 8f6da32

File tree

11 files changed

+397
-31
lines changed

11 files changed

+397
-31
lines changed

aries-core/src/js/components/core/Identifier/Identifier.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
43
import { Box, Heading, Text } from 'grommet';
54

65
export const Identifier = ({
@@ -13,7 +12,7 @@ export const Identifier = ({
1312
}) => (
1413
<Box align="center" {...rest}>
1514
{children}
16-
<Box>
15+
<Box direction="row" align="center" justify="center" gap="xsmall">
1716
{level ? (
1817
<Heading level={level} margin="none">
1918
{title}

aries-site/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
"main": "src/pages/index.js",
77
"private": true,
88
"dependencies": {
9-
"aries-core": "*",
109
"@mdx-js/loader": "^2.3.0",
1110
"@mdx-js/react": "^2.3.0",
1211
"@next/mdx": "^13.4.4",
12+
"aries-core": "*",
1313
"next": "13.4.4",
1414
"react-ga": "^2.7.0",
1515
"react-syntax-highlighter": "^15.4.4",

aries-site/src/components/cards/ContentCard.js

+42-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1-
import React, { forwardRef } from 'react';
1+
import React, { forwardRef, useContext } from 'react';
22
import PropTypes from 'prop-types';
33
import { Box, CardBody, Image, Text } from 'grommet';
44
import { Identifier } from 'aries-core';
55
import { PreviewImageCard } from './PreviewCard';
66
import { LinkCard } from './LinkCard';
77
import { useDarkMode } from '../../utils';
8+
import { pageVisitTracker } from '../../utils/pageVisitTracker';
9+
import { NotificationTag } from '../../layouts/content/NotificationTag';
10+
import { ViewContext } from '../../pages/_app';
811

912
export const ContentCard = forwardRef(
1013
({ level, topic, minimal, ...rest }, ref) => {
1114
const { description, name, parent, preview, render } = topic;
1215
const darkMode = useDarkMode();
16+
17+
const { contentHistory } = useContext(ViewContext);
18+
let showUpdate = false;
19+
let changeKind;
20+
if (contentHistory && name in contentHistory) {
21+
// still run pageVisitTracker on it
22+
showUpdate = pageVisitTracker(name, contentHistory);
23+
changeKind = contentHistory[name].changeKind;
24+
}
25+
1326
return (
1427
<LinkCard fill pad="medium" ref={ref} {...rest}>
1528
<CardBody gap="large">
@@ -51,9 +64,34 @@ export const ContentCard = forwardRef(
5164
level={level}
5265
>
5366
{parent && parent.icon && !minimal && (
54-
<Box direction="row" align="center" gap="xsmall">
55-
{parent.icon('small', parent.color)}
56-
<Text>{parent.name}</Text>
67+
<Box
68+
direction="row"
69+
align="center"
70+
fill="horizontal"
71+
justify="between"
72+
>
73+
<Box gap="xsmall" direction="row" align="center">
74+
{parent.icon('small', parent.color)}
75+
<Text>{parent.name}</Text>
76+
</Box>
77+
{showUpdate && changeKind === 'Update' && (
78+
<NotificationTag
79+
backgroundColor="teal"
80+
a11yTitle={`There have been updates for ${
81+
render || name
82+
}`}
83+
value="Updated"
84+
size="small"
85+
/>
86+
)}
87+
{showUpdate && changeKind === 'New' && (
88+
<NotificationTag
89+
backgroundColor="purple"
90+
a11yTitle={`There's a new item called ${render || name}`}
91+
value="New!"
92+
size="small"
93+
/>
94+
)}
5795
</Box>
5896
)}
5997
</Identifier>

aries-site/src/components/seo/Meta.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const Meta = ({
1919
const pageContent = 'products';
2020
const csp = `default-src 'self' 'unsafe-eval';
2121
style-src 'self' *.hpe.com/hfws-static/5/css/ 'unsafe-inline';
22-
connect-src 'self' *.githubusercontent.com/grommet/hpe-design-system/ https://www.google-analytics.com https://www.github.com/grommet/ https://eyes.applitools.com *.hpe.com/hpe/api/ https://ca1.qualtrics.com/API/v3/surveys/ https://api.spacexdata.com/;
22+
connect-src 'self' *.githubusercontent.com/grommet/hpe-design-system/ https://api.github.com/repos/grommet/hpe-design-system/pulls https://api.github.com/repos/grommet/hpe-design-system/commits https://www.google-analytics.com https://www.github.com/grommet/ https://eyes.applitools.com *.hpe.com/hpe/api/ https://ca1.qualtrics.com/API/v3/surveys/ https://api.spacexdata.com/;
2323
media-src 'self' https://d3hq6blov2iije.cloudfront.net/media/;
2424
img-src 'self' data: https://www.google-analytics.com https://images.unsplash.com/ http://s.gravatar.com/avatar/ *.hpe.com/hfws-static/5/ https://d3hq6blov2iije.cloudfront.net/images/textures/ https://d3hq6blov2iije.cloudfront.net/images/gradients/ https://d3hq6blov2iije.cloudfront.net/images/hpe-greenlake/;
2525
script-src 'self' *.hpe.com https://www.google-analytics.com/analytics.js https://netlify-cdp-loader.netlify.app/netlify.js ${

aries-site/src/layouts/content/InPageNavigation.js

+36-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import Link from 'next/link';
33
import PropTypes from 'prop-types';
44
import { Box, Button, Nav, Text } from 'grommet';
55
import styled, { ThemeContext } from 'styled-components';
6+
import { StatusGoodSmall } from 'grommet-icons';
67
import { nameToSlug } from '../../utils';
8+
import { ViewContext } from '../../pages/_app';
79

810
const SectionButton = styled(Button)`
911
border-radius: 0 ${props => props.theme.global.edgeSize.xsmall}
@@ -44,7 +46,7 @@ const useActiveHeadingId = (headings, options) => {
4446
return activeHeadingId;
4547
};
4648

47-
export const InPageNavigation = ({ headings }) => {
49+
export const InPageNavigation = ({ headings, title }) => {
4850
const theme = useContext(ThemeContext);
4951

5052
let { large, medium } = theme.global.edgeSize;
@@ -61,6 +63,8 @@ export const InPageNavigation = ({ headings }) => {
6163
// align "Jump to section" with page title at start
6264
const marginTop = `${large + medium}px`;
6365

66+
const { pageUpdateReady, contentHistory } = useContext(ViewContext);
67+
6468
return (
6569
<Box
6670
pad={{ horizontal: 'xxsmall' }} // pad for keyboard focus
@@ -108,6 +112,23 @@ export const InPageNavigation = ({ headings }) => {
108112
if (level.length > 3) subsectionPad = 'large';
109113
else if (level.length === 3) subsectionPad = 'medium';
110114

115+
let sectionList;
116+
let showUpdate = false;
117+
118+
if (
119+
contentHistory &&
120+
title in contentHistory &&
121+
contentHistory[title].update &&
122+
contentHistory[title].sections[0].length > 0
123+
) {
124+
sectionList = contentHistory[title].sections;
125+
Object.values(sectionList).forEach(val => {
126+
if (val.toLowerCase() === headingTitle.toLowerCase()) {
127+
showUpdate = true;
128+
}
129+
});
130+
}
131+
111132
return (
112133
<Link key={index} href={`#${nameToSlug(headingTitle)}`} passHref>
113134
<SectionButton theme={theme} hoverIndicator>
@@ -123,10 +144,23 @@ export const InPageNavigation = ({ headings }) => {
123144
? undefined
124145
: { left: theme.global.borderSize.small }
125146
}
147+
direction="row"
148+
align="top"
149+
gap="small"
126150
>
127151
<Text color="text-strong" size="small" weight="normal">
128152
{headingTitle}
129153
</Text>
154+
{showUpdate && pageUpdateReady && (
155+
<Box background={{ dark: true }} justify="top">
156+
<StatusGoodSmall
157+
a11yTitle="Section has been updated"
158+
size="10px"
159+
color="teal"
160+
height="small"
161+
/>
162+
</Box>
163+
)}
130164
</Box>
131165
</Box>
132166
</SectionButton>
@@ -140,4 +174,5 @@ export const InPageNavigation = ({ headings }) => {
140174

141175
InPageNavigation.propTypes = {
142176
headings: PropTypes.arrayOf(PropTypes.array),
177+
title: PropTypes.string,
143178
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import PropTypes from 'prop-types';
2+
import { Tag } from 'grommet';
3+
4+
export const NotificationTag = ({ backgroundColor, ...rest }) => {
5+
return (
6+
<Tag
7+
border={{
8+
color: 'border-weak',
9+
size: 'xsmall',
10+
style: 'solid',
11+
side: 'all',
12+
}}
13+
background={{ dark: true, color: backgroundColor }}
14+
{...rest}
15+
/>
16+
);
17+
};
18+
19+
NotificationTag.propTypes = {
20+
backgroundColor: PropTypes.string,
21+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import PropTypes from 'prop-types';
2+
import { Anchor, Text, Notification } from 'grommet';
3+
import { useContext } from 'react';
4+
import { ViewContext } from '../../pages/_app';
5+
6+
export const UpdateNotification = ({ name }) => {
7+
const { contentHistory } = useContext(ViewContext);
8+
const updateDate = contentHistory[name]?.date;
9+
10+
if (contentHistory && name in contentHistory) {
11+
return (
12+
<Notification
13+
status="info"
14+
margin={{ bottom: 'medium' }}
15+
width="large"
16+
message={
17+
contentHistory[name]?.changeKind === 'Update' ? (
18+
<Text>
19+
{`${contentHistory[name]?.description} `}
20+
{contentHistory[name]?.action?.length > 1 && (
21+
<Anchor
22+
label="Jump to section"
23+
href={contentHistory[name]?.action}
24+
/>
25+
)}
26+
</Text>
27+
) : (
28+
<Text>
29+
This item is new. Let the Design System team know if you have any
30+
feedback.
31+
</Text>
32+
)
33+
}
34+
title={`${
35+
contentHistory[name]?.changeKind === 'Update'
36+
? 'Updated '
37+
: 'Added on '
38+
}${Intl.DateTimeFormat(undefined, { dateStyle: 'long' }).format(
39+
new Date(updateDate),
40+
)}`}
41+
/>
42+
);
43+
}
44+
return null;
45+
};
46+
47+
UpdateNotification.propTypes = {
48+
name: PropTypes.string,
49+
};

aries-site/src/layouts/main/Layout.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import {
3838
import { Config } from '../../../config';
3939
import { getRelatedContent, getPageDetails } from '../../utils';
4040
import { siteContents } from '../../data/search/contentForSearch';
41+
import { UpdateNotification } from '../content/UpdateNotification';
42+
import { ViewContext } from '../../pages/_app';
4143

4244
export const Layout = ({
4345
backgroundImage,
@@ -127,6 +129,15 @@ export const Layout = ({
127129
{ id: 'main', label: 'Main Content' },
128130
].filter(link => link !== undefined);
129131

132+
const { contentHistory, pageUpdateReady, setPageUpdateReady } =
133+
useContext(ViewContext);
134+
135+
// every time a new page loads, initalize ready
136+
// state to false, until app.js declares otherwise
137+
useEffect(() => {
138+
setPageUpdateReady(false);
139+
}, [setPageUpdateReady, title]);
140+
130141
return (
131142
<>
132143
{/* When a backgroundImage is present, the main page content becomes
@@ -164,7 +175,7 @@ export const Layout = ({
164175
{showInPageNav ? (
165176
<Box pad={{ left: 'large' }}>
166177
<SkipLinkTarget id="toc" />
167-
<InPageNavigation headings={headings} />
178+
<InPageNavigation title={title} headings={headings} />
168179
</Box>
169180
) : undefined}
170181
<Box
@@ -182,6 +193,9 @@ export const Layout = ({
182193
topic={topic}
183194
render={render}
184195
/>
196+
{pageUpdateReady && contentHistory[title]?.update && (
197+
<UpdateNotification name={title} />
198+
)}
185199
{children}
186200
</ContentSection>
187201
{relatedContent.length > 0 && (

aries-site/src/layouts/navigation/SearchResult.js

+38-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
import PropTypes from 'prop-types';
22
import { Box, Paragraph, Text } from 'grommet';
33

4+
import { useContext } from 'react';
45
import { getPageDetails } from '../../utils';
56
import { HighlightPhrase } from '../../components';
67

8+
import { pageVisitTracker } from '../../utils/pageVisitTracker';
9+
import { NotificationTag } from '../content/NotificationTag';
10+
import { ViewContext } from '../../pages/_app';
11+
712
export const SearchResult = ({ query, result }) => {
813
const hub = result.url && result.url.split('/')[1];
914
const parent = getPageDetails(hub);
1015

16+
const { contentHistory } = useContext(ViewContext);
17+
let showUpdate;
18+
let changeKind;
19+
if (result.title in contentHistory) {
20+
showUpdate = pageVisitTracker(result.title, contentHistory);
21+
changeKind = contentHistory[result.title].changeKind;
22+
} else {
23+
showUpdate = false;
24+
}
25+
1126
return (
1227
<Box gap="xsmall" pad={{ vertical: 'xxsmall' }} width="large">
1328
<>
@@ -20,11 +35,29 @@ export const SearchResult = ({ query, result }) => {
2035
</Box>
2136
)}
2237
{result.title && (
23-
<Text size="large" color="text-strong">
24-
<HighlightPhrase phrase={query} fade={false} size="large">
25-
{result.title}
26-
</HighlightPhrase>
27-
</Text>
38+
<Box direction="row" gap="medium" align="center">
39+
<Text size="large" color="text-strong">
40+
<HighlightPhrase phrase={query} fade={false} size="large">
41+
{result.title}
42+
</HighlightPhrase>
43+
</Text>
44+
{showUpdate && changeKind === 'New' && (
45+
<NotificationTag
46+
size="xsmall"
47+
backgroundColor="purple"
48+
value="New!"
49+
a11yTitle={`There's a new item called ${result.title}`}
50+
/>
51+
)}
52+
{showUpdate && changeKind === 'Update' && (
53+
<NotificationTag
54+
size="xsmall"
55+
backgroundColor="teal"
56+
value="Updated"
57+
a11yTitle={`There have been updates for ${result.title}`}
58+
/>
59+
)}
60+
</Box>
2861
)}
2962
</>
3063
{result.matches?.length > 0 ? (

0 commit comments

Comments
 (0)