refactor: timeline style tweaks

This commit is contained in:
Carlos Valente
2025-07-12 18:55:30 +02:00
committed by Carlos Valente
parent cdd021e76d
commit 0eaec1f88f
12 changed files with 427 additions and 162 deletions
@@ -1,6 +1,10 @@
import { useMemo } from 'react';
import { useSearchParams } from 'react-router-dom';
import { getTimeOption } from '../../common/components/view-params-editor/common.options';
import { OptionTitle } from '../../common/components/view-params-editor/constants';
import { ViewOption } from '../../common/components/view-params-editor/viewParams.types';
import { isStringBoolean } from '../../features/viewers/common/viewUtils';
export const getTimelineOptions = (timeFormat: string): ViewOption[] => {
return [
@@ -16,7 +20,40 @@ export const getTimelineOptions = (timeFormat: string): ViewOption[] => {
type: 'boolean',
defaultValue: false,
},
{
id: 'autosize',
title: 'Autosize timeline',
description: 'Timeline will adjust sizes to help with readability and automatically scroll if necessary',
type: 'boolean',
defaultValue: false,
},
],
},
];
};
type TimelineOptions = {
hidePast: boolean;
autosize: boolean;
};
/**
* Utility extract the view options from URL Params
* the names and fallback are manually matched with timerOptions
*/
function getOptionsFromParams(searchParams: URLSearchParams): TimelineOptions {
// we manually make an object that matches the key above
return {
hidePast: isStringBoolean(searchParams.get('hidePast')),
autosize: isStringBoolean(searchParams.get('autosize')),
};
}
/**
* Hook exposes the timeline view options
*/
export function useTimelineOptions(): TimelineOptions {
const [searchParams] = useSearchParams();
const options = useMemo(() => getOptionsFromParams(searchParams), [searchParams]);
return options;
}