Skip to content

Commit

Permalink
CDC #157 - Adding options argument to useUserDefinedColumns hook
Browse files Browse the repository at this point in the history
  • Loading branch information
dleadbetter committed May 13, 2024
1 parent 9eef215 commit 95ffe6d
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/user-defined-fields/src/hooks/UserDefinedFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ import UserDefinedFieldsService from '../services/UserDefinedFields';
*
* @param defineableId
* @param defineableType
* @param options
*
* @returns {{userDefinedColumns: [], loading: boolean}}
*/
const useUserDefinedColumns = (defineableId, defineableType) => {
const useUserDefinedColumns = (defineableId, defineableType, options = {}) => {
const [fields, setFields] = useState([]);
const [loading, setLoading] = useState(false);

Expand All @@ -30,12 +31,18 @@ const useUserDefinedColumns = (defineableId, defineableType) => {
* @type {(function(*, *): (null|*))|*}
*/
const resolveValue = useCallback((item, field) => {
if (!item.user_defined) {
let record = item;

if (options.resolveRecord) {
record = options.resolveRecord(item);
}

if (!record.user_defined) {
return null;
}

return item.user_defined[field.uuid];
}, []);
return record.user_defined[field.uuid];
}, [options.resolveRecord]);

/**
* Memo-izes the columns.
Expand Down

0 comments on commit 95ffe6d

Please sign in to comment.