Skip to content

Commit

Permalink
Fixes whole campaign not being fetched (#97115)
Browse files Browse the repository at this point in the history
* Fixes whole campaign not being fetched

* Fixes whole campaign not being fetched
  • Loading branch information
j6ll authored Dec 6, 2024
1 parent db6e07b commit 26a3b5e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,12 @@ export default function CampaignItemDetails( props: Props ) {

const activeDays = getCampaignActiveDays( start_date, end_date );

const [ selectedDateRange, setSelectedDateRange ] = useState< ChartSourceDateRanges >(
activeDays >= 7 ? ChartSourceDateRanges.LAST_7_DAYS : ChartSourceDateRanges.WHOLE_CAMPAIGN
);
const initialRange =
activeDays <= 7 ? ChartSourceDateRanges.WHOLE_CAMPAIGN : ChartSourceDateRanges.LAST_7_DAYS;
const initialResolution = activeDays < 3 ? ChartResolution.Hour : ChartResolution.Day;

const [ selectedDateRange, setSelectedDateRange ] =
useState< ChartSourceDateRanges >( initialRange );

const getChartStartDate = ( dateRange: ChartSourceDateRanges ) => {
const effectiveEndDate = getEffectiveEndDate();
Expand Down Expand Up @@ -310,18 +313,18 @@ export default function CampaignItemDetails( props: Props ) {
};

const [ chartParams, setChartParams ] = useState( {
startDate: getChartStartDate( ChartSourceDateRanges.LAST_7_DAYS ),
startDate: getChartStartDate( initialRange ),
endDate: getEffectiveEndDate().toISOString().split( 'T' )[ 0 ],
resolution: ChartResolution.Day,
resolution: initialResolution,
} );

const updateChartParams = ( newDateRange: ChartSourceDateRanges ) => {
// These shorter time frames can show hourly data, we can show up to 30 days of hourly data (max days stored in Druid)
const newResolution = [ ChartSourceDateRanges.TODAY, ChartSourceDateRanges.YESTERDAY ].includes(
newDateRange
)
? ChartResolution.Hour
: ChartResolution.Day;
const newResolution =
[ ChartSourceDateRanges.TODAY, ChartSourceDateRanges.YESTERDAY ].includes( newDateRange ) ||
activeDays < 3
? ChartResolution.Hour
: ChartResolution.Day;

const newStartDate = getChartStartDate( newDateRange );

Expand All @@ -343,7 +346,7 @@ export default function CampaignItemDetails( props: Props ) {
const { isLoading: campaignsStatsIsLoading } = campaignStatsQuery;
const { data: campaignStats } = campaignStatsQuery;
const getCampaignStatsChart = (
data: CampaignChartSeriesData[],
data: CampaignChartSeriesData[] | null,
source: ChartSourceOptions,
isLoading = false
) => {
Expand All @@ -356,7 +359,8 @@ export default function CampaignItemDetails( props: Props ) {
</div>
);
}
if ( ! data || data.length === 0 ) {

if ( ! data ) {
return null;
}

Expand Down Expand Up @@ -507,7 +511,7 @@ export default function CampaignItemDetails( props: Props ) {

// The controls that are always shown
chartControls.push( {
onClick: () => setSelectedDateRange( ChartSourceDateRanges.WHOLE_CAMPAIGN ),
onClick: () => updateChartParams( ChartSourceDateRanges.WHOLE_CAMPAIGN ),
title: ChartSourceDateRangeLabels[ ChartSourceDateRanges.WHOLE_CAMPAIGN ],
isDisabled: selectedDateRange === ChartSourceDateRanges.WHOLE_CAMPAIGN,
} );
Expand Down Expand Up @@ -875,7 +879,7 @@ export default function CampaignItemDetails( props: Props ) {
label={ chartSource }
/>
{ getCampaignStatsChart(
campaignStats?.series[ chartSource ] ?? [],
campaignStats?.series[ chartSource ] ?? null,
chartSource,
campaignsStatsIsLoading
) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const CampaignStatsLineChart = ( { data, source, resolution }: GraphProps ) => {

const formatDate = ( date: Date, hourly: boolean ) => {
const options: Intl.DateTimeFormatOptions = hourly
? { hour: 'numeric', minute: 'numeric' }
? { month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric' }
: { month: 'short', day: 'numeric' };
return new Intl.DateTimeFormat( locale, options ).format( date );
};
Expand Down

0 comments on commit 26a3b5e

Please sign in to comment.