Skip to content

Commit

Permalink
Merge pull request apache#56 from KudosInc/kudos_master
Browse files Browse the repository at this point in the history
Kudos master
  • Loading branch information
michelle-kudos authored Sep 21, 2023
2 parents f825279 + ad1f124 commit 65a54af
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,14 @@ class SliceHeaderControls extends React.PureComponent<

return (
<>
{slice.description && (
<Tooltip title={slice.description}>
<Icons.QuestionCircleOutlined
style={{ fontSize: 22, cursor: 'pointer' }}
/>
</Tooltip>
)}

<CrossFilterScopingModal
chartId={slice.slice_id}
isOpen={this.state.showCrossFilterScopingModal}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ enum DateType {
Month = 'month',
LastMonth = 'lastMonth',
LastYear = 'LastYear',
Last30Day = 'Last30Day',
}

export function CustomFrame(props: FrameComponentProps) {
Expand Down Expand Up @@ -82,9 +83,16 @@ export function CustomFrame(props: FrameComponentProps) {
const localFromFlaskBabel = useSelector(
(state: ExplorePageState) => state?.common?.locale,
);

const [untilDate, setUntilDate] = useState('' as unknown as moment.Moment);
const [sinceDate, setSinceDate] = useState('' as unknown as moment.Moment);
const [untilDate, setUntilDate] = useState(
props.value !== 'No filter' && props.value.split(' : ').length > 1
? moment(props.value.split(' : ')[1])
: ('' as unknown as moment.Moment),
);
const [sinceDate, setSinceDate] = useState(
props.value !== 'No filter' && props.value.split(' : ').length > 1
? moment(props.value.split(' : ')[0])
: ('' as unknown as moment.Moment),
);

const datePickerLocale =
locales[LOCALE_MAPPING[localFromFlaskBabel]]?.DatePicker;
Expand Down Expand Up @@ -115,24 +123,38 @@ export function CustomFrame(props: FrameComponentProps) {
[sinceDatetime, untilDatetime] = setLastMonth();
} else if (type === DateType.LastYear) {
[sinceDatetime, untilDatetime] = setLastYear();
} else if (type === DateType.Week) {
untilDatetime = moment().format(MOMENT_FORMAT);
setUntilDate(moment());
sinceDatetime = moment().subtract(1, 'weeks').format(MOMENT_FORMAT);
setSinceDate(moment().subtract(1, 'weeks'));
} else if (type === DateType.Month) {
untilDatetime = moment().format(MOMENT_FORMAT);
setUntilDate(moment());
} else {
const untilDate = moment().format(dateFormat);
untilDatetime = moment(
`${untilDate} 23:59:59`,
`YYYY/MM/DD HH:mm:ss`,
).format(MOMENT_FORMAT);
setUntilDate(moment(`${untilDate} 23:59:59`, `YYYY/MM/DD HH:mm:ss`));
}
if (type === DateType.Week) {
const sinceDate = moment().subtract(1, 'weeks').format(dateFormat);
sinceDatetime = moment(
`${sinceDate} 00:00:00`,
`YYYY/MM/DD HH:mm:ss`,
).format(MOMENT_FORMAT);
setSinceDate(moment(`${sinceDate} 00:00:00`, `YYYY/MM/DD HH:mm:ss`));
}
if (type === DateType.Last30Day) {
const sinceDate = moment().subtract(1, 'month').format(dateFormat);
sinceDatetime = moment(
`${sinceDate} 00:00:00`,
`YYYY/MM/DD HH:mm:ss`,
).format(MOMENT_FORMAT);
setSinceDate(moment(`${sinceDate} 00:00:00`, `YYYY/MM/DD HH:mm:ss`));
}
if (type === DateType.Month) {
sinceDatetime = moment().startOf('month').format(MOMENT_FORMAT);
setSinceDate(moment().startOf('month'));
} else if (type === DateType.Year) {
untilDatetime = moment().format(MOMENT_FORMAT);
setUntilDate(moment());
}
if (type === DateType.Year) {
sinceDatetime = moment().startOf('year').format(MOMENT_FORMAT);
setSinceDate(moment().startOf('year'));
}
console.log(sinceDatetime);
console.log(untilDatetime);
onChange({ sinceDatetime, untilDatetime });
};

Expand All @@ -159,6 +181,12 @@ export function CustomFrame(props: FrameComponentProps) {
>
Last Month
</Button>
<Button
onClick={() => selectDate(DateType.Last30Day)}
buttonStyle="link"
>
Last 30 Day
</Button>
<Button
onClick={() => selectDate(DateType.LastYear)}
buttonStyle="link"
Expand All @@ -177,9 +205,19 @@ export function CustomFrame(props: FrameComponentProps) {
if (arr !== null) {
setSinceDate(arr[0]!);
setUntilDate(arr[1]!);
const sinceDate = arr[0]?.format(dateFormat);
const untilDate = arr[1]?.format(dateFormat);
const sinceDatetime = moment(
`${sinceDate} 00:00:00`,
`YYYY/MM/DD HH:mm:ss`,
).format(MOMENT_FORMAT);
const untilDatetime = moment(
`${untilDate} 23:59:59`,
`YYYY/MM/DD HH:mm:ss`,
).format(MOMENT_FORMAT);
onChange({
sinceDatetime: arr[0]?.format(MOMENT_FORMAT),
untilDatetime: arr[1]?.format(MOMENT_FORMAT),
sinceDatetime,
untilDatetime,
});
} else {
setSinceDate('' as unknown as moment.Moment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,6 @@ export const customTimeRangeEncode = (customRange: CustomRangeType): string => {
untilGrainValue,
anchorValue,
} = { ...customRange };
// specific : specific
// if (SPECIFIC_MODE.includes(sinceMode) && SPECIFIC_MODE.includes(untilMode)) {
// const since =
// sinceMode === 'specific' ? dttmToString(sinceDatetime) : sinceMode;
// const until =
// untilMode === 'specific' ? dttmToString(untilDatetime) : untilMode;
// }
if (sinceDatetime || untilDatetime) {
const since =
sinceMode === 'specific' ? dttmToString(sinceDatetime) : sinceMode;
Expand All @@ -214,29 +207,4 @@ export const customTimeRangeEncode = (customRange: CustomRangeType): string => {
return `${since} : ${until}`;
}
return 'No filter';

// specific : relative
// if (SPECIFIC_MODE.includes(sinceMode) && untilMode === 'relative') {
// const since =
// sinceMode === 'specific' ? dttmToString(sinceDatetime) : sinceMode;
// const until = `DATEADD(DATETIME("${since}"), ${untilGrainValue}, ${untilGrain})`;
// return `${since} : ${until}`;
// }

// relative : specific
// if (sinceMode === 'relative' && SPECIFIC_MODE.includes(untilMode)) {
// const until =
// untilMode === 'specific' ? dttmToString(untilDatetime) : untilMode;
// const since = `DATEADD(DATETIME("${until}"), ${-Math.abs(
// sinceGrainValue,
// )}, ${sinceGrain})`;
// return `${since} : ${until}`;
// }

// relative : relative
// const since = `DATEADD(DATETIME("${anchorValue}"), ${-Math.abs(
// sinceGrainValue,
// )}, ${sinceGrain})`;
// const until = `DATEADD(DATETIME("${anchorValue}"), ${untilGrainValue}, ${untilGrain})`;
// return `${since} : ${until}`;
};

0 comments on commit 65a54af

Please sign in to comment.