Exemple #1
0
        if (masterValue != null) {
          const { [relTable]: { entities } } = tables
          if (entities != null) {
            const allowed = Object.keys(entities).filter(
              _id => entities[_id].values[link] === masterValue,
            )
            theField.allowed = allowed
          }
        }
      }
    }
    fragments.push({ field, label, valType, multiple, fragment: theField })
  }
  return fragments
}

export const toFieldInfo = (eId, fragments) => {
  const fieldInfo = { _id: eId }
  for (const { field, fragment: { myValues: value } } of fragments) {
    fieldInfo[field] = value
  }
  return fieldInfo
}

export const dealWithProvenance = memoize((settings, fields) => {
  const { provenanceFields, hideProvenance } = settings
  return hideProvenance
    ? pickBy(fields, (value, key) => !provenanceFields.has(key))
    : fields
})
Exemple #2
0
 * - w: yield the workflow information for a key.
 *
 * The server adds workflow information to some records in the form of key values
 * and templates have access to them by means of w.
 * In this way, we can make the presentation of items very sensitive
 * to the role they play in the workflow as a whole.
 *
 * We pass all these functions together in a single object to the templates.
 *
 * OK, here are the factory functions, they all start with make.
 */

const makeM = memoize(
  fieldInfo => field => {
    const { [field]: { valType, fragment: { editable } } = emptyO } = fieldInfo
    return editable && (typeof valType != 'object' || !valType.fixed)
  },
  emptyO,
)

const makeL = memoize(
  (tables, table) => field => {
    const {
      [table]: {
        fieldSpecs: { [field]: { label } = emptyO } = emptyO,
      } = emptyO,
    } = tables
    return label
  },
  emptyO,
)
Exemple #3
0
    {!dirty && !invalid && !submitting && !canSubmit ? (
      <Tooltip tip={'you have visited this record'} at={'right'}>
        <span className={`fa fa-${active ? 'pencil' : 'check'}`} />
      </Tooltip>
    ) : null}
    {submitting ? (
      <Tooltip tip={'busy saving this record'} at={'right'}>
        <span className={'special-o fa fa-spinner fa-spin'} />
      </Tooltip>
    ) : null}{' '}
    {error && canSubmit && <span className={'invalid diag'}>{error}</span>}
  </Fragment>
)

export const makeSubmit = memoize(
  (dirty, invalid, submitting, submit) =>
    dirty && !invalid && !submitting ? submit : () => null,
)

export const makeSubmitTime = memoize(submit => () => setTimeout(submit, 10))

export const makeChangeSave = memoize((onChange, submit) => val => {
  onChange(val)
  submit()
})

export const makeChangeSaveVal = memoize((onChange, submit, val) => () => {
  onChange(val)
  submit()
})

export const makeReset = memoize(
Exemple #4
0
      }
    }
    return newState
  },
}

export default makeReducer(flows)

/* SELECTORS */

export const getAltSection = ({ alter }, { alterSection }) => ({
  alter: alter[alterSection] || emptyO,
})

/* HELPERS */

export const compileAlternatives = memoize(
  (alterSection, nAlts, initial, dispatch) => alterTag => ({
    getAlt: alter => {
      const { [alterTag]: alt = initial || 0 } = alter
      return alt
    },
    nextAlt: handle(dispatch, nextAlt, alterSection, alterTag, nAlts, initial),
    initAlt: handle(dispatch, setAlt, alterSection, alterTag, initial),
    setAlt: alt => handle(dispatch, setAlt, alterSection, alterTag, alt),
    putAlt: alt => dispatch(setAlt(alterSection, alterTag, alt)),
  }),
  null,
  { debug: 'compileAlternatives' },
)