-
Notifications
You must be signed in to change notification settings - Fork 8
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
Allow filter feeds by network #81
Conversation
gabaldon
commented
Sep 16, 2021
- Show select to filter feeds by network
- Fix responsive
packages/api/src/repository/Feed.ts
Outdated
let query | ||
network !== 'all' | ||
? (query = this.collection.find({ | ||
feedFullName: { $in: this.dataFeedsFullNames }, | ||
network | ||
})) | ||
: (query = this.collection.find({ | ||
feedFullName: { $in: this.dataFeedsFullNames } | ||
})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a rule of thumb, ternaries shouldn't be used as a replacement for if
/else
statements, and they shouldn't have procedural code in them (e.g. variable binding / value assignment). They're better suited for expressions:
let query | |
network !== 'all' | |
? (query = this.collection.find({ | |
feedFullName: { $in: this.dataFeedsFullNames }, | |
network | |
})) | |
: (query = this.collection.find({ | |
feedFullName: { $in: this.dataFeedsFullNames } | |
})) | |
// Base query will filter by allowed feed names. | |
// If a network is specified, the query will be refined to only include feeds for that network. | |
const baseQuery = { feedFullName: { $in: this.dataFeedsFullNames } } | |
const query = network === 'all' ? baseQuery : { ...baseQuery, network } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or for a mutable, simpler approach:
let query | |
network !== 'all' | |
? (query = this.collection.find({ | |
feedFullName: { $in: this.dataFeedsFullNames }, | |
network | |
})) | |
: (query = this.collection.find({ | |
feedFullName: { $in: this.dataFeedsFullNames } | |
})) | |
// Base query will filter by allowed feed names. | |
// If a network is specified, the query will be refined to only include feeds for that network. | |
const query = { feedFullName: { $in: this.dataFeedsFullNames } } | |
if (network !== 'all') { | |
query['network'] = network | |
} |
9b99707
to
f93a75b
Compare