|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
17 | | -import { useState } from 'react' |
18 | | -import { useHistory, useLocation, useParams } from 'react-router-dom' |
| 17 | +import { useLocation, useParams } from 'react-router-dom' |
19 | 18 |
|
20 | | -import { ReactComponent as AddIcon } from '@Icons/ic-add.svg' |
21 | | -import { ReactComponent as DropDown } from '@Icons/ic-caret-down-small.svg' |
22 | | -import { ReactComponent as ChartIcon } from '@Icons/ic-charts.svg' |
23 | | -import { ReactComponent as JobIcon } from '@Icons/ic-k8s-job.svg' |
| 19 | +import { SERVER_MODE, URLS } from '@Common/Constants' |
| 20 | +import { noop } from '@Common/Helper' |
| 21 | +import { ActionMenu } from '@Shared/Components/ActionMenu' |
| 22 | +import { ButtonComponentType } from '@Shared/Components/Button' |
24 | 23 | import Button from '@Shared/Components/Button/Button.component' |
| 24 | +import { Icon } from '@Shared/Components/Icon' |
| 25 | +import { AppListConstants, ComponentSizeType } from '@Shared/constants' |
| 26 | +import { useMainContext } from '@Shared/Providers' |
25 | 27 |
|
26 | | -import { Modal, SERVER_MODE, URLS } from '../../../../Common' |
27 | | -import { AppListConstants, ComponentSizeType } from '../../../constants' |
28 | | -import { useMainContext } from '../../../Providers' |
29 | 28 | import PageHeader from '../PageHeader' |
30 | | -import { getIsShowingLicenseData } from '../utils' |
31 | | - |
32 | | -import './HeaderWithCreateButton.scss' |
33 | | - |
34 | | -export interface HeaderWithCreateButtonProps { |
35 | | - headerName: string |
36 | | -} |
| 29 | +import { HeaderWithCreateButtonProps } from './types' |
| 30 | +import { getCreateActionMenuOptions } from './utils' |
37 | 31 |
|
38 | 32 | export const HeaderWithCreateButton = ({ headerName }: HeaderWithCreateButtonProps) => { |
| 33 | + // HOOKS |
| 34 | + const { serverMode } = useMainContext() |
39 | 35 | const params = useParams<{ appType: string }>() |
40 | | - const history = useHistory() |
41 | 36 | const location = useLocation() |
42 | | - const { serverMode, licenseData } = useMainContext() |
43 | | - const [showCreateSelectionModal, setShowCreateSelectionModal] = useState(false) |
44 | | - |
45 | | - const showingLicenseBar = getIsShowingLicenseData(licenseData) |
46 | | - |
47 | | - const handleCreateButton = () => { |
48 | | - setShowCreateSelectionModal((prevState) => !prevState) |
49 | | - } |
50 | 37 |
|
51 | | - const redirectToHelmAppDiscover = () => { |
52 | | - history.push(URLS.CHARTS_DISCOVER) |
53 | | - } |
54 | | - |
55 | | - const openCreateDevtronAppModel = () => { |
56 | | - const _urlPrefix = `${URLS.APP}/${URLS.APP_LIST}/${params.appType ?? AppListConstants.AppType.DEVTRON_APPS}` |
57 | | - history.push(`${_urlPrefix}/${AppListConstants.CREATE_DEVTRON_APP_URL}${location.search}`) |
58 | | - } |
59 | | - |
60 | | - const openCreateJobModel = () => { |
61 | | - history.push(`${URLS.JOB}/${URLS.APP_LIST}/${URLS.CREATE_JOB}`) |
62 | | - } |
| 38 | + // CONSTANTS |
| 39 | + const createCustomAppURL = `${URLS.APP}/${URLS.APP_LIST}/${params.appType ?? AppListConstants.AppType.DEVTRON_APPS}/${AppListConstants.CREATE_DEVTRON_APP_URL}${location.search}` |
63 | 40 |
|
64 | 41 | const renderActionButtons = () => |
65 | 42 | serverMode === SERVER_MODE.FULL ? ( |
66 | | - <Button |
67 | | - text="Create" |
68 | | - onClick={handleCreateButton} |
69 | | - dataTestId="create-app-button-on-header" |
70 | | - endIcon={<DropDown className="icon-dim-20" />} |
71 | | - size={ComponentSizeType.small} |
| 43 | + <ActionMenu |
| 44 | + id="page-header-create-app-action-menu" |
| 45 | + alignment="end" |
| 46 | + onClick={noop} |
| 47 | + options={getCreateActionMenuOptions(createCustomAppURL)} |
| 48 | + buttonProps={{ |
| 49 | + text: 'Create', |
| 50 | + dataTestId: 'create-app-button-on-header', |
| 51 | + endIcon: <Icon name="ic-caret-down-small" color={null} />, |
| 52 | + size: ComponentSizeType.small, |
| 53 | + }} |
72 | 54 | /> |
73 | 55 | ) : ( |
74 | 56 | <Button |
75 | 57 | text="Deploy helm charts" |
76 | | - onClick={redirectToHelmAppDiscover} |
| 58 | + component={ButtonComponentType.link} |
| 59 | + linkProps={{ to: URLS.CHARTS_DISCOVER }} |
77 | 60 | dataTestId="deploy-helm-chart-on-header" |
78 | 61 | size={ComponentSizeType.small} |
79 | 62 | /> |
80 | 63 | ) |
81 | 64 |
|
82 | | - const renderCreateSelectionModal = () => ( |
83 | | - <Modal |
84 | | - rootClassName={`create-modal-wrapper ${showingLicenseBar ? 'with-bar' : ''} |
85 | | - ${window._env_.FEATURE_PROMO_EMBEDDED_BUTTON_TEXT ? 'create-modal-wrapper--try-devtron' : ''}`} |
86 | | - onClick={handleCreateButton} |
87 | | - > |
88 | | - <div |
89 | | - className="create-modal-child cursor" |
90 | | - onClick={openCreateDevtronAppModel} |
91 | | - data-testid="create-custom-app-button-in-dropdown" |
92 | | - > |
93 | | - <AddIcon className="icon-dim-20 fcn-9" /> |
94 | | - <div className="ml-8"> |
95 | | - <strong>Custom app</strong> |
96 | | - <div> |
97 | | - Connect a git repository to deploy <br /> a custom application |
98 | | - </div> |
99 | | - </div> |
100 | | - </div> |
101 | | - <div |
102 | | - className="create-modal-child cursor" |
103 | | - onClick={redirectToHelmAppDiscover} |
104 | | - data-testid="create-from-chart-store-button" |
105 | | - > |
106 | | - <ChartIcon className="icon-dim-20 fcn-9" /> |
107 | | - <div className="ml-8"> |
108 | | - <strong>From Chart store</strong> |
109 | | - <div> |
110 | | - Deploy apps using third party helm <br /> charts (eg. prometheus, redis etc.) |
111 | | - </div> |
112 | | - </div> |
113 | | - </div> |
114 | | - <div |
115 | | - className="create-modal-child cursor" |
116 | | - onClick={openCreateJobModel} |
117 | | - data-testid="create-job-button-in-dropdown" |
118 | | - > |
119 | | - <JobIcon className="icon-dim-20 scn-9" /> |
120 | | - <div className="ml-8"> |
121 | | - <strong>Job</strong> |
122 | | - <div> |
123 | | - Jobs allow manual and automated <br /> execution of developer actions. |
124 | | - </div> |
125 | | - </div> |
126 | | - </div> |
127 | | - </Modal> |
128 | | - ) |
129 | 65 | return ( |
130 | 66 | <div className="create-button-container dc__position-sticky dc__top-0 bg__primary dc__zi-4"> |
131 | 67 | <PageHeader headerName={headerName} renderActionButtons={renderActionButtons} /> |
132 | | - {showCreateSelectionModal && renderCreateSelectionModal()} |
133 | 68 | </div> |
134 | 69 | ) |
135 | 70 | } |
|
0 commit comments