Skip to content

Commit

Permalink
fix(explore): Ensure missing columns are rendered in column editor (#…
Browse files Browse the repository at this point in the history
…81351)

When switching projects or if the tags didn't load, we shouldn't render
nothing.
  • Loading branch information
Zylphrex authored Nov 27, 2024
1 parent 71ebb64 commit 0fa3e2f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
6 changes: 6 additions & 0 deletions static/app/utils/discover/fields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
AggregationKey,
DISCOVER_FIELDS,
FieldKey,
FieldKind,
FieldValueType,
getFieldDefinition,
MEASUREMENT_FIELDS,
Expand Down Expand Up @@ -1641,6 +1642,11 @@ export const COMBINED_DATASET_FILTER_KEY_SECTIONS: FilterKeySection[] = [

export const TYPED_TAG_KEY_RE = /tags\[([^\s]*),([^\s]*)\]/;

export function classifyTagKey(key: string): FieldKind {
const result = key.match(TYPED_TAG_KEY_RE);
return result?.[2] === 'number' ? FieldKind.MEASUREMENT : FieldKind.TAG;
}

export function prettifyTagKey(key: string): string {
const result = key.match(TYPED_TAG_KEY_RE);
return result?.[1] ?? key;
Expand Down
16 changes: 15 additions & 1 deletion static/app/views/explore/tables/columnEditorModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {t} from 'sentry/locale';
import {space} from 'sentry/styles/space';
import type {TagCollection} from 'sentry/types/group';
import {defined} from 'sentry/utils';
import {classifyTagKey, prettifyTagKey} from 'sentry/utils/discover/fields';
import {FieldKind} from 'sentry/utils/fields';
import {TypeBadge} from 'sentry/views/explore/components/typeBadge';

Expand All @@ -41,6 +42,19 @@ export function ColumnEditorModal({
}: ColumnEditorModalProps) {
const tags: SelectOption<string>[] = useMemo(() => {
const allTags = [
...columns
.filter(
column =>
!stringTags.hasOwnProperty(column) && !numberTags.hasOwnProperty(column)
)
.map(column => {
return {
label: prettifyTagKey(column),
value: column,
textValue: column,
trailingItems: <TypeBadge kind={classifyTagKey(column)} />,
};
}),
...Object.values(stringTags).map(tag => {
return {
label: tag.name,
Expand Down Expand Up @@ -70,7 +84,7 @@ export function ColumnEditorModal({
return 0;
});
return allTags;
}, [stringTags, numberTags]);
}, [columns, stringTags, numberTags]);

// We keep a temporary state for the columns so that we can apply the changes
// only when the user clicks on the apply button.
Expand Down
14 changes: 2 additions & 12 deletions static/app/views/explore/toolbar/toolbarSortBy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import {Tooltip} from 'sentry/components/tooltip';
import {t} from 'sentry/locale';
import type {Sort} from 'sentry/utils/discover/fields';
import {
classifyTagKey,
parseFunction,
prettifyParsedFunction,
prettifyTagKey,
TYPED_TAG_KEY_RE,
} from 'sentry/utils/discover/fields';
import {FieldKind} from 'sentry/utils/fields';
import {TypeBadge} from 'sentry/views/explore/components/typeBadge';
import {useSpanTags} from 'sentry/views/explore/contexts/spanTagsContext';
import {useResultMode} from 'sentry/views/explore/hooks/useResultsMode';
Expand Down Expand Up @@ -66,20 +65,11 @@ export function ToolbarSortBy({fields, setSorts, sorts}: ToolbarSortByProps) {
trailingItems: <TypeBadge func={func} />,
};
}

const result = field.match(TYPED_TAG_KEY_RE);
const kind =
result?.[2] === 'string'
? FieldKind.TAG
: result?.[2] === 'number'
? FieldKind.MEASUREMENT
: undefined;

return {
label: prettifyTagKey(field),
value: field,
textValue: field,
trailingItems: <TypeBadge kind={kind} />,
trailingItems: <TypeBadge kind={classifyTagKey(field)} />,
};
});

Expand Down
10 changes: 5 additions & 5 deletions static/app/views/explore/toolbar/toolbarVisualize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ export function ToolbarVisualize({}: ToolbarVisualizeProps) {
});

const options = [
...unknownOptions.map(option => ({
label: prettifyTagKey(option),
value: option,
textValue: option,
})),
...Object.values(numberTags).map(tag => {
return {
label: tag.name,
value: tag.key,
textValue: tag.name,
};
}),
...unknownOptions.map(option => ({
label: prettifyTagKey(option),
value: option,
textValue: option,
})),
];

options.sort((a, b) => {
Expand Down

0 comments on commit 0fa3e2f

Please sign in to comment.