mirror of
https://github.com/apache/superset.git
synced 2024-09-12 08:39:45 -04:00
refactor(explore): remove side effect in render from CalendarFrame for DatePicker (#15147)
This commit is contained in:
parent
9c3c3fa125
commit
53225e8d17
@ -16,7 +16,7 @@
|
|||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
import React from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import { t } from '@superset-ui/core';
|
import { t } from '@superset-ui/core';
|
||||||
import { Radio } from 'src/components/Radio';
|
import { Radio } from 'src/components/Radio';
|
||||||
import {
|
import {
|
||||||
@ -29,12 +29,15 @@ import {
|
|||||||
FrameComponentProps,
|
FrameComponentProps,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
|
|
||||||
export function CalendarFrame(props: FrameComponentProps) {
|
export function CalendarFrame({ onChange, value }: FrameComponentProps) {
|
||||||
let calendarRange = PreviousCalendarWeek;
|
useEffect(() => {
|
||||||
if (CALENDAR_RANGE_SET.has(props.value as CalendarRangeType)) {
|
if (!CALENDAR_RANGE_SET.has(value as CalendarRangeType)) {
|
||||||
calendarRange = props.value;
|
onChange(PreviousCalendarWeek);
|
||||||
} else {
|
}
|
||||||
props.onChange(calendarRange);
|
}, [onChange, value]);
|
||||||
|
|
||||||
|
if (!CALENDAR_RANGE_SET.has(value as CalendarRangeType)) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -43,8 +46,8 @@ export function CalendarFrame(props: FrameComponentProps) {
|
|||||||
{t('Configure Time Range: Previous...')}
|
{t('Configure Time Range: Previous...')}
|
||||||
</div>
|
</div>
|
||||||
<Radio.Group
|
<Radio.Group
|
||||||
value={calendarRange}
|
value={value}
|
||||||
onChange={(e: any) => props.onChange(e.target.value)}
|
onChange={(e: any) => onChange(e.target.value)}
|
||||||
>
|
>
|
||||||
{CALENDAR_RANGE_OPTIONS.map(({ value, label }) => (
|
{CALENDAR_RANGE_OPTIONS.map(({ value, label }) => (
|
||||||
<Radio key={value} value={value} className="vertical-radio">
|
<Radio key={value} value={value} className="vertical-radio">
|
||||||
|
Loading…
Reference in New Issue
Block a user