-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathDashboardName.tsx
More file actions
101 lines (93 loc) · 2.97 KB
/
Copy pathDashboardName.tsx
File metadata and controls
101 lines (93 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2025 V Kontakte LLC
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
import { memo, useMemo, useState } from 'react';
import { Tooltip } from '@/components/UI';
import { DashboardNameTitle } from './DashboardNameTitle';
import { useStatsHouseShallow } from '@/store2';
import { MarkdownRender } from '@/components/Markdown/MarkdownRender';
import { produce } from 'immer';
import { StickyTop } from '../StickyTop';
import { SaveButton } from '../SaveButton';
import { HistoryDashboardLabel } from '../HistoryDashboardLabel';
export const DashboardName = memo(function DashboardName() {
const {
dashboardName,
dashboardDescription,
saveParams,
saveDashboard,
setParams,
dashboardVersion,
dashboardCurrentVersion,
} = useStatsHouseShallow(
({
params: { dashboardName, dashboardDescription, dashboardVersion, dashboardCurrentVersion },
saveParams,
saveDashboard,
setParams,
}) => ({
dashboardName,
dashboardDescription,
saveParams,
saveDashboard,
setParams,
dashboardVersion,
dashboardCurrentVersion,
})
);
const [dropdown, setDropdown] = useState(false);
const isHistoricalDashboard = useMemo(
() => !!dashboardVersion && !!dashboardCurrentVersion && dashboardCurrentVersion !== dashboardVersion,
[dashboardVersion, dashboardCurrentVersion]
);
if (!dashboardName) {
return null;
}
const onDashboardSave = async (copy?: boolean) => {
const dashResponse = await saveDashboard(copy);
if (dashResponse) {
setParams(
produce((params) => {
params.dashboardCurrentVersion = undefined;
})
);
setDropdown(false);
}
};
const isDashNamesEqual = dashboardName === saveParams.dashboardName;
return (
<StickyTop>
<div className="container-xl d-flex">
<Tooltip
className="d-flex flex-row gap-2 w-75 my-auto"
title={<DashboardNameTitle name={dashboardName} description={dashboardDescription} />}
hover
horizontal="left"
>
<div className="overflow-hidden text-truncate">
{dashboardName}
{!!dashboardDescription && ':'}
</div>
{!!dashboardDescription && (
<div className="text-secondary flex-grow-1 w-0 d-flex overflow-hidden">
<MarkdownRender inline>{dashboardDescription}</MarkdownRender>
</div>
)}
</Tooltip>
{isHistoricalDashboard && (
<div className="d-flex flex-row gap-2 ms-auto">
<HistoryDashboardLabel />
<SaveButton
onSave={onDashboardSave}
isNamesEqual={isDashNamesEqual}
dropdown={dropdown}
setDropdown={setDropdown}
/>
</div>
)}
</div>
</StickyTop>
);
});