Skip to content

Commit de83a62

Browse files
committed
test dynamic ui hidden annotation
1 parent 233d2de commit de83a62

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

app/admin/fiori-service.cds

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ annotate AdminService.Books with @(UI : {
3939
},
4040
{
4141
// TODO: should work dynamically
42-
@UI.Hidden,
4342
$Type : 'UI.ReferenceFacet',
4443
Label : '{i18n>Contents}',
45-
Target : 'contents/@UI.PresentationVariant'
44+
Target : 'contents/@UI.PresentationVariant',
45+
![@UI.Hidden] : contentsHidden
46+
4647
}
4748
],
4849
FieldGroup #General : {Data : [

db/books.cds

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ entity Books : cuid, managed {
2323
on reviews.book = $self;
2424
isReviewable : TechnicalBooleanFlag not null default true;
2525
contents : Composition of many Contents on contents.book = $self @odata.contained:false;
26+
virtual contentsHidden : Boolean default false;
2627
}
2728

2829
entity Authors : cuid, managed {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package my.bookshop.handlers;
2+
3+
4+
import java.util.List;
5+
import java.util.Map;
6+
7+
import org.springframework.context.annotation.Profile;
8+
import org.springframework.stereotype.Component;
9+
10+
import com.sap.cds.services.EventContext;
11+
import com.sap.cds.services.handler.EventHandler;
12+
import com.sap.cds.services.handler.annotations.After;
13+
import com.sap.cds.services.handler.annotations.On;
14+
import com.sap.cds.services.handler.annotations.ServiceName;
15+
16+
import cds.gen.adminservice.AdminService_;
17+
import cds.gen.adminservice.Books_;
18+
19+
@Component
20+
@ServiceName(AdminService_.CDS_NAME)
21+
/**
22+
* Example of a custom handler for nextSiblingAction
23+
*/
24+
@Profile("hybrid")
25+
public class SetHiddenHandler implements EventHandler {
26+
27+
@After(entity = Books_.CDS_NAME)
28+
void removeUIHidden(EventContext context){
29+
Object result = context.get("result");
30+
if (result instanceof Map row) {
31+
row.put("contentsHidden", true);
32+
} else if (result instanceof List rows && rows.size() == 1) {
33+
((Map)rows.get(0)).put("contentsHidden", true);
34+
}
35+
}
36+
}
37+
38+

0 commit comments

Comments
 (0)