ui: keep state in storage
This commit is contained in:
parent
f7f28de014
commit
be51fba227
3 changed files with 21 additions and 13 deletions
|
|
@ -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>
|
||||
`;
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue