All Downloads are FREE. Search and download functionalities are using the official Maven repository.

apps.websight-package-manager.web-resources.components.PackageBuildDetails.js Maven / Gradle / Ivy

The newest version!
import React from "/apps/websight-atlaskit-esm/web-resources/react.js";
import Tooltip from "/apps/websight-atlaskit-esm/web-resources/@atlaskit/tooltip.js";
import styled from "/apps/websight-atlaskit-esm/web-resources/styled-components.js";
import { colors } from "/apps/websight-admin/web-resources/theme.js";
import { DateTimeOffset, isSameDay } from "/apps/websight-admin/web-resources/DateUtils.js";
const BuildDetails = styled.div`
    font-size: 12px;
    color: ${colors.darkGrey};
`;

const buildPackageBuildDetails = entry => {
  let details = '';
  const version = entry.packageInfo ? entry.packageInfo.versionString : null;

  if (version) {
    details += 'Version: ' + version + ' | ';
  }

  const buildsCount = entry.buildCount;

  if (buildsCount) {
    details += 'Build #' + buildsCount + ' | ';
  }

  return details;
};

const getActionInfo = entry => {
  if (entry.status && entry.status.installation) {
    return /*#__PURE__*/React.createElement(ActionInfo, {
      name: "Installed",
      dateString: entry.status.installation.date,
      executedBy: entry.status.installation.executedBy
    });
  } else if (entry.status && entry.status.build) {
    return /*#__PURE__*/React.createElement(ActionInfo, {
      name: "Built",
      dateString: entry.status.build.date,
      executedBy: entry.status.build.executedBy
    });
  } else if (entry.modification) {
    return /*#__PURE__*/React.createElement(ActionInfo, {
      name: "Modified",
      dateString: entry.modification.date,
      executedBy: entry.modification.executedBy
    });
  }
};

const ActionInfo = ({
  name: actionName,
  dateString,
  executedBy
}) => {
  const actionDateTimeOffset = new DateTimeOffset(dateString);
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Tooltip, {
    tag: "span",
    content: `Server time: ${actionDateTimeOffset.getEnGbDateTimeOffsetString()}`
  }, /*#__PURE__*/React.createElement("span", null, `${actionName} ${formatActionDate(actionDateTimeOffset)}`)), ' | ' + executedBy);
};

const formatActionDate = actionDateTimeOffset => {
  const now = new Date();
  const actionDate = new Date(actionDateTimeOffset.iso8601DateTimeOffsetString);

  if (isSameDay(actionDate, now)) {
    return `${actionDateTimeOffset.hours}:${actionDateTimeOffset.minutes}`;
  }

  if (actionDate.getFullYear() === now.getFullYear()) {
    return `${actionDateTimeOffset.shortMonth} ${actionDateTimeOffset.day}`;
  }

  return actionDateTimeOffset.getEnGbDateString();
};

export default class PackageBuildDetails extends React.Component {
  render() {
    const {
      packageData
    } = this.props;
    const packageBuildDetails = buildPackageBuildDetails(packageData);
    const buildInfo = getActionInfo(packageData);
    return /*#__PURE__*/React.createElement(BuildDetails, null, packageBuildDetails, buildInfo);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy