Skip to content

Commit

Permalink
disabled add button when no datasource selected
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Sep 23, 2019
1 parent 20751be commit 72b08a0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,13 @@
@include gphFieldBadgeSize;
color: $euiColorPrimary;
}

.gphFieldPicker__button--disabled {
color: $euiTextColor;
cursor: not-allowed !important;

&:hover,
&:focus {
text-decoration: none;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import React, { useState, useEffect, ReactNode } from 'react';
import { EuiPopover, EuiSelectable, EuiBadge } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import classNames from 'classnames';
import { WorkspaceField } from '../../types';

import { FieldIcon } from './field_icon';
Expand All @@ -24,6 +25,8 @@ export function FieldPicker({ fieldMap, selectField, deselectField }: FieldPicke
const unselectedFields = allFields.filter(field => !field.selected);
const hasSelectedFields = unselectedFields.length < allFields.length;

const hasFields = allFields.length > 0;

const [fieldOptions, setFieldOptions] = useState(toOptions(allFields));

useEffect(() => {
Expand Down Expand Up @@ -51,12 +54,17 @@ export function FieldPicker({ fieldMap, selectField, deselectField }: FieldPicke
panelPaddingSize="none"
button={
<EuiBadge
className="gphFieldPicker__button"
className={classNames('gphFieldPicker__button', {
'gphFieldPicker__button--disabled': !hasFields,
})}
color="hollow"
iconType="plusInCircleFilled"
onClick={() => setOpen(true)}
onClick={() => {
if (hasFields) {
setOpen(true);
}
}}
onClickAriaLabel={badgeDescription}
title=""
>
{badgeDescription}
</EuiBadge>
Expand Down

0 comments on commit 72b08a0

Please sign in to comment.