Skip to content

Commit

Permalink
refactor: modify the sorting in the inbox based on descending creatio…
Browse files Browse the repository at this point in the history
…n time

# Conflicts:
#	app/services/inbox_service.rb
  • Loading branch information
Tasnim Mehzabin committed Oct 23, 2023
1 parent 5f6d6ad commit 12953d0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
11 changes: 8 additions & 3 deletions app/api/entities/inbox_entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ def children
dataset_page = options[:dataset_page].to_i || 1
start_index = (dataset_page - 1) * DATASETS_PER_PAGE
end_index = start_index + DATASETS_PER_PAGE - 1
serialize_children(object.hash_tree(limit_depth: depth)[object].to_a.slice(start_index..end_index).to_h)

parent_objects = object.hash_tree(limit_depth: depth)[object].to_a
sorted_parents = parent_objects.sort_by { |container, _| container.created_at }.reverse
parents_slice = sorted_parents[start_index..end_index]

serialize_children(parents_slice.to_h)
end

def serialize_children(container_tree_hash)
Expand All @@ -49,7 +54,7 @@ def unlinked_attachments
attachable_type: 'Container',
attachable_id: nil,
created_for: object&.containable&.id,
)
).order(created_at: :desc)
end

def all_descendants_attachments
Expand All @@ -59,7 +64,7 @@ def all_descendants_attachments
FROM attachments AS sub_attachments
WHERE sub_attachments.attachable_id = attachments.attachable_id
LIMIT 50
)")
)").order(created_at: :desc)
end

def inbox_count
Expand Down
3 changes: 0 additions & 3 deletions app/packs/src/apps/mydb/collections/CollectionTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,6 @@ export default class CollectionTree extends React.Component {

let boxes = '';
if (inbox.children) {
inbox.children.sort((a, b) => {
if (a.name > b.name) { return 1; } if (a.name < b.name) { return -1; } return 0;
});
boxes = inbox.children.map((deviceBox) => (
<DeviceBox key={`box_${deviceBox.id}`} device_box={deviceBox} fromCollectionTree />
));
Expand Down
4 changes: 0 additions & 4 deletions app/packs/src/apps/mydb/inbox/DeviceBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,6 @@ export default class DeviceBox extends React.Component {
</span>
);

device_box.children.sort((a, b) => {
if (a.name > b.name) { return 1; } if (a.name < b.name) { return -1; } return 0;
});

const datasets = device_box.children.map((dataset) => (
<DatasetContainer
key={`dataset_${dataset.id}`}
Expand Down
3 changes: 0 additions & 3 deletions app/packs/src/apps/mydb/inbox/InboxModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@ export default class InboxModal extends React.Component {

let boxes = '';
if (inbox.children) {
inbox.children.sort((a, b) => {
if (a.name > b.name) { return 1; } if (a.name < b.name) { return -1; } return 0;
});
boxes = inbox.children.map(deviceBox => (
<DeviceBox
key={`box_${deviceBox.id}`}
Expand Down

0 comments on commit 12953d0

Please sign in to comment.