export function getTextValueChange()

in src/components/activity/activity__history-value.ts [17:104]


export function getTextValueChange(params: TextValueChangeParams): string {
  if (!params.activity) {
    return '';
  }

  const eventValue = params.isRemovedValue
    ? params.activity.removed
    : params.activity.added;

  if (!eventValue) {
    return getEmptyFieldValue(params.activity, params.issueFields).presentation;
  }

  const eventField = params.activity.field;
  const value = {
    presentation: eventValue,
  };

  switch (true) {
    case isActivityCategory.project(params.activity):
      value.presentation = getProjectPresentation(eventValue);
      break;

    case isActivityCategory.issueResolved(params.activity):
      value.presentation = absDate(eventValue);
      break;

    case isActivityCategory.attachment(params.activity) ||
      isActivityCategory.tag(params.activity):
      value.presentation = eventValue;
      break;
  }

  if (
    eventField &&
    eventField.customField &&
    isActivityCategory.customField(params.activity)
  ) {
    const simpleCustomFieldType = getCustomFieldType(
      eventField.customField,
    );
    setSimpleCustomFieldPresentationByType(
      simpleCustomFieldType,
      value,
      params.workTimeSettings,
    );
  }

  if (Array.isArray(value.presentation)) {
    value.presentation = value.presentation
      .map(getEntityPresentation)
      .join(', ');
  }

  return value.presentation;

  function setSimpleCustomFieldPresentationByType(
    simpleCustomFieldType,
    value,
    workTimeSettings: WorkTimeSettings,
  ) {
    const SIMPLE_CUSTOM_FIELDS_TYPES = {
      integer: 'integer',
      float: 'float',
      string: 'string',
      date: 'date',
      period: 'period',
      dateTime: 'date and time',
    };

    switch (simpleCustomFieldType) {
      case SIMPLE_CUSTOM_FIELDS_TYPES.period:
        value.presentation = getPeriodPresentationFor(
          eventValue,
          workTimeSettings,
        );
        break;

      case SIMPLE_CUSTOM_FIELDS_TYPES.date:
        value.presentation = absDate(eventValue);
        break;

      case SIMPLE_CUSTOM_FIELDS_TYPES.dateTime:
        value.presentation = absDate(eventValue);
        break;
    }
  }
}