Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix problems with field selection for visualizations #3249

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ limitations under the License.
<TsEventFieldSelect
:field="selectedField"
@selectedField="selectedField = $event"
:timelineFields="timelineFields"
:loadingFields="loadingFields"
:rules="[rules.required]"
>
</TsEventFieldSelect>
Expand Down Expand Up @@ -116,14 +114,6 @@ export default {
splitByTimeline: {
type: Boolean,
},
timelineFields: {
type: Array,
default: () => [],
},
loadingFields: {
type: Boolean,
default: false
},
},
data() {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ limitations under the License.
<v-autocomplete
outlined
v-model="selectedField"
:items="mappedTimelineFields"
:items="allNonTimestampFields"
label="Field name to aggregate"
:loading="loadingFields"
@input="$emit('selectedField', $event)"
>
<template
Expand Down Expand Up @@ -57,40 +56,33 @@ export default {
field: {
type: Object,
},
timelineFields: {
type: Array,
default: () => [],
},
loadingFields: {
type: Boolean,
default: false
},
},
data() {
return {
selectedField: this.field,
}
},
computed: {
mappedTimelineFields() {
const mappings = this.$store.state.meta.mappings;

return this.timelineFields.map(field => {
const mapping = mappings.find(m => m.field === field);
const type = mapping ? mapping.type : 'unknown';
return { text: field, value: { field, type } };
});
allNonTimestampFields() {
let mappings = this.$store.state.meta.mappings
.filter(
(mapping) => {
return (
mapping['field'] !== 'datetime'
&& mapping['field'] !== 'timestamp'
)
})
.map(
(mapping) => {
return {text: mapping['field'], value: mapping}}
)
return mappings
},
},
watch: {
field() {
this.selectedField = this.field
},
timelineFields(newFields) {
if (!newFields || newFields.length === 0) {
this.selectedField = null;
}
},
}
}
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ limitations under the License.
<v-row class="mt-3">
<v-col>
<TsAggregationEventSelect
@updateTimelineIDs="getTimelineFields"
@updateTimelineIDs="selectedTimelineIDs = $event"
:timelineIDs="selectedTimelineIDs"
@updateQueryString="selectedQueryString = $event"
:queryString="selectedQueryString"
Expand All @@ -48,8 +48,6 @@ limitations under the License.
>
</TsAggregationEventSelect>
<TsAggregationConfig
:timelineFields="availableTimelineFields"
:loadingFields="loadingFields"
:field="selectedField"
@updateField="selectedField = $event"
:aggregator="selectedAggregator"
Expand Down Expand Up @@ -292,8 +290,6 @@ export default {
selectedYTitle: this.yTitle,
renameVisualDialog: false,
selectedChartTitleDraft: this.selectedChartTitleDraft,
availableTimelineFields: [],
loadingFields: false,
}
},
computed: {
Expand All @@ -320,51 +316,6 @@ export default {
},
},
methods: {
getTimelineFields(timelineIDs) {
this.selectedTimelineIDs = timelineIDs
if (!timelineIDs || timelineIDs.length === 0 ) {
this.availableTimelineFields = []
return;
}

this.loadingFields = true;

if (timelineIDs.length === 1) {
ApiClient.getTimelineFields(this.sketch.id, timelineIDs[0])
.then(response => {
this.availableTimelineFields = response.data.objects
this.loadingFields = false
})
.catch(error => {
console.error("Error fetching fields:", error);
this.availableTimelineFields = [];
this.loadingFields = false
});
}
else {
const promises = timelineIDs.map(timelineID => {
return ApiClient.getTimelineFields(this.sketch.id, timelineID)
.then(response => response.data.objects)
.catch(error => {
console.error("Error fetching timeline fields:", error);
return []
})
})

Promise.all(promises)
.then(results => {
// Flatten the arrays and create a set to guarantee uniqueness
const union = [...new Set(results.flat())];
this.availableTimelineFields = union
this.loadingFields = false;
})
.catch(error => {
console.error("Error in Promise.all", error)
this.availableTimelineFields = []
this.loadingFields = false;
})
}
},
rename() {
this.renameVisualDialog = false
this.selectedChartTitle = this.selectedChartTitleDraft
Expand Down
Loading