-
Notifications
You must be signed in to change notification settings - Fork 2
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
86 pagination #97
86 pagination #97
Conversation
added basic Pagination to DatasetList added .idea to .gitignore added basic search functionality retain search criteria when paginating across filtered results made offset computed property of currentPageIndex WIP - building framework for sorting renamed var enabled sorting by columns in Dataset table changed comments account for no sorting allow for sort criteria to not be included in request added comment fixed comments retrieve updated results by query only re-trigger result retrieval when sort query changes visually indicate default sort field; sort by one field at a time update page count whenever results are retrieved visually indicate default sorting field on page load; update source refs instead of computed property when sort criteria changes watch computed properties instead of source refs edited comments edited comments edited comments edited comments minor refactoring made pagination part of table enabled sorting datasets by num_genome_files field added filters for Staged and Archived fields retain filter criteria across pages
.gitignore
Outdated
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.
db/postgres has scripts/install_extensions.sh, a script to install pg extensions. Could you please specify why this directory is ignored?
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.
I didn't add the ignore. My IDE simply added a newline character after the last line.
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.
I believe that I added this ignore a while ago to prevent database data files from being included when developing locally with docker. Now that we're using prisma migrations, we may need to adjust this rule.
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.
I see, I'll update it. Rishi, you can ignore this.
query('type').isIn(config.dataset_types).optional(), | ||
query('name').notEmpty().escape().optional(), | ||
query('days_since_last_staged').isInt().toInt().optional(), | ||
query('limit').isInt().toInt().optional(), |
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.
prisma query may fail when limit / offset are null/undefined
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.
The UI service method which calls this endpoint will simply omit any null / undefined fields.
I tried explicitly sending limit=null
in my URL, in which case the response complains about invalid value being supplied to limit
, since we have isInt()
validation defined on it. As far as I can tell, this is what we want?
Did you have any other scenario in mind?
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.
No, you are correct that the validator will throw error if the request has null values.
FYI, along with the UI, this API is also used by the workers.
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.
The workers' watch script uses this API to get the list of names of all registered datasets. So, it would be simpler to return all results when limit and offset are not provided which I guess this current design does.
api/src/routes/datasets.js
Outdated
@@ -22,6 +22,80 @@ const isPermittedTo = accessControl('datasets'); | |||
const router = express.Router(); | |||
const prisma = new PrismaClient(); | |||
|
|||
const default_metadata_field_comparison_fns = { |
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.
can you use this instead?
function cmp(a, b) {
return a != null && b != null ? (a < b ? -1 : a > b ? 1 : 0) : 0;
}
api/src/routes/datasets.js
Outdated
@@ -176,6 +329,17 @@ router.get( | |||
}, | |||
}); | |||
|
|||
// Perform sorting by metadata fields, if said fields are included in request. |
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.
Sorting after filtering and pagination will not yield correct results.
Drop the feature of sorting datasets by metadata fields, this would reduce the code complexity.
api/src/routes/datasets.js
Outdated
router.get( | ||
'/', | ||
'/count', |
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.
It would be beneficial to consider incorporating the count within the /datasets endpoint rather than having it as a distinct endpoint. This adjustment is not just about code organization and aesthetics; it has practical implications. When the count is separated from the data endpoint, there is potential for variations in results when different users attempt to add, update, or delete datasets.
One approach to address this concern is to encapsulate the count Prisma function and the data function within a transaction. The response to the /datasets endpoint could take the following form:
{
"metadata": {
"total": 50
},
"datasets": []
}
TODO: By changing API response format, we need to update the code that consumes this API.
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.
Updated this for the UI side.
working with simplified compare fn further simplified sort function removed sorting by num_genome_files
I have fixed this as well. Turns out that Prisma does not support sorting by the nulls-last option for non-nullable columns. It also does not support sorting by multiple columns when some of them are nullable, and others are not. Therefore, to enable sorting in both nullable-field and non-nullable-field cases, I had to limit the sortBy to a single column. |
api/src/routes/datasets.js
Outdated
}, | ||
}; | ||
} | ||
|
||
const datasets = await prisma.dataset.findMany({ |
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.
get total count and results in one transaction. see https://stackoverflow.com/a/74334140
@@ -219,7 +260,7 @@ const columns = ref([ | |||
label: "archived", | |||
thAlign: "center", | |||
tdAlign: "center", | |||
sortable: true, | |||
sortingFn: () => {}, // overrides va-data-table's default sorting behavior |
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.
do we need sortingFn on columns where sortable is false (default)?
Description
Related Issue(s)
Closes #86
Changes Made
metadata
column, with some reasonable defaults.Checklist
Before submitting this PR, please make sure that: