From 7a01254c0490e1a9033e4d2daeea91003e186f60 Mon Sep 17 00:00:00 2001 From: "Gabriel L. Maljkovich" Date: Fri, 13 Aug 2021 16:53:47 -0300 Subject: [PATCH] Sort disputes by date --- src/commands/list.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/commands/list.ts b/src/commands/list.ts index dd4641f..47cdec7 100644 --- a/src/commands/list.ts +++ b/src/commands/list.ts @@ -49,14 +49,23 @@ export const listCommand = { networkSettings, false, ) - data[chalk.whiteBright.underline(dispute.id)] = disputeEntry + data[dispute.id] = disputeEntry }), ) spinner.stop() + // sort disputes + const findDisputeById = (id: string) => disputes.find(d => d.id === id) + const orderedDisputeIds = Object.keys(data).sort((d1, d2) => + findDisputeById(d1).createdAt > findDisputeById(d2).createdAt ? 1 : -1, + ) + const sortedData = {} + orderedDisputeIds.forEach(disputeId => { + sortedData[chalk.whiteBright.underline(disputeId)] = data[disputeId] + }) // Display disputes log.info('Disputes') log.info('--------') - log.info(treeify.asTree(data, true, true)) + log.info(treeify.asTree(sortedData, true, true)) }, }