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 Console warning about required type #163

Merged

Conversation

sabina-talipova
Copy link
Contributor

@sabina-talipova sabina-talipova commented Jan 10, 2024

Description

  • Updated property required type for props types.
  • If $this->getOwner()->canEdit() returns boolean value, then $attributes['data-can-create'] is populated with 'data-can-create' instead of boolean value. Now return string value.

Parent issue

Copy link
Member

@emteknetnz emteknetnz left a comment

Choose a reason for hiding this comment

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

Note: I haven't tested locally

Should revert the using of string booleans because they're confusing and instead just rely on native Silverstripe behaviour. Seems like the actual bug is coming from the use of types being an array instead of an object

@@ -44,7 +44,7 @@ protected function getDefaultAttributes(): array
{
$attributes = parent::getDefaultAttributes();
$attributes['data-value'] = $this->Value();
$attributes['data-can-create'] = $this->getOwner()->canEdit();
$attributes['data-can-create'] = $this->getOwner()->canEdit() ? 'true' : 'false';
Copy link
Member

Choose a reason for hiding this comment

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

I don't like the use of string booleans here, it gets confusing. Revert this and just do things how Silverstripe does them natively

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@@ -61,7 +61,7 @@ protected function getDefaultAttributes(): array
{
$attributes = parent::getDefaultAttributes();
$attributes['data-value'] = $this->getValueArray();
$attributes['data-can-create'] = $this->getOwner()->canEdit();
$attributes['data-can-create'] = $this->getOwner()->canEdit() ? 'true' : 'false';
Copy link
Member

Choose a reason for hiding this comment

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

Revert so that we're not using string booleans

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@@ -53,8 +53,8 @@ jQuery.entwine('ss', ($) => {
ownerRelation: inputField.data('owner-relation'),
onChange: this.handleChange.bind(this),
isMulti: this.data('is-multi') ?? false,
types: this.data('types') ?? [],
canCreate: this.getInputField().data('can-create') ?? false,
types: this.data('types') ?? {},
Copy link
Member

Choose a reason for hiding this comment

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

Revert so that we're not using string booleans

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I leave this part with new changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If canEdit() returns true, then data-can-create attribute exists and inputField.data('can-create') = data-can-create, if canEdit() returns false, then inputField.data('can-create') = undefined. So we can use this in JS to return true instead of return a string data-can-create.

@sabina-talipova sabina-talipova force-pushed the pulls/4/fix-console-error branch from f574157 to 23f49e1 Compare January 10, 2024 21:40
Copy link
Member

@emteknetnz emteknetnz left a comment

Choose a reason for hiding this comment

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

Need to rebase to fix merge conflicts

@sabina-talipova sabina-talipova force-pushed the pulls/4/fix-console-error branch from 23f49e1 to f22ce6d Compare January 11, 2024 02:50
@sabina-talipova
Copy link
Contributor Author

Rebased.

Copy link
Member

@emteknetnz emteknetnz left a comment

Choose a reason for hiding this comment

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

Tested locally works good

@emteknetnz emteknetnz merged commit 082657d into silverstripe:4 Jan 11, 2024
10 checks passed
@emteknetnz emteknetnz deleted the pulls/4/fix-console-error branch January 11, 2024 05:28
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.

2 participants