Traces: Order keys in span filter select (#66689)

* Order logs keys last

* Add tests
This commit is contained in:
Joey 2023-04-25 08:56:06 +01:00 committed by GitHub
parent 3bc002cd27
commit 5c2a344ce1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 7 deletions

View File

@ -151,6 +151,23 @@ describe('SpanFilters', () => {
await selectAndCheckValue(user, tagValue, 'TagValue0');
});
it('should order tag filters', async () => {
render(<SpanFiltersWithProps />);
const tagKey = screen.getByLabelText('Select tag key');
await user.click(tagKey);
jest.advanceTimersByTime(1000);
await waitFor(() => {
const container = screen.getByText('TagKey0').parentElement?.parentElement?.parentElement;
expect(container?.childNodes[0].textContent).toBe('ProcessKey0');
expect(container?.childNodes[1].textContent).toBe('ProcessKey1');
expect(container?.childNodes[2].textContent).toBe('TagKey0');
expect(container?.childNodes[3].textContent).toBe('TagKey1');
expect(container?.childNodes[4].textContent).toBe('LogKey0');
expect(container?.childNodes[5].textContent).toBe('LogKey1');
});
});
it('should allow adding/removing tags', async () => {
render(<SpanFiltersWithProps />);
expect(screen.getAllByLabelText('Select tag key').length).toBe(1);

View File

@ -112,7 +112,8 @@ export const SpanFilters = memo((props: SpanFilterProps) => {
const getTagKeys = () => {
if (!tagKeys) {
const keys: string[] = [];
let keys: string[] = [];
let logKeys: string[] = [];
trace.spans.forEach((span) => {
span.tags.forEach((tag) => {
@ -124,18 +125,18 @@ export const SpanFilters = memo((props: SpanFilterProps) => {
if (span.logs !== null) {
span.logs.forEach((log) => {
log.fields.forEach((field) => {
keys.push(field.key);
logKeys.push(field.key);
});
});
}
});
keys = uniq(keys).sort();
logKeys = uniq(logKeys).sort();
setTagKeys(
uniq(keys)
.sort()
.map((name) => {
return toOption(name);
})
[...keys, ...logKeys].map((name) => {
return toOption(name);
})
);
}
};