Skip to content

Commit

Permalink
Merge pull request #1672 from kaloudis/channels-sort-by-close-height
Browse files Browse the repository at this point in the history
Channels: sort by close height
  • Loading branch information
kaloudis authored Sep 21, 2023
2 parents d8c441d + ebaab63 commit ec513b8
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 69 deletions.
2 changes: 1 addition & 1 deletion views/Channels/Channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export default class ChannelView extends React.Component<
sensitive
/>
)}
{closeHeight && (
{!!closeHeight && (
<KeyValue
keyValue={localeString(
'views.Channel.closeHeight'
Expand Down
164 changes: 96 additions & 68 deletions views/Channels/ChannelsPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,72 +40,97 @@ interface ChannelsProps {
@inject('ChannelsStore', 'SettingsStore')
@observer
export default class ChannelsPane extends React.PureComponent<ChannelsProps> {
private getChannelsSortKeys = () => [
{
key: `${localeString('views.Channel.capacity')} (${localeString(
'views.Channel.SortButton.largestFirst'
)})`,
value: {
param: 'channelCapacity',
dir: 'DESC',
type: 'numeric'
}
},
{
key: `${localeString('views.Channel.capacity')} (${localeString(
'views.Channel.SortButton.smallestFirst'
)})`,
value: { param: 'channelCapacity', dir: 'ASC', type: 'numeric' }
},
{
key: `${localeString(
'views.Channel.inboundCapacity'
)} (${localeString('views.Channel.SortButton.largestFirst')})`,
value: { param: 'remoteBalance', dir: 'DESC', type: 'numeric' }
},
{
key: `${localeString(
'views.Channel.inboundCapacity'
)} (${localeString('views.Channel.SortButton.smallestFirst')})`,
value: { param: 'remoteBalance', dir: 'ASC', type: 'numeric' }
},
{
key: `${localeString(
'views.Channel.outboundCapacity'
)} (${localeString('views.Channel.SortButton.largestFirst')})`,
value: { param: 'localBalance', dir: 'DESC', type: 'numeric' }
},
{
key: `${localeString(
'views.Channel.outboundCapacity'
)} (${localeString('views.Channel.SortButton.smallestFirst')})`,
value: { param: 'localBalance', dir: 'ASC', type: 'numeric' }
},
{
key: `${localeString('views.Channel.displayName')} (${localeString(
'views.Channel.SortButton.ascending'
)})`,
value: { param: 'displayName', dir: 'ASC', type: 'alphanumeric' }
},
{
key: `${localeString('views.Channel.displayName')} (${localeString(
'views.Channel.SortButton.descending'
)})`,
value: { param: 'displayName', dir: 'DESC', type: 'alphanumeric' }
private getChannelsSortKeys = (closed?: boolean) => {
const sortKeys = [];

if (closed) {
sortKeys.push(
{
key: `${localeString(
'views.Channel.closeHeight'
)} (${localeString('views.Channel.SortButton.ascending')})`,
value: { param: 'closeHeight', dir: 'ASC', type: 'numeric' }
},
{
key: `${localeString(
'views.Channel.closeHeight'
)} (${localeString(
'views.Channel.SortButton.descending'
)})`,
value: {
param: 'closeHeight',
dir: 'DESC',
type: 'numeric'
}
}
);
}
// {
// key: `${localeString('views.Channel.channelId')} (${localeString(
// 'views.Channel.SortButton.ascending'
// )})`,
// value: { param: 'channelId', dir: 'ASC', type: 'alphanumeric' }
// },
// {
// key: `${localeString('views.Channel.channelId')} (${localeString(
// 'views.Channel.SortButton.descending'
// )})`,
// value: { param: 'channelId', dir: 'DESC', type: 'alphanumeric' }
// }
];

sortKeys.push(
{
key: `${localeString('views.Channel.capacity')} (${localeString(
'views.Channel.SortButton.largestFirst'
)})`,
value: {
param: 'channelCapacity',
dir: 'DESC',
type: 'numeric'
}
},
{
key: `${localeString('views.Channel.capacity')} (${localeString(
'views.Channel.SortButton.smallestFirst'
)})`,
value: { param: 'channelCapacity', dir: 'ASC', type: 'numeric' }
},
{
key: `${localeString(
'views.Channel.inboundCapacity'
)} (${localeString('views.Channel.SortButton.largestFirst')})`,
value: { param: 'remoteBalance', dir: 'DESC', type: 'numeric' }
},
{
key: `${localeString(
'views.Channel.inboundCapacity'
)} (${localeString('views.Channel.SortButton.smallestFirst')})`,
value: { param: 'remoteBalance', dir: 'ASC', type: 'numeric' }
},
{
key: `${localeString(
'views.Channel.outboundCapacity'
)} (${localeString('views.Channel.SortButton.largestFirst')})`,
value: { param: 'localBalance', dir: 'DESC', type: 'numeric' }
},
{
key: `${localeString(
'views.Channel.outboundCapacity'
)} (${localeString('views.Channel.SortButton.smallestFirst')})`,
value: { param: 'localBalance', dir: 'ASC', type: 'numeric' }
},
{
key: `${localeString(
'views.Channel.displayName'
)} (${localeString('views.Channel.SortButton.ascending')})`,
value: {
param: 'displayName',
dir: 'ASC',
type: 'alphanumeric'
}
},
{
key: `${localeString(
'views.Channel.displayName'
)} (${localeString('views.Channel.SortButton.descending')})`,
value: {
param: 'displayName',
dir: 'DESC',
type: 'alphanumeric'
}
}
);

return sortKeys;
};

renderItem = ({ item }) => {
const { ChannelsStore, navigation } = this.props;
Expand Down Expand Up @@ -196,7 +221,6 @@ export default class ChannelsPane extends React.PureComponent<ChannelsProps> {

render() {
const { ChannelsStore, SettingsStore, navigation } = this.props;
const { channelsType, search } = ChannelsStore;
const {
loading,
getChannels,
Expand All @@ -207,7 +231,9 @@ export default class ChannelsPane extends React.PureComponent<ChannelsProps> {
filteredPendingChannels,
filteredClosedChannels,
setSort,
showSearch
showSearch,
channelsType,
search
} = ChannelsStore;

const lurkerMode: boolean =
Expand Down Expand Up @@ -287,7 +313,9 @@ export default class ChannelsPane extends React.PureComponent<ChannelsProps> {
onValueChange={(value: any) => {
setSort(value);
}}
values={this.getChannelsSortKeys()}
values={this.getChannelsSortKeys(
channelsType === ChannelsType.Closed
)}
/>
</Row>
<FilterOptions ChannelsStore={ChannelsStore} />
Expand Down

0 comments on commit ec513b8

Please sign in to comment.