|
1 | 1 | import * as _ from 'lodash-es';
|
2 | 2 | import * as React from 'react';
|
3 |
| -import { connect } from 'react-redux'; |
4 |
| -import { Link } from 'react-router-dom-v5-compat'; |
5 |
| -import { Button, Hint, HintTitle, HintBody } from '@patternfly/react-core'; |
6 |
| -import { useTranslation, Trans } from 'react-i18next'; |
| 3 | +import { useSelector } from 'react-redux'; |
| 4 | +import { Button, ButtonVariant, Divider, EmptyStateVariant } from '@patternfly/react-core'; |
| 5 | +import { useTranslation } from 'react-i18next'; |
7 | 6 |
|
8 | 7 | import { FLAGS } from '@console/shared/src/constants';
|
9 | 8 | import { useActiveNamespace } from '@console/shared/src/hooks/useActiveNamespace';
|
10 | 9 | import { useActivePerspective } from '@console/dynamic-plugin-sdk';
|
11 |
| -import { createProjectMessageStateToProps } from '../reducers/ui'; |
12 |
| -import { Disabled, ExternalLink, openshiftHelpBase, LinkifyExternal } from './utils'; |
13 |
| -import { connectToFlags } from '../reducers/connectToFlags'; |
| 10 | +import { Disabled, openshiftHelpBase, LinkifyExternal, ConsoleEmptyState } from './utils'; |
14 | 11 | import { ProjectModel } from '../models';
|
15 | 12 | import { K8sResourceKind } from '../module/k8s/types';
|
16 | 13 | import { useCreateNamespaceOrProjectModal } from '@console/shared/src/hooks/useCreateNamespaceOrProjectModal';
|
| 14 | +import { RootState } from '../redux'; |
| 15 | +import { useFlag } from '@console/shared/src'; |
| 16 | +import { ExternalLinkAltIcon, OpenshiftIcon } from '@patternfly/react-icons'; |
17 | 17 |
|
18 |
| -export const OpenShiftGettingStarted = connect(createProjectMessageStateToProps)( |
19 |
| - ({ canCreate = true, createProjectMessage }: OpenShiftGettingStartedProps) => { |
20 |
| - const { t } = useTranslation(); |
21 |
| - const [, setActiveNamespace] = useActiveNamespace(); |
22 |
| - const [perspective] = useActivePerspective(); |
23 |
| - const createNamespaceOrProjectModal = useCreateNamespaceOrProjectModal(); |
| 18 | +export const OpenShiftGettingStarted: React.FCC<OpenShiftGettingStartedProps> = ({ title }) => { |
| 19 | + const { t } = useTranslation(); |
| 20 | + const [, setActiveNamespace] = useActiveNamespace(); |
| 21 | + const [perspective] = useActivePerspective(); |
| 22 | + const canCreateNamespace = useFlag(FLAGS.CAN_CREATE_NS); |
| 23 | + const canCreateProject = useFlag(FLAGS.CAN_CREATE_PROJECT); |
| 24 | + const canCreate = canCreateNamespace || canCreateProject; |
| 25 | + const createProjectMessage = useSelector(({ UI }: RootState) => UI.get('createProjectMessage')); |
| 26 | + const createNamespaceOrProjectModal = useCreateNamespaceOrProjectModal(); |
| 27 | + const onClickCreate = () => |
| 28 | + createNamespaceOrProjectModal({ |
| 29 | + onSubmit: |
| 30 | + perspective !== 'admin' |
| 31 | + ? (project: K8sResourceKind) => { |
| 32 | + setActiveNamespace(project.metadata?.name); |
| 33 | + } |
| 34 | + : undefined, |
| 35 | + }); |
| 36 | + |
| 37 | + const primaryActions = canCreate |
| 38 | + ? [ |
| 39 | + <Button key="create-project-action" variant={ButtonVariant.primary} onClick={onClickCreate}> |
| 40 | + {t('public~Create a new Project')} |
| 41 | + </Button>, |
| 42 | + ] |
| 43 | + : []; |
24 | 44 |
|
25 |
| - return ( |
26 |
| - <> |
27 |
| - {canCreate ? ( |
28 |
| - <p> |
29 |
| - {t( |
30 |
| - 'public~OpenShift helps you quickly develop, host, and scale applications. To get started, create a project for your application.', |
31 |
| - )} |
32 |
| - </p> |
33 |
| - ) : ( |
34 |
| - <p> |
35 |
| - {t( |
36 |
| - "public~OpenShift helps you quickly develop, host, and scale applications. To get started, you'll need a project. Currently, you can't create or access any projects.", |
37 |
| - )} |
38 |
| - {!createProjectMessage && ( |
39 |
| - <> {t("public~You'll need to contact a cluster administrator for help.")}</> |
40 |
| - )} |
41 |
| - </p> |
42 |
| - )} |
43 |
| - {createProjectMessage && ( |
44 |
| - <p className="co-pre-line"> |
45 |
| - <LinkifyExternal>{createProjectMessage}</LinkifyExternal> |
46 |
| - </p> |
47 |
| - )} |
| 45 | + const secondaryActions = [ |
| 46 | + <Button |
| 47 | + key="download-cli-tools" |
| 48 | + variant={ButtonVariant.link} |
| 49 | + component="a" |
| 50 | + href="/command-line-tools" |
| 51 | + > |
| 52 | + {t('public~Download command-line tools')} |
| 53 | + </Button>, |
| 54 | + <Button |
| 55 | + key="visit-docs" |
| 56 | + variant={ButtonVariant.link} |
| 57 | + component="a" |
| 58 | + href={openshiftHelpBase} |
| 59 | + target="_blank" |
| 60 | + rel="noopener noreferrer" |
| 61 | + icon={<ExternalLinkAltIcon />} |
| 62 | + > |
| 63 | + {t('public~View documentation')} |
| 64 | + </Button>, |
| 65 | + ]; |
| 66 | + return ( |
| 67 | + <ConsoleEmptyState |
| 68 | + variant={EmptyStateVariant.xl} |
| 69 | + icon={OpenshiftIcon} |
| 70 | + title={title || t('public~Getting started in OpenShift')} |
| 71 | + primaryActions={primaryActions} |
| 72 | + secondaryActions={secondaryActions} |
| 73 | + > |
| 74 | + {canCreate ? ( |
48 | 75 | <p>
|
49 |
| - <Trans t={t} ns="public"> |
50 |
| - To learn more, visit the OpenShift{' '} |
51 |
| - <ExternalLink href={openshiftHelpBase}>documentation</ExternalLink>. |
52 |
| - </Trans> |
| 76 | + {t( |
| 77 | + 'public~OpenShift helps you quickly develop, host, and scale applications. To get started, create a project for your application.', |
| 78 | + )} |
53 | 79 | </p>
|
| 80 | + ) : ( |
54 | 81 | <p>
|
55 |
| - <Trans t={t} ns="public"> |
56 |
| - Download the <Link to="/command-line-tools">command-line tools</Link> |
57 |
| - </Trans> |
| 82 | + {t( |
| 83 | + "public~OpenShift helps you quickly develop, host, and scale applications. To get started, you'll need a project. Currently, you can't create or access any projects.", |
| 84 | + )} |
| 85 | + {!createProjectMessage && |
| 86 | + t("public~ You'll need to contact a cluster administrator for help.")} |
58 | 87 | </p>
|
59 |
| - {canCreate ? ( |
60 |
| - <Button |
61 |
| - variant="link" |
62 |
| - onClick={() => |
63 |
| - createNamespaceOrProjectModal({ |
64 |
| - onSubmit: |
65 |
| - perspective !== 'admin' |
66 |
| - ? (project: K8sResourceKind) => { |
67 |
| - setActiveNamespace(project.metadata?.name); |
68 |
| - } |
69 |
| - : undefined, |
70 |
| - }) |
71 |
| - } |
72 |
| - > |
73 |
| - {t('public~Create a new project')} |
74 |
| - </Button> |
75 |
| - ) : null} |
76 |
| - </> |
77 |
| - ); |
78 |
| - }, |
79 |
| -); |
| 88 | + )} |
| 89 | + {createProjectMessage && ( |
| 90 | + <p className="co-pre-line"> |
| 91 | + <LinkifyExternal>{createProjectMessage}</LinkifyExternal> |
| 92 | + </p> |
| 93 | + )} |
| 94 | + </ConsoleEmptyState> |
| 95 | + ); |
| 96 | +}; |
80 | 97 |
|
81 | 98 | type WithStartGuide = <P>(
|
82 | 99 | WrappedComponent: React.ComponentType<P & WithStartGuideProps>,
|
83 | 100 | disable?: boolean,
|
84 | 101 | ) => React.ComponentType<P>;
|
85 | 102 |
|
86 |
| -export const withStartGuide: WithStartGuide = (WrappedComponent, disable = true) => |
87 |
| - connectToFlags<any>( |
88 |
| - FLAGS.SHOW_OPENSHIFT_START_GUIDE, |
89 |
| - FLAGS.CAN_CREATE_NS, |
90 |
| - FLAGS.CAN_CREATE_PROJECT, |
91 |
| - )(({ flags, ...rest }: any) => { |
92 |
| - const { kindObj } = rest; |
93 |
| - const kind = _.get(kindObj, 'kind', rest.kind); |
94 |
| - const { t } = useTranslation(); |
| 103 | +export const withStartGuide: WithStartGuide = (WrappedComponent, disable = true) => ( |
| 104 | + props: any, |
| 105 | +) => { |
| 106 | + const showOpenshiftStartGuide = useFlag(FLAGS.SHOW_OPENSHIFT_START_GUIDE); |
| 107 | + const { kindObj } = props; |
| 108 | + const kind = _.get(kindObj, 'kind', props.kind); |
95 | 109 |
|
96 |
| - // The start guide does not need to be shown on the Projects list page. |
97 |
| - if (kind === ProjectModel.kind) { |
98 |
| - return <WrappedComponent {...rest} />; |
99 |
| - } |
| 110 | + // The start guide does not need to be shown on the Projects list page. |
| 111 | + if (kind === ProjectModel.kind || !showOpenshiftStartGuide) { |
| 112 | + return <WrappedComponent {...props} />; |
| 113 | + } |
100 | 114 |
|
101 |
| - if (flags[FLAGS.SHOW_OPENSHIFT_START_GUIDE]) { |
102 |
| - return ( |
103 |
| - <> |
104 |
| - <Hint className="pf-v6-u-m-md"> |
105 |
| - <HintTitle>{t('public~Getting Started')}</HintTitle> |
106 |
| - <HintBody> |
107 |
| - <OpenShiftGettingStarted |
108 |
| - canCreate={flags[FLAGS.CAN_CREATE_NS] || flags[FLAGS.CAN_CREATE_PROJECT]} |
109 |
| - /> |
110 |
| - </HintBody> |
111 |
| - </Hint> |
112 |
| - {!disable || (rest.kindObj && !rest.kindObj.namespaced) ? ( |
113 |
| - <WrappedComponent {...rest} noProjectsAvailable /> |
114 |
| - ) : ( |
115 |
| - <Disabled> |
116 |
| - <WrappedComponent {...rest} noProjectsAvailable /> |
117 |
| - </Disabled> |
118 |
| - )} |
119 |
| - </> |
120 |
| - ); |
121 |
| - } |
122 |
| - return <WrappedComponent {...rest} />; |
123 |
| - }); |
| 115 | + return ( |
| 116 | + <> |
| 117 | + <OpenShiftGettingStarted /> |
| 118 | + <Divider /> |
| 119 | + {!disable || (props.kindObj && !props.kindObj.namespaced) ? ( |
| 120 | + <WrappedComponent {...props} noProjectsAvailable /> |
| 121 | + ) : ( |
| 122 | + <Disabled> |
| 123 | + <WrappedComponent {...props} noProjectsAvailable /> |
| 124 | + </Disabled> |
| 125 | + )} |
| 126 | + </> |
| 127 | + ); |
| 128 | +}; |
124 | 129 |
|
125 | 130 | type OpenShiftGettingStartedProps = {
|
126 |
| - canCreate: boolean; |
127 |
| - createProjectMessage: string; |
| 131 | + title?: string; |
128 | 132 | };
|
129 | 133 |
|
130 | 134 | export type WithStartGuideProps = {
|
|
0 commit comments