ui: keep state in storage

This commit is contained in:
nick-delirium 2025-01-08 11:20:55 +01:00
parent f7f28de014
commit be51fba227
No known key found for this signature in database
GPG key ID: 93ABD695DF5FDBA0
3 changed files with 21 additions and 13 deletions

View file

@ -199,22 +199,12 @@ export function customTooltipFormatter(uuid: string) {
const partnerColor =
(window as any).__seriesColorMap?.[uuid]?.[partnerName] || '#999';
tooltipContent += `
<div class="flex gap-2 items-center mt-2">
<div style="
border-radius: 99px;
background: ${partnerColor};
width: 1rem;
height: 1rem;">
</div>
<div class="font-medium">${partnerName}</div>
</div>
<div style="border-left: 2px dashed ${partnerColor};" class="flex flex-col px-2 ml-2">
<div class="text-neutral-600 text-sm">
${secondTs ? formatTimeOrDate(secondTs) : categoryLabel}
</div>
<div class="flex items-center gap-1">
<div class="font-medium">${partnerVal ?? '—'}</div>
${buildCompareTag(partnerVal, value)}
</div>
</div>
`;

View file

@ -138,7 +138,7 @@ const WidgetViewTypeOptions = observer(({ metric }: { metric: any }) => {
lineChart: 'Line',
areaChart: 'Stacked Area',
barChart: 'Column',
progressChart: 'Vertical Bar',
progressChart: 'Bar',
columnChart: 'Horizontal Bar',
pieChart: 'Pie',
metric: 'Metric',

View file

@ -33,8 +33,15 @@ interface Props {
siteId: any;
}
const LAYOUT_KEY = '$__layout__$'
function getDefaultState() {
const layout = localStorage.getItem(LAYOUT_KEY)
return layout || 'flex-row'
}
function WidgetView(props: Props) {
const [layout, setLayout] = useState('flex-row');
const [layout, setLayout] = useState(getDefaultState);
const {
match: {
params: { siteId, dashboardId, metricId },
@ -65,7 +72,13 @@ function WidgetView(props: Props) {
metricStore.init();
}
}
const wasCollapsed = settingsStore.menuCollapsed;
settingsStore.updateMenuCollapsed(true)
return () => {
if (!wasCollapsed) {
settingsStore.updateMenuCollapsed(false)
}
}
}, []);
const undoChanges = () => {
@ -104,6 +117,11 @@ function WidgetView(props: Props) {
}
};
const updateLayout = (layout: string) => {
localStorage.setItem(LAYOUT_KEY, layout)
setLayout(layout)
}
return (
<Loader loading={loading}>
<Prompt
@ -148,7 +166,7 @@ function WidgetView(props: Props) {
<Segmented
size='small'
value={layout}
onChange={setLayout}
onChange={updateLayout}
options={[
{
value: 'flex-row',