Skip to content

Commit

Permalink
feat: Allow sort records by event_timestamp or last_updated fields (#…
Browse files Browse the repository at this point in the history
…1924)

* feat: Allow sort records by event_timestamp or last_updated fields

closes #1835

This PR includes the fields event_timestamp and last_updated in the sort filter allowing to sort records by these values

* fix lint

* refactor code

* refactor and clean code after review

* refactor after review
  • Loading branch information
leiyre committed Nov 21, 2022
1 parent 937b410 commit 1c08c36
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
27 changes: 25 additions & 2 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);
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 Down Expand Up @@ -290,6 +299,20 @@ export default {
this.$emit("applySortBy", sortList);
this.close();
},
sortByDateFilter(id, name, group = "Sort") {
return {
id,
key: id,
group,
name,
disabled: this.recordPropertyHasValue(id),
};
},
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

0 comments on commit 1c08c36

Please sign in to comment.