Skip to content

Commit

Permalink
Association display (#1015)
Browse files Browse the repository at this point in the history
* add a new object to reference.js called BulkCreateForeignKeyObject
* Update changes based on comments
* add test cases
* make sure 2 foreign keys are not composite and add a test case for that
* return null instead of an error
* add a new 'context' for reference for selecting foreign key values in bulk in recordedit
* function for generating the unique id for a row when we have the fk pseudo column and the row data
* add test for pseudocolumn generateUniqueId function
  • Loading branch information
jrchudy authored Oct 3, 2024
1 parent b7718e3 commit 7c354b9
Show file tree
Hide file tree
Showing 22 changed files with 1,376 additions and 18 deletions.
73 changes: 71 additions & 2 deletions docs/dev-docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ to use for ERMrest JavaScript agents.
* [.citation](#ERMrest.Reference+citation) : <code>ERMrest.Citation</code>
* [.googleDatasetMetadata](#ERMrest.Reference+googleDatasetMetadata) : <code>ERMrest.GoogleDatasetMetadata</code>
* [.cascadingDeletedItems](#ERMrest.Reference+cascadingDeletedItems) : <code>Array.&lt;Object&gt;</code>
* [.bulkCreateForeignKeyObject](#ERMrest.Reference+bulkCreateForeignKeyObject) : <code>ERMrest.BulkCreateForeignKeyObject</code>
* [.generateFacetColumns()](#ERMrest.Reference+generateFacetColumns)
* [.validateFacetsFilters(facetAndFilters, facetObjectWrappers, searchTerm, skipMappingEntityChoices, changeLocation)](#ERMrest.Reference+validateFacetsFilters)
* [.removeAllFacetFilters(sameFilter, sameCustomFacet, sameFacet)](#ERMrest.Reference+removeAllFacetFilters) ⇒ <code>ERMrest.reference</code>
Expand All @@ -386,6 +387,7 @@ to use for ERMrest JavaScript agents.
* [.getColumnByName(name)](#ERMrest.Reference+getColumnByName)[<code>ReferenceColumn</code>](#ERMrest.ReferenceColumn)
* [.generateColumnsList(tuple, columnsList, dontChangeReference, skipLog)](#ERMrest.Reference+generateColumnsList)[<code>Array.&lt;ReferenceColumn&gt;</code>](#ERMrest.ReferenceColumn)
* [.generateActiveList([tuple])](#ERMrest.Reference+generateActiveList) ⇒ <code>Object</code>
* [.computeBulkCreateForeignKeyObject(prefillObject)](#ERMrest.Reference+computeBulkCreateForeignKeyObject) ⇒ <code>BulkCreateForeignKeyObject</code>
* [._getReadPath(useEntity, getTRS, getTCRS, getUnlinkTRS)](#ERMrest.Reference+_getReadPath) : <code>Object</code>
* [~processSortObject()](#ERMrest.Reference+_getReadPath..processSortObject)
* [.Page](#ERMrest.Page)
Expand Down Expand Up @@ -483,6 +485,7 @@ to use for ERMrest JavaScript agents.
* [.defaultReference](#ERMrest.ForeignKeyPseudoColumn+defaultReference) : <code>ERMrest.Refernece</code>
* [.RID](#ERMrest.ForeignKeyPseudoColumn+RID) : <code>string</code>
* [.displayname](#ERMrest.ForeignKeyPseudoColumn+displayname) : <code>Object</code>
* [.generateUniqueId(linkedData)](#ERMrest.ForeignKeyPseudoColumn+generateUniqueId)
* [.filteredRef(column, data)](#ERMrest.ForeignKeyPseudoColumn+filteredRef)[<code>Reference</code>](#ERMrest.Reference)
* [.KeyPseudoColumn](#ERMrest.KeyPseudoColumn)
* [new KeyPseudoColumn(reference, key)](#new_ERMrest.KeyPseudoColumn_new)
Expand Down Expand Up @@ -705,6 +708,7 @@ to use for ERMrest JavaScript agents.
* [.citation](#ERMrest.Reference+citation) : <code>ERMrest.Citation</code>
* [.googleDatasetMetadata](#ERMrest.Reference+googleDatasetMetadata) : <code>ERMrest.GoogleDatasetMetadata</code>
* [.cascadingDeletedItems](#ERMrest.Reference+cascadingDeletedItems) : <code>Array.&lt;Object&gt;</code>
* [.bulkCreateForeignKeyObject](#ERMrest.Reference+bulkCreateForeignKeyObject) : <code>ERMrest.BulkCreateForeignKeyObject</code>
* [.generateFacetColumns()](#ERMrest.Reference+generateFacetColumns)
* [.validateFacetsFilters(facetAndFilters, facetObjectWrappers, searchTerm, skipMappingEntityChoices, changeLocation)](#ERMrest.Reference+validateFacetsFilters)
* [.removeAllFacetFilters(sameFilter, sameCustomFacet, sameFacet)](#ERMrest.Reference+removeAllFacetFilters) ⇒ <code>ERMrest.reference</code>
Expand All @@ -724,6 +728,7 @@ to use for ERMrest JavaScript agents.
* [.getColumnByName(name)](#ERMrest.Reference+getColumnByName)[<code>ReferenceColumn</code>](#ERMrest.ReferenceColumn)
* [.generateColumnsList(tuple, columnsList, dontChangeReference, skipLog)](#ERMrest.Reference+generateColumnsList)[<code>Array.&lt;ReferenceColumn&gt;</code>](#ERMrest.ReferenceColumn)
* [.generateActiveList([tuple])](#ERMrest.Reference+generateActiveList) ⇒ <code>Object</code>
* [.computeBulkCreateForeignKeyObject(prefillObject)](#ERMrest.Reference+computeBulkCreateForeignKeyObject) ⇒ <code>BulkCreateForeignKeyObject</code>
* [._getReadPath(useEntity, getTRS, getTCRS, getUnlinkTRS)](#ERMrest.Reference+_getReadPath) : <code>Object</code>
* [~processSortObject()](#ERMrest.Reference+_getReadPath..processSortObject)
* [.AttributeGroupReference](#ERMrest.AttributeGroupReference) : <code>object</code>
Expand Down Expand Up @@ -3162,6 +3167,7 @@ Constructor for a ParsedFilter.
* [.citation](#ERMrest.Reference+citation) : <code>ERMrest.Citation</code>
* [.googleDatasetMetadata](#ERMrest.Reference+googleDatasetMetadata) : <code>ERMrest.GoogleDatasetMetadata</code>
* [.cascadingDeletedItems](#ERMrest.Reference+cascadingDeletedItems) : <code>Array.&lt;Object&gt;</code>
* [.bulkCreateForeignKeyObject](#ERMrest.Reference+bulkCreateForeignKeyObject) : <code>ERMrest.BulkCreateForeignKeyObject</code>
* [.generateFacetColumns()](#ERMrest.Reference+generateFacetColumns)
* [.validateFacetsFilters(facetAndFilters, facetObjectWrappers, searchTerm, skipMappingEntityChoices, changeLocation)](#ERMrest.Reference+validateFacetsFilters)
* [.removeAllFacetFilters(sameFilter, sameCustomFacet, sameFacet)](#ERMrest.Reference+removeAllFacetFilters) ⇒ <code>ERMrest.reference</code>
Expand All @@ -3181,6 +3187,7 @@ Constructor for a ParsedFilter.
* [.getColumnByName(name)](#ERMrest.Reference+getColumnByName)[<code>ReferenceColumn</code>](#ERMrest.ReferenceColumn)
* [.generateColumnsList(tuple, columnsList, dontChangeReference, skipLog)](#ERMrest.Reference+generateColumnsList)[<code>Array.&lt;ReferenceColumn&gt;</code>](#ERMrest.ReferenceColumn)
* [.generateActiveList([tuple])](#ERMrest.Reference+generateActiveList) ⇒ <code>Object</code>
* [.computeBulkCreateForeignKeyObject(prefillObject)](#ERMrest.Reference+computeBulkCreateForeignKeyObject) ⇒ <code>BulkCreateForeignKeyObject</code>
* [._getReadPath(useEntity, getTRS, getTCRS, getUnlinkTRS)](#ERMrest.Reference+_getReadPath) : <code>Object</code>
* [~processSortObject()](#ERMrest.Reference+_getReadPath..processSortObject)

Expand Down Expand Up @@ -3405,11 +3412,14 @@ Returns true if

#### reference.display : <code>Object</code>
An object which contains row display properties for this reference.
It is determined based on the `table-display` annotation. It has the
It is determined based on the `table-display`, `display`, and 'chaise-config' annotations. It has the
following properties:

- `rowOrder`: `[{ column: '`_column object_`', descending:` {`true` | `false` } `}`...`]` or `undefined`,
- `type`: {`'table'` | `'markdown'` | `'module'`} (default: `'table'`)
- `showFaceting`: A boolean indicating whether we should show the faceting feature or not.
- `maxFacetDepth`: A number indicating the facet depth.
- `facetPanelOpen`: Whether the facet panel should be opened by default or not.

If type is `'markdown'`, the object will also these additional
properties:
Expand Down Expand Up @@ -3552,6 +3562,13 @@ a Metadata object
#### reference.cascadingDeletedItems : <code>Array.&lt;Object&gt;</code>
The related reference or tables that might be deleted as a result of deleting the current table.

**Kind**: instance property of [<code>Reference</code>](#ERMrest.Reference)
<a name="ERMrest.Reference+bulkCreateForeignKeyObject"></a>

#### reference.bulkCreateForeignKeyObject : <code>ERMrest.BulkCreateForeignKeyObject</code>
If prefill object is defined and has the required attributes, will return
a BulkCreateForeignKeyObject object with the necessary objects used for a association modal picker

**Kind**: instance property of [<code>Reference</code>](#ERMrest.Reference)
<a name="ERMrest.Reference+generateFacetColumns"></a>

Expand Down Expand Up @@ -3984,6 +4001,20 @@ so if the fk definition is based on fkcolum and and not the RID, it would handle
| --- | --- |
| [tuple] | [<code>Tuple</code>](#ERMrest.Tuple) |

<a name="ERMrest.Reference+computeBulkCreateForeignKeyObject"></a>

#### reference.computeBulkCreateForeignKeyObject(prefillObject) ⇒ <code>BulkCreateForeignKeyObject</code>
Will compute and return a BulkCreateForeignKeyObject if:
- the prefillObject is defined
- there are only 2 foreign key columns for this table that are not system columns
- using the prefill object, we can determine the main column for prefilling and leaf column for bulk selection

**Kind**: instance method of [<code>Reference</code>](#ERMrest.Reference)

| Param | Type | Description |
| --- | --- | --- |
| prefillObject | <code>Object</code> | computed prefill object from chaise |

<a name="ERMrest.Reference+_getReadPath"></a>

#### reference.\_getReadPath(useEntity, getTRS, getTCRS, getUnlinkTRS) : <code>Object</code>
Expand Down Expand Up @@ -4951,6 +4982,7 @@ In other cases, the returned data will only include the scalar value.
* [.defaultReference](#ERMrest.ForeignKeyPseudoColumn+defaultReference) : <code>ERMrest.Refernece</code>
* [.RID](#ERMrest.ForeignKeyPseudoColumn+RID) : <code>string</code>
* [.displayname](#ERMrest.ForeignKeyPseudoColumn+displayname) : <code>Object</code>
* [.generateUniqueId(linkedData)](#ERMrest.ForeignKeyPseudoColumn+generateUniqueId)
* [.filteredRef(column, data)](#ERMrest.ForeignKeyPseudoColumn+filteredRef)[<code>Reference</code>](#ERMrest.Reference)

<a name="new_ERMrest.ForeignKeyPseudoColumn_new"></a>
Expand Down Expand Up @@ -5038,6 +5070,17 @@ returns the ermrest generated RID for the foreign key relationship this pseudo c
use table's displayname disambiguated with columns' displayname, i.e. `table_1 (col_1, col_2)`.

**Kind**: instance property of [<code>ForeignKeyPseudoColumn</code>](#ERMrest.ForeignKeyPseudoColumn)
<a name="ERMrest.ForeignKeyPseudoColumn+generateUniqueId"></a>

#### foreignKeyPseudoColumn.generateUniqueId(linkedData)
Given the available tuple data, generate the uniqueId for the selected row from the table this pseudo column points to

**Kind**: instance method of [<code>ForeignKeyPseudoColumn</code>](#ERMrest.ForeignKeyPseudoColumn)

| Param | Type | Description |
| --- | --- | --- |
| linkedData | <code>Object</code> | key-value pairs of column values of the table this pseudocolumn points to |

<a name="ERMrest.ForeignKeyPseudoColumn+filteredRef"></a>

#### foreignKeyPseudoColumn.filteredRef(column, data) ⇒ [<code>Reference</code>](#ERMrest.Reference)
Expand Down Expand Up @@ -7053,6 +7096,7 @@ get PathColumn object by column name
* [.citation](#ERMrest.Reference+citation) : <code>ERMrest.Citation</code>
* [.googleDatasetMetadata](#ERMrest.Reference+googleDatasetMetadata) : <code>ERMrest.GoogleDatasetMetadata</code>
* [.cascadingDeletedItems](#ERMrest.Reference+cascadingDeletedItems) : <code>Array.&lt;Object&gt;</code>
* [.bulkCreateForeignKeyObject](#ERMrest.Reference+bulkCreateForeignKeyObject) : <code>ERMrest.BulkCreateForeignKeyObject</code>
* [.generateFacetColumns()](#ERMrest.Reference+generateFacetColumns)
* [.validateFacetsFilters(facetAndFilters, facetObjectWrappers, searchTerm, skipMappingEntityChoices, changeLocation)](#ERMrest.Reference+validateFacetsFilters)
* [.removeAllFacetFilters(sameFilter, sameCustomFacet, sameFacet)](#ERMrest.Reference+removeAllFacetFilters) ⇒ <code>ERMrest.reference</code>
Expand All @@ -7072,6 +7116,7 @@ get PathColumn object by column name
* [.getColumnByName(name)](#ERMrest.Reference+getColumnByName)[<code>ReferenceColumn</code>](#ERMrest.ReferenceColumn)
* [.generateColumnsList(tuple, columnsList, dontChangeReference, skipLog)](#ERMrest.Reference+generateColumnsList)[<code>Array.&lt;ReferenceColumn&gt;</code>](#ERMrest.ReferenceColumn)
* [.generateActiveList([tuple])](#ERMrest.Reference+generateActiveList) ⇒ <code>Object</code>
* [.computeBulkCreateForeignKeyObject(prefillObject)](#ERMrest.Reference+computeBulkCreateForeignKeyObject) ⇒ <code>BulkCreateForeignKeyObject</code>
* [._getReadPath(useEntity, getTRS, getTCRS, getUnlinkTRS)](#ERMrest.Reference+_getReadPath) : <code>Object</code>
* [~processSortObject()](#ERMrest.Reference+_getReadPath..processSortObject)

Expand Down Expand Up @@ -7296,11 +7341,14 @@ Returns true if

#### reference.display : <code>Object</code>
An object which contains row display properties for this reference.
It is determined based on the `table-display` annotation. It has the
It is determined based on the `table-display`, `display`, and 'chaise-config' annotations. It has the
following properties:

- `rowOrder`: `[{ column: '`_column object_`', descending:` {`true` | `false` } `}`...`]` or `undefined`,
- `type`: {`'table'` | `'markdown'` | `'module'`} (default: `'table'`)
- `showFaceting`: A boolean indicating whether we should show the faceting feature or not.
- `maxFacetDepth`: A number indicating the facet depth.
- `facetPanelOpen`: Whether the facet panel should be opened by default or not.

If type is `'markdown'`, the object will also these additional
properties:
Expand Down Expand Up @@ -7443,6 +7491,13 @@ a Metadata object
#### reference.cascadingDeletedItems : <code>Array.&lt;Object&gt;</code>
The related reference or tables that might be deleted as a result of deleting the current table.

**Kind**: instance property of [<code>Reference</code>](#ERMrest.Reference)
<a name="ERMrest.Reference+bulkCreateForeignKeyObject"></a>

#### reference.bulkCreateForeignKeyObject : <code>ERMrest.BulkCreateForeignKeyObject</code>
If prefill object is defined and has the required attributes, will return
a BulkCreateForeignKeyObject object with the necessary objects used for a association modal picker

**Kind**: instance property of [<code>Reference</code>](#ERMrest.Reference)
<a name="ERMrest.Reference+generateFacetColumns"></a>

Expand Down Expand Up @@ -7875,6 +7930,20 @@ so if the fk definition is based on fkcolum and and not the RID, it would handle
| --- | --- |
| [tuple] | [<code>Tuple</code>](#ERMrest.Tuple) |

<a name="ERMrest.Reference+computeBulkCreateForeignKeyObject"></a>

#### reference.computeBulkCreateForeignKeyObject(prefillObject) ⇒ <code>BulkCreateForeignKeyObject</code>
Will compute and return a BulkCreateForeignKeyObject if:
- the prefillObject is defined
- there are only 2 foreign key columns for this table that are not system columns
- using the prefill object, we can determine the main column for prefilling and leaf column for bulk selection

**Kind**: instance method of [<code>Reference</code>](#ERMrest.Reference)

| Param | Type | Description |
| --- | --- | --- |
| prefillObject | <code>Object</code> | computed prefill object from chaise |

<a name="ERMrest.Reference+_getReadPath"></a>

#### reference.\_getReadPath(useEntity, getTRS, getTCRS, getUnlinkTRS) : <code>Object</code>
Expand Down
1 change: 1 addition & 0 deletions docs/user-docs/annotation.md
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,7 @@ List of _context_ names that are used in ERMrest:
- `"compact/select/association/link"`: A sub-context of `compact/select/association` used for selecting entities to link to the main record.
- `"compact/select/association/unlink"`: A sub-context of `compact/select/association` used for selecting entities to unlink from the main record.
- `"compact/select/foreign_key"`: A sub-context of `compact/select` used for selecting entities for a foreign key value in an `entry` context.
- `"compactSelectBulkForeignKey"`: a sub-context of `compact/select` used for selecting multiple entities to fill in foreign key values in multiple forms in `entry/create` context.
- `"compact/select/saved_queries"`: A sub-context of `compact/select` used for selecting a saved query to apply in `compact` context.
- `"compact/select/show_more"`: A sub-context of `compact/select` used for selecting entities as a facet value.
- `"detailed"`: Any detailed read-only, entity-level presentation context.
Expand Down
9 changes: 9 additions & 0 deletions js/column.js
Original file line number Diff line number Diff line change
Expand Up @@ -1663,6 +1663,15 @@ function ForeignKeyPseudoColumn (reference, fk, sourceObjectWrapper, name) {
// extend the prototype
module._extends(ForeignKeyPseudoColumn, ReferenceColumn);

/**
* Given the available tuple data, generate the uniqueId for the selected row from the table this pseudo column points to
*
* @param {Object} linkedData key-value pairs of column values of the table this pseudocolumn points to
*/
ForeignKeyPseudoColumn.prototype.generateUniqueId = function (linkedData) {
return module._generateTupleUniqueId(this.reference.table.shortestKey, linkedData);
};

// properties to be overriden:
/**
* This function takes in a tuple and generates a reference that is
Expand Down
Loading

0 comments on commit 7c354b9

Please sign in to comment.