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(Layout): convert boolean true/false for omits to the required "tr… #12

Merged
merged 3 commits into from
May 3, 2024

Conversation

Smef
Copy link
Contributor

@Smef Smef commented May 2, 2024

Query is typed with

{
    omit?: boolean
}

but it must actually be a string of "true" or "false". This updates the typing to allow those values, as well as to properly convert boolean values to the string format required for the query to the Data API.

@lart2150
Copy link
Member

lart2150 commented May 2, 2024

@DASPRiD it looks like FM is expecting a string for some reason. since it really should be a string should we change the type to

omit ?: 'true' | 'false';

so we don't need to do the extra mapping?

@lart2150 lart2150 requested a review from DASPRiD May 2, 2024 19:28
@Smef
Copy link
Contributor Author

Smef commented May 2, 2024

I think passing a boolean value makes sense from a JS perspective. It's much easier to think about it like that, rather than dealing with weird fm parameter requirements. My preference would be to use booleans, personally.

@DASPRiD
Copy link
Collaborator

DASPRiD commented May 2, 2024

I'd say, keep the parameter typing unchanged, but run query.omit.toString() to convert it to a boolean string. Something like:

query: (Array.isArray(query) ? query : [query]).map(query => ({
    ...query,
    omit: query.omit?.toString(),
})),

@Smef
Copy link
Contributor Author

Smef commented May 2, 2024

Sounds good. I've pushed those changes.

src/Layout.ts Outdated
@@ -236,8 +236,12 @@ export default class Layout<T extends FieldData = FieldData, U extends GenericPo
params : ListParams<T, U> = {},
ignoreEmptyResult = false
) : Promise<GetResponse<T, U>> {
// convert any boolean "omit" values in the query in the query to "true" or "false" strings
Copy link
Collaborator

Choose a reason for hiding this comment

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

That comment is quite redundant I'd say, think you can get rid of it :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I think it was explaining why before, but got trimmed out at some point

@DASPRiD DASPRiD merged commit 89c9f3f into soliantconsulting:main May 3, 2024
2 checks passed
github-actions bot pushed a commit that referenced this pull request May 3, 2024
## [1.3.1](v1.3.0...v1.3.1) (2024-05-03)

### Bug Fixes

* **Layout:** convert boolean true/false for omits to string ([#12](#12)) ([89c9f3f](89c9f3f))
Copy link

github-actions bot commented May 3, 2024

🎉 This PR is included in version 1.3.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Smef Smef deleted the fix-omit-type-handling branch May 3, 2024 21:21
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.

None yet

3 participants