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

Adding a copy action to filter chips #2990

Merged
merged 7 commits into from
Dec 1, 2023
Merged
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
30 changes: 29 additions & 1 deletion timesketch/frontend-ng/src/views/Explore.vue
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,12 @@ limitations under the License.
</template>
<ts-filter-menu app :selected-chip="chip" @updateChip="updateChip($event, chip)"></ts-filter-menu>
</v-menu>

<v-list-item @click="copyFilterChip(chip)">
<v-list-item-action>
<v-icon>mdi-content-copy</v-icon>
</v-list-item-action>
<v-list-item-subtitle>Copy filter</v-list-item-subtitle>
</v-list-item>
<v-list-item @click="toggleChip(chip)">
<v-list-item-action>
<v-icon v-if="chip.active">mdi-eye-off</v-icon>
Expand Down Expand Up @@ -249,6 +254,7 @@ limitations under the License.
close
close-icon="mdi-close"
@click:close="removeChip(chip)"
@click="copyFilterChip(chip)"
v-bind="attrs"
v-on="onTooltip"
>
Expand Down Expand Up @@ -543,6 +549,28 @@ export default {
chip.active = !chip.active
this.search()
},
copyFilterChip(chip) {
let textToCopy = '';
// Different handling based on chip type
if (chip.type.startsWith('datetime')) {
// For datetime chips, just copy the value
textToCopy = chip.value;
} else {
// For other chips, copy both field and value
textToCopy = chip.operator === 'must_not'
? `NOT ${chip.field ? `${chip.field}:` : ''}"${chip.value}"`
: `${chip.field ? `${chip.field}:` : ''}"${chip.value}"`;
}
// Copy to clipboard
navigator.clipboard.writeText(textToCopy)
.then(() => {
this.infoSnackBar('Copied to clipboard!')
})
.catch((e) => {
this.errorSnackBar('Failed to copy to clipboard.')
console.error(e)
});
},
removeChip: function (chip, search = true) {
let chipIndex = this.currentQueryFilter.chips.findIndex((c) => c.value === chip.value)
this.currentQueryFilter.chips.splice(chipIndex, 1)
Expand Down