Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dashboard): Add description to the native filter #17025

Merged
merged 11 commits into from
Oct 27, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
* under the License.
*/
import React, { useMemo } from 'react';
import { styled, t } from '@superset-ui/core';
import Form from 'antd/lib/form';
import { InfoTooltipWithTrigger } from '@superset-ui/chart-controls';
import { styled } from '@superset-ui/core';
import { FormItem as StyledFormItem, Form } from 'src/components/Form';
import Icons from 'src/components/Icons';
import { Tooltip } from 'src/components/Tooltip';
import { theme as supersetTheme } from 'src/preamble';
michael-s-molina marked this conversation as resolved.
Show resolved Hide resolved
import { checkIsMissingRequiredValue } from '../utils';
import FilterValue from './FilterValue';
Expand All @@ -43,11 +44,6 @@ const StyledFilterControlTitleBox = styled.div`
align-items: center;
justify-content: space-between;
margin-bottom: ${({ theme }) => theme.gridUnit}px;
.ant-form-item-required:not(.ant-form-item-required-mark-optional) {
&::before {
display: none;
}
}
`;

const StyledFilterControlContainer = styled(Form)`
Expand All @@ -62,21 +58,56 @@ const StyledFilterControlContainer = styled(Form)`
}
`;

const FormItem = styled(Form.Item)`
const FormItem = styled(StyledFormItem)`
${({ theme }) => `
.ant-form-item-label {
padding-bottom: ${theme.gridUnit}px;
label.ant-form-item-required:not(.ant-form-item-required-mark-optional){
&::after {
display: none;
}
}
}

`}
`}
`;

const ToolTipContainer = styled.div`
font-size: ${({ theme }) => theme.typography.sizes.m}px;
display: flex;
padding-left: ${({ theme }) => theme.gridUnit}px;
`;

const RequiredFieldIndicator = () => (
<span
css={{
color: supersetTheme.colors.error.base,
michael-s-molina marked this conversation as resolved.
Show resolved Hide resolved
fontSize: `${supersetTheme.typography.sizes.s}px`,
paddingLeft: '2px',
}}
>
*
</span>
);

const DescriptoinToolTip = ({ description }: { description: string }) => (
michael-s-molina marked this conversation as resolved.
Show resolved Hide resolved
<ToolTipContainer>
<Tooltip
title={description}
placement="top"
overlayInnerStyle={{
display: '-webkit-box',
overflow: 'hidden',
// @ts-ignore -webkit-line-clamp is not in the CSS type
'-webkit-line-clamp': '20',
'-webkit-box-orient': 'vertical',
'text-overflow': 'ellipsis',
}}
>
<Icons.InfoCircle
className="text-muted"
css={{ color: supersetTheme.colors.grayscale.light1 }}
michael-s-molina marked this conversation as resolved.
Show resolved Hide resolved
/>
</Tooltip>
</ToolTipContainer>
);
const FilterControl: React.FC<FilterProps> = ({
dataMaskSelected,
filter,
Expand All @@ -99,29 +130,14 @@ const FilterControl: React.FC<FilterProps> = ({
<StyledFilterControlTitle data-test="filter-control-name">
{name}
</StyledFilterControlTitle>
{isRequired && (
<span
css={{
color: supersetTheme.colors.error.base,
fontSize: `${supersetTheme.typography.sizes.s}px`,
}}
>
*
</span>
)}
{isRequired && <RequiredFieldIndicator />}
{filter.description && filter.description.trim() && (
michael-s-molina marked this conversation as resolved.
Show resolved Hide resolved
<ToolTipContainer>
<InfoTooltipWithTrigger
label={t('description')}
tooltip={filter.description}
placement="top"
/>
</ToolTipContainer>
<DescriptoinToolTip description={filter.description} />
michael-s-molina marked this conversation as resolved.
Show resolved Hide resolved
)}
<StyledIcon data-test="filter-icon">{icon}</StyledIcon>
</StyledFilterControlTitleBox>
),
[icon, name],
[name, isRequired, filter.description, icon],
);

return (
Expand All @@ -139,7 +155,6 @@ const FilterControl: React.FC<FilterProps> = ({
inView={inView}
/>
</FormItem>
{filter.requiredFirst ? <span>Test</span> : null}
</StyledFilterControlContainer>
);
};
Expand Down