Skip to content

Commit

Permalink
chore: Changes the RefreshIntervalModal component to use the new sele…
Browse files Browse the repository at this point in the history
…ct component (apache#16048)
  • Loading branch information
michael-s-molina authored Aug 6, 2021
1 parent 423ff50 commit e59f318
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('RefreshIntervalModal', () => {
});
it('should change refreshFrequency with edit mode', () => {
const wrapper = getMountWrapper(mockedProps);
wrapper.instance().handleFrequencyChange({ value: 30 });
wrapper.instance().handleFrequencyChange(30);
wrapper.instance().onSave();
expect(mockedProps.onChange).toHaveBeenCalled();
expect(mockedProps.onChange).toHaveBeenCalledWith(30, mockedProps.editMode);
Expand All @@ -69,11 +69,11 @@ describe('RefreshIntervalModal', () => {
const wrapper = getMountWrapper(props);
wrapper.find('span[role="button"]').simulate('click');

wrapper.instance().handleFrequencyChange({ value: 30 });
wrapper.instance().handleFrequencyChange(30);
wrapper.update();
expect(wrapper.find(ModalTrigger).find(Alert)).toExist();

wrapper.instance().handleFrequencyChange({ value: 3601 });
wrapper.instance().handleFrequencyChange(3601);
wrapper.update();
expect(wrapper.find(ModalTrigger).find(Alert)).not.toExist();
});
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ const Select = ({
const handleTopOptions = useCallback(
(selectedValue: AntdSelectValue | undefined) => {
// bringing selected options to the top of the list
if (selectedValue) {
if (selectedValue !== undefined && selectedValue !== null) {
const topOptions: OptionsType = [];
const otherOptions: OptionsType = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/
import React, { RefObject } from 'react';
import Select from 'src/components/Select';
import { Select } from 'src/components';
import { t, styled } from '@superset-ui/core';
import Alert from 'src/components/Alert';
import Button from 'src/components/Button';
Expand All @@ -36,7 +36,7 @@ export const options = [
[21600, t('6 hours')],
[43200, t('12 hours')],
[86400, t('24 hours')],
].map(o => ({ value: o[0], label: o[1] }));
].map(o => ({ value: o[0] as number, label: o[1] }));

const StyledModalTrigger = styled(ModalTrigger)`
.ant-modal-body {
Expand Down Expand Up @@ -95,10 +95,9 @@ class RefreshIntervalModal extends React.PureComponent<
this.modalRef.current?.close();
}

handleFrequencyChange(opt: Record<string, any>) {
const value = opt ? opt.value : options[0].value;
handleFrequencyChange(value: number) {
this.setState({
refreshFrequency: value,
refreshFrequency: value || options[0].value,
});
}

Expand All @@ -117,10 +116,10 @@ class RefreshIntervalModal extends React.PureComponent<
<div>
<FormLabel>{t('Refresh frequency')}</FormLabel>
<Select
ariaLabel={t('Refresh interval')}
options={options}
value={{ value: refreshFrequency }}
value={refreshFrequency}
onChange={this.handleFrequencyChange}
forceOverflow
/>
{showRefreshWarning && (
<RefreshWarningContainer>
Expand Down

0 comments on commit e59f318

Please sign in to comment.