fixes flow-types

This commit is contained in:
zmagod 2018-01-05 09:59:08 +01:00
parent 862b73cae7
commit be014000ab
3 changed files with 59 additions and 51 deletions

View file

@ -1,6 +1,7 @@
// @flow
import React from "react";
import type { Node } from "react";
import { FormattedDate } from "react-intl";
import { Tooltip, OverlayTrigger } from "react-bootstrap";
import styled from "styled-components";
@ -14,6 +15,10 @@ import {
import { NAME_TRUNCATION_LENGTH } from "../../../config/constants/numeric";
type InputActivity = {
activity: Activity
}
const StyledLi = styled.li`
border-radius: 0.25em;
margin-bottom: 1em;
@ -37,42 +42,42 @@ const TextSpan = styled.span`
display: table-cell;
padding: 3px 10px;
text-align: justify;
`
`;
function truncatedTooltip(id, text) {
function truncatedTooltip(id: string, text: any): Node {
return (
<OverlayTrigger overlay={(
<Tooltip id={id}>
{text}
</Tooltip>
)} placement="bottom">
<span>
{text.substring(0, NAME_TRUNCATION_LENGTH)}...
</span>
<OverlayTrigger
overlay={<Tooltip id={id}>{text}</Tooltip>}
placement="bottom"
>
<span>{text.substring(0, NAME_TRUNCATION_LENGTH)}...</span>
</OverlayTrigger>
);
}
function taskPath(activity) {
function taskPath(activity: Activity): Node {
return (
<span>&nbsp;
[&nbsp;<FormattedMessage id="general.project" />:&nbsp;
<span>
&nbsp; [&nbsp;<FormattedMessage id="general.project" />:&nbsp;
{activity.project.length > NAME_TRUNCATION_LENGTH ? (
truncatedTooltip('activity_modal.long_project_tooltip', activity.project)
):(
truncatedTooltip(
"activity_modal.long_project_tooltip",
activity.project
)
) : (
<span>{activity.project}</span>
)},&nbsp;
<FormattedMessage id="general.task" />:&nbsp;
{activity.task.length > NAME_TRUNCATION_LENGTH ? (
truncatedTooltip('activity_modal.long_task_tooltip', activity.task)
):(
truncatedTooltip("activity_modal.long_task_tooltip", activity.task)
) : (
<span>{activity.task}</span>
)}&nbsp;]
</span>
);
}
const ActivityElement = ({ activity }: Activity ): Node => (
const ActivityElement = ({ activity }: InputActivity ): Node => (
<StyledLi>
<TimeSpan>
<FormattedDate
@ -87,6 +92,7 @@ const ActivityElement = ({ activity }: Activity ): Node => (
<span dangerouslySetInnerHTML={{ __html: activity.message }} />
{activity.task && taskPath(activity)}
</TextSpan>
</StyledLi>;
</StyledLi>
);
export default ActivityElement;

View file

@ -1,7 +1,7 @@
// @flow
import React, { Component } from "react";
import type { Element } from "react";
import type { Element, Node } from "react";
import { FormattedMessage } from "react-intl";
import { Button, Modal } from "react-bootstrap";
import _ from "lodash";
@ -62,7 +62,7 @@ class GlobalActivitiesModal extends Component<Props, State> {
key: number,
activity: Activity,
date: Date
) {
): Node {
return [
<ActivityDateElement key={date} date={date} />,
<ActivityElement key={key} activity={activity} />
@ -95,35 +95,37 @@ class GlobalActivitiesModal extends Component<Props, State> {
}
mapActivities(): Array<*> {
return this.state.activities.map((activity, i, arr) => {
// when the backend bug will be fixed
const newDate = new Date(activity.createdAt);
// returns a label with "today" if the date of the activity is today
if (i === 0 && newDate.toDateString() === new Date().toDateString()) {
return GlobalActivitiesModal.renderActivityDateElement(
i,
activity,
newDate
);
return this.state.activities.map(
(activity: Activity, i: number, arr: Array<*>) => {
// when the backend bug will be fixed
const newDate = new Date(activity.createdAt);
// returns a label with "today" if the date of the activity is today
if (i === 0 && newDate.toDateString() === new Date().toDateString()) {
return GlobalActivitiesModal.renderActivityDateElement(
i,
activity,
newDate
);
}
// else checks if the previous activity is newer than current
// and displays a label with the date
const prevDate =
i !== 0 ? new Date(arr[i - 1].createdAt) : new Date(1901, 1, 1);
// filter only date from createdAt without minutes and seconds
// used to compare dates
const parsePrevDate = new Date(prevDate.toDateString());
const parseNewDate = new Date(newDate.toDateString());
if (parsePrevDate.getTime() > parseNewDate.getTime()) {
return GlobalActivitiesModal.renderActivityDateElement(
i,
activity,
newDate
);
}
// returns the default activity element
return <ActivityElement key={activity.id} activity={activity} />;
}
// else checks if the previous activity is newer than current
// and displays a label with the date
const prevDate =
i !== 0 ? new Date(arr[i - 1].createdAt) : new Date(1901, 1, 1);
// filter only date from createdAt without minutes and seconds
// used to compare dates
const parsePrevDate = new Date(prevDate.toDateString());
const parseNewDate = new Date(newDate.toDateString());
if (parsePrevDate.getTime() > parseNewDate.getTime()) {
return GlobalActivitiesModal.renderActivityDateElement(
i,
activity,
newDate
);
}
// returns the default activity element
return <ActivityElement key={activity.id} activity={activity} />;
});
);
}
displayActivities() {

4
flow-typed/types.js vendored
View file

@ -35,8 +35,8 @@ export type Activity = {
message: string,
createdAt: string,
timezone: string,
project?: string,
task?: string
project: string,
task: string
};
export type Notification = {