Skip to content

Commit 92b6081

Browse files
authored
Merge pull request #754 from devtron-labs/feat/open-doc-link
feat: DocLink: enhance component to open devtron docs in SidePanel
2 parents 195a393 + 2ca529c commit 92b6081

File tree

31 files changed

+146
-110
lines changed

31 files changed

+146
-110
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "1.14.1-pre-4",
3+
"version": "1.14.1-pre-5",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Common/CustomTagSelector/PropagateTagInfo.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export default function PropagateTagInfo({ isCreateApp }: { isCreateApp: boolean
4747
interactive
4848
documentationLink={isCreateApp ? "APP_TAGS" : "APP_OVERVIEW_TAGS"}
4949
documentationLinkText="View Documentation"
50+
openInNewTab
5051
>
5152
<div className="flexbox cursor">
5253
<InjectTag className="icon-dim-16 mt-2 mr-4" />

src/Common/TippyCustomized.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import 'tippy.js/animations/shift-toward-subtle.css'
2323
import 'tippy.js/animations/shift-toward.css'
2424
import { TippyCustomizedProps, TippyTheme } from './Types'
2525
import { not, stopPropagation } from './Helper'
26-
import { DocLink } from '../Shared/DocLink'
26+
import { DocLink } from '@Shared/Components'
2727

2828
// This component will handle some of the new tippy designs and interactions
2929
// So this can be updated to support further for new features or interactions
@@ -79,8 +79,8 @@ export const TippyCustomized = <T extends boolean = false>(props: TippyCustomize
7979
additionalContent,
8080
documentationLink,
8181
documentationLinkText,
82-
isEnterprise,
8382
isExternalLink,
83+
openInNewTab,
8484
} = props
8585
return (
8686
<>
@@ -164,9 +164,9 @@ export const TippyCustomized = <T extends boolean = false>(props: TippyCustomize
164164
dataTestId="learn-more-about-tippy-link"
165165
showExternalIcon
166166
onClick={closeTippy}
167-
isEnterprise={isEnterprise}
168167
isExternalLink={isExternalLink}
169168
docLinkKey={documentationLink}
169+
openInNewTab={openInNewTab}
170170
/>
171171
</div>
172172
)}

src/Common/Types.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ import {
2828
ButtonProps,
2929
ComponentLayoutType,
3030
StatusType,
31+
DocLinkProps,
3132
} from '../Shared'
3233
import {
3334
ACTION_STATE,
3435
DEPLOYMENT_WINDOW_TYPE,
3536
DockerConfigOverrideType,
36-
DOCUMENTATION,
3737
RefVariableType,
3838
SortingOrder,
3939
TaskErrorObj,
@@ -120,10 +120,9 @@ export interface CheckboxProps {
120120
children?: ReactNode
121121
}
122122

123-
export type TippyWithBaseDocLinkTypes<T extends boolean> = {
124-
isExternalLink?: T
125-
isEnterprise?: boolean
126-
documentationLink?: T extends true ? string : keyof typeof DOCUMENTATION
123+
export interface TippyWithBaseDocLinkTypes<T extends boolean>
124+
extends Pick<DocLinkProps<T>, 'isExternalLink' | 'openInNewTab'> {
125+
documentationLink?: DocLinkProps<T>['docLinkKey']
127126
}
128127

129128
export type TippyCustomizedProps<T extends boolean> = Pick<TippyProps, 'appendTo'> &
@@ -169,8 +168,8 @@ export interface InfoIconTippyProps<T extends boolean = false>
169168
| 'Icon'
170169
| 'headingInfo'
171170
| 'documentationLink'
172-
| 'isEnterprise'
173171
| 'isExternalLink'
172+
| 'openInNewTab'
174173
> {
175174
dataTestid?: string
176175
children?: TippyCustomizedProps<T>['children']

src/Common/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
export * from '../Shared/DocLink'
1817
export * from './AddCDButton'
1918
export * from './API'
2019
export { BreadCrumb, useBreadcrumb } from './BreadCrumb/BreadCrumb'

src/Shared/Components/AboutDevtron/AboutDevtronBody.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ import { EULA_LINK, PRIVACY_POLICY_LINK, TERMS_OF_USE_LINK } from '@Shared/const
55
import { useMainContext } from '@Shared/Providers'
66

77
import { Button, ButtonComponentType, ButtonStyleType, ButtonVariantType } from '../Button'
8-
import { InstallationType } from '../Header/types'
98
import { Icon } from '../Icon'
109

1110
const AboutDevtronBody = ({ isFELibAvailable }: { isFELibAvailable: boolean }) => {
12-
const { currentServerInfo } = useMainContext()
11+
const { currentServerInfo, isEnterprise } = useMainContext()
1312

1413
const currentVersion = currentServerInfo?.serverInfo?.currentVersion
15-
const isEnterprise = currentServerInfo?.serverInfo?.installationType === InstallationType.ENTERPRISE
1614

1715
const isVersionCompatible = isFELibAvailable === isEnterprise
1816

src/Shared/Components/CICDHistory/Artifacts.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ import folder from '@Icons/ic-folder.svg'
2424
import { ReactComponent as ICHelpOutline } from '@Icons/ic-help.svg'
2525
import { ReactComponent as MechanicalOperation } from '@Icons/ic-mechanical-operation.svg'
2626
import noartifact from '@Images/no-artifact.webp'
27-
import { DocLink } from '@Shared/DocLink'
2827
import { getIsApprovalPolicyConfigured } from '@Shared/Helpers'
2928
import { useDownload } from '@Shared/Hooks'
3029

3130
import { ClipboardButton, extractImage, GenericEmptyState, ImageTagsContainer, useGetUserRoles } from '../../../Common'
3231
import { EMPTY_STATE_STATUS } from '../../constants'
32+
import { DocLink } from '../DocLink'
3333
import { TargetPlatformBadgeList } from '../TargetPlatforms'
3434
import { TERMINAL_STATUS_MAP } from './constants'
3535
import { ArtifactType, CIListItemType } from './types'

src/Shared/Components/CICDHistory/LogsRenderer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { ReactComponent as ICArrow } from '@Icons/ic-caret-down.svg'
2323
import { ReactComponent as ICCollapseAll } from '@Icons/ic-collapse-all.svg'
2424
import { ReactComponent as ICExpandAll } from '@Icons/ic-expand-all.svg'
2525
import { ANSI_UP_REGEX, ComponentSizeType } from '@Shared/constants'
26-
import { DocLink } from '@Shared/DocLink'
2726
import { escapeRegExp, sanitizeTargetPlatforms } from '@Shared/Helpers'
2827
import { AppThemeType, getComponentSpecificThemeClass } from '@Shared/Providers'
2928

@@ -40,6 +39,7 @@ import {
4039
useRegisterShortcut,
4140
useUrlFilters,
4241
} from '../../../Common'
42+
import { DocLink } from '../DocLink'
4343
import {
4444
EVENT_STREAM_EVENTS_MAP,
4545
LOGS_RETRY_COUNT,
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { MouseEvent } from 'react'
2+
3+
import { DOCUMENTATION_HOME_PAGE } from '@Common/Constants'
4+
import { Button, ButtonComponentType, ButtonVariantType, Icon } from '@Shared/Components'
5+
import { ComponentSizeType } from '@Shared/constants'
6+
import { useMainContext } from '@Shared/Providers'
7+
8+
import { DocLinkProps } from './types'
9+
import { getDocumentationUrl } from './utils'
10+
11+
export const DocLink = <T extends boolean = false>({
12+
docLinkKey,
13+
text = 'Learn more',
14+
dataTestId,
15+
showExternalIcon,
16+
onClick,
17+
size = ComponentSizeType.medium,
18+
variant = ButtonVariantType.text,
19+
isExternalLink,
20+
openInNewTab = false,
21+
fullWidth = true,
22+
}: DocLinkProps<T>) => {
23+
// HOOKS
24+
const { isEnterprise, setSidePanelConfig } = useMainContext()
25+
26+
// CONSTANTS
27+
const documentationLink = getDocumentationUrl({
28+
docLinkKey,
29+
isEnterprise,
30+
isExternalLink,
31+
})
32+
33+
// HANDLERS
34+
const handleClick = (e: MouseEvent<HTMLAnchorElement>) => {
35+
if (!isExternalLink && !openInNewTab && !e.metaKey && documentationLink.startsWith(DOCUMENTATION_HOME_PAGE)) {
36+
e.preventDefault()
37+
setSidePanelConfig((prev) => ({ ...prev, open: true, docLink: documentationLink }))
38+
}
39+
onClick?.(e)
40+
}
41+
42+
return (
43+
<Button
44+
component={ButtonComponentType.anchor}
45+
anchorProps={{
46+
href: documentationLink,
47+
}}
48+
onClick={handleClick}
49+
dataTestId={dataTestId}
50+
text={text}
51+
variant={variant}
52+
size={size}
53+
endIcon={showExternalIcon && <Icon name="ic-open-in-new" color={null} />}
54+
fullWidth={fullWidth}
55+
/>
56+
)
57+
}

0 commit comments

Comments
 (0)