Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ class ControlPanelsContainer extends React.Component {
if (visibility && !visibility.call(config, this.props, controlData)) {
return null;
}

return (
<Control
key={`control-${name}`}
name={name}
validationErrors={validationErrors}
actions={actions}
formData={provideFormDataToProps ? formData : null}
datasource={formData?.datasource}
{...restProps}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ const fetchTimeRange = async (
) => {
const query = rison.encode(timeRange);
const endpoint = `/api/v1/time_range/?q=${query}`;

try {
const response = await SupersetClient.get({ endpoint });
const timeRangeString = buildTimeRangeString(
Expand Down Expand Up @@ -171,20 +170,23 @@ interface DateFilterLabelProps {
onChange: (timeRange: string) => void;
value?: string;
endpoints?: TimeRangeEndpoints;
datasource?: string;
}

export default function DateFilterControl(props: DateFilterLabelProps) {
const { value = 'Last week', endpoints, onChange } = props;
const { value = 'Last week', endpoints, onChange, datasource } = props;
const [actualTimeRange, setActualTimeRange] = useState<string>(value);

const [show, setShow] = useState<boolean>(false);
const [frame, setFrame] = useState<FrameType>(guessFrame(value));
const [isMounted, setIsMounted] = useState<boolean>(false);
const [timeRangeValue, setTimeRangeValue] = useState(value);
const [validTimeRange, setValidTimeRange] = useState<boolean>(false);
const [evalResponse, setEvalResponse] = useState<string>(value);
const [tooltipTitle, setTooltipTitle] = useState<string>(value);

useEffect(() => {
if (!isMounted) setIsMounted(true);
fetchTimeRange(value, endpoints).then(({ value: actualRange, error }) => {
if (error) {
setEvalResponse(error || '');
Expand Down Expand Up @@ -219,6 +221,14 @@ export default function DateFilterControl(props: DateFilterLabelProps) {
});
}, [value]);

useEffect(() => {
if (isMounted) {
onChange('Last week');
setTimeRangeValue('Last week');
setFrame(guessFrame('Last week'));
Comment on lines +227 to +228

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two lines can be removed. Because when the value changed(onChange('last week')) then the component can reload.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. Ignore me. Shouldn't be removed. merged.

}
}, [datasource]);

useEffect(() => {
fetchTimeRange(timeRangeValue, endpoints).then(({ value, error }) => {
if (error) {
Expand All @@ -237,8 +247,8 @@ export default function DateFilterControl(props: DateFilterLabelProps) {
}

function onHide() {
setFrame(guessFrame(value));
setTimeRangeValue(value);
setFrame(guessFrame(value));
setShow(false);
}

Expand Down