Skip to content

Commit 3f5ed77

Browse files
committed
Optimise Html App of PQ-table (#11667)
1 parent dc30efa commit 3f5ed77

17 files changed

+991
-639
lines changed

ydb/core/persqueue/common_app.cpp

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
#include "common_app.h"
2+
3+
4+
namespace NKikimr::NPQ::NApp {
5+
6+
THtmlPart::THtmlPart(IOutputStream& str)
7+
: Str(str) {
8+
}
9+
10+
THtmlPart::~THtmlPart() {
11+
}
12+
13+
THtmlAppPage::THtmlAppPage(IOutputStream& str, const TString& title)
14+
: THtmlPart(str) {
15+
Str << R"(
16+
<STYLE>
17+
.row {
18+
--bs-gutter-x: 1.5rem;
19+
--bs-gutter-y: 0;
20+
display: flex;
21+
flex-wrap: wrap;
22+
margin-top: calc(-1 * var(--bs-gutter-y));
23+
margin-right: calc(-0.5 * var(--bs-gutter-x));
24+
margin-left: calc(-0.5 * var(--bs-gutter-x));
25+
}
26+
27+
.row > * {
28+
box-sizing: border-box;
29+
flex-shrink: 0;
30+
width: 100%;
31+
max-width: 100%;
32+
padding-right: calc(var(--bs-gutter-x) * 0.5);
33+
padding-left: calc(var(--bs-gutter-x) * 0.5);
34+
margin-top: var(--bs-gutter-y);
35+
}
36+
37+
.col {
38+
flex: 1 0 0%;
39+
}
40+
41+
.properties {
42+
border-bottom-style: solid;
43+
border-top-style: solid;
44+
border-width: 1px;
45+
border-color: darkgrey;
46+
padding-bottom: 10px;
47+
width: 100%;
48+
}
49+
50+
.tgrid {
51+
width: 100%;
52+
border: 0;
53+
}
54+
</STYLE>)";
55+
}
56+
57+
THtmlAppPage::~THtmlAppPage() {
58+
}
59+
60+
TNavigationBar::TNavigationBar(IOutputStream& str)
61+
: THtmlPart(str) {
62+
Str << R"(<UL CLASS="nav nav-tabs">)";
63+
}
64+
65+
TNavigationBar::~TNavigationBar() {
66+
if (FirstContent) {
67+
Str << R"(</UL>)";
68+
} else {
69+
Str << R"(</DIV>)";
70+
}
71+
}
72+
73+
void TNavigationBar::Add(const TString& code, const TString& caption) {
74+
auto& __stream = Str;
75+
76+
auto link = [&]() {
77+
__stream << "<a href=\"#" << code << "\" data-toggle=\"tab\">" << caption << "</a>";
78+
};
79+
80+
if (FirstTab) {
81+
FirstTab = false;
82+
LI_CLASS("active") {
83+
link();
84+
}
85+
} else {
86+
LI() {
87+
link();
88+
}
89+
}
90+
}
91+
92+
TNavigationBarContent::TNavigationBarContent(TNavigationBar& navigationBar, const TString& id)
93+
: NavigationBar(navigationBar) {
94+
95+
auto& __stream = NavigationBar.Str;
96+
if (NavigationBar.FirstContent) {
97+
__stream << R"(
98+
</UL>
99+
<DIV CLASS="tab-content">
100+
<DIV CLASS="tab-pane fade in active container" id=")" << id << R"(">)";
101+
} else {
102+
__stream << R"(<DIV CLASS="tab-pane fade" id=")" << id << R"(">)";
103+
}
104+
}
105+
106+
TNavigationBarContent::~TNavigationBarContent() {
107+
auto& __stream = NavigationBar.Str;
108+
__stream << R"(</DIV>)";
109+
NavigationBar.FirstContent = false;
110+
}
111+
112+
TNavigationBarContentPart::TNavigationBarContentPart(IOutputStream& str, const TString& id)
113+
: THtmlPart(str) {
114+
Str << R"(<DIV CLASS="tab-pane fade" id=")" << id << R"(">)";
115+
}
116+
117+
TNavigationBarContentPart::~TNavigationBarContentPart() {
118+
Str << R"(</DIV>)";
119+
}
120+
121+
TProperties::TProperties(IOutputStream& str, const TString& caption)
122+
: THtmlPart(str) {
123+
124+
Str << R"(
125+
<TABLE CLASS="properties">
126+
<CAPTION>)" << caption << R"(</CAPTION>
127+
<TBODY>
128+
)";
129+
}
130+
131+
TProperties::~TProperties() {
132+
Str << R"(
133+
</TBODY>
134+
</TABLE>
135+
)";
136+
}
137+
138+
void TProperties::Add(const TString& name, const TString& value) {
139+
auto& __stream = Str;
140+
141+
TABLER() {
142+
TABLED() { __stream << name;}
143+
TABLED() { __stream << value; }
144+
}
145+
}
146+
147+
TConfiguration::TConfiguration(IOutputStream& str, const TString& value)
148+
: THtmlPart(str) {
149+
150+
auto& __stream = Str;
151+
DIV() {
152+
DIV() {
153+
Str << "Configuration";
154+
}
155+
PRE() {
156+
Str << value;
157+
}
158+
}
159+
}
160+
161+
162+
}

ydb/core/persqueue/common_app.h

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#pragma once
2+
3+
#include <library/cpp/monlib/service/pages/templates.h>
4+
#include <util/string/builder.h>
5+
6+
7+
#define HTML_APP_PAGE(str, title) WITH_SCOPED(__stream, ::NKikimr::NPQ::NApp::THtmlAppPage(str, TStringBuilder() << title))
8+
#define HTML_PART(str) WITH_SCOPED(__stream, ::NKikimr::NPQ::NApp::THtmlPart(str))
9+
10+
#define NAVIGATION_BAR() WITH_SCOPED(__navigationBar, ::NKikimr::NPQ::NApp::TNavigationBar(__stream))
11+
#define NAVIGATION_TAB(id, caption) __navigationBar.Add(TStringBuilder() << id, TStringBuilder() << caption)
12+
#define NAVIGATION_TAB_CONTENT(id) WITH_SCOPED(__navigationContent, ::NKikimr::NPQ::NApp::TNavigationBarContent(__navigationBar, id))
13+
#define NAVIGATION_TAB_CONTENT_PART(id) WITH_SCOPED(__navigationContent, ::NKikimr::NPQ::NApp::TNavigationBarContentPart(__stream, TStringBuilder() << id))
14+
15+
#define PROPERTIES(caption) WITH_SCOPED(__properties, ::NKikimr::NPQ::NApp::TProperties(__stream, caption))
16+
#define PROPERTY(caption, value) __properties.Add(caption, TStringBuilder() << value)
17+
18+
#define LAYOUT() DIV()
19+
#define LAYOUT_ROW() DIV_CLASS("row")
20+
#define LAYOUT_COLUMN() DIV_CLASS("col")
21+
22+
#define CONFIGURATION(val) WITH_SCOPED(__configuration, ::NKikimr::NPQ::NApp::TConfiguration(__stream, val)) {}
23+
24+
25+
namespace NKikimr::NPQ::NApp {
26+
27+
struct THtmlPart {
28+
THtmlPart(IOutputStream&);
29+
~THtmlPart();
30+
31+
inline operator IOutputStream&() noexcept {
32+
return Str;
33+
}
34+
35+
protected:
36+
IOutputStream& Str;
37+
};
38+
39+
struct THtmlAppPage : public THtmlPart {
40+
THtmlAppPage(IOutputStream&, const TString& title);
41+
~THtmlAppPage();
42+
};
43+
44+
struct TNavigationBar : public THtmlPart {
45+
friend struct TNavigationBarContent;
46+
47+
TNavigationBar(IOutputStream&);
48+
~TNavigationBar();
49+
50+
void Add(const TString& id, const TString& caption);
51+
52+
private:
53+
bool FirstTab = true;
54+
bool FirstContent = true;
55+
};
56+
57+
struct TNavigationBarContent {
58+
TNavigationBarContent(TNavigationBar&, const TString& id);
59+
~TNavigationBarContent();
60+
private:
61+
TNavigationBar& NavigationBar;
62+
};
63+
64+
struct TNavigationBarContentPart : public THtmlPart {
65+
TNavigationBarContentPart(IOutputStream&, const TString& id);
66+
~TNavigationBarContentPart();
67+
};
68+
69+
struct TProperties : public THtmlPart {
70+
TProperties(IOutputStream&, const TString& caption);
71+
~TProperties();
72+
73+
void Add(const TString& name, const TString& value);
74+
};
75+
76+
struct TConfiguration : public THtmlPart {
77+
TConfiguration(IOutputStream&, const TString& value);
78+
~TConfiguration() = default;
79+
};
80+
81+
}

ydb/core/persqueue/events/internal.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,19 +325,16 @@ struct TEvPQ {
325325
};
326326

327327
struct TEvMonResponse : public TEventLocal<TEvMonResponse, EvMonResponse> {
328-
TEvMonResponse(const NPQ::TPartitionId& partition, const TVector<TString>& res, const TString& str)
328+
TEvMonResponse(const NPQ::TPartitionId& partition, const TString& str)
329329
: Partition(partition)
330-
, Res(res)
331330
, Str(str)
332331
{}
333332

334-
TEvMonResponse(const TVector<TString>& res, const TString& str)
335-
: Res(res)
336-
, Str(str)
333+
TEvMonResponse(const TString& str)
334+
: Str(str)
337335
{}
338336

339337
TMaybe<NPQ::TPartitionId> Partition;
340-
TVector<TString> Res;
341338
TString Str;
342339
};
343340

0 commit comments

Comments
 (0)