diff --git a/app/components/Package/TrendsChart.vue b/app/components/Package/TrendsChart.vue index a1e4158c9..a62c7ccf2 100644 --- a/app/components/Package/TrendsChart.vue +++ b/app/components/Package/TrendsChart.vue @@ -6,28 +6,44 @@ import { useCssVariables } from '~/composables/useColors' import { OKLCH_NEUTRAL_FALLBACK, transparentizeOklch } from '~/utils/colors' import { getFrameworkColor, isListedFramework } from '~/utils/frameworks' import { drawNpmxLogoAndTaglineWatermark } from '~/composables/useChartWatermark' +import type { + ChartTimeGranularity, + DailyDataPoint, + DateRangeFields, + EvolutionData, + EvolutionOptions, + MonthlyDataPoint, + WeeklyDataPoint, + YearlyDataPoint, +} from '~/types/chart' + +const props = withDefaults( + defineProps<{ + // For single package downloads history + weeklyDownloads?: WeeklyDataPoint[] + inModal?: boolean -const props = defineProps<{ - // For single package downloads history - weeklyDownloads?: WeeklyDataPoint[] - inModal?: boolean - - /** - * Backward compatible single package mode. - * Used when `weeklyDownloads` is provided. - */ - packageName?: string + /** + * Backward compatible single package mode. + * Used when `weeklyDownloads` is provided. + */ + packageName?: string - /** - * Multi-package mode. - * Used when `weeklyDownloads` is not provided. - */ - packageNames?: string[] - createdIso?: string | null + /** + * Multi-package mode. + * Used when `weeklyDownloads` is not provided. + */ + packageNames?: string[] + createdIso?: string | null - /** When true, shows facet selector (e.g. Downloads / Likes). */ - showFacetSelector?: boolean -}>() + /** When true, shows facet selector (e.g. Downloads / Likes). */ + showFacetSelector?: boolean + permalink?: boolean + }>(), + { + permalink: false, + }, +) const { locale } = useI18n() const { accentColors, selectedAccentColor } = useAccentColor() @@ -110,14 +126,7 @@ const watermarkColors = computed(() => ({ const mobileBreakpointWidth = 640 const isMobile = computed(() => width.value > 0 && width.value < mobileBreakpointWidth) -type ChartTimeGranularity = 'daily' | 'weekly' | 'monthly' | 'yearly' const DEFAULT_GRANULARITY: ChartTimeGranularity = 'weekly' -type EvolutionData = DailyDataPoint[] | WeeklyDataPoint[] | MonthlyDataPoint[] | YearlyDataPoint[] - -type DateRangeFields = { - startDate?: string - endDate?: string -} function isRecord(value: unknown): value is Record { return typeof value === 'object' && value !== null @@ -322,7 +331,10 @@ const effectivePackageNames = computed(() => { return single ? [single] : [] }) -const selectedGranularity = shallowRef(DEFAULT_GRANULARITY) +const selectedGranularity = usePermalink('granularity', DEFAULT_GRANULARITY, { + permanent: props.permalink, +}) + const displayedGranularity = shallowRef(DEFAULT_GRANULARITY) const isEndDateOnPeriodEnd = computed(() => { @@ -352,8 +364,13 @@ const shouldRenderEstimationOverlay = computed( () => !pending.value && isEstimationGranularity.value, ) -const startDate = shallowRef('') // YYYY-MM-DD -const endDate = shallowRef('') // YYYY-MM-DD +const startDate = usePermalink('start', '', { + permanent: props.permalink, +}) +const endDate = usePermalink('end', '', { + permanent: props.permalink, +}) + const hasUserEditedDates = shallowRef(false) /** @@ -578,7 +595,9 @@ const METRICS = computed(() => [ }, ]) -const selectedMetric = shallowRef(DEFAULT_METRIC_ID) +const selectedMetric = usePermalink('facet', DEFAULT_METRIC_ID, { + permanent: props.permalink, +}) // Per-metric state keyed by metric id const metricStates = reactive< diff --git a/app/components/Package/WeeklyDownloadStats.vue b/app/components/Package/WeeklyDownloadStats.vue index 0bf59e4bc..dfe7da4f6 100644 --- a/app/components/Package/WeeklyDownloadStats.vue +++ b/app/components/Package/WeeklyDownloadStats.vue @@ -1,6 +1,7 @@