Skip to content

Commit

Permalink
Fix empty related sections not showing bug (#2160)
Browse files Browse the repository at this point in the history
* make sure to check association tables and all related tables in the inline section for show/hide empty sections initialization
* failing test case in permissions delete that was relying on generated to hide a related association table but the annotation was set on the leaf and not association table
  • Loading branch information
jrchudy authored Mar 10, 2022
1 parent 222b35e commit c242fbe
Show file tree
Hide file tree
Showing 9 changed files with 275 additions and 13 deletions.
12 changes: 10 additions & 2 deletions record/record.app.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@
tableModel: recordAppUtils.getTableModel(reference, index, true)
};
$rootScope.hasInline = true;

// check if user can create related or associations that are inline to set showEmptyRelatedTables on load
// user can modify the current record page and can modify at least 1 of the related tables
var canCreateRelation = reference.derivedAssociationReference ? reference.derivedAssociationReference.canCreate : reference.canCreate;
if (!$rootScope.showEmptyRelatedTables && $rootScope.modifyRecord && canCreateRelation) {
$rootScope.showEmptyRelatedTables = true;
}
}
// columns that are relying on aggregates or are aggregate themselves
else if (col.hasWaitFor || !col.isUnique) {
Expand All @@ -264,8 +271,9 @@
$rootScope.lastRendered = null;
related.forEach(function (ref, index) {
ref = ref.contextualize.compactBrief;
// user can modify the current record page and can modify at least 1 of the related tables
if (!$rootScope.showEmptyRelatedTables && $rootScope.modifyRecord && ref.canCreate) {
// user can modify the current record page and can modify at least 1 of the related tables in visible-foreignkeys
var canCreateRelation = ref.derivedAssociationReference ? ref.derivedAssociationReference.canCreate : ref.canCreate;
if (!$rootScope.showEmptyRelatedTables && $rootScope.modifyRecord && canCreateRelation) {
$rootScope.showEmptyRelatedTables = true;
}

Expand Down
15 changes: 13 additions & 2 deletions record/record.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,23 @@
};

vm.noVisibleRelatedTables = function () {
var noneVisible = true;
if ($rootScope.relatedTableModels) {
return !$rootScope.relatedTableModels.some(function (tm, index) {
// sets noneVisible to false if at least one related table can be shown
noneVisible = !$rootScope.relatedTableModels.some(function (tm, index) {
return vm.showRelatedTable(index);
});
}
return true;

// only check the coumn models if one of them is an inline related table
// if noneVisible is already false, no need to iterate the columns too
if ($rootScope.hasInline && noneVisible) {
// sets noneVisible to false if at least one inline table can be shown
noneVisible = !$rootScope.columnModels.some(function (cm, index) {
return cm.isInline && ($rootScope.showEmptyRelatedTables || (cm.tableModel.page && cm.tableModel.page.length > 0))
});
}
return noneVisible;
};

vm.toggleDisplayMode = function(dataModel) {
Expand Down
1 change: 1 addition & 0 deletions test/e2e/data_setup/data/links/association_table.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
1 change: 1 addition & 0 deletions test/e2e/data_setup/data/links/inline_table.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"id": 1, "text": "Test text for inline", "int": 7}]
1 change: 1 addition & 0 deletions test/e2e/data_setup/data/links/related_table.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"id": "1", "term": "value"}]
4 changes: 3 additions & 1 deletion test/e2e/data_setup/schema/multi-permissions.json
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,9 @@
"annotations": {}
}
],
"annotations": {}
"annotations": {
"tag:isrd.isi.edu,2016:generated": null
}
},
"other_delete_table": {
"table_name": "other_delete_table",
Expand Down
198 changes: 191 additions & 7 deletions test/e2e/data_setup/schema/record/links.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@
"links-table": {
"kind": "table",
"keys": [
{
"comment": null,
"annotations": {},
"unique_columns": [
"id"
]
}
{"unique_columns": ["id"]},
{"unique_columns": ["int"]}
],
"foreign_keys": [],
"table_name": "links-table",
Expand Down Expand Up @@ -40,6 +35,195 @@
}
}
],
"annotations": {
"tag:isrd.isi.edu,2016:visible-columns" : {
"detailed": ["id", "text", "int" ]
},
"tag:isrd.isi.edu,2016:visible-foreign-keys": {
"*": [ ["links", "fk_assoc_links"] ]
}
}
},
"related_table": {
"comment": "Related table set to generated only to test can create on association",
"kind": "table",
"keys": [
{"unique_columns": ["id"]},
{"unique_columns": ["term"]}
],
"foreign_keys": [],
"table_name": "related_table",
"schema_name": "links",
"column_definitions": [
{
"name": "id",
"nullok": false,
"type": {
"typename": "text"
}
},
{
"name": "term",
"type": {
"typename": "text"
}
}
],
"annotations": {
"tag:isrd.isi.edu,2016:generated": null
}
},
"association_table": {
"kind": "table",
"keys": [
{
"comment": null,
"annotations": {},
"unique_columns": [
"id_related", "id_links"
]
}
],
"foreign_keys": [
{
"names": [["links", "fk_assoc_related_table"]],
"foreign_key_columns": [{
"table_name": "association_table",
"schema_name": "links",
"column_name": "id_related"
}],
"referenced_columns": [{
"table_name": "related_table",
"schema_name": "links",
"column_name": "term"
}]
},
{
"names": [["links", "fk_assoc_links"]],
"foreign_key_columns": [{
"table_name": "association_table",
"schema_name": "links",
"column_name": "id_links"
}],
"referenced_columns": [{
"table_name": "links-table",
"schema_name": "links",
"column_name": "int"
}]
}
],
"table_name": "association_table",
"schema_name": "links",
"column_definitions": [
{
"name": "id_related",
"nullok": false,
"type": {
"typename": "text"
}
},
{
"name": "id_links",
"nullok": false,
"type": {
"typename": "int"
}
}
],
"annotations": {}
},
"inline_table": {
"kind": "table",
"keys": [
{"unique_columns": ["id"]},
{"unique_columns": ["int"]}
],
"foreign_keys": [],
"table_name": "inline_table",
"schema_name": "links",
"column_definitions": [
{
"name": "id",
"type": {
"typename": "int"
}
}, {
"name": "text",
"type": {
"typename": "text"
}
}, {
"name": "int",
"type": {
"typename": "int"
}
}
],
"annotations": {
"tag:isrd.isi.edu,2016:visible-columns" : {
"detailed": [
"id", "text", "int", ["links", "fk_assoc_links"]
]
}
}
},
"inline_association_table": {
"kind": "table",
"keys": [
{
"comment": null,
"annotations": {},
"unique_columns": [
"id_related", "id_inline"
]
}
],
"foreign_keys": [
{
"names": [["links", "fk_inline_assoc_related_table"]],
"foreign_key_columns": [{
"table_name": "inline_association_table",
"schema_name": "links",
"column_name": "id_related"
}],
"referenced_columns": [{
"table_name": "related_table",
"schema_name": "links",
"column_name": "term"
}]
},
{
"names": [["links", "fk_inline_assoc_inline"]],
"foreign_key_columns": [{
"table_name": "inline_association_table",
"schema_name": "links",
"column_name": "id_inline"
}],
"referenced_columns": [{
"table_name": "inline_table",
"schema_name": "links",
"column_name": "int"
}]
}
],
"table_name": "inline_association_table",
"schema_name": "links",
"column_definitions": [
{
"name": "id_related",
"nullok": false,
"type": {
"typename": "text"
}
},
{
"name": "id_inline",
"nullok": false,
"type": {
"typename": "int"
}
}
],
"annotations": {}
}
},
Expand Down
55 changes: 54 additions & 1 deletion test/e2e/specs/default-config/record/links.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ var testParams = {
file_names: [
"links-table.csv",
"links-table_" + chaisePage.getEntityRow("links", "links-table", [{column: "id",value: "1"}]).RID + ".zip"
]
],
headers: ["association_table"],
tocHeaders: ["Summary", "association_table (0)"]
};

describe('View existing record,', function() {
Expand Down Expand Up @@ -107,6 +109,18 @@ describe('View existing record,', function() {
});
});

it ("should show the empty related association tables and table of contents on page load", function (done) {
browser.wait(function() {
return chaisePage.recordPage.getSidePanelHeadings().count().then(function(ct) {
return (ct == testParams.tocHeaders.length);
});
}, browser.params.defaultTimeout);
expect(chaisePage.recordPage.getSidePanelTableTitles()).toEqual(testParams.tocHeaders, "list of related tables in toc is incorrect");

expect(chaisePage.recordPage.getRelatedTableTitles()).toEqual(testParams.headers, "list of related table accordion headers is incorret");
done();
});

it ("The proper permalink (browser url) should appear in the share popup if resolverImplicitCatalog is undefined", function (done) {
var shareButton = chaisePage.recordPage.getShareButton(),
shareModal = chaisePage.recordPage.getShareModal();
Expand Down Expand Up @@ -186,3 +200,42 @@ describe('View existing record,', function() {
}
});
});

var inlineParams = {
table_name: "inline_table",
key: {
name: "id",
value: "1",
operator: "="
},
headers: ["inline_association_table"],
tocHeaders: ["Summary", "inline_association_table (0)"],
}
describe('View existing record for testing "show empty sections" heuristics,', function() {

describe("For table " + inlineParams.table_name + ",", function() {

beforeAll(function () {
var keys = [];
keys.push(inlineParams.key.name + inlineParams.key.operator + inlineParams.key.value);
browser.ignoreSynchronization=true;
var url = browser.params.url + "/record/#" + browser.params.catalogId + "/links:" + inlineParams.table_name + "/" + keys.join("&");
browser.get(url);

chaisePage.waitForElement(element(by.id('tblRecord')));
});


it ("should show the empty related association tables and table of contents on page load", function (done) {
browser.wait(function() {
return chaisePage.recordPage.getSidePanelHeadings().count().then(function(ct) {
return (ct == inlineParams.tocHeaders.length);
});
}, browser.params.defaultTimeout);
expect(chaisePage.recordPage.getSidePanelTableTitles()).toEqual(inlineParams.tocHeaders, "list of related tables in toc is incorrect");

expect(chaisePage.recordPage.getRelatedTableTitles()).toEqual(inlineParams.headers, "list of related table accordion headers is incorret");
done();
});
});
});

0 comments on commit c242fbe

Please sign in to comment.