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: allow parsing of nested values #275

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/).

## [Unreleased]

### Added
- `Table` - allow parsing of nested values

## v6.3.1 - 2022-01-24

### Fixed
Expand Down
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"dependencies": {
"@a-ui/core": "^5.0.0",
"classnames": "~2.2.6",
"lodash.get": "^4.4.2",
"moment": "^2.29.1",
"react-input-mask": "^2.0.4",
"react-modal": "~3.5.1",
Expand Down
1 change: 1 addition & 0 deletions packages/table/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"rc-slider": "~8.6.1",
"classnames": "~2.2.6",
"moment": "^2.24.0",
"lodash.get": "^4.4.2",
"react-input-mask": "^2.0.4",
"icon": "0.0.1-0"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/table/src/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ const Table = ({
</tbody>
</table>
</div>
{currentPage && totalItems && currentPage && (
{!!currentPage && !!totalItems && !!currentPage && (
<div className="m-table-pagination">
<Select
inline={true}
Expand Down
4 changes: 3 additions & 1 deletion packages/table/src/helpers/Table.helpers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as get from 'lodash.get';

export const isNull = (value) => value === null;
export const isUndefined = (value) => value === undefined;
export const isNil = (value) => isNull(value) || isUndefined(value);
Expand All @@ -14,7 +16,7 @@ const getCellValue = (rowData, key, fallback) => {
return null;
}

const value = rowData[key];
const value = get(rowData, key);

if (isObject(value)) {
return String(value);
Expand Down
66 changes: 43 additions & 23 deletions packages/table/src/mocks/Table.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ export const TABLE_MOCK_COLUMNS = (
{
id: 'firstName',
label: "First name",
value: "firstName",
value: "user.firstName",
},
{
id: 'lastName',
label: "Last name",
value: "lastName",
value: "user.lastName",
},
{
id: 'fullName',
label: "Full name",
value: "fullName",
format(data, col, rowData) {
const { firstName, lastName } = rowData;
const { user: { firstName, lastName } } = rowData;

return `${firstName} ${lastName}`;
},
Expand Down Expand Up @@ -94,53 +94,73 @@ export const TABLE_MOCK_FILTER = [
export const TABLE_MOCK_ROWS = [
{
id: 0,
firstName: "Wyatt",
lastName: "Cooper",
user: {
firstName: "Wyatt",
lastName: "Cooper",
}
},
{
id: 1,
firstName: "Mullen",
lastName: "Ballard",
user: {
firstName: "Mullen",
lastName: "Ballard",
}
},
{
id: 2,
firstName: "Sonia",
lastName: "Bass",
user: {
firstName: "Sonia",
lastName: "Bass",
}
},
{
id: 3,
firstName: "Kristen",
lastName: "Moore",
user: {
firstName: "Kristen",
lastName: "Moore",
}
},
{
id: 4,
firstName: "Moss",
lastName: "Bowen",
user: {
firstName: "Moss",
lastName: "Bowen",
}
},
{
id: 5,
firstName: "Elaine",
lastName: "Michael",
user: {
firstName: "Elaine",
lastName: "Michael",
}
},
{
id: 6,
firstName: "Jerri",
lastName: "Hicks",
user: {
firstName: "Jerri",
lastName: "Hicks",
}
},
{
id: 7,
firstName: "Sharron",
lastName: "Castro",
user: {
firstName: "Sharron",
lastName: "Castro",
}
},
{
id: 8,
firstName: "Harriett",
lastName: "Horton",
user: {
firstName: "Harriett",
lastName: "Horton",
}
},
{
id: 9,
firstName: "Griffin",
lastName: "Navarro",
user: {
firstName: "Griffin",
lastName: "Navarro",
}
},
];

Expand Down