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: app router support #76

Merged
merged 12 commits into from Nov 29, 2023
Merged

feat: app router support #76

merged 12 commits into from Nov 29, 2023

Conversation

foyarash
Copy link
Collaborator

#54

Copy link

changeset-bot bot commented Nov 28, 2023

🦋 Changeset detected

Latest commit: 78b6728

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@premieroctet/next-admin Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

.github/workflows/e2e.yml Outdated Show resolved Hide resolved
Comment on lines 139 to 183
data.forEach((item, index) => {
Object.keys(item).forEach((key) => {
let itemValue;

if (typeof item[key] === "object" && item[key] !== null) {
switch (item[key].type) {
case "link":
itemValue = item[key].value.label;
break;
case "count":
itemValue = item[key].value;
break;
case "date":
itemValue = item[key].value.toString();
break;
default:
itemValue = item[key].id;
break;
}

item[key].__nextadmin_formatted = itemValue;
} else if (isScalar(item[key]) && item[key] !== null) {
item[key] = {
type: "scalar",
value: item[key],
__nextadmin_formatted: item[key].toString(),
};
itemValue = item[key].value;
}

if (
appDir &&
key in listFields &&
listFields[key as keyof typeof listFields]?.formatter &&
!!itemValue
) {
item[key].__nextadmin_formatted = listFields[
key as keyof typeof listFields
// @ts-expect-error
]?.formatter?.(itemValue ?? item[key]);
} else {
data[index][key] = item[key];
}
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need these new formatters ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So the initial behavior was to pass the options object as a prop of the NextAdmin component, which was causing issues with the fields with the formatter function since those were not serializable. So for the app router, the idea was to run the formatting on the server side. To achieve that, we needed to take the behavior of the Cell component and apply it on the server side

@foyarash foyarash merged commit 16aba39 into main Nov 29, 2023
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.

None yet

2 participants