Skip to content

Commit

Permalink
Add event selection to VisualizationEditor
Browse files Browse the repository at this point in the history
  • Loading branch information
sydp committed Sep 18, 2024
1 parent fcda4e6 commit e19a589
Show file tree
Hide file tree
Showing 2 changed files with 221 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
<!--
Copyright 2023 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<template>
<v-container class='ma-0'>
<v-row class="mt-3">
<v-col >
<!-- <v-container class="ma-0"> -->
<ts-timeline-search
componentName="visualization"
:analyzer-timeline-id="timelineIDs"
@selectedTimelines="selectedTimelineIDs = $event"
>
</ts-timeline-search>
<!-- </v-container> -->
</v-col>
</v-row>
<v-row class="mt-n10">
<v-col>
<v-text-field
outlined
autofocus
label="Event query"
v-model="selectedQueryString"

>
</v-text-field>
</v-col>
</v-row>
<v-row class="mt-n10">
<v-col>
<v-autocomplete
v-bind="$attrs"
v-model="selectedRecentSearch"
:items="allRecentSearches"
clearable
outlined
label="Select a recent search"
:disabled="!!selectedSavedSearch"

>
</v-autocomplete>
</v-col>
<v-col >
<v-autocomplete
:disabled="!!selectedRecentSearch"
v-bind="$attrs"
v-model="selectedSavedSearch"
:items="allSavedSearches"
clearable
outlined
label="Select a saved search"
>
</v-autocomplete>
</v-col>
</v-row>
</v-container>
</template>

<script>
import TsTimelineSearch from '../Analyzer/TimelineSearch.vue'
export default {
components: {
TsTimelineSearch,
},
props: {
queryString: {
type: String
},
queryChips: {
type: Object
},
recentSearch: {
type: Object,
},
timelineIDs: {
type: Array,
default: function() {
return []
},
},
},
data() {
return {
selectedFilter: '',
selectedRecentSearch: null,
selectedSavedSearch: null,
selectedTimelineIDs: this.timelineIDs,
selectedQueryString: this.queryString,
selectedQueryChips: this.queryChips
}
},
computed: {
sketch() {
return this.$store.state.sketch
},
allReadyTimelines() {
// Sort alphabetically based on timeline name.
const timelines = this.sketch.timelines.filter(
tl => tl.status[0].status === 'ready'
);
timelines.sort((a, b) => a.name.localeCompare(b.name))
return timelines;
},
allRecentSearches() {
let searchHistory = this.$store.state.searchHistory
if (Array.isArray(searchHistory)) {
let recentSearches = this.$store.state.searchHistory.map(
(view) => {
return {
text: `${view['query_string']} (${view['query_result_count']})`,
value: view
}
}
)
return recentSearches
}
return []
},
allSavedSearches() {
let savedSearches = this.$store.state.meta.views.map(
(view) => {
return {
text: view['name'], value: view
}
}
)
return savedSearches
}
},
watch: {
queryString() {
console.log(this.queryString)
if (this.queryString) {
return
}
this.selectedRecentSearch = null
this.selectedSavedSearch = null
},
selectedSavedSearch() {
if (!this.selectedSavedSearch) {
this.selectedQueryString = ''
this.selectedTimelineIDs = []
this.selectedQueryChips = null
} else {
this.selectedQueryString = this.selectedSavedSearch.query
let queryFilter = JSON.parse(this.selectedSavedSearch.filter)
let indices = queryFilter.indices
if (indices === '_all') {
this.selectedTimelineIDs = this.allReadyTimelines.map((x) => x.id)
} else {
this.selectedTimelineIDs = indices
}
this.selectedQueryChips = queryFilter.chips.filter(
(chip) => chip.type === 'label' || chip.type === 'term' || chip.type === 'datetime_range'
);
}
},
selectedRecentSearch() {
if (!this.selectedRecentSearch) {
this.selectedQueryString = ''
this.selectedTimelineIDs = []
this.selectedQueryChips = null
} else {
this.selectedQueryString = this.selectedRecentSearch.query_string
let queryFilter = JSON.parse(this.selectedRecentSearch.query_filter)
let indices = queryFilter.indices
if (indices === '_all') {
this.selectedTimelineIDs = this.allReadyTimelines.map((x) => x.id)
} else {
this.selectedTimelineIDs = indices
}
this.selectedQueryChips = queryFilter.chips.filter(
(chip) => chip.type === 'label' || chip.type === 'term' || chip.type === 'datetime_range'
);
}
},
selectedTimelineIDs() {
this.$emit('updateTimelineIDs', this.selectedTimelineIDs)
},
selectedQueryString() {
this.$emit('updateQueryString', this.selectedQueryString)
},
selectedQueryChips() {
this.$emit('updateQueryChips', this.selectedQueryChips)
}
}
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,18 @@ limitations under the License.
</v-btn>
</v-toolbar>
<v-divider class="mx-3"></v-divider>
<v-row class="mt-3">
<v-col >
<v-container class="ma-0">
<ts-timeline-search
componentName="visualization"
@selectedTimelines="selectedTimelineIDs = $event"></ts-timeline-search>
</v-container>
</v-col>
</v-row>
<v-row class="mt-3">
<v-col>
<TsAggregationEventSelect
@updateTimelineIDs="selectedTimelineIDs = $event"
:timelineIDs="selectedTimelineIDs"
@updateQueryString="selectedQueryString = $event"
:queryString="selectedQueryString"
@updateQueryChips="selectedQueryChips = $event"
:queryChips="selectedQueryChips"
>
</TsAggregationEventSelect>
<TsAggregationConfig
@enabled="selectedTimelineIDs.length > 0"
:field="selectedField"
@updateField="selectedField = $event"
:aggregator="selectedAggregator"
Expand Down Expand Up @@ -120,7 +119,7 @@ limitations under the License.
text
color="primary"
@click="loadAggregationData"
:disabled="selectedTimelineIDs.length == 0 || !(
:disabled="!validAggregation || !(
selectedField &&
selectedAggregator &&
selectedChartType
Expand All @@ -133,7 +132,7 @@ limitations under the License.
<v-btn
text
@click="clear"
:disabled="!(
:disabled="!validAggregation || !(
selectedField &&
selectedAggregator &&
selectedChartType
Expand All @@ -157,14 +156,14 @@ import ApiClient from '../../utils/RestApiClient'
import TsAggregationConfig from './AggregationConfig.vue'
import TsChartConfig from './ChartConfig.vue'
import TsChartCard from './ChartCard.vue'
import TsTimelineSearch from '../Analyzer/TimelineSearch.vue'
import TsAggregationEventSelect from './AggregationEventSelect.vue'
export default {
components: {
TsAggregationConfig,
TsChartConfig,
TsChartCard,
TsTimelineSearch,
TsAggregationEventSelect,
},
props: {
aggregator: {
Expand Down Expand Up @@ -286,6 +285,9 @@ export default {
}
},
computed: {
validAggregation() {
return this.selectedTimelineIDs.length > 0 && this.selectedQueryString
},
sketch() {
return this.$store.state.sketch
},
Expand All @@ -304,13 +306,6 @@ export default {
}
return undefined
},
currentQueryString() {
const currentSearchNode = this.$store.state.currentSearchNode
if (!currentSearchNode) {
return ""
}
return currentSearchNode.query_string
},
},
methods: {
rename() {
Expand Down

0 comments on commit e19a589

Please sign in to comment.