Skip to content
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

feat: use human readable title instead of field title #377

Conversation

alexanderleegs
Copy link
Contributor

@alexanderleegs alexanderleegs commented Jan 30, 2024

This PR modifies the behaviour for dgs-v2 pages. For datasets on dgs v2, fields have both an internal name (e.g. notification_no) and a human readable name (e.g. Notification number). We previously were using the internal name for the display of the table header, as well as the field dropdown, as the dgs-v1 datasets only contain an internal name. This PR changes that behaviour such that dgs-v2 pages will use the new human readable names for page display, while still sending the internal name to be used for search queries.

Note that this means the field provided by the frontmatter should now be the human readable name. However, existing pages are unaffected in functionality - for the 2 sites currently making use of dgs-v2 pages, the deslugified versions of the internal representation and the field name are identical.

@alexanderleegs alexanderleegs force-pushed the Feat/use-human-readable-title-instead-of-field-title-for-dgs-v2 branch from a915539 to 64fb8cf Compare March 13, 2024 11:41
@alexanderleegs alexanderleegs changed the base branch from next-gen to next-gen-develop March 13, 2024 11:42
Copy link
Contributor

@seaerchin seaerchin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should aim to verify behaviour of async code here, it's potentially buggy.

style-wise, the disjoint between initialisation and assignment is abit confusing

let formattedSearchField = searchField ? searchField.replace(" ", "_") : ""
if (!!searchField) {
// Datagov-v2 search
if (!!defaultField) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this change required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was previously incorrect and only applying for dgs-v2 layouts where someone had entered a search term - it was supposed to be for any dgs-v2 layout

Comment on lines 120 to 127
if (!columnMetadata) {
// V1 search, id and title are the same
columnMetadata = data.result.fields.map(field => ({
id: field.id,
title: field.id,
}))
}
columnMetadata = columnMetadata || data.result.fields
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is confusing on 2 fronts:

  1. columnMetadata is defined up above but we do the mapping here
  2. why do the map if data.result.fields is sufficient?

without context, i'd have thought data.result.fields alone would be enough. also, columnMeta exists only if there's a default field - i'm assuming without, we will use v1?

also, this is abit confusing here - we initialisecolumMetadata on resp.data - we seem to be assuming order of operations here (that the earlier initialisation will occur before request.done) but i'm not entirely sure this is true, especially in an async context.

can we just verify this behaviour or split up columnMetadata by the if/else?

Copy link
Contributor Author

@alexanderleegs alexanderleegs Mar 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry the columnMetadata = columnMetadata || data.result.fields assignment isn't useful - have removed it in 282e2fa

The order of operations here holds because this is only executed after request.done - where the earlier assignment is done

@@ -115,12 +134,12 @@ function databaseSearch(searchTerm, index, callback) {

// The fieldArray is the array containing the field names in the data.gov.sg table
const removableFields = ["_id", "_full_count", "rank", `rank ${formattedSearchField}`]
fieldArray = remove(data.result.fields, removableFields);
fieldArray = remove(columnMetadata, removableFields);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pointing htis out because of sussy stuff wrt columMetadata above

Copy link
Contributor

@seaerchin seaerchin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm pls add comment for the order cos it mgiht be confusing

@alexanderleegs alexanderleegs merged commit 47ff9bc into next-gen-develop Apr 9, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants