How to use the platform/utilities/data/set function in platform

To help you get started, we’ve selected a few platform examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github department-of-veterans-affairs / vets-website / src / applications / vaos / reducers / newAppointment.js View on Github external
let newSchema = action.schema;
      let newData = state.data;
      const systems = action.systems || state.systems;

      // For both systems and facilities, we want to put them in the form
      // schema as radio options if we have more than one to choose from.
      // If we only have one, then we want to just set the value in the
      // form data and remove the schema for that field, so we don't
      // show the question to the user
      if (systems.length > 1) {
        newSchema = set(
          'properties.vaSystem.enum',
          systems.map(sys => sys.institutionCode),
          action.schema,
        );
        newSchema = set(
          'properties.vaSystem.enumNames',
          systems.map(sys => sys.authoritativeName),
          newSchema,
        );
      } else {
        newSchema = unset('properties.vaSystem', newSchema);
        newData = {
          ...newData,
          vaSystem: systems[0]?.institutionCode,
        };
      }

      const facilities =
        action.facilities ||
        getFacilities(state, action.typeOfCareId, newData.vaSystem);
github department-of-veterans-affairs / vets-website / src / applications / vaos / reducers / newAppointment.js View on Github external
...state,
        loadingSystems: true,
      };
    }
    case FORM_PAGE_FACILITY_OPEN_SUCCEEDED: {
      let newSchema = action.schema;
      let newData = state.data;
      const systems = action.systems || state.systems;

      // For both systems and facilities, we want to put them in the form
      // schema as radio options if we have more than one to choose from.
      // If we only have one, then we want to just set the value in the
      // form data and remove the schema for that field, so we don't
      // show the question to the user
      if (systems.length > 1) {
        newSchema = set(
          'properties.vaSystem.enum',
          systems.map(sys => sys.institutionCode),
          action.schema,
        );
        newSchema = set(
          'properties.vaSystem.enumNames',
          systems.map(sys => sys.authoritativeName),
          newSchema,
        );
      } else {
        newSchema = unset('properties.vaSystem', newSchema);
        newData = {
          ...newData,
          vaSystem: systems[0]?.institutionCode,
        };
      }
github department-of-veterans-affairs / vets-website / src / applications / vaos / utils / address.js View on Github external
(city, addressSchema) => {
      const schemaUpdate = {
        properties: addressSchema.properties,
      };

      const stateList = usaStates;
      const labelList = usaLabels;

      // We constrain the state list when someone picks a city that’s a military base
      if (
        isMilitaryCity(city) &&
        schemaUpdate.properties.state.enum !== militaryStates
      ) {
        const withEnum = set(
          'state.enum',
          militaryStates,
          schemaUpdate.properties,
        );
        schemaUpdate.properties = set(
          'state.enumNames',
          militaryLabels,
          withEnum,
        );
      } else {
        schemaUpdate.properties = set(
          'state.enumNames',
          labelList,
          schemaUpdate.properties,
        );
        schemaUpdate.properties = set(
github department-of-veterans-affairs / vets-website / src / applications / personalization / rated-disabilities / reducers / index.js View on Github external
function ratedDisabilities(state = initialState, action) {
  switch (action.type) {
    case FETCH_RATED_DISABILITIES_SUCCESS:
      return set('ratedDisabilities', action.response, state);

    case FETCH_RATED_DISABILITIES_FAILED:
      return set('ratedDisabilities', action.response, state);

    default:
      return state;
  }
}
github department-of-veterans-affairs / vets-website / src / applications / personalization / profile360 / reducers / index.js View on Github external
function vaProfile(state = initialState, action) {
  switch (action.type) {
    case FETCH_HERO_SUCCESS:
      return set('hero', action.hero, state);

    case FETCH_PERSONAL_INFORMATION_SUCCESS:
      return set('personalInformation', action.personalInformation, state);

    case FETCH_MILITARY_INFORMATION_SUCCESS:
      return set('militaryInformation', action.militaryInformation, state);

    case PAYMENT_INFORMATION_FETCH_SUCCEEDED:
    case PAYMENT_INFORMATION_SAVE_SUCCEEDED: {
      let newState = set('paymentInformation', action.response, state);
      newState = set('paymentInformationUiState.isEditing', false, newState);
      return set('paymentInformationUiState.isSaving', false, newState);
    }

    case PAYMENT_INFORMATION_EDIT_MODAL_TOGGLED: {
      let newState = set(
        'paymentInformationUiState.isEditing',
        !state.paymentInformationUiState.isEditing,
        state,
      );

      newState = set('paymentInformationUiState.responseError', null, newState);

      return set(
        'paymentInformationUiState.editModalForm',
        editModalFormsInitialState,
github department-of-veterans-affairs / vets-website / src / applications / vaos / reducers / newAppointment.js View on Github external
function updateFacilitiesSchemaAndData(systems, facilities, schema, data) {
  let newSchema = schema;
  let newData = data;

  const availableFacilities = getEligibleFacilities(facilities);

  if (
    availableFacilities.length > 1 ||
    (availableFacilities.length === 1 && systems.length > 1)
  ) {
    newSchema = unset('properties.vaFacilityMessage', newSchema);
    newSchema = set(
      'properties.vaFacility',
      {
        type: 'string',
        enum: availableFacilities.map(
          facility => facility.institution.institutionCode,
        ),
        enumNames: availableFacilities.map(
          facility =>
            `${facility.institution.authoritativeName} (${
              facility.institution.city
            }, ${facility.institution.stateAbbrev})`,
        ),
      },
      newSchema,
    );
  } else if (newData.vaSystem) {
github department-of-veterans-affairs / vets-website / src / applications / vaos / utils / address.js View on Github external
'state.enum',
          militaryStates,
          schemaUpdate.properties,
        );
        schemaUpdate.properties = set(
          'state.enumNames',
          militaryLabels,
          withEnum,
        );
      } else {
        schemaUpdate.properties = set(
          'state.enumNames',
          labelList,
          schemaUpdate.properties,
        );
        schemaUpdate.properties = set(
          'state.enum',
          stateList,
          schemaUpdate.properties,
        );
      }

      return schemaUpdate;
    },
  );
github department-of-veterans-affairs / vets-website / src / applications / personalization / profile360 / reducers / index.js View on Github external
case FETCH_PERSONAL_INFORMATION_SUCCESS:
      return set('personalInformation', action.personalInformation, state);

    case FETCH_MILITARY_INFORMATION_SUCCESS:
      return set('militaryInformation', action.militaryInformation, state);

    case PAYMENT_INFORMATION_FETCH_SUCCEEDED:
    case PAYMENT_INFORMATION_SAVE_SUCCEEDED: {
      let newState = set('paymentInformation', action.response, state);
      newState = set('paymentInformationUiState.isEditing', false, newState);
      return set('paymentInformationUiState.isSaving', false, newState);
    }

    case PAYMENT_INFORMATION_EDIT_MODAL_TOGGLED: {
      let newState = set(
        'paymentInformationUiState.isEditing',
        !state.paymentInformationUiState.isEditing,
        state,
      );

      newState = set('paymentInformationUiState.responseError', null, newState);

      return set(
        'paymentInformationUiState.editModalForm',
        editModalFormsInitialState,
        newState,
      );
    }

    case PAYMENT_INFORMATION_EDIT_MODAL_FIELD_CHANGED:
      return set(