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 1 commit
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
61 changes: 49 additions & 12 deletions timesketch/frontend-ng/src/views/Explore.vue
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ limitations under the License.
</v-list-item-action>
<v-list-item-subtitle>Remove filter</v-list-item-subtitle>
</v-list-item>
<v-list-item @click="copyChipValue(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>
</v-card>
</v-menu>
Expand Down Expand Up @@ -246,21 +252,25 @@ limitations under the License.
close
close-icon="mdi-close"
@click:close="removeChip(chip)"
@click="copyChipValue(chip)"
v-bind="attrs"
v-on="onTooltip"
>
<v-icon v-if="chip.value === '__ts_star'" left small color="amber">mdi-star</v-icon>
<v-icon v-if="chip.value === '__ts_comment'" left small>mdi-comment-multiple-outline</v-icon>
<v-icon v-if="getQuickTag(chip.value)" left small :color="getQuickTag(chip.value).color">{{
getQuickTag(chip.value).label
}}</v-icon>
<span v-if="chip.operator === 'must_not'" class="filter-chip-truncate">
<span style="color: red">NOT </span>
{{ (chip.field ? `${chip.field} : ${chip.value}` : chip.value) | formatLabelText }}
</span>
<span v-else class="filter-chip-truncate">
{{ (chip.field ? `${chip.field} : ${chip.value}` : chip.value) | formatLabelText }}
</span>
<span v-if="copiedChip === chip">Copied!</span>
<template v-else>
<v-icon v-if="chip.value === '__ts_star'" left small color="amber">mdi-star</v-icon>
<v-icon v-if="chip.value === '__ts_comment'" left small>mdi-comment-multiple-outline</v-icon>
<v-icon v-if="getQuickTag(chip.value)" left small :color="getQuickTag(chip.value).color">{{
getQuickTag(chip.value).label
}}</v-icon>
<span v-if="chip.operator === 'must_not'" class="filter-chip-truncate">
<span style="color: red">NOT </span>
{{ (chip.field ? `${chip.field} : ${chip.value}` : chip.value) | formatLabelText }}
</span>
<span v-else class="filter-chip-truncate">
{{ (chip.field ? `${chip.field} : ${chip.value}` : chip.value) | formatLabelText }}
</span>
</template>
</v-chip>
</template>
<span>{{ chip.value }}</span>
Expand Down Expand Up @@ -327,6 +337,7 @@ export default {
props: ['sketchId'],
data() {
return {
copiedChip: null,
countPerIndex: {},
countPerTimeline: {},
currentItemsPerPage: 40,
Expand Down Expand Up @@ -540,6 +551,32 @@ export default {
chip.active = !chip.active
this.search()
},
copyChipValue(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
if (chip.operator === 'must_not') {
textToCopy = `NOT ${chip.field ? `${chip.field} : ` : ''}${chip.value}`;
} else {
textToCopy = `${chip.field ? `${chip.field} : ` : ''}${chip.value}`;
}
}

// Copy to clipboard
navigator.clipboard.writeText(textToCopy)
.then(() => {
this.copiedChip = chip;
setTimeout(() => this.copiedChip = null, 2000); // Reset after 2 seconds
})
.catch(err => {
// Handle errors (e.g., clipboard access denied)
});
},
removeChip: function (chip, search = true) {
let chipIndex = this.currentQueryFilter.chips.findIndex((c) => c.value === chip.value)
this.currentQueryFilter.chips.splice(chipIndex, 1)
Expand Down