@parca/profile 0.16.73 → 0.16.75
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/Callgraph/index.d.ts +1 -0
- package/dist/Callgraph/index.js +1 -1
- package/dist/GraphTooltip/index.d.ts +1 -0
- package/dist/IcicleGraph.d.ts +1 -0
- package/dist/MatchersInput/SuggestionItem.d.ts +1 -0
- package/dist/MatchersInput/SuggestionsList.d.ts +24 -0
- package/dist/MatchersInput/SuggestionsList.js +162 -0
- package/dist/MatchersInput/index.d.ts +1 -0
- package/dist/MatchersInput/index.js +70 -183
- package/dist/MetricsCircle/index.d.ts +1 -0
- package/dist/MetricsGraph/index.d.ts +1 -0
- package/dist/MetricsSeries/index.d.ts +1 -0
- package/dist/ProfileExplorer/ProfileExplorerCompare.d.ts +1 -0
- package/dist/ProfileExplorer/ProfileExplorerSingle.d.ts +1 -0
- package/dist/ProfileExplorer/index.d.ts +1 -0
- package/dist/ProfileIcicleGraph.d.ts +1 -0
- package/dist/ProfileMetricsGraph/index.d.ts +1 -0
- package/dist/ProfileMetricsGraph/index.js +1 -1
- package/dist/ProfileSelector/CompareButton.d.ts +1 -0
- package/dist/ProfileSelector/MergeButton.d.ts +1 -0
- package/dist/ProfileSelector/index.d.ts +1 -0
- package/dist/ProfileSource.d.ts +1 -0
- package/dist/ProfileTypeSelector/index.d.ts +1 -0
- package/dist/ProfileView/FilterByFunctionButton.d.ts +1 -0
- package/dist/ProfileView/index.d.ts +3 -2
- package/dist/ProfileViewWithData.d.ts +2 -1
- package/dist/ProfileViewWithData.js +1 -1
- package/dist/TopTable.d.ts +1 -0
- package/dist/components/DiffLegend.d.ts +1 -0
- package/dist/components/ProfileShareButton/ResultBox.d.ts +1 -0
- package/dist/components/ProfileShareButton/index.d.ts +1 -0
- package/dist/components/ProfileShareButton/index.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/styles.css +1 -1
- package/dist/useGrpcQuery/index.d.ts +11 -0
- package/dist/useGrpcQuery/index.js +64 -0
- package/dist/useQuery.js +59 -23
- package/dist/utils.js +1 -1
- package/package.json +7 -5
- package/src/MatchersInput/SuggestionsList.tsx +291 -0
- package/src/MatchersInput/index.tsx +78 -285
- package/src/useGrpcQuery/index.ts +42 -0
- package/src/useQuery.tsx +16 -27
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
// Copyright 2022 The Parca Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
|
|
14
|
+
import {Fragment, useCallback, useEffect, useState} from 'react';
|
|
15
|
+
import {Transition} from '@headlessui/react';
|
|
16
|
+
import SuggestionItem from './SuggestionItem';
|
|
17
|
+
import {usePopper} from 'react-popper';
|
|
18
|
+
import {useParcaContext} from '@parca/components';
|
|
19
|
+
|
|
20
|
+
export class Suggestion {
|
|
21
|
+
type: string;
|
|
22
|
+
typeahead: string;
|
|
23
|
+
value: string;
|
|
24
|
+
|
|
25
|
+
constructor(type: string, typeahead: string, value: string) {
|
|
26
|
+
this.type = type;
|
|
27
|
+
this.typeahead = typeahead;
|
|
28
|
+
this.value = value;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class Suggestions {
|
|
33
|
+
literals: Suggestion[];
|
|
34
|
+
labelNames: Suggestion[];
|
|
35
|
+
labelValues: Suggestion[];
|
|
36
|
+
|
|
37
|
+
constructor() {
|
|
38
|
+
this.literals = [];
|
|
39
|
+
this.labelNames = [];
|
|
40
|
+
this.labelValues = [];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface Props {
|
|
45
|
+
suggestions: Suggestions;
|
|
46
|
+
applySuggestion: (suggestion: Suggestion) => void;
|
|
47
|
+
inputRef: HTMLTextAreaElement | null;
|
|
48
|
+
runQuery: () => void;
|
|
49
|
+
focusedInput: boolean;
|
|
50
|
+
isLabelNamesLoading: boolean;
|
|
51
|
+
isLabelValuesLoading: boolean;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const LoadingSpinner = (): JSX.Element => {
|
|
55
|
+
const {loader: Spinner} = useParcaContext();
|
|
56
|
+
|
|
57
|
+
return <div className="pt-2 pb-4">{Spinner}</div>;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const SuggestionsList = ({
|
|
61
|
+
suggestions,
|
|
62
|
+
applySuggestion,
|
|
63
|
+
inputRef,
|
|
64
|
+
runQuery,
|
|
65
|
+
focusedInput,
|
|
66
|
+
isLabelNamesLoading,
|
|
67
|
+
isLabelValuesLoading,
|
|
68
|
+
}: Props): JSX.Element => {
|
|
69
|
+
const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(null);
|
|
70
|
+
const {styles, attributes} = usePopper(inputRef, popperElement, {
|
|
71
|
+
placement: 'bottom-start',
|
|
72
|
+
});
|
|
73
|
+
const [highlightedSuggestionIndex, setHighlightedSuggestionIndex] = useState<number>(-1);
|
|
74
|
+
const [showSuggest, setShowSuggest] = useState(true);
|
|
75
|
+
|
|
76
|
+
const suggestionsLength =
|
|
77
|
+
suggestions.literals.length + suggestions.labelNames.length + suggestions.labelValues.length;
|
|
78
|
+
|
|
79
|
+
const getSuggestion = useCallback(
|
|
80
|
+
(index: number): Suggestion => {
|
|
81
|
+
if (index < suggestions.labelNames.length) {
|
|
82
|
+
return suggestions.labelNames[index];
|
|
83
|
+
}
|
|
84
|
+
if (index < suggestions.labelNames.length + suggestions.literals.length) {
|
|
85
|
+
return suggestions.literals[index - suggestions.labelNames.length];
|
|
86
|
+
}
|
|
87
|
+
return suggestions.labelValues[
|
|
88
|
+
index - suggestions.labelNames.length - suggestions.literals.length
|
|
89
|
+
];
|
|
90
|
+
},
|
|
91
|
+
[suggestions]
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
const resetHighlight = useCallback(
|
|
95
|
+
(): void => setHighlightedSuggestionIndex(-1),
|
|
96
|
+
[setHighlightedSuggestionIndex]
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
const applyHighlightedSuggestion = useCallback((): void => {
|
|
100
|
+
applySuggestion(getSuggestion(highlightedSuggestionIndex));
|
|
101
|
+
resetHighlight();
|
|
102
|
+
}, [resetHighlight, applySuggestion, highlightedSuggestionIndex, getSuggestion]);
|
|
103
|
+
|
|
104
|
+
const applySuggestionWithIndex = useCallback(
|
|
105
|
+
(index: number): void => {
|
|
106
|
+
applySuggestion(getSuggestion(index));
|
|
107
|
+
resetHighlight();
|
|
108
|
+
},
|
|
109
|
+
[resetHighlight, applySuggestion, getSuggestion]
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const highlightNext = useCallback((): void => {
|
|
113
|
+
const nextIndex = highlightedSuggestionIndex + 1;
|
|
114
|
+
if (nextIndex === suggestionsLength) {
|
|
115
|
+
resetHighlight();
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
setHighlightedSuggestionIndex(nextIndex);
|
|
119
|
+
}, [highlightedSuggestionIndex, suggestionsLength, resetHighlight]);
|
|
120
|
+
|
|
121
|
+
const highlightPrevious = useCallback((): void => {
|
|
122
|
+
if (highlightedSuggestionIndex === -1) {
|
|
123
|
+
// Didn't select anything, so starting at the bottom.
|
|
124
|
+
setHighlightedSuggestionIndex(suggestionsLength - 1);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
setHighlightedSuggestionIndex(highlightedSuggestionIndex - 1);
|
|
129
|
+
}, [highlightedSuggestionIndex, suggestionsLength]);
|
|
130
|
+
|
|
131
|
+
const handleKeyPress = useCallback(
|
|
132
|
+
(event: React.KeyboardEvent<HTMLTextAreaElement>): void => {
|
|
133
|
+
if (event.key === 'Enter') {
|
|
134
|
+
// Disable new line in the text area
|
|
135
|
+
event.preventDefault();
|
|
136
|
+
}
|
|
137
|
+
// If there is a highlighted suggestion and enter is hit, we complete
|
|
138
|
+
// with the highlighted suggestion.
|
|
139
|
+
if (highlightedSuggestionIndex >= 0 && event.key === 'Enter') {
|
|
140
|
+
applyHighlightedSuggestion();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// If no suggestions is highlighted and we hit enter, we run the query,
|
|
144
|
+
// and hide suggestions until another actions enables them again.
|
|
145
|
+
if (highlightedSuggestionIndex === -1 && event.key === 'Enter') {
|
|
146
|
+
setShowSuggest(false);
|
|
147
|
+
runQuery();
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
setShowSuggest(true);
|
|
152
|
+
},
|
|
153
|
+
[highlightedSuggestionIndex, applyHighlightedSuggestion, runQuery]
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
const handleKeyDown = useCallback(
|
|
157
|
+
(event: KeyboardEvent): void => {
|
|
158
|
+
// Don't need to handle any key interactions if no suggestions there.
|
|
159
|
+
if (suggestionsLength === 0 || !['Tab', 'ArrowUp', 'ArrowDown'].includes(event.key)) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
event.preventDefault();
|
|
164
|
+
|
|
165
|
+
// Handle tabbing through suggestions.
|
|
166
|
+
if (event.key === 'Tab' && suggestionsLength > 0) {
|
|
167
|
+
event.preventDefault();
|
|
168
|
+
if (event.shiftKey) {
|
|
169
|
+
// Shift + tab goes up.
|
|
170
|
+
highlightPrevious();
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
// Just tab goes down.
|
|
174
|
+
highlightNext();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Up arrow highlights previous suggestions.
|
|
178
|
+
if (event.key === 'ArrowUp') {
|
|
179
|
+
highlightPrevious();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Down arrow highlights next suggestions.
|
|
183
|
+
if (event.key === 'ArrowDown') {
|
|
184
|
+
highlightNext();
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
[suggestionsLength, highlightNext, highlightPrevious]
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
useEffect(() => {
|
|
191
|
+
if (inputRef == null) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
inputRef.addEventListener('keydown', handleKeyDown);
|
|
196
|
+
inputRef.addEventListener('keypress', handleKeyPress as any);
|
|
197
|
+
|
|
198
|
+
return () => {
|
|
199
|
+
inputRef.removeEventListener('keydown', handleKeyDown);
|
|
200
|
+
inputRef.removeEventListener('keypress', handleKeyPress as any);
|
|
201
|
+
};
|
|
202
|
+
}, [inputRef, highlightedSuggestionIndex, suggestions, handleKeyPress, handleKeyDown]);
|
|
203
|
+
|
|
204
|
+
return (
|
|
205
|
+
<>
|
|
206
|
+
{suggestionsLength > 0 && (
|
|
207
|
+
<div
|
|
208
|
+
ref={setPopperElement}
|
|
209
|
+
style={{...styles.popper, marginLeft: 0}}
|
|
210
|
+
{...attributes.popper}
|
|
211
|
+
className="z-50"
|
|
212
|
+
>
|
|
213
|
+
<Transition
|
|
214
|
+
show={focusedInput && showSuggest}
|
|
215
|
+
as={Fragment}
|
|
216
|
+
leave="transition ease-in duration-100"
|
|
217
|
+
leaveFrom="opacity-100"
|
|
218
|
+
leaveTo="opacity-0"
|
|
219
|
+
>
|
|
220
|
+
<div
|
|
221
|
+
style={{width: inputRef?.offsetWidth}}
|
|
222
|
+
className="absolute z-10 max-h-[400px] mt-1 bg-gray-50 dark:bg-gray-900 shadow-lg rounded-md text-base ring-1 ring-black ring-opacity-5 overflow-auto focus:outline-none sm:text-sm"
|
|
223
|
+
>
|
|
224
|
+
{isLabelNamesLoading ? (
|
|
225
|
+
<LoadingSpinner />
|
|
226
|
+
) : (
|
|
227
|
+
<>
|
|
228
|
+
{suggestions.labelNames.map((l, i) => (
|
|
229
|
+
<SuggestionItem
|
|
230
|
+
isHighlighted={highlightedSuggestionIndex === i}
|
|
231
|
+
onHighlight={() => setHighlightedSuggestionIndex(i)}
|
|
232
|
+
onApplySuggestion={() => applySuggestionWithIndex(i)}
|
|
233
|
+
onResetHighlight={() => resetHighlight()}
|
|
234
|
+
value={l.value}
|
|
235
|
+
key={l.value}
|
|
236
|
+
/>
|
|
237
|
+
))}
|
|
238
|
+
</>
|
|
239
|
+
)}
|
|
240
|
+
|
|
241
|
+
{suggestions.literals.map((l, i) => (
|
|
242
|
+
<SuggestionItem
|
|
243
|
+
isHighlighted={highlightedSuggestionIndex === i + suggestions.labelNames.length}
|
|
244
|
+
onHighlight={() =>
|
|
245
|
+
setHighlightedSuggestionIndex(i + suggestions.labelNames.length)
|
|
246
|
+
}
|
|
247
|
+
onApplySuggestion={() =>
|
|
248
|
+
applySuggestionWithIndex(i + suggestions.labelNames.length)
|
|
249
|
+
}
|
|
250
|
+
onResetHighlight={() => resetHighlight()}
|
|
251
|
+
value={l.value}
|
|
252
|
+
key={l.value}
|
|
253
|
+
/>
|
|
254
|
+
))}
|
|
255
|
+
|
|
256
|
+
{isLabelValuesLoading ? (
|
|
257
|
+
<LoadingSpinner />
|
|
258
|
+
) : (
|
|
259
|
+
<>
|
|
260
|
+
{suggestions.labelValues.map((l, i) => (
|
|
261
|
+
<SuggestionItem
|
|
262
|
+
isHighlighted={
|
|
263
|
+
highlightedSuggestionIndex ===
|
|
264
|
+
i + suggestions.labelNames.length + suggestions.literals.length
|
|
265
|
+
}
|
|
266
|
+
onHighlight={() =>
|
|
267
|
+
setHighlightedSuggestionIndex(
|
|
268
|
+
i + suggestions.labelNames.length + suggestions.literals.length
|
|
269
|
+
)
|
|
270
|
+
}
|
|
271
|
+
onApplySuggestion={() =>
|
|
272
|
+
applySuggestionWithIndex(
|
|
273
|
+
i + suggestions.labelNames.length + suggestions.literals.length
|
|
274
|
+
)
|
|
275
|
+
}
|
|
276
|
+
onResetHighlight={() => resetHighlight()}
|
|
277
|
+
value={l.value}
|
|
278
|
+
key={l.value}
|
|
279
|
+
/>
|
|
280
|
+
))}
|
|
281
|
+
</>
|
|
282
|
+
)}
|
|
283
|
+
</div>
|
|
284
|
+
</Transition>
|
|
285
|
+
</div>
|
|
286
|
+
)}
|
|
287
|
+
</>
|
|
288
|
+
);
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
export default SuggestionsList;
|