@patternfly/quickstarts 2.0.1 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -99,7 +99,7 @@ const App = () => {
99
99
  setTimeout(() => {
100
100
  // simulate loading time to get the quick starts from somewhere
101
101
  load();
102
- }, 1500);
102
+ }, 500);
103
103
  }, []);
104
104
 
105
105
  const withQueryParams = true;
@@ -166,38 +166,17 @@ See above usage of `useLegacyHeaderColors` boolean to opt-out of update. Should
166
166
 
167
167
  ## Quick starts format
168
168
 
169
- Quick starts are parsed as markdown. To write your own quick start, if you use Typescript you can [check out the type definition here](https://github.com/patternfly/patternfly-quickstarts/blob/d52b194119f1ff16e69bf589d49a14931a19ac4b/packages/module/src/utils/quick-start-types.ts#L6).
170
-
171
- A basic quick start has this structure:
172
- ```yaml
173
- metadata:
174
- name: id-of-this-quick-start
175
- spec:
176
- displayName: Get started with Node
177
- durationMinutes: 10
178
- description: 'Import a Node Application from git, build, and deploy it onto OpenShift.'
179
- introduction: >-
180
- **Node.js** is based on the V8 JavaScript engine and allows you to write
181
- server-side JavaScript applications. It provides an I/O model based on
182
- events and non-blocking operations that enables you to write efficient
183
- applications.
184
- tasks:
185
- - title: Create a Node application
186
- description: First task description
187
- review:
188
- failedTaskHelp: This task isn’t verified yet. Try the task again.
189
- instructions: >-
190
- The application is represented by the light grey area with the white border. The deployment is a white circle. Verify that the application was successfully created.
191
- - title: View the build status
192
- description: Second task description
193
- review:
194
- failedTaskHelp: This task isn’t verified yet. Try the task again.
195
- instructions: >-
196
- This build may take a few minutes. When it's finished, a **Complete** badge will surface on the page header beside build name **nodejsrest-http-redhat-1**. Did this badge appear?
197
- conclusion: Your Node application is deployed and ready.
198
- ```
199
-
200
- For more examples of quick starts, [you can go here](https://github.com/patternfly/patternfly-quickstarts/tree/main/packages/dev/src/quickstarts-data/mocks/yamls).
169
+ Quick starts are parsed as markdown. To write your own quick start, if you use Typescript you can [check out the type definition here](https://github.com/patternfly/patternfly-quickstarts/blob/main/packages/module/src/utils/quick-start-types.ts).
170
+
171
+ Here's a [yaml template](https://github.com/patternfly/patternfly-quickstarts/blob/main/packages/dev/src/quickstarts-data/yaml/template.yaml) to get you started on writing your own quick starts.
172
+
173
+ ## Writing quick starts
174
+
175
+ Quick starts are typically written in yaml, but we've also seen projects use asciidoc and json. As long as you can pass in an [array of quick starts](https://github.com/patternfly/patternfly-quickstarts/blob/b086faefb0699e4259ca23d058ed330df1d87f8a/packages/module/src/QuickStartDrawer.tsx#L18) it doesn't really matter in what format your content is sourced.
176
+ - We have a [yaml starter template here](https://github.com/patternfly/patternfly-quickstarts/blob/main/packages/dev/src/quickstarts-data/yaml/template.yaml)
177
+ - The easiest way to preview the content as you're writing it, is to use Visual Studio code with our [quickstarts-preview extension](https://marketplace.visualstudio.com/items?itemName=PatternFly.quickstarts-preview).
178
+ - Alternatively, you can use [github.dev](https://github.dev/) which is basically VS Code on the web, and install the extension there, then edit your yaml content!
179
+ - For guidelines on writing a quick start, the fine folks at OpenShift have created [this guide](https://docs.openshift.com/container-platform/4.9/web_console/creating-quick-start-tutorials.html)
201
180
 
202
181
  ### Highlighting elements
203
182
 
@@ -228,6 +207,30 @@ You can have inline or block copyable text.
228
207
  ```{{copy}}
229
208
  ```
230
209
 
210
+ ## Markdown extensions
211
+ If your source material content is defined in markdown (yaml + markdown / json + markdown), then you can add your own markdown extensions, example:
212
+ ```
213
+ const drawerProps: QuickStartContainerProps = {
214
+ markdown: {
215
+ extensions: [
216
+ // variable substitution example
217
+ // this replaces the strings [APPLICATION] and [PRODUCT]
218
+ {
219
+ type: 'output',
220
+ filter: function(html: string) {
221
+ html = html.replace(/\[APPLICATION\]/g, 'Mercury');
222
+ html = html.replace(/\[PRODUCT\]/g, 'Lightning');
223
+
224
+ return html;
225
+ },
226
+ },
227
+ ],
228
+ },
229
+ };
230
+
231
+ return <QuickStartContainer {...drawerProps}>My page content</QuickStartContainer>
232
+ ```
233
+
231
234
  ## Localization
232
235
  We use English as the default language. You can override the default by providing your own key/value pairs to the `QuickStartContainer` or `QuickStartContextProvider` resourceBundle prop.
233
236
 
@@ -250,4 +253,285 @@ return (
250
253
  Use this [file](https://github.com/patternfly/patternfly-quickstarts/blob/main/packages/module/src/locales/en/quickstart.json) as a base for your translations.
251
254
  Each language is different, especially when it comes to plurals. Try [this utility](https://jsfiddle.net/6bpxsgd4) sourced from [i18next](https://www.i18next.com/translation-function/plurals#how-to-find-the-correct-plural-suffix) to determine the suffixes for the right plural format.
252
255
 
253
- ####
256
+ For localizing the content of quick starts files, we provide the option to include `language` and `countryCode` key to your translated file. Based on these keys you can filter out quick starts. We have a demo of this behaviour in our [demo app](https://quickstarts.netlify.app/quickstarts-localized). You can have a look at the code [here](https://github.com/patternfly/patternfly-quickstarts/blob/main/packages/dev/src/AppLocalized.tsx).
257
+
258
+ ## In-App / In Context Help Panel
259
+
260
+ The quickstarts package is being extended to support a side panel that displays smaller chunks (defined as the `HelpTopic` type) of documentation.
261
+
262
+ ### Help Topic type definition
263
+
264
+ ```ts
265
+ type HelpTopic = {
266
+ name: string; // unique identifier
267
+ title: string; // displayed in header of side panel
268
+ tags: string[]; // metadata to filter/add relationships between HelpTopics and some piece of data in your application
269
+ content: string; // main content of topic, supports markdown
270
+ links: string[]; // list of related information, use markdown link syntax
271
+ };
272
+ ```
273
+
274
+ ### Example Help Topic in yaml with markdown support for content and links
275
+
276
+ ```yml
277
+ - name: auto-deploy
278
+ tags:
279
+ - page-1
280
+ title: Automatic Deployment
281
+ content: |-
282
+ **An Automatic Deployment** is...
283
+
284
+ Etiam viverra et tortor et maximus. Aliquam quis scelerisque metus. Proin luctus pretium sodales. Mauris nibh nibh, auctor eu scelerisque et, hendrerit a metus. Vivamus pharetra bibendum finibus. Sed a pulvinar ipsum. Fusce pharetra venenatis porttitor. Praesent justo metus, consectetur quis erat id, congue varius metus. Suspendisse dui est, tempor nec diam quis, facilisis sodales erat. Curabitur viverra convallis ex. Ut egestas condimentum augue, id euismod leo volutpat vitae. Quisque aliquet ac dolor quis pretium. Nunc at nibh quis arcu maximus elementum vel a mi.
285
+ links:
286
+ - '[Creating quick starts](https://docs.openshift.com/container-platform/4.9/web_console/creating-quick-start-tutorials.html)'
287
+ - '[Redhat Console](https://console.redhat.com/)'
288
+ - name: workspace
289
+ tags:
290
+ - page-1
291
+ - page-2
292
+ - page-3
293
+ title: Workspace
294
+ content: |-
295
+ **A Workspace** is...
296
+
297
+ Fusce nunc risus, vehicula feugiat pellentesque sit amet, pretium non urna. Phasellus nibh mi, ornare quis euismod a, iaculis et eros. Vivamus auctor nunc odio, quis porttitor diam pellentesque nec. In et varius tellus, eget porta urna. Etiam bibendum, est eget mollis lobortis, velit risus efficitur lacus, sed pulvinar sem est vel libero. In sodales placerat tincidunt. Proin vitae risus elit. Ut lobortis ligula est, cursus rhoncus enim scelerisque ac. Donec lacus nisl, tempor porta hendrerit nec, volutpat vitae arcu. Curabitur ornare ullamcorper mi in tincidunt. Aenean efficitur posuere auctor. Pellentesque accumsan mauris vel arcu congue, nec sagittis nisl condimentum. Suspendisse mauris nulla, dignissim at viverra sed, fringilla eu purus.
298
+ links:
299
+ - '[Creating quick starts](https://docs.openshift.com/container-platform/4.9/web_console/creating-quick-start-tutorials.html)'
300
+ - '[Redhat Console](https://console.redhat.com/)'
301
+ ```
302
+
303
+ ### Usage Example
304
+
305
+ See the [HelpTopicDemo](https://github.com/patternfly/patternfly-quickstarts/blob/6b35d3c346b3e92ed0003de955421c8dff58a22b/packages/dev/src/AppHelpTopicDemo.tsx)
306
+
307
+ - Similar to standard Quickstarts usage
308
+ - Load yaml defined `HelpTopic` array
309
+ - Pass `HelpTopicContainerProps`, including loaded `HelpTopics` to the `<HelpTopicContainer/>`
310
+
311
+ ```tsx
312
+ import './App.css';
313
+ import { Page } from '@patternfly/react-core';
314
+ import { LoadingBox, HelpTopicContainerProps, HelpTopicContainer } from '@patternfly/quickstarts';
315
+ import { helpTopics } from './quickstarts-data/quick-start-test-data';
316
+ import React from 'react';
317
+ import i18n from './i18n/i18n';
318
+ import { AppHeader, AppSidebar } from './common/Page';
319
+
320
+ type AppProps = {
321
+ children?: React.ReactNode;
322
+ showCardFooters?: boolean;
323
+ };
324
+
325
+ const AppHelpTopicDemo: React.FC<AppProps> = ({ children }) => {
326
+ const language = localStorage.getItem('bridge/language') || 'en';
327
+ const resourceBundle = i18n.getResourceBundle(language, 'quickstart');
328
+
329
+ const [loading, setLoading] = React.useState(true);
330
+ React.useEffect(() => {
331
+ const load = async () => {
332
+ setLoading(false);
333
+ };
334
+ setTimeout(() => {
335
+ load();
336
+ }, 500);
337
+ }, []);
338
+
339
+ const inContextHelpProps: HelpTopicContainerProps = {
340
+ helpTopics,
341
+ resourceBundle,
342
+ language,
343
+ loading,
344
+ };
345
+
346
+ return (
347
+ <React.Suspense fallback={<LoadingBox />}>
348
+ <HelpTopicContainer {...inContextHelpProps}>
349
+ <Page header={AppHeader} sidebar={AppSidebar} isManagedSidebar>
350
+ {children}
351
+ </Page>
352
+ </HelpTopicContainer>
353
+ </React.Suspense>
354
+ );
355
+ };
356
+ ```
357
+
358
+ In the example above `<HelpTopicContainer />` wraps the `<Page/>` element as well as a mock "console" showing how to trigger the side panel and allow navigation to all `HelpTopics` available on each console page:
359
+
360
+ Live [preview](https://deploy-preview-140--quickstarts.netlify.app/in-context-help) of code below:
361
+
362
+ ```tsx
363
+ import * as React from 'react';
364
+ import {
365
+ Banner,
366
+ Button,
367
+ Divider,
368
+ Form,
369
+ FormGroup,
370
+ PageSection,
371
+ Popover,
372
+ Split,
373
+ SplitItem,
374
+ TextInput,
375
+ Title,
376
+ } from '@patternfly/react-core';
377
+ import { HelpTopicContext, HelpTopicContextValues } from '@patternfly/quickstarts';
378
+ import HelpIcon from '@patternfly/react-icons/dist/js/icons/help-icon';
379
+ import { HelpTopic } from '@patternfly/quickstarts/dist/utils/help-topic-types';
380
+
381
+ // Example usage of topics, render certain topics depending on the page
382
+ // used this case when "consolePageState" below is between 4 - 6
383
+ // these HelpTopics with the following names will be rendered
384
+ const helpTopicNamesByPage = [
385
+ ['auto-deploy', 'code-sample', 'manual-deployment'],
386
+ ['manual-deployment', 'target-port', 'build-configuration'],
387
+ ['deploy-configuration', 'environment-variables', 'health-checks'],
388
+ ];
389
+
390
+ interface FormGroupWithHelpTopicPopoverProps extends React.HTMLProps<HTMLDivElement> {
391
+ topic: HelpTopic;
392
+ }
393
+
394
+ // Example usage of setActiveHelpTopicByName()
395
+ // render a popover with a learn more link to open the drawer
396
+ const FormGroupWithHelpTopicPopover: React.FC<FormGroupWithHelpTopicPopoverProps> = ({ topic }) => {
397
+ const { setActiveHelpTopicByName } = React.useContext<HelpTopicContextValues>(HelpTopicContext);
398
+
399
+ return (
400
+ <FormGroup
401
+ label={topic.title}
402
+ isRequired
403
+ fieldId={topic.name}
404
+ key={topic.name}
405
+ labelIcon={
406
+ <Popover
407
+ bodyContent={(hide) => (
408
+ <div>
409
+ {topic.title} is quite amaizing{' '}
410
+ <Button
411
+ variant="link"
412
+ onClick={() => {
413
+ setActiveHelpTopicByName(topic.name);
414
+ hide();
415
+ }}
416
+ >
417
+ Learn more
418
+ </Button>
419
+ </div>
420
+ )}
421
+ >
422
+ <Button variant="plain">
423
+ <HelpIcon noVerticalAlign />
424
+ </Button>
425
+ </Popover>
426
+ }
427
+ >
428
+ <TextInput isRequired type="text" id={topic.name} />
429
+ </FormGroup>
430
+ );
431
+ };
432
+
433
+ export const MockConsole: React.FC = () => {
434
+ const { helpTopics, setFilteredHelpTopics, filteredHelpTopics, setActiveHelpTopicByName } =
435
+ React.useContext<HelpTopicContextValues>(HelpTopicContext);
436
+
437
+ // mock console page identifiers: 1 - 6
438
+ // click handlers to change page
439
+ const [consolePageState, setConsolePageState] = React.useState(1);
440
+
441
+ const handleClickNext = () => {
442
+ setActiveHelpTopicByName('');
443
+ if (consolePageState === 6) {
444
+ setConsolePageState(1);
445
+ return;
446
+ }
447
+ setConsolePageState(consolePageState + 1);
448
+ };
449
+
450
+ const handleClickBack = () => {
451
+ setActiveHelpTopicByName('');
452
+ if (consolePageState === 6) {
453
+ setConsolePageState(4);
454
+ return;
455
+ }
456
+ setConsolePageState(consolePageState - 1);
457
+ };
458
+
459
+ // Example usage setFilteredHelpTopics()
460
+ // After rendering the console, set the filtered help topics
461
+ React.useEffect(() => {
462
+ // set filtered topics using tags, matching to the consolePageState
463
+ if (consolePageState < 4) {
464
+ const topics = helpTopics.filter((topic: HelpTopic) => {
465
+ const pageTagNumbers = topic.tags.map((tag: string) => {
466
+ return Number(tag.slice(-1));
467
+ });
468
+ return pageTagNumbers.includes(consolePageState);
469
+ });
470
+ setFilteredHelpTopics(topics);
471
+ } else {
472
+ // set filtered topics using the appropriate helpTopicNamesByPage array above
473
+ setFilteredHelpTopics(
474
+ helpTopics.filter((topic) => {
475
+ return helpTopicNamesByPage[consolePageState - 4].includes(topic.name);
476
+ }),
477
+ );
478
+ }
479
+ }, [consolePageState, helpTopics, setFilteredHelpTopics]);
480
+
481
+ // Render filteredHelpTopics in a <FormGroupWithHelpTopicPopover />
482
+ const formGroupsFromTags = filteredHelpTopics.map((topic: HelpTopic, index) => {
483
+ return <FormGroupWithHelpTopicPopover topic={topic} key={index} />;
484
+ });
485
+
486
+ // From an array of topic names, render all topics in a <FormGroupWithHelpTopicPopover />
487
+ const formGroupsFromTopicNames = (helpTopicNames: string[]) => {
488
+ return helpTopicNames.map((topicName: string, index) => {
489
+ const topicToRender = helpTopics.find((topic) => {
490
+ return topicName === topic.name;
491
+ });
492
+
493
+ if (topicToRender) {
494
+ return <FormGroupWithHelpTopicPopover topic={topicToRender} key={index} />;
495
+ }
496
+ });
497
+ };
498
+
499
+ return (
500
+ <>
501
+ <PageSection>
502
+ <Banner variant="info">
503
+ <Title headingLevel="h1">Console Page {consolePageState}</Title>
504
+ </Banner>
505
+ </PageSection>
506
+ <PageSection>
507
+ <Title headingLevel="h3">
508
+ Example usage of help topics opened via popover{' '}
509
+ <b>
510
+ {consolePageState < 4
511
+ ? 'using tags that match the Console Page number'
512
+ : 'by defining which help topics should be present on each page'}
513
+ </b>
514
+ </Title>
515
+ <Divider />
516
+ <Form>
517
+ {consolePageState < 4
518
+ ? formGroupsFromTags
519
+ : formGroupsFromTopicNames(helpTopicNamesByPage[consolePageState - 4])}
520
+ </Form>
521
+ </PageSection>
522
+ <PageSection>
523
+ <Split hasGutter>
524
+ <SplitItem>
525
+ <Button onClick={handleClickBack} variant="tertiary">
526
+ Previous
527
+ </Button>
528
+ </SplitItem>
529
+ <SplitItem>
530
+ <Button onClick={handleClickNext}>Next</Button>
531
+ </SplitItem>
532
+ </Split>
533
+ </PageSection>
534
+ </>
535
+ );
536
+ };
537
+ ```
@@ -16,6 +16,7 @@ export declare type OwnerReference = {
16
16
  blockOwnerDeletion?: boolean;
17
17
  };
18
18
  export declare type ObjectMetadata = {
19
+ name: string;
19
20
  annotations?: {
20
21
  [key: string]: string;
21
22
  };
@@ -30,9 +31,12 @@ export declare type ObjectMetadata = {
30
31
  [key: string]: string;
31
32
  };
32
33
  managedFields?: any[];
33
- name?: string;
34
34
  namespace?: string;
35
35
  ownerReferences?: OwnerReference[];
36
36
  resourceVersion?: string;
37
37
  uid?: string;
38
+ language?: string;
39
+ country?: string;
40
+ locale?: string;
41
+ [key: string]: any;
38
42
  };
@@ -0,0 +1,7 @@
1
+ import './showdown-extension.scss';
2
+ declare const useAdmonitionShowdownExtension: () => {
3
+ type: string;
4
+ regex: RegExp;
5
+ replace: (text: string, content: string, admonitionLabel: string, admonitionType: string, groupId: string) => string;
6
+ };
7
+ export default useAdmonitionShowdownExtension;
@@ -1,3 +1,4 @@
1
1
  export { default as MarkdownCopyClipboard } from './MarkdownCopyClipboard';
2
2
  export { default as useInlineCopyClipboardShowdownExtension } from './inline-clipboard-extension';
3
3
  export { default as useMultilineCopyClipboardShowdownExtension } from './multiline-clipboard-extension';
4
+ export { default as useAdmonitionShowdownExtension } from './admonition-extension';
@@ -0,0 +1,26 @@
1
+ import './QuickStartDrawer.scss';
2
+ import * as React from 'react';
3
+ import { QuickStartContextValues } from './utils/quick-start-context';
4
+ import { HelpTopic } from './utils/help-topic-types';
5
+ export interface HelpTopicContainerProps extends React.HTMLProps<HTMLDivElement> {
6
+ helpTopics: HelpTopic[];
7
+ resourceBundle?: any;
8
+ language?: string;
9
+ loading?: boolean;
10
+ /**
11
+ * Additional markdown extensions and renderers to use
12
+ * TODO: example usage - In the meantime you can take a look at:
13
+ * https://github.com/openshift/console/blob/master/frontend/packages/console-app/src/components/quick-starts/utils/quick-start-context.tsx#L235
14
+ */
15
+ markdown?: {
16
+ extensions?: any[];
17
+ renderExtension?: (docContext: HTMLDocument, rootSelector: string) => React.ReactNode;
18
+ };
19
+ contextProps?: QuickStartContextValues;
20
+ }
21
+ export declare const HelpTopicContainer: React.FC<HelpTopicContainerProps>;
22
+ export interface HelpTopicDrawerProps extends React.HTMLProps<HTMLDivElement> {
23
+ helpTopics?: HelpTopic[];
24
+ children?: React.ReactNode;
25
+ }
26
+ export declare const HelpTopicDrawer: React.FC<HelpTopicDrawerProps>;
@@ -0,0 +1,11 @@
1
+ import * as React from 'react';
2
+ import { HelpTopic } from './utils/help-topic-types';
3
+ import './QuickStartPanelContent.scss';
4
+ declare type HelpTopicPanelContentProps = {
5
+ activeHelpTopic: HelpTopic;
6
+ filteredHelpTopics?: HelpTopic[];
7
+ isResizable?: boolean;
8
+ onClose: () => void;
9
+ };
10
+ declare const HelpTopicPanelContent: React.FC<HelpTopicPanelContentProps>;
11
+ export default HelpTopicPanelContent;
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { QuickStart } from './utils/quick-start-types';
3
- declare type QuickStartCatalogPageProps = {
3
+ export declare type QuickStartCatalogPageProps = {
4
4
  quickStarts?: QuickStart[];
5
5
  showFilter?: boolean;
6
6
  sortFnc?: (q1: QuickStart, q2: QuickStart) => number;
@@ -12,4 +12,3 @@ export declare const QuickStartCatalogEmptyState: ({ clearFilters }: {
12
12
  clearFilters: any;
13
13
  }) => JSX.Element;
14
14
  export declare const QuickStartCatalogPage: React.FC<QuickStartCatalogPageProps>;
15
- export {};
@@ -9,6 +9,7 @@ declare type QuickStartTaskHeaderProps = {
9
9
  size?: 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl';
10
10
  isActiveTask?: boolean;
11
11
  onTaskSelect: (index: number) => void;
12
+ chidlren?: React.ReactNode;
12
13
  };
13
14
  declare const QuickStartTaskHeader: React.FC<QuickStartTaskHeaderProps>;
14
15
  export default QuickStartTaskHeader;
package/dist/index.d.ts CHANGED
@@ -3,9 +3,12 @@ export * from './QuickStartCatalogPage';
3
3
  export * from './catalog';
4
4
  export * from './ConsoleInternal/components/utils';
5
5
  export * from './QuickStartDrawer';
6
+ export * from './HelpTopicDrawer';
6
7
  export * from './utils/const';
7
8
  export * from './utils/quick-start-context';
8
9
  export * from './utils/quick-start-types';
10
+ export * from './utils/help-topic-context';
11
+ export * from './utils/help-topic-types';
9
12
  export * from './utils/quick-start-utils';
10
13
  export * from './utils/useLocalStorage';
11
14
  export { default as QuickStartPanelContent } from './QuickStartPanelContent';