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

fix: fix buildSortBy issue when sort is undefined #52

Merged
merged 1 commit into from
Feb 12, 2024

Conversation

dziraf
Copy link
Collaborator

@dziraf dziraf commented Feb 12, 2024

No description provided.

@@ -35,6 +37,7 @@ export class Resource extends BaseResource {
this.enums = getEnums(clientModule);
this.manager = this.client[lowerCase(model.name)];
this.propertiesObject = this.prepareProperties();
this.idProperty = this.properties().find((p) => p.isId())!;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

non-null assertion should be safe here... A resource without ID property wouldn't work in AdminJS anyway

@@ -69,15 +72,18 @@ export class Resource extends BaseResource {

public async find(
filter: Filter,
params: Record<string, any> = {},
params: {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copied types from BaseResource. adminjs should export a proper type for this

let { sortBy: path } = sort;
const { direction = 'desc' } = sort;

if (!path) path = this.idProperty.path();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sort by id column if nothing to sort by is specified

@dziraf dziraf merged commit 74ecdad into main Feb 12, 2024
6 checks passed
Copy link

🎉 This PR is included in version 5.0.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant