All files / utils deletedPlaceholder.js

100% Statements 5/5
100% Branches 6/6
100% Functions 3/3
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28              48x     20x       400x       8x     48x            
// Shared marker for field values that used to reference something (a user, an
// item, a select option) which has since been deleted. Mandatory fields cannot
// be safely SET_NULL'd (other code assumes they always carry a value — e.g. a
// workflow condition or a required-field render), so they're replaced with a
// short human-readable placeholder carrying this prefix instead. The prefix
// lets reference-validation.js recognise "already resolved as deleted" values
// and skip re-validating them, and lets the UI apply a distinct muted style.
const DELETED_PLACEHOLDER_PREFIX = '::deleted::'
 
function buildDeletedPlaceholder(label) {
  return `${DELETED_PLACEHOLDER_PREFIX}${label}`
}
 
function isDeletedPlaceholder(value) {
  return typeof value === 'string' && value.startsWith(DELETED_PLACEHOLDER_PREFIX)
}
 
function shortId(id) {
  return typeof id === 'string' && id.length > 6 ? id.slice(-6) : id
}
 
module.exports = {
  DELETED_PLACEHOLDER_PREFIX,
  buildDeletedPlaceholder,
  isDeletedPlaceholder,
  shortId
}