Skip to content

Beta#560

Merged
wojtek-krysiak merged 17 commits intomasterfrom
beta
Aug 27, 2020
Merged

Beta#560
wojtek-krysiak merged 17 commits intomasterfrom
beta

Conversation

@wojtek-krysiak
Copy link
Copy Markdown
Contributor

fixes: #352, #304 and #161

What I did I:

  • moved all the frontend code related to handling record state to useRecord folder - along with useRecord hook
  • removed obsolete hooks, which were replaced by useRecord
  • handled passing empty arrays, objects and nulls by changing them to fixed constants on the frontend and bringing them back to original values on the backend

wojtek-krysiak and others added 6 commits August 26, 2020 09:00
# [3.1.0-beta.1](v3.0.1...v3.1.0-beta.1) (2020-08-26)

### Bug Fixes

* propert handle null valuescloses [#304](#304) ([7d16a4e](7d16a4e))

### Features

* allow to clear <select> field ([19e8db9](19e8db9)), closes [#161](#161)
* unify flatten unflatten logic ([b8435de](b8435de)), closes [#352](#352)
},
} as BaseResource

it('converts empty string to an empty array', function () {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

requst parser changes now constant to empty array.

return { ...memo, [path]: null }
}
}
if (property.isArray() && value === '') {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

line 24 handles that

onChange(property.name, selected.value, selected.record)
} else {
onChange(property.name, '')
onChange(property.name, null)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

now null can be handled by onChange so we can clear select fields

* @param {RecordJSON} record
* @return {FormData}
*/
export default function recordToFormData(record: RecordJSON): FormData {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this function allows onChange to transport string, [], null and {} to the backend

@@ -0,0 +1,78 @@
import flat from 'flat'
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

left this file as it was but moved to use-record/

Object.keys(flattened).forEach((key) => {
paramsCopy[`${property}.${key}`] = flattened[key]
})
} else if (Array.isArray(value)) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added that, so before when user gave {} or [] nothing happened. Now it is stored as "[]" or "{}" and then in toFormData converted to constants so it can be passed in the correct form to the backend

}
}

if (selectedRecord) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

before this was in the above if. But I think that users may set populated record even when value is null like this:

onChange('populatedPropertyName', null, record).

to reset the param but to maintain the value in populated. This is not super likely but possible, and I don't see a place when it could break something

Comment thread src/backend/utils/request-parser.ts Outdated

const payload = Object.entries(originalPayload || {}).reduce((memo, [path, value]) => {
const payload = Object.entries(originalPayload || {}).reduce((memo, [path, formValue]) => {
const property = resource.property(path)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

here is a known issue - resource.property doesn't take into consideration nested properties and options. So when user changes type of the property it wont be affected here. The same goes for nested properties - they wont be properly converted back.

I am on it

wojtek-krysiak and others added 11 commits August 27, 2020 10:21
…ies-send-by-the-wire

fix: disabled fields are stripped from the payloadrelates to #430
# [3.1.0-beta.2](v3.1.0-beta.1...v3.1.0-beta.2) (2020-08-27)

### Bug Fixes

* disabled fields are stripped from the payloadrelates to [#430](#430) ([f0b4319](f0b4319))

### Features

* release ([d21ec77](d21ec77))
# [3.1.0-beta.3](v3.1.0-beta.2...v3.1.0-beta.3) (2020-08-27)

### Bug Fixes

* make sure old adapters also work ([cb0bd3f](cb0bd3f))
…-updated-from-other-inputs

fix: onChange can also update other fields
# [3.1.0-beta.4](v3.1.0-beta.3...v3.1.0-beta.4) (2020-08-27)

### Bug Fixes

* onChange can also update other fields ([46dacb9](46dacb9))
@wojtek-krysiak wojtek-krysiak merged commit b2c456b into master Aug 27, 2020
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 3.1.0 🎉

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.

AdminBro crashes when saving record with an empty array

2 participants