-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(native-filters): Re-arrange controls in FilterBar (#18784)
* feat(native-filters): Re-arrange controls in FilterBar * Typo fix * Add tests * Fix tests * Address PR reviews * Add 1px bottom padding to icon * Fix test * Tiny refactor * Change buttons background * Add hover state to Clear all button * Fix Clear All button logic so it clears all selections * Remove redundant useEffect * Set zindex higher than loading icon * Fix scrolling issue
- Loading branch information
Showing
13 changed files
with
308 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...end/src/dashboard/components/nativeFilters/FilterBar/ActionButtons/ActionButtons.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import React from 'react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { render, screen } from 'spec/helpers/testing-library'; | ||
import { ActionButtons } from './index'; | ||
|
||
const createProps = () => ({ | ||
onApply: jest.fn(), | ||
onClearAll: jest.fn(), | ||
dataMaskSelected: { | ||
DefaultsID: { | ||
filterState: { | ||
value: null, | ||
}, | ||
}, | ||
}, | ||
dataMaskApplied: { | ||
DefaultsID: { | ||
id: 'DefaultsID', | ||
filterState: { | ||
value: null, | ||
}, | ||
}, | ||
}, | ||
isApplyDisabled: false, | ||
}); | ||
|
||
test('should render the "Apply" button', () => { | ||
const mockedProps = createProps(); | ||
render(<ActionButtons {...mockedProps} />, { useRedux: true }); | ||
expect(screen.getByText('Apply filters')).toBeInTheDocument(); | ||
expect(screen.getByText('Apply filters').parentElement).toBeEnabled(); | ||
}); | ||
|
||
test('should render the "Clear all" button as disabled', () => { | ||
const mockedProps = createProps(); | ||
render(<ActionButtons {...mockedProps} />, { useRedux: true }); | ||
const clearBtn = screen.getByText('Clear all'); | ||
expect(clearBtn.parentElement).toBeDisabled(); | ||
}); | ||
|
||
test('should render the "Apply" button as disabled', () => { | ||
const mockedProps = createProps(); | ||
const applyDisabledProps = { | ||
...mockedProps, | ||
isApplyDisabled: true, | ||
}; | ||
render(<ActionButtons {...applyDisabledProps} />, { useRedux: true }); | ||
const applyBtn = screen.getByText('Apply filters'); | ||
expect(applyBtn.parentElement).toBeDisabled(); | ||
userEvent.click(applyBtn); | ||
expect(mockedProps.onApply).not.toHaveBeenCalled(); | ||
}); | ||
|
||
test('should apply', () => { | ||
const mockedProps = createProps(); | ||
render(<ActionButtons {...mockedProps} />, { useRedux: true }); | ||
const applyBtn = screen.getByText('Apply filters'); | ||
expect(mockedProps.onApply).not.toHaveBeenCalled(); | ||
userEvent.click(applyBtn); | ||
expect(mockedProps.onApply).toHaveBeenCalled(); | ||
}); |
125 changes: 125 additions & 0 deletions
125
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/ActionButtons/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import React, { useMemo } from 'react'; | ||
import { | ||
css, | ||
DataMaskState, | ||
DataMaskStateWithId, | ||
styled, | ||
t, | ||
} from '@superset-ui/core'; | ||
import Button from 'src/components/Button'; | ||
import { isNullish } from 'src/utils/common'; | ||
import { OPEN_FILTER_BAR_WIDTH } from 'src/dashboard/constants'; | ||
import { getFilterBarTestId } from '../index'; | ||
|
||
interface ActionButtonsProps { | ||
onApply: () => void; | ||
onClearAll: () => void; | ||
dataMaskSelected: DataMaskState; | ||
dataMaskApplied: DataMaskStateWithId; | ||
isApplyDisabled: boolean; | ||
} | ||
|
||
const ActionButtonsContainer = styled.div` | ||
${({ theme }) => css` | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
position: fixed; | ||
z-index: 100; | ||
// filter bar width minus 1px for border | ||
width: ${OPEN_FILTER_BAR_WIDTH - 1}px; | ||
bottom: 0; | ||
padding: ${theme.gridUnit * 4}px; | ||
padding-top: ${theme.gridUnit * 6}px; | ||
background: linear-gradient(transparent, white 25%); | ||
pointer-events: none; | ||
& > button { | ||
pointer-events: auto; | ||
} | ||
& > .filter-apply-button { | ||
margin-bottom: ${theme.gridUnit * 3}px; | ||
} | ||
&& > .filter-clear-all-button { | ||
color: ${theme.colors.grayscale.base}; | ||
margin-left: 0; | ||
&:hover { | ||
color: ${theme.colors.primary.dark1}; | ||
} | ||
&[disabled], | ||
&[disabled]:hover { | ||
color: ${theme.colors.grayscale.light1}; | ||
} | ||
} | ||
`}; | ||
`; | ||
|
||
export const ActionButtons = ({ | ||
onApply, | ||
onClearAll, | ||
dataMaskApplied, | ||
dataMaskSelected, | ||
isApplyDisabled, | ||
}: ActionButtonsProps) => { | ||
const isClearAllEnabled = useMemo( | ||
() => | ||
Object.values(dataMaskApplied).some( | ||
filter => | ||
!isNullish(dataMaskSelected[filter.id]?.filterState?.value) || | ||
(!dataMaskSelected[filter.id] && | ||
!isNullish(filter.filterState?.value)), | ||
), | ||
[dataMaskApplied, dataMaskSelected], | ||
); | ||
|
||
return ( | ||
<ActionButtonsContainer> | ||
<Button | ||
disabled={isApplyDisabled} | ||
buttonStyle="primary" | ||
htmlType="submit" | ||
className="filter-apply-button" | ||
onClick={onApply} | ||
{...getFilterBarTestId('apply-button')} | ||
> | ||
{t('Apply filters')} | ||
</Button> | ||
<Button | ||
disabled={!isClearAllEnabled} | ||
buttonStyle="link" | ||
buttonSize="small" | ||
className="filter-clear-all-button" | ||
onClick={onClearAll} | ||
{...getFilterBarTestId('clear-button')} | ||
> | ||
{t('Clear all')} | ||
</Button> | ||
</ActionButtonsContainer> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.