This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Added defaultValue to ManualDecorators. #258
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3c88b6d
Added defaultValue to ManualDecorators.
niegowski 8246201
Merge branch 'master' into i/6031
Reinmar 2068a0f
Added upcast conversion for link manual decorators with default values.
niegowski e631e7e
Merge branch 'master' into i/6031
niegowski 5ea7fac
Changed logic of link manual decorator's defaultValue.
niegowski b2dc424
Added more documentation and fixed the pointless interface doc.
Reinmar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -284,10 +284,18 @@ describe( 'LinkCommand', () => { | |
target: '_blank' | ||
} | ||
} ) ); | ||
command.manualDecorators.add( new ManualDecorator( { | ||
id: 'linkIsSth', | ||
label: 'Sth', | ||
attributes: { | ||
class: 'sth' | ||
}, | ||
defaultValue: true | ||
} ) ); | ||
|
||
model.schema.extend( '$text', { | ||
allowIn: '$root', | ||
allowAttributes: [ 'linkHref', 'linkIsFoo', 'linkIsBar' ] | ||
allowAttributes: [ 'linkHref', 'linkIsFoo', 'linkIsBar', 'linkIsSth' ] | ||
} ); | ||
|
||
model.schema.register( 'p', { inheritAllFrom: '$block' } ); | ||
|
@@ -302,19 +310,19 @@ describe( 'LinkCommand', () => { | |
it( 'should insert additional attributes to link when it is created', () => { | ||
setData( model, 'foo[]bar' ); | ||
|
||
command.execute( 'url', { linkIsFoo: true, linkIsBar: true } ); | ||
command.execute( 'url', { linkIsFoo: true, linkIsBar: true, linkIsSth: true } ); | ||
|
||
expect( getData( model ) ).to | ||
.equal( 'foo[<$text linkHref="url" linkIsBar="true" linkIsFoo="true">url</$text>]bar' ); | ||
.equal( 'foo[<$text linkHref="url" linkIsBar="true" linkIsFoo="true" linkIsSth="true">url</$text>]bar' ); | ||
} ); | ||
|
||
it( 'should add additional attributes to link when link is modified', () => { | ||
setData( model, 'f<$text linkHref="url">o[]oba</$text>r' ); | ||
|
||
command.execute( 'url', { linkIsFoo: true, linkIsBar: true } ); | ||
command.execute( 'url', { linkIsFoo: true, linkIsBar: true, linkIsSth: true } ); | ||
|
||
expect( getData( model ) ).to | ||
.equal( 'f[<$text linkHref="url" linkIsBar="true" linkIsFoo="true">ooba</$text>]r' ); | ||
.equal( 'f[<$text linkHref="url" linkIsBar="true" linkIsFoo="true" linkIsSth="true">ooba</$text>]r' ); | ||
} ); | ||
|
||
it( 'should remove additional attributes to link if those are falsy', () => { | ||
|
@@ -324,25 +332,33 @@ describe( 'LinkCommand', () => { | |
|
||
expect( getData( model ) ).to.equal( 'foo[<$text linkHref="url">url</$text>]bar' ); | ||
} ); | ||
|
||
it( 'should add additional attributes to link if those are falsy but decorator\'s defaultValue is set to true', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why storing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
setData( model, 'foo<$text linkHref="url" linkIsBar="true" linkIsFoo="true">u[]rl</$text>bar' ); | ||
|
||
command.execute( 'url', { linkIsFoo: false, linkIsBar: false, linkIsSth: false } ); | ||
|
||
expect( getData( model ) ).to.equal( 'foo[<$text linkHref="url" linkIsSth="false">url</$text>]bar' ); | ||
} ); | ||
} ); | ||
|
||
describe( 'range selection', () => { | ||
it( 'should insert additional attributes to link when it is created', () => { | ||
setData( model, 'f[ooba]r' ); | ||
|
||
command.execute( 'url', { linkIsFoo: true, linkIsBar: true } ); | ||
command.execute( 'url', { linkIsFoo: true, linkIsBar: true, linkIsSth: true } ); | ||
|
||
expect( getData( model ) ).to | ||
.equal( 'f[<$text linkHref="url" linkIsBar="true" linkIsFoo="true">ooba</$text>]r' ); | ||
.equal( 'f[<$text linkHref="url" linkIsBar="true" linkIsFoo="true" linkIsSth="true">ooba</$text>]r' ); | ||
} ); | ||
|
||
it( 'should add additional attributes to link when link is modified', () => { | ||
setData( model, 'f[<$text linkHref="foo">ooba</$text>]r' ); | ||
|
||
command.execute( 'url', { linkIsFoo: true, linkIsBar: true } ); | ||
command.execute( 'url', { linkIsFoo: true, linkIsBar: true, linkIsSth: true } ); | ||
|
||
expect( getData( model ) ).to | ||
.equal( 'f[<$text linkHref="url" linkIsBar="true" linkIsFoo="true">ooba</$text>]r' ); | ||
.equal( 'f[<$text linkHref="url" linkIsBar="true" linkIsFoo="true" linkIsSth="true">ooba</$text>]r' ); | ||
} ); | ||
|
||
it( 'should remove additional attributes to link if those are falsy', () => { | ||
|
@@ -352,29 +368,66 @@ describe( 'LinkCommand', () => { | |
|
||
expect( getData( model ) ).to.equal( 'foo[<$text linkHref="url">url</$text>]bar' ); | ||
} ); | ||
|
||
it( 'should add additional attributes to link if those are falsy but decorator\'s defaultValue is set to true', () => { | ||
setData( model, 'foo[<$text linkHref="url" linkIsBar="true" linkIsFoo="true">url</$text>]bar' ); | ||
|
||
command.execute( 'url', { linkIsFoo: false, linkIsBar: false, linkIsSth: false } ); | ||
|
||
expect( getData( model ) ).to.equal( 'foo[<$text linkHref="url" linkIsSth="false">url</$text>]bar' ); | ||
} ); | ||
} ); | ||
|
||
describe( 'restoreManualDecoratorStates()', () => { | ||
it( 'synchronize values with current model state', () => { | ||
setData( model, 'foo<$text linkHref="url" linkIsBar="true" linkIsFoo="true">u[]rl</$text>bar' ); | ||
setData( model, 'foo<$text linkHref="url" linkIsBar="true" linkIsFoo="true" linkIsSth="true">u[]rl</$text>bar' ); | ||
|
||
expect( decoratorStates( command.manualDecorators ) ).to.deep.equal( { | ||
linkIsFoo: true, | ||
linkIsBar: true | ||
linkIsBar: true, | ||
linkIsSth: true | ||
} ); | ||
|
||
command.manualDecorators.first.value = false; | ||
|
||
expect( decoratorStates( command.manualDecorators ) ).to.deep.equal( { | ||
linkIsFoo: false, | ||
linkIsBar: true | ||
linkIsBar: true, | ||
linkIsSth: true | ||
} ); | ||
|
||
command.restoreManualDecoratorStates(); | ||
|
||
expect( decoratorStates( command.manualDecorators ) ).to.deep.equal( { | ||
linkIsFoo: true, | ||
linkIsBar: true, | ||
linkIsSth: true | ||
} ); | ||
} ); | ||
|
||
it( 'synchronize values with current model state when the decorator that is "on" default is "off"', () => { | ||
setData( model, 'foo<$text linkHref="url" linkIsBar="true" linkIsFoo="true" linkIsSth="false">u[]rl</$text>bar' ); | ||
|
||
expect( decoratorStates( command.manualDecorators ) ).to.deep.equal( { | ||
linkIsFoo: true, | ||
linkIsBar: true, | ||
linkIsSth: false | ||
} ); | ||
|
||
command.manualDecorators.last.value = true; | ||
|
||
expect( decoratorStates( command.manualDecorators ) ).to.deep.equal( { | ||
linkIsFoo: true, | ||
linkIsBar: true, | ||
linkIsSth: true | ||
} ); | ||
|
||
command.restoreManualDecoratorStates(); | ||
|
||
expect( decoratorStates( command.manualDecorators ) ).to.deep.equal( { | ||
linkIsFoo: true, | ||
linkIsBar: true | ||
linkIsBar: true, | ||
linkIsSth: false | ||
} ); | ||
} ); | ||
} ); | ||
|
@@ -383,8 +436,16 @@ describe( 'LinkCommand', () => { | |
it( 'obtain current values from the model', () => { | ||
setData( model, 'foo[<$text linkHref="url" linkIsBar="true">url</$text>]bar' ); | ||
|
||
expect( command._getDecoratorStateFromModel( 'linkIsFoo' ) ).to.be.false; | ||
expect( command._getDecoratorStateFromModel( 'linkIsBar' ) ).to.be.true; | ||
expect( command._getDecoratorStateFromModel( command.manualDecorators.get( 'linkIsFoo' ) ) ).to.be.false; | ||
expect( command._getDecoratorStateFromModel( command.manualDecorators.get( 'linkIsBar' ) ) ).to.be.true; | ||
} ); | ||
|
||
it( 'fallbacks to defaultValue if there is no attribute in model', () => { | ||
setData( model, 'foo[<$text linkHref="url">url</$text>]bar' ); | ||
|
||
expect( command._getDecoratorStateFromModel( command.manualDecorators.get( 'linkIsFoo' ) ) ).to.be.false; | ||
expect( command._getDecoratorStateFromModel( command.manualDecorators.get( 'linkIsBar' ) ) ).to.be.false; | ||
expect( command._getDecoratorStateFromModel( command.manualDecorators.get( 'linkIsSth' ) ) ).to.be.true; | ||
} ); | ||
} ); | ||
} ); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why storing the
false
value in the model? Also, how do you actually remove the value from the model?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I see this – the only thing that needs to change when
defalutValue
istrue
is the state of this button in the UI when you create a new link. Since it'll be on at that point, the command will be executed withisSth:true
and then our job's done. The rest will work the way it works so far. Do I miss something?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed on a call:
LinkFormView
is binding itsisOn
property tovalue
of manual decorator,value
of a manual decorator is updated every timeLinkCommand
isrefresh
ed,value
is extracted from the model's attribute,false
in the attribute to indicate that user already decided whether the manual decorator is supposed to be applied or not