Skip to content

Commit 4f851f9

Browse files
Oliwer ChristGerrit Code Review
authored andcommitted
Merge "[INTERNAL] sap.ui.model.odata.v4.Context#isInactive: 1 if create activate has been prevented"
2 parents e8b7ca8 + cf534a1 commit 4f851f9

File tree

6 files changed

+65
-19
lines changed

6 files changed

+65
-19
lines changed

src/sap.ui.core/src/sap/ui/model/odata/v4/Context.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,8 @@ sap.ui.define([
513513
.catch(that.oModel.getReporter());
514514
if (oBinding.fireCreateActivate(that)) {
515515
that.bInactive = false;
516+
} else {
517+
that.bInactive = 1;
516518
}
517519
}
518520

@@ -984,14 +986,25 @@ sap.ui.define([
984986
* Returns whether this context is inactive. The result of this function can also be accessed
985987
* via instance annotation "@$ui5.context.isInactive" at the entity.
986988
*
987-
* @returns {boolean|undefined} <code>true</code> if this context is inactive,
988-
* <code>false</code> if it was created in an inactive state and has been activated, and
989+
* Since 1.110.0, <code>1</code> is returned in case
990+
* {@link sap.ui.model.odata.v4.ODataListBinding#event:createActivate activation} has been
991+
* prevented. Note that
992+
* <ul>
993+
* <li> it is truthy: <code>!!1 === true</code>,
994+
* <li> it is almost like <code>true</code>: <code>1 == true</code>,
995+
* <li> but it can easily be distinguished: <code>1 !== true</code>,
996+
* <li> and <code>if (oContext.isInactive()) {...}</code> treats inactive contexts the same,
997+
* no matter whether activation has been prevented or not.
998+
* </ul>
999+
*
1000+
* @returns {boolean|number|undefined} <code>true</code> if this context is inactive,
1001+
* <code>false</code> if it was created in an inactive state and has been activated,
1002+
* <code>1</code> in case activation has been prevented (since 1.110.0), and
9891003
* <code>undefined</code> otherwise.
9901004
*
9911005
* @public
9921006
* @see #isTransient
9931007
* @see sap.ui.model.odata.v4.ODataListBinding#create
994-
* @see sap.ui.model.odata.v4.ODataListBinding#event:createActivate
9951008
* @since 1.98.0
9961009
*/
9971010
Context.prototype.isInactive = function () {

src/sap.ui.core/src/sap/ui/model/odata/v4/lib/_Cache.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2110,7 +2110,11 @@ sap.ui.define([
21102110
// When updating a transient entity, the above _Helper.updateAll has already updated
21112111
// the POST request.
21122112
// If the entity remains inactive, update the request, but keep it parked
2113-
if (sParkedGroup && !bInactive) {
2113+
if (bInactive) {
2114+
_Helper.updateAll(that.mChangeListeners, sEntityPath, oEntity,
2115+
{"@$ui5.context.isInactive" : 1}
2116+
);
2117+
} else if (sParkedGroup) {
21142118
_Helper.setPrivateAnnotation(oEntity, "transient", sTransientGroup);
21152119
that.oRequestor.relocate(sParkedGroup, oPostBody, sTransientGroup);
21162120
}

src/sap.ui.core/test/sap/ui/core/demokit/sample/odata/v4/MultipleInlineCreationRowsGrid/Main.view.xml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,15 @@
9797
enabled="{= %{@$ui5.context.isInactive} !== undefined}" />
9898
<Input id="name" value="{name}"/>
9999
<Input id="amount" value="{amount}"/>
100-
<Button id="delete" enabled="{= !%{@$ui5.context.isInactive} }"
101-
icon="sap-icon://delete" press="onDelete"
102-
tooltip="Delete product"/>
100+
<Button id="productDelete"
101+
enabled="{= %{@$ui5.context.isInactive} !== true }"
102+
icon="{= %{@$ui5.context.isInactive} === 1
103+
? 'sap-icon://reset'
104+
: 'sap-icon://delete' }"
105+
press="onDelete"
106+
tooltip="{= %{@$ui5.context.isInactive} === 1
107+
? 'Reset'
108+
: 'Delete Product' }"/>
103109
</ColumnListItem>
104110
</Table>
105111
</f:beginColumnPages>
@@ -167,9 +173,14 @@
167173
<t:Column width="4em">
168174
<t:template>
169175
<Button id="partDelete"
170-
enabled="{= !%{@$ui5.context.isInactive} }"
171-
icon="sap-icon://delete" press="onDelete"
172-
tooltip="Delete part"/>
176+
enabled="{= %{@$ui5.context.isInactive} !== true }"
177+
icon="{= %{@$ui5.context.isInactive} === 1
178+
? 'sap-icon://reset'
179+
: 'sap-icon://delete' }"
180+
press="onDelete"
181+
tooltip="{= %{@$ui5.context.isInactive} === 1
182+
? 'Reset'
183+
: 'Delete Part' }"/>
173184
</t:template>
174185
</t:Column>
175186
</t:columns>

src/sap.ui.core/test/sap/ui/core/qunit/odata/v4/Context.qunit.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2832,6 +2832,7 @@ sap.ui.define([
28322832
oError = new Error("This call intentionally failed"),
28332833
oFireCreateActivateExpectation,
28342834
oGroupLock = {},
2835+
bInactive,
28352836
oMetaModel = {
28362837
fetchUpdateData : function () {},
28372838
getUnitOrCurrencyPath : function () {}
@@ -2855,6 +2856,8 @@ sap.ui.define([
28552856
that = this;
28562857

28572858
if (oInactive) {
2859+
bInactive = oInactive.activate ? false : 1;
2860+
28582861
assert.strictEqual(
28592862
// code under test
28602863
oContext.toString(),
@@ -2915,11 +2918,9 @@ sap.ui.define([
29152918
/*fnErrorCallback*/bSkipRetry ? undefined : sinon.match.func, "/edit/url",
29162919
"helper/path", "unit/or/currency/path",
29172920
sinon.match.same(bPatchWithoutSideEffects), /*fnPatchSent*/sinon.match.func,
2918-
/*fnIsKeepAlive*/sinon.match.func,
2919-
oInactive ? !oInactive.activate : undefined)
2921+
/*fnIsKeepAlive*/sinon.match.func, bInactive)
29202922
.callsFake(function () {
2921-
assert.strictEqual(oContext.isInactive(),
2922-
oInactive ? !oInactive.activate : undefined);
2923+
assert.strictEqual(oContext.isInactive(), bInactive);
29232924
return SyncPromise.resolve(
29242925
fnScenario(assert, that.mock(oModel), oBinding, oBindingMock,
29252926
/*fnErrorCallback*/arguments[3], /*fnPatchSent*/arguments[8],

src/sap.ui.core/test/sap/ui/core/qunit/odata/v4/ODataModel.integration.qunit.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45081,6 +45081,7 @@ sap.ui.define([
4508145081
oModel = this.createTeaBusiModel({autoExpandSelect : true}),
4508245082
sView = '\
4508345083
<Table id="table" items="{/TEAMS}">\
45084+
<Text id="inactive" text="{= %{@$ui5.context.isInactive} }"/>\
4508445085
<Input id="id" value="{Team_Id}"/>\
4508545086
<Input id="name" value="{Name}"/>\
4508645087
</Table>',
@@ -45090,7 +45091,8 @@ sap.ui.define([
4509045091
value : [{Name : "Team #1", Team_Id : "TEAM_01"}]
4509145092
})
4509245093
.expectChange("id", ["TEAM_01"])
45093-
.expectChange("name", ["Team #1"]);
45094+
.expectChange("name", ["Team #1"])
45095+
.expectChange("inactive", [undefined]);
4509445096

4509545097
return this.createView(assert, sView, oModel).then(function () {
4509645098
oBinding = that.oView.byId("table").getBinding("items");
@@ -45103,20 +45105,28 @@ sap.ui.define([
4510345105
});
4510445106

4510545107
that.expectChange("id", [, "", ""])
45106-
.expectChange("name", [, "", ""]);
45108+
.expectChange("name", [, "", ""])
45109+
.expectChange("inactive", [, true, true]);
4510745110

4510845111
oContext1 = oBinding.create({}, true, true, /*bInactive*/true);
4510945112
oContext2 = oBinding.create({}, true, true, /*bInactive*/true);
4511045113

45114+
assert.strictEqual(oContext1.isInactive(), true);
45115+
assert.strictEqual(oContext2.isInactive(), true);
45116+
4511145117
return that.waitForChanges(assert);
4511245118
}).then(function () {
4511345119
// no request is sent
45114-
that.expectChange("name", [, "Team #2", "Team #3"]);
45120+
that.expectChange("name", [, "Team #2", "Team #3"])
45121+
.expectChange("inactive", [, 1, 1]);
4511545122

4511645123
// code under test
4511745124
oContext1.setProperty("Name", "Team #2");
4511845125
oContext2.setProperty("Name", "Team #3");
4511945126

45127+
assert.strictEqual(oContext1.isInactive(), 1);
45128+
assert.strictEqual(oContext2.isInactive(), 1);
45129+
4512045130
return that.waitForChanges(assert);
4512145131
}).then(function () {
4512245132
that.expectRequest({
@@ -45130,11 +45140,14 @@ sap.ui.define([
4513045140
Team_Id : "TEAM_02",
4513145141
Name : "Team #2"
4513245142
})
45133-
.expectChange("id", [, "TEAM_02"]);
45143+
.expectChange("id", [, "TEAM_02"])
45144+
.expectChange("inactive", [, false]);
4513445145

4513545146
// code under test
4513645147
oContext1.setProperty("Team_Id", "TEAM_02");
4513745148

45149+
assert.strictEqual(oContext1.isInactive(), false);
45150+
4513845151
return Promise.all([
4513945152
oContext1.created(),
4514045153
that.waitForChanges(assert)

src/sap.ui.core/test/sap/ui/core/qunit/odata/v4/lib/_Cache.qunit.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8780,6 +8780,10 @@ sap.ui.define([
87808780
}
87818781

87828782
this.mock(oUpdateGroupLock).expects("getGroupId").withExactArgs().returns("updateGroup");
8783+
oHelperMock.expects("updateAll").exactly(bStayInactive ? 1 : 0)
8784+
.withExactArgs(sinon.match.same(oCache.mChangeListeners), sTransientPredicate,
8785+
sinon.match.same(oCache.aElements[bAtEndOfCreated ? 1 : 0]),
8786+
{"@$ui5.context.isInactive" : 1}).callThrough();
87838787
this.oRequestorMock.expects("relocate").exactly(bInactive && !bStayInactive ? 1 : 0)
87848788
.withExactArgs("$inactive.updateGroup",
87858789
sinon.match.same(oCache.aElements[bAtEndOfCreated ? 1 : 0]["@$ui5._"].postBody),
@@ -8813,7 +8817,7 @@ sap.ui.define([
88138817
if (bInactive) {
88148818
assert.strictEqual(
88158819
oCache.aElements[bAtEndOfCreated ? 1 : 0]["@$ui5.context.isInactive"],
8816-
bStayInactive);
8820+
bStayInactive ? 1 : false, "isInactive");
88178821
assert.strictEqual(oCache.iActiveElements, bStayInactive ? 0 : 1);
88188822
} else {
88198823
assert.strictEqual(

0 commit comments

Comments
 (0)