Skip to content

Commit

Permalink
chore(Dashboard): Highlight errored filters on the left pane of the N…
Browse files Browse the repository at this point in the history
…ative Filters form plus several enhancements (apache#16940)

* Implement errored filters

* Clean up

* Handle errors on the fly

* Implement handleErroredFilters

* Reset errors
  • Loading branch information
geido authored and Emmanuel Bavoux committed Nov 14, 2021
1 parent beca501 commit 68b3b19
Show file tree
Hide file tree
Showing 5 changed files with 393 additions and 297 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const StyledSpan = styled.span`
`;

export const StyledFilterTitle = styled.span`
width: ${FILTER_WIDTH}px;
width: 100%;
white-space: normal;
color: ${({ theme }) => theme.colors.grayscale.dark1};
`;
Expand All @@ -61,6 +61,7 @@ export const FilterTabTitle = styled.span`
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
@keyframes tabTitleRemovalAnimation {
0%,
Expand All @@ -79,6 +80,17 @@ export const FilterTabTitle = styled.span`
animation-name: tabTitleRemovalAnimation;
animation-duration: ${REMOVAL_DELAY_SECS}s;
}
&.errored > span {
color: ${({ theme }) => theme.colors.error.base};
}
`;

const StyledWarning = styled(Icons.Warning)`
color: ${({ theme }) => theme.colors.error.base};
&.anticon {
margin-right: 0;
}
`;

const FilterTabsContainer = styled(LineEditableTabs)`
Expand Down Expand Up @@ -169,6 +181,7 @@ type FilterTabsProps = {
currentFilterId: string;
onEdit: (filterId: string, action: 'add' | 'remove') => void;
filterIds: string[];
erroredFilters: string[];
removedFilters: Record<string, FilterRemoval>;
restoreFilter: Function;
children: Function;
Expand All @@ -180,6 +193,7 @@ const FilterTabs: FC<FilterTabsProps> = ({
onChange,
currentFilterId,
filterIds = [],
erroredFilters = [],
removedFilters = [],
restoreFilter,
children,
Expand Down Expand Up @@ -217,34 +231,47 @@ const FilterTabs: FC<FilterTabsProps> = ({
),
}}
>
{filterIds.map(id => (
<LineEditableTabs.TabPane
tab={
<FilterTabTitle className={removedFilters[id] ? 'removed' : ''}>
<StyledFilterTitle>
{removedFilters[id] ? t('(Removed)') : getFilterTitle(id)}
</StyledFilterTitle>
{removedFilters[id] && (
<StyledSpan
role="button"
data-test="undo-button"
tabIndex={0}
onClick={() => restoreFilter(id)}
>
{t('Undo?')}
</StyledSpan>
)}
</FilterTabTitle>
}
key={id}
closeIcon={removedFilters[id] ? <></> : <StyledTrashIcon />}
>
{
// @ts-ignore
children(id)
}
</LineEditableTabs.TabPane>
))}
{filterIds.map(id => {
const showErroredFilter = erroredFilters.includes(id);
const filterName = getFilterTitle(id);
return (
<LineEditableTabs.TabPane
tab={
<FilterTabTitle
className={
removedFilters[id]
? 'removed'
: showErroredFilter
? 'errored'
: ''
}
>
<StyledFilterTitle>
{removedFilters[id] ? t('(Removed)') : filterName}
</StyledFilterTitle>
{!removedFilters[id] && showErroredFilter && <StyledWarning />}
{removedFilters[id] && (
<StyledSpan
role="button"
data-test="undo-button"
tabIndex={0}
onClick={() => restoreFilter(id)}
>
{t('Undo?')}
</StyledSpan>
)}
</FilterTabTitle>
}
key={id}
closeIcon={removedFilters[id] ? <></> : <StyledTrashIcon />}
>
{
// @ts-ignore
children(id)
}
</LineEditableTabs.TabPane>
);
})}
</FilterTabsContainer>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('FilterScope', () => {
const mockedProps = {
filterId: 'DefaultFilterId',
restoreFilter: jest.fn(),
setErroredFilters: jest.fn(),
parentFilters: [],
save,
removedFilters: {},
Expand Down
Loading

0 comments on commit 68b3b19

Please sign in to comment.