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

feat: Allow sort records by event_timestamp or last_updated fields #1924

Merged
merged 5 commits into from Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 26 additions & 3 deletions frontend/components/commons/header/filters/FiltersList.vue
Expand Up @@ -235,6 +235,10 @@ export default {
a.key.toLowerCase() > b.key.toLowerCase() ? 1 : -1
)) ||
[];
const dateFields = [
this.sortByDateFilter("last_updated", "Last Updated"),
this.sortByDateFilter("event_timestamp", "Event Timestamp"),
].filter(({ disabled }) => !disabled);
leiyre marked this conversation as resolved.
Show resolved Hide resolved
const uncoveredByRules = {
id: "uncovered_by_rules",
key: "uncovered_by_rules",
Expand All @@ -243,9 +247,14 @@ export default {
options: [true, false],
selected:
this.dataset.query.uncovered_by_rules &&
this.dataset.query.uncovered_by_rules.length > 0,
this.dataset.query.uncovered_by_rules?.length > 0,
};
return [...filters, ...sortedMetadataFilters, uncoveredByRules];
return [
...filters,
...dateFields,
...sortedMetadataFilters,
uncoveredByRules,
];
},
},
methods: {
Expand All @@ -264,7 +273,7 @@ export default {
},
selectGroup(group) {
if (this.initialVisibleGroup === group) {
this.initialVisibleGroup = null;
this.initialVisibleGroup = null;
} else {
this.initialVisibleGroup = group;
}
Expand All @@ -290,6 +299,20 @@ export default {
this.$emit("applySortBy", sortList);
this.close();
},
sortByDateFilter(id, name) {
return {
id: id,
key: id,
group: "Sort",
name: name,
disabled: this.recordPropertyHasValue(id),
};
leiyre marked this conversation as resolved.
Show resolved Hide resolved
},
recordPropertyHasValue(prop) {
return (
!this.dataset.results.records.some((record) => record[prop]) || false
);
},
},
};
</script>
Expand Down
2 changes: 2 additions & 0 deletions frontend/models/Common.js
Expand Up @@ -31,6 +31,7 @@ class BaseRecord {
status,
selected,
event_timestamp,
last_updated,
search_keywords,
}) {
this.id = id;
Expand All @@ -40,6 +41,7 @@ class BaseRecord {
this.status = status;
this.selected = selected || false;
this.event_timestamp = event_timestamp;
this.last_updated = last_updated;
this.search_keywords = search_keywords || [];
}

Expand Down