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: add dynamic table columns on resource page #181

Merged

Conversation

Placeholder30
Copy link
Collaborator

No description provided.

@Placeholder30 Placeholder30 self-assigned this Nov 15, 2021
Copy link
Member

@bahdcoder bahdcoder left a comment

Choose a reason for hiding this comment

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

Shared some feedback. Please have a look !

@@ -26,6 +26,7 @@ import {
filterClauses,
FilterClause
} from '../../../store/resource'
import { truncate } from 'lodash'
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need this function here. Also quick note, you won't wanna use lodash in your project coz there's most likely a better way. And ... if you were actually gonna use lodash, its better to import using import truncate from 'lodash/truncate', that way we enjoy tree shaking from webpack, pulling in only required functions from the package.

But yeah, we don't need it in this case 😅

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it was auto import, lol forgot to clear it.

field: 'nationality'
},
...(resource?.fields
.filter((resource, idx) => resource.showOnIndex && idx != 0)
Copy link
Member

Choose a reason for hiding this comment

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

We are looping through resource?.fields, so a better variable name should be field and not resource. Also, even if it was supposed to be resource, we'll have to give it another name, so as to avoid shadow variables. since we have another variable called resource, it's not easily understandable to have another variable with same name.

So here, I suggest we have (resource?.fields.filter((field, idx) => field.showOnIndex)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, i will implement.

field: 'nationality'
},
...(resource?.fields
.filter((resource, idx) => resource.showOnIndex && idx != 0)
Copy link
Member

Choose a reason for hiding this comment

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

Quick question, why idx != 0? Also, in future, it's much recommended to check using !== if you need to. Its a much more exact search and better for code predictability.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I noticed the ID field was not shown in the example, so I filtered it. I can put it back if it is required.

...(resource?.fields
.filter((resource, idx) => resource.showOnIndex && idx != 0)
.map(resource => ({
field: resource.name,
Copy link
Member

Choose a reason for hiding this comment

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

So the field here would be the name of how the data is returned from the API, it'll be field: field.databaseField.

@bahdcoder
Copy link
Member

@Placeholder30 one more thing to note. In the Filter component we have, have a look at the useMemo. We wanna do exact same thing here so this loop does not run on every component rerender. We wanna cache this and only recompute when the resource changes.

...(resource?.fields
.filter(field => field.showOnIndex)
.map(field => ({
field: field.name,
Copy link
Member

Choose a reason for hiding this comment

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

You mixed it up 😬 . field is field.databaseField and name is field.name

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sorry, I'll fix it.

Copy link
Member

@bahdcoder bahdcoder left a comment

Choose a reason for hiding this comment

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

Sweet ! Thanks !

@bahdcoder bahdcoder merged commit ffa42e0 into master Nov 15, 2021
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