Skip to content

Instantly share code, notes, and snippets.

@beardedtim
Last active April 2, 2018 18:58
Show Gist options
  • Select an option

  • Save beardedtim/3423cd41b659659c5c610214cc74f657 to your computer and use it in GitHub Desktop.

Select an option

Save beardedtim/3423cd41b659659c5c610214cc74f657 to your computer and use it in GitHub Desktop.
List Building Architecture

List Building Architecture Outline

Add/Edit Modal

Needs

  • Current Subject/Object
  • Current Path to Subject/Object

Uses

  • Current Path to Subject/Object
  • Options at Path
  • Values at Path

Sets

  • Form State

Reads From

  • Form State
  • Domain/API Model

Methods

  • getView :: (path, Subject/Object) -> { Options /* left side */, Values /* right side */ }
    • Given a path and the current Subject/Object, return the Options and Values for the Modal
  • setForm :: (path, values) -> void
    • Given a path and the values selected, tell Form State to update.
  • dive :: (path, Subject/Object) -> void
    • Given a path and next Subject/Object, tell Form State to update the path for the next Modal.

Internal Data Structure

const modal = {
  path: [1234 /* contactInformation ID */],
  title: 'Contact Information > Contact Fields',
  //( Contact Fields ID )
  subject: '12345',
  // Choices on Left
  children: [{ id: 123456, text: 'Type' }],
  // No choices on Right
  values: [],
  // Type of qualifier for Right side
  qualifier: {}
}

const drilledModal = {
  path: [1234 /* contactInformation ID */, 12345 /* contact fields ID */],
  title: 'Contact Information > Contact Fields > Gender',
  // Gender Contact Field ID
  subject: 123456,
  // No choices on Left
  children: [],
  values: [
    { id: 1234567, label: 'Female', value: 'API return value for female' },
    { id: 1234568, label: 'Male', value: 'API Return value for male'},
    { id: 1234569, label: '[No Value]', value: 'API return value for no value' }
  ],
  qualifier: {
    title: 'Gender',
    type: 'dropdown',
    options: [
      { id: 12345688, label: 'Equal To', value: 'Some API Data thing' }
    ]
  }
}

Criteria Viewing

Needs

  • Criteria List
  • Ids to Form State

Uses

  • Form State

Reads From

  • Mapped Form state

Methods

  • edit :: id -> void
    • Given a criteria id, opens a Modal to update that Criteria
  • delete :: id -> void
    • Given a criteria id, opens the Delete modal

Form State

Needs

  • API contract

Uses

  • API Data

Sets

  • Structure for Modal and Criteria Viewing

Reads From

  • API Data

Methods

  • update :: Update -> FormState
    • Given an update, return a new FormState value

Internal Data Structure

const form = {
  groups: [
    {
      evaluator: {
        conjunction: 'and',
        evaluation: 1 // 'Meets all'
      },
      children: {
        123456789: {
          /* Org Item ID */
          path: [12345],
          sets: [
            {
              /* Org Item Field Id */
              path: [123456],
              values: [
                {
                  id: 12345,
                  value: 'Commercial',
                  equality: 1
                }
              ]
            },
            {
              /* Org Item Net Worth ID*/
              path: [12345],
              values: [
                {
                  id: 123456,
                  value: '$2',
                  equality: 3
                }
              ]
            }
          ]
        }
      },
      rules: [
        /*
         Contact has Contact Information that 
          has Contact Type equal to Person 
        */
        {
          path: [
            12345, /* contact information id */
          ],
          sets: [
            {
              /* contact type id */
              path: [123456],
              values: [{
               value: 'Person',
               id: 123456789 /* some id for this option */
              }],
              equality: 1,
            }
          ]
        },
        /*
          Contact has Relationship to John that 
           has Type equal to Customer or Prospect 
           is with Org Item that 
             has Field equal to Commercial 
             has Net Worth greater than $2 

        */
        {
          path: [
            12348, /* relationshipToJohn ID */
          ],
          sets: [
            {
              /* Type id */
              path: [123456],
              values: [
                { id: 123456, title: 'Customer' },
                { id: 123456, title: 'Propsect' }
              ],
              equality: 0
            },
          ],
          children: [123456789]
        }
      ]
    }
  ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment