Skip to content

Commit

Permalink
feat: add tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
topliceanurazvan committed Apr 28, 2023
1 parent 56d7fee commit 94dc35c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 16 deletions.
19 changes: 15 additions & 4 deletions src/components/organisms/NavigatorPane/KindRenderer/KindSuffix.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useCallback} from 'react';
import React, {useCallback, useMemo} from 'react';

import {Button, Tooltip} from 'antd';

Expand All @@ -7,6 +7,7 @@ import {PlusOutlined} from '@ant-design/icons';
import styled from 'styled-components';

import {TOOLTIP_DELAY} from '@constants/constants';
import {DisabledAddResourceTooltip} from '@constants/tooltips';

import {isInClusterModeSelector} from '@redux/appConfig';
import {useAppDispatch, useAppSelector} from '@redux/hooks';
Expand All @@ -27,7 +28,8 @@ const ButtonContainer = styled.span`
display: flex;
align-items: center;
padding: 0 4px;
margin-right: 2px;
margin-right: 16px;
& .ant-btn-sm {
height: 20px;
width: 20px;
Expand All @@ -48,6 +50,8 @@ const KindSuffix: React.FC<Props> = props => {
const isInClusterMode = useAppSelector(isInClusterModeSelector);
const isSectionCollapsed = useAppSelector(state => state.ui.navigator.collapsedResourceKinds.includes(resourceKind));

const isAddResourceDisabled = useMemo(() => isInPreviewMode || isInClusterMode, [isInClusterMode, isInPreviewMode]);

const createResource = useCallback(() => {
if (!resourceKind) {
return;
Expand All @@ -67,13 +71,20 @@ const KindSuffix: React.FC<Props> = props => {
return (
<SuffixContainer>
<ButtonContainer>
<Tooltip mouseEnterDelay={TOOLTIP_DELAY} title={`Create a new ${resourceKind}`}>
<Tooltip
mouseEnterDelay={TOOLTIP_DELAY}
title={
isAddResourceDisabled
? DisabledAddResourceTooltip({type: isInClusterMode ? 'cluster' : 'preview', kind: resourceKind})
: `Create a new ${resourceKind}`
}
>
<Button
icon={<PlusOutlined />}
type="link"
onClick={createResource}
size="small"
disabled={isInPreviewMode || isInClusterMode}
disabled={isAddResourceDisabled}
style={{color: isSelected && isSectionCollapsed ? Colors.blackPure : undefined}}
/>
</Tooltip>
Expand Down
37 changes: 26 additions & 11 deletions src/components/organisms/NavigatorPane/NavigatorPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {PlusOutlined} from '@ant-design/icons';
import styled from 'styled-components';

import {TOOLTIP_DELAY} from '@constants/constants';
import {NewResourceTooltip} from '@constants/tooltips';
import {DisabledAddResourceTooltip, NewResourceTooltip} from '@constants/tooltips';

import {isInClusterModeSelector} from '@redux/appConfig';
import {useAppDispatch, useAppSelector} from '@redux/hooks';
Expand Down Expand Up @@ -47,6 +47,11 @@ const NavPane: React.FC = () => {
const height = usePaneHeight();
const newResourceMenuItems = useNewResourceMenuItems();

const isAddResourceDisabled = useMemo(
() => !isFolderOpen || isInPreviewMode || isInClusterMode,
[isFolderOpen, isInClusterMode, isInPreviewMode]
);

const resourceFilterButtonHandler = useCallback(() => {
dispatch(toggleResourceFilters());
}, [dispatch]);
Expand All @@ -72,25 +77,35 @@ const NavPane: React.FC = () => {
actions={
<S.TitleBarRightButtons>
<CollapseAction />
<Tooltip mouseEnterDelay={TOOLTIP_DELAY} title={NewResourceTooltip}>
<Dropdown
trigger={['click']}
menu={{items: newResourceMenuItems}}
overlayClassName="dropdown-secondary"
disabled={!isFolderOpen || isInPreviewMode || isInClusterMode}

<Dropdown
trigger={['click']}
menu={{items: newResourceMenuItems}}
overlayClassName="dropdown-secondary"
disabled={isAddResourceDisabled}
>
<Tooltip
mouseEnterDelay={TOOLTIP_DELAY}
title={
isAddResourceDisabled
? DisabledAddResourceTooltip({
type: isInClusterMode ? 'cluster' : isInPreviewMode ? 'preview' : 'other',
})
: NewResourceTooltip
}
>
<S.PlusButton
id="create-resource-button"
$disabled={!isFolderOpen || isInPreviewMode || isInClusterMode}
$disabled={isAddResourceDisabled}
$highlighted={isHighlighted}
className={isHighlighted ? 'animated-highlight' : ''}
disabled={!isFolderOpen || isInPreviewMode || isInClusterMode}
disabled={isAddResourceDisabled}
icon={<PlusOutlined />}
size="small"
type="link"
/>
</Dropdown>
</Tooltip>
</Tooltip>
</Dropdown>
</S.TitleBarRightButtons>
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ export const ItemContainer = styled.span<ItemContainerProps>`
min-width: 0;
}
padding-left: 30px;
padding-right: 8px;
padding-right: 20px;
margin-bottom: 2px;
cursor: pointer;
${props => {
if (props.isLastItem) {
return `margin-bottom: 12px;`;
}
}}
${props => {
if (!props.isSelected && props.isHighlighted) {
if (props.isHovered) {
Expand Down
8 changes: 8 additions & 0 deletions src/constants/tooltips.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,11 @@ export const GitCommitEnabledTooltip = ({branchName}: {branchName: string}) => (
export const ClusterDashboardErrorsWarningTooltip = ({type}: {type: 'errors' | 'warnings'}) => (
<div>Click to see all your cluster {type}</div>
);
export const DisabledAddResourceTooltip = ({type, kind}: {type: 'cluster' | 'preview' | 'other'; kind?: string}) =>
type === 'other' ? (
<div>Adding a resource is not possible</div>
) : (
<div>
Adding a {kind || 'resource'} is not possible in {type === 'cluster' ? 'cluster' : 'preview'} mode
</div>
);

0 comments on commit 94dc35c

Please sign in to comment.