diff --git a/frontend/app/components/Client/Integrations/Integrations.js b/frontend/app/components/Client/Integrations/Integrations.js index 2f4ed073f..b4a421980 100644 --- a/frontend/app/components/Client/Integrations/Integrations.js +++ b/frontend/app/components/Client/Integrations/Integrations.js @@ -1,36 +1,36 @@ -import React from 'react'; -import { connect } from 'react-redux'; -import withPageTitle from 'HOCs/withPageTitle'; -import { Loader, IconButton, Button, Icon, SlideModal } from 'UI'; -import { fetchList as fetchListSlack } from 'Duck/integrations/slack'; -import { remove as removeIntegrationConfig } from 'Duck/integrations/actions'; -import { fetchList, init } from 'Duck/integrations/actions'; -import cn from 'classnames'; +import React from "react"; +import { connect } from "react-redux"; +import withPageTitle from "HOCs/withPageTitle"; +import { Loader, IconButton, SlideModal } from "UI"; +import { fetchList as fetchListSlack } from "Duck/integrations/slack"; +import { remove as removeIntegrationConfig } from "Duck/integrations/actions"; +import { fetchList, init } from "Duck/integrations/actions"; +import cn from "classnames"; -import IntegrationItem from './IntegrationItem'; -import SentryForm from './SentryForm'; -import GithubForm from './GithubForm'; -import SlackForm from './SlackForm'; -import DatadogForm from './DatadogForm'; -import StackdriverForm from './StackdriverForm'; -import RollbarForm from './RollbarForm'; -import NewrelicForm from './NewrelicForm'; -import BugsnagForm from './BugsnagForm'; -import CloudwatchForm from './CloudwatchForm'; -import ElasticsearchForm from './ElasticsearchForm'; -import SumoLogicForm from './SumoLogicForm'; -import JiraForm from './JiraForm'; -import styles from './integrations.module.css'; -import ReduxDoc from './ReduxDoc'; -import VueDoc from './VueDoc'; -import GraphQLDoc from './GraphQLDoc'; -import NgRxDoc from './NgRxDoc/NgRxDoc'; -import SlackAddForm from './SlackAddForm'; -import FetchDoc from './FetchDoc'; -import MobxDoc from './MobxDoc'; -import ProfilerDoc from './ProfilerDoc'; -import AssistDoc from './AssistDoc'; -import AxiosDoc from './AxiosDoc/AxiosDoc'; +import IntegrationItem from "./IntegrationItem"; +import SentryForm from "./SentryForm"; +import GithubForm from "./GithubForm"; +import SlackForm from "./SlackForm"; +import DatadogForm from "./DatadogForm"; +import StackdriverForm from "./StackdriverForm"; +import RollbarForm from "./RollbarForm"; +import NewrelicForm from "./NewrelicForm"; +import BugsnagForm from "./BugsnagForm"; +import CloudwatchForm from "./CloudwatchForm"; +import ElasticsearchForm from "./ElasticsearchForm"; +import SumoLogicForm from "./SumoLogicForm"; +import JiraForm from "./JiraForm"; +import styles from "./integrations.module.css"; +import ReduxDoc from "./ReduxDoc"; +import VueDoc from "./VueDoc"; +import GraphQLDoc from "./GraphQLDoc"; +import NgRxDoc from "./NgRxDoc/NgRxDoc"; +import SlackAddForm from "./SlackAddForm"; +import FetchDoc from "./FetchDoc"; +import MobxDoc from "./MobxDoc"; +import ProfilerDoc from "./ProfilerDoc"; +import AssistDoc from "./AssistDoc"; +import AxiosDoc from "./AxiosDoc/AxiosDoc"; const NONE = -1; const SENTRY = 0; @@ -56,468 +56,578 @@ const ASSIST = 19; const AXIOS = 20; const TITLE = { - [ SENTRY ]: 'Sentry', - [ SLACK ]: 'Slack', - [ DATADOG ]: 'Datadog', - [ STACKDRIVER ]: 'Stackdriver', - [ ROLLBAR ]: 'Rollbar', - [ NEWRELIC ]: 'New Relic', - [ BUGSNAG ]: 'Bugsnag', - [ CLOUDWATCH ]: 'CloudWatch', - [ ELASTICSEARCH ]: 'Elastic Search', - [ SUMOLOGIC ]: 'Sumo Logic', - [ JIRA ]: 'Jira', - [ GITHUB ]: 'Github', - [ REDUX ] : 'Redux', - [ VUE ] : 'VueX', - [ GRAPHQL ] : 'GraphQL', - [ NGRX ] : 'NgRx', - [ FETCH ] : 'Fetch', - [ MOBX ] : 'MobX', - [ PROFILER ] : 'Profiler', - [ ASSIST ] : 'Assist', - [ AXIOS ] : 'Axios', -} + [SENTRY]: "Sentry", + [SLACK]: "Slack", + [DATADOG]: "Datadog", + [STACKDRIVER]: "Stackdriver", + [ROLLBAR]: "Rollbar", + [NEWRELIC]: "New Relic", + [BUGSNAG]: "Bugsnag", + [CLOUDWATCH]: "CloudWatch", + [ELASTICSEARCH]: "Elastic Search", + [SUMOLOGIC]: "Sumo Logic", + [JIRA]: "Jira", + [GITHUB]: "Github", + [REDUX]: "Redux", + [VUE]: "VueX", + [GRAPHQL]: "GraphQL", + [NGRX]: "NgRx", + [FETCH]: "Fetch", + [MOBX]: "MobX", + [PROFILER]: "Profiler", + [ASSIST]: "Assist", + [AXIOS]: "Axios", +}; -const DOCS = [REDUX, VUE, GRAPHQL, NGRX, FETCH, MOBX, PROFILER, ASSIST] +const DOCS = [REDUX, VUE, GRAPHQL, NGRX, FETCH, MOBX, PROFILER, ASSIST]; -const integrations = [ 'sentry', 'datadog', 'stackdriver', 'rollbar', 'newrelic', 'bugsnag', 'cloudwatch', 'elasticsearch', 'sumologic', 'issues' ]; +const integrations = [ + "sentry", + "datadog", + "stackdriver", + "rollbar", + "newrelic", + "bugsnag", + "cloudwatch", + "elasticsearch", + "sumologic", + "issues", +]; -@connect(state => { - const props = {}; - integrations.forEach(name => { - props[ `${ name }Integrated`] = name === 'issues' ? - !!(state.getIn([ name, 'list' ]).first() && state.getIn([ name, 'list' ]).first().token) : - state.getIn([ name, 'list' ]).size > 0; - props.loading = props.loading || state.getIn([ name, 'fetchRequest', 'loading']); - }) - const site = state.getIn([ 'site', 'instance' ]); - return { - ...props, - issues: state.getIn([ 'issues', 'list']).first() || {}, - slackChannelListExists: state.getIn([ 'slack', 'list' ]).size > 0, - tenantId: state.getIn([ 'user', 'account', 'tenantId' ]), - jwt: state.get('jwt'), - projectKey: site ? site.projectKey : '' - }; -}, { - fetchList, - init, - fetchListSlack, - removeIntegrationConfig -}) -@withPageTitle('Integrations - OpenReplay Preferences') -export default class Integrations extends React.PureComponent { - state = { - modalContent: NONE, - showDetailContent: false, - }; - - componentWillMount() { - integrations.forEach(name => - this.props.fetchList(name) - ); - this.props.fetchListSlack(); - } - - onClickIntegrationItem = (e, url) => { - e.preventDefault(); - window.open(url); - } - - closeModal = () => this.setState({ modalContent: NONE, showDetailContent: false }); - - onOauthClick = (source) => { - if (source === GITHUB) { - const githubUrl = `https://auth.openreplay.com/oauth/login?provider=github&back_url=${document.location.href}`; - const options = { - method: 'GET', - credentials: 'include', - headers: new Headers({ - 'Authorization': 'Bearer ' + this.props.jwt.toString() - }) - }; - fetch(githubUrl, options).then((resp) => resp.text().then((txt) => window.open(txt, '_self'))) - } - } - - renderDetailContent() { - switch (this.state.modalContent) { - case SLACK: - return this.setState({ showDetailContent: false }) } />; - } - } - - renderModalContent() { - const { projectKey } = this.props; - - switch (this.state.modalContent) { - case SENTRY: - return ; - case GITHUB: - return ; - case SLACK: - return this.setState({ showDetailContent: true })} - /> - case DATADOG: - return ; - case STACKDRIVER: - return ; - case ROLLBAR: - return ; - case NEWRELIC: - return ; - case BUGSNAG: - return ; - case CLOUDWATCH: - return ; - case ELASTICSEARCH: - return ; - case SUMOLOGIC: - return ; - case JIRA: - return ; - case REDUX: - return - case VUE: - return - case GRAPHQL: - return - case NGRX: - return - case FETCH: - return - case MOBX: - return - case PROFILER: - return - case ASSIST: - return - case AXIOS: - return - default: - return null; +@connect( + (state) => { + const props = {}; + integrations.forEach((name) => { + props[`${name}Integrated`] = + name === "issues" + ? !!( + state.getIn([name, "list"]).first() && + state.getIn([name, "list"]).first().token + ) + : state.getIn([name, "list"]).size > 0; + props.loading = + props.loading || state.getIn([name, "fetchRequest", "loading"]); + }); + const site = state.getIn(["site", "instance"]); + return { + ...props, + issues: state.getIn(["issues", "list"]).first() || {}, + slackChannelListExists: state.getIn(["slack", "list"]).size > 0, + tenantId: state.getIn(["user", "account", "tenantId"]), + jwt: state.get("jwt"), + projectKey: site ? site.projectKey : "", + }; + }, + { + fetchList, + init, + fetchListSlack, + removeIntegrationConfig, } - } +) +@withPageTitle("Integrations - OpenReplay Preferences") +export default class Integrations extends React.PureComponent { + state = { + modalContent: NONE, + showDetailContent: false, + }; - deleteHandler = name => { - this.props.removeIntegrationConfig(name, null).then(function() { - this.props.fetchList(name) - }.bind(this)); - } - - showIntegrationConfig = (type) => { - this.setState({ modalContent: type }); - } + componentWillMount() { + integrations.forEach((name) => this.props.fetchList(name)); + this.props.fetchListSlack(); + } - render() { - const { - loading, - sentryIntegrated, - stackdriverIntegrated, - datadogIntegrated, - rollbarIntegrated, - newrelicIntegrated, - bugsnagIntegrated, - cloudwatchIntegrated, - elasticsearchIntegrated, - sumologicIntegrated, - hideHeader=false, - plugins=false, - jiraIntegrated, - issuesIntegrated, - tenantId, - slackChannelListExists, - issues, - } = this.props; - const { modalContent, showDetailContent } = this.state; - return ( -
- -
{TITLE[ modalContent ]}
- { modalContent === SLACK && ( - this.setState({ showDetailContent: true })} - /> - )} -
- } - isDisplayed={ modalContent !== NONE } - onClose={ this.closeModal } - size={ DOCS.includes(this.state.modalContent) ? 'middle' : 'small' } - content={ this.renderModalContent() } - detailContent={ showDetailContent && this.renderDetailContent() } - /> + onClickIntegrationItem = (e, url) => { + e.preventDefault(); + window.open(url); + }; - {!hideHeader && ( -
-

{ 'Integrations' }

-

Power your workflow with your favourite tools.

-
-
- )} + closeModal = () => + this.setState({ modalContent: NONE, showDetailContent: false }); - {plugins && ( -
-
Use plugins to better debug your application's store, monitor queries and track performance issues.
-
- this.showIntegrationConfig(REDUX) } - // integrated={ sentryIntegrated } - /> - this.showIntegrationConfig(VUE) } - // integrated={ sentryIntegrated } - /> - this.showIntegrationConfig(GRAPHQL) } - // integrated={ sentryIntegrated } - /> - this.showIntegrationConfig(NGRX) } - // integrated={ sentryIntegrated } - /> - this.showIntegrationConfig(MOBX) } - // integrated={ sentryIntegrated } - /> - this.showIntegrationConfig(FETCH) } - // integrated={ sentryIntegrated } - /> - this.showIntegrationConfig(PROFILER) } - // integrated={ sentryIntegrated } - /> - this.showIntegrationConfig(AXIOS) } - // integrated={ sentryIntegrated } - /> - this.showIntegrationConfig(ASSIST) } - // integrated={ sentryIntegrated } - /> -
-
- )} + onOauthClick = (source) => { + if (source === GITHUB) { + const githubUrl = `https://auth.openreplay.com/oauth/login?provider=github&back_url=${document.location.href}`; + const options = { + method: "GET", + credentials: "include", + headers: new Headers({ + Authorization: "Bearer " + this.props.jwt.toString(), + }), + }; + fetch(githubUrl, options).then((resp) => + resp.text().then((txt) => window.open(txt, "_self")) + ); + } + }; - {!plugins && ( - -
-
-
How are you monitoring errors and crash reporting?
-
- { - (!issues.token || issues.provider !== 'github') && - this.showIntegrationConfig(JIRA) } - integrated={ issuesIntegrated } - /> - } - { (!issues.token || issues.provider !== 'jira') && - this.showIntegrationConfig(GITHUB) } - integrated={ issuesIntegrated } - deleteHandler={issuesIntegrated ? () => this.deleteHandler('issues') : null} - /> - } - {/* this.showIntegrationConfig(GITHUB) } - integrated={ sentryIntegrated } - /> - this.showIntegrationConfig(JIRA) } - integrated={ sentryIntegrated } - /> */} - this.showIntegrationConfig(SLACK) } - integrated={ sentryIntegrated } - /> - this.showIntegrationConfig(SENTRY) } - integrated={ sentryIntegrated } - /> + renderDetailContent() { + switch (this.state.modalContent) { + case SLACK: + return ( + + this.setState({ showDetailContent: false }) + } + /> + ); + } + } - this.showIntegrationConfig(BUGSNAG) } - integrated={ bugsnagIntegrated } - /> + renderModalContent() { + const { projectKey } = this.props; - this.showIntegrationConfig(ROLLBAR) } - integrated={ rollbarIntegrated } - /> + switch (this.state.modalContent) { + case SENTRY: + return ; + case GITHUB: + return ; + case SLACK: + return ( + + this.setState({ showDetailContent: true }) + } + /> + ); + case DATADOG: + return ; + case STACKDRIVER: + return ; + case ROLLBAR: + return ; + case NEWRELIC: + return ; + case BUGSNAG: + return ; + case CLOUDWATCH: + return ; + case ELASTICSEARCH: + return ; + case SUMOLOGIC: + return ; + case JIRA: + return ; + case REDUX: + return ( + + ); + case VUE: + return ( + + ); + case GRAPHQL: + return ( + + ); + case NGRX: + return ( + + ); + case FETCH: + return ( + + ); + case MOBX: + return ( + + ); + case PROFILER: + return ( + + ); + case ASSIST: + return ( + + ); + case AXIOS: + return ( + + ); + default: + return null; + } + } - this.showIntegrationConfig(ELASTICSEARCH) } - integrated={ elasticsearchIntegrated } - /> + deleteHandler = (name) => { + this.props.removeIntegrationConfig(name, null).then( + function () { + this.props.fetchList(name); + }.bind(this) + ); + }; - this.showIntegrationConfig(DATADOG) } - integrated={ datadogIntegrated } - /> - this.showIntegrationConfig(SUMOLOGIC) } - integrated={ sumologicIntegrated } - /> - this.showIntegrationConfig(STACKDRIVER) } - integrated={ stackdriverIntegrated } - /> + showIntegrationConfig = (type) => { + this.setState({ modalContent: type }); + }; - this.showIntegrationConfig(CLOUDWATCH) } - integrated={ cloudwatchIntegrated } - /> + render() { + const { + loading, + sentryIntegrated, + stackdriverIntegrated, + datadogIntegrated, + rollbarIntegrated, + newrelicIntegrated, + bugsnagIntegrated, + cloudwatchIntegrated, + elasticsearchIntegrated, + sumologicIntegrated, + hideHeader = false, + plugins = false, + jiraIntegrated, + issuesIntegrated, + tenantId, + slackChannelListExists, + issues, + } = this.props; + const { modalContent, showDetailContent } = this.state; + return ( +
+ +
{TITLE[modalContent]}
+ {modalContent === SLACK && ( + + this.setState({ + showDetailContent: true, + }) + } + /> + )} +
+ } + isDisplayed={modalContent !== NONE} + onClose={this.closeModal} + size={ + DOCS.includes(this.state.modalContent) + ? "middle" + : "small" + } + content={this.renderModalContent()} + detailContent={ + showDetailContent && this.renderDetailContent() + } + /> - this.showIntegrationConfig(NEWRELIC) } - integrated={ newrelicIntegrated } - /> -
-
- - {/*
-
How are you logging backend errors?
-
- -
-
*/} - {/* - - */} -
-
- )} -
- ); - } -} \ No newline at end of file + {!hideHeader && ( +
+

+ {"Integrations"} +

+

+ Power your workflow with your favourite tools. +

+
+
+ )} + + {plugins && ( +
+
+ Use plugins to better debug your application's + store, monitor queries and track performance issues. +
+
+ + this.showIntegrationConfig(REDUX) + } + // integrated={ sentryIntegrated } + /> + this.showIntegrationConfig(VUE)} + // integrated={ sentryIntegrated } + /> + + this.showIntegrationConfig(GRAPHQL) + } + // integrated={ sentryIntegrated } + /> + this.showIntegrationConfig(NGRX)} + // integrated={ sentryIntegrated } + /> + this.showIntegrationConfig(MOBX)} + // integrated={ sentryIntegrated } + /> + + this.showIntegrationConfig(FETCH) + } + // integrated={ sentryIntegrated } + /> + + this.showIntegrationConfig(PROFILER) + } + // integrated={ sentryIntegrated } + /> + + this.showIntegrationConfig(AXIOS) + } + // integrated={ sentryIntegrated } + /> + + this.showIntegrationConfig(ASSIST) + } + // integrated={ sentryIntegrated } + /> +
+
+ )} + + {!plugins && ( + +
+
+
+ How are you monitoring errors and crash + reporting? +
+
+ {(!issues.token || + issues.provider !== "github") && ( + + this.showIntegrationConfig(JIRA) + } + integrated={issuesIntegrated} + /> + )} + {(!issues.token || + issues.provider !== "jira") && ( + + this.showIntegrationConfig( + GITHUB + ) + } + integrated={issuesIntegrated} + deleteHandler={ + issuesIntegrated + ? () => + this.deleteHandler( + "issues" + ) + : null + } + /> + )} + + + this.showIntegrationConfig(SLACK) + } + integrated={sentryIntegrated} + /> + + this.showIntegrationConfig(SENTRY) + } + integrated={sentryIntegrated} + /> + + + this.showIntegrationConfig(BUGSNAG) + } + integrated={bugsnagIntegrated} + /> + + + this.showIntegrationConfig(ROLLBAR) + } + integrated={rollbarIntegrated} + /> + + + this.showIntegrationConfig( + ELASTICSEARCH + ) + } + integrated={elasticsearchIntegrated} + /> + + + this.showIntegrationConfig(DATADOG) + } + integrated={datadogIntegrated} + /> + + this.showIntegrationConfig( + SUMOLOGIC + ) + } + integrated={sumologicIntegrated} + /> + + this.showIntegrationConfig( + STACKDRIVER + ) + } + integrated={stackdriverIntegrated} + /> + + + this.showIntegrationConfig( + CLOUDWATCH + ) + } + integrated={cloudwatchIntegrated} + /> + + + this.showIntegrationConfig(NEWRELIC) + } + integrated={newrelicIntegrated} + /> +
+
+
+
+ )} +
+ ); + } +} diff --git a/frontend/app/components/Client/Integrations/SlackChannelList/SlackChannelList.js b/frontend/app/components/Client/Integrations/SlackChannelList/SlackChannelList.js index e854dfce2..f78527204 100644 --- a/frontend/app/components/Client/Integrations/SlackChannelList/SlackChannelList.js +++ b/frontend/app/components/Client/Integrations/SlackChannelList/SlackChannelList.js @@ -16,9 +16,10 @@ function SlackChannelList(props) {
-
Integrate Slack with OpenReplay and share insights with the rest of the team, directly from the recording page.
- +
+
Integrate Slack with OpenReplay and share insights with the rest of the team, directly from the recording page.
+ {/* */} +
} size="small" diff --git a/frontend/app/components/Dashboard/Widgets/CustomMetricsWidgets/CustomMetricTableSessions/CustomMetricTableSessions.tsx b/frontend/app/components/Dashboard/Widgets/CustomMetricsWidgets/CustomMetricTableSessions/CustomMetricTableSessions.tsx index c5ab0ee85..faf725da6 100644 --- a/frontend/app/components/Dashboard/Widgets/CustomMetricsWidgets/CustomMetricTableSessions/CustomMetricTableSessions.tsx +++ b/frontend/app/components/Dashboard/Widgets/CustomMetricsWidgets/CustomMetricTableSessions/CustomMetricTableSessions.tsx @@ -1,8 +1,7 @@ import { useObserver } from 'mobx-react-lite'; -import React, { useEffect } from 'react'; +import React from 'react'; import SessionItem from 'Shared/SessionItem'; import { Pagination, NoContent } from 'UI'; -import { useModal } from 'App/components/Modal'; interface Props { metric: any; @@ -17,6 +16,7 @@ function CustomMetricTableSessions(props: Props) {
{metric.data.sessions && metric.data.sessions.map((session: any, index: any) => ( diff --git a/frontend/app/types/app/period.js b/frontend/app/types/app/period.js index 1922e55b3..646f0087e 100644 --- a/frontend/app/types/app/period.js +++ b/frontend/app/types/app/period.js @@ -1,132 +1,138 @@ -import origMoment from 'moment'; -import { extendMoment } from 'moment-range'; -import Record from 'Types/Record'; +import origMoment from "moment"; +import { extendMoment } from "moment-range"; +import Record from "Types/Record"; const moment = extendMoment(origMoment); -export const LAST_30_MINUTES = 'LAST_30_MINUTES'; -export const TODAY = 'TODAY'; -export const LAST_24_HOURS = 'LAST_24_HOURS'; -export const YESTERDAY = 'YESTERDAY'; -export const LAST_7_DAYS = 'LAST_7_DAYS'; -export const LAST_30_DAYS = 'LAST_30_DAYS'; -export const THIS_MONTH = 'THIS_MONTH'; -export const LAST_MONTH = 'LAST_MONTH'; -export const THIS_YEAR = 'THIS_YEAR'; -export const CUSTOM_RANGE = 'CUSTOM_RANGE'; +export const LAST_30_MINUTES = "LAST_30_MINUTES"; +export const TODAY = "TODAY"; +export const LAST_24_HOURS = "LAST_24_HOURS"; +export const YESTERDAY = "YESTERDAY"; +export const LAST_7_DAYS = "LAST_7_DAYS"; +export const LAST_30_DAYS = "LAST_30_DAYS"; +export const THIS_MONTH = "THIS_MONTH"; +export const LAST_MONTH = "LAST_MONTH"; +export const THIS_YEAR = "THIS_YEAR"; +export const CUSTOM_RANGE = "CUSTOM_RANGE"; const RANGE_LABELS = { - [ LAST_30_MINUTES ]: 'Last 30 Minutes', - [ TODAY ]: 'Today', - [ YESTERDAY ]: 'Yesterday', - [ LAST_24_HOURS ]: 'Last 24 Hours', - [ LAST_7_DAYS ]: 'Last 7 Days', - [ LAST_30_DAYS ]: 'Last 30 Days', - [ THIS_MONTH ]: 'This Month', - [ LAST_MONTH ]: 'Last Month', - [ THIS_YEAR ]: 'This Year', -} + [LAST_30_MINUTES]: "Last 30 Minutes", + [TODAY]: "Today", + [YESTERDAY]: "Yesterday", + [LAST_24_HOURS]: "Last 24 Hours", + [LAST_7_DAYS]: "Last 7 Days", + [LAST_30_DAYS]: "Last 30 Days", + [THIS_MONTH]: "This Month", + [LAST_MONTH]: "Last Month", + [THIS_YEAR]: "This Year", +}; function getRange(rangeName) { - switch (rangeName) { - case TODAY: - return moment.range( - moment().startOf('day'), - moment().endOf('day'), - ); - case YESTERDAY: - return moment.range( - moment().subtract(1, 'days').startOf('day'), - moment().subtract(1, 'days').endOf('day'), - ); - case LAST_24_HOURS: - return moment.range( - moment().startOf('hour').subtract(24, 'hours'), - moment().startOf('hour'), - ); - case LAST_30_MINUTES: - return moment.range( - moment().startOf('hour').subtract(30, 'minutes'), - moment().startOf('hour'), - ); - case LAST_7_DAYS: - return moment.range( - moment().subtract(7, 'days').startOf('day'), - moment().endOf('day'), - ); - case LAST_30_DAYS: - return moment.range( - moment().subtract(30, 'days').startOf('day'), - moment().endOf('day'), - ); - case THIS_MONTH: - return moment().range('month'); - case LAST_MONTH: - return moment().subtract(1, 'months').range('month'); - case THIS_YEAR: - return moment().range('year'); - default: - return moment.range(); - } + switch (rangeName) { + case TODAY: + return moment.range(moment().startOf("day"), moment().endOf("day")); + case YESTERDAY: + return moment.range( + moment().subtract(1, "days").startOf("day"), + moment().subtract(1, "days").endOf("day") + ); + case LAST_24_HOURS: + return moment.range( + // moment().startOf("hour").subtract(24, "hours"), + // moment().startOf("hour") + moment().subtract(24, 'hours'), + moment(), + ); + case LAST_30_MINUTES: + return moment.range( + moment().startOf("hour").subtract(30, "minutes"), + moment().startOf("hour") + ); + case LAST_7_DAYS: + return moment.range( + moment().subtract(7, "days").startOf("day"), + moment().endOf("day") + ); + case LAST_30_DAYS: + return moment.range( + moment().subtract(30, "days").startOf("day"), + moment().endOf("day") + ); + case THIS_MONTH: + return moment().range("month"); + case LAST_MONTH: + return moment().subtract(1, "months").range("month"); + case THIS_YEAR: + return moment().range("year"); + default: + return moment.range(); + } } -export default Record({ - start: 0, - end: 0, - rangeName: CUSTOM_RANGE, - range: moment.range(), -}, { - fromJS: period => { - if (!period.rangeName || period.rangeName === CUSTOM_RANGE) { - const range = moment.range( - moment(period.start || 0), - moment(period.end || 0), - ); - return { - ...period, - range, - start: range.start.unix() * 1000, - end: range.end.unix() * 1000, - }; - } - const range = getRange(period.rangeName); - return { - ...period, - range, - start: range.start.unix() * 1000, - end: range.end.unix() * 1000, - } - }, - // fromFilter: filter => { - // const range = getRange(filter.rangeName); - // return { - // start: range.start.unix() * 1000, - // end: range.end.unix() * 1000, - // rangeName: filter.rangeName, - // } - // }, - methods: { - toJSON() { - return { - startDate: this.start, - endDate: this.end, - rangeName: this.rangeName, - rangeValue: this.rangeName, - } - }, - toTimestamps() { - return { - startTimestamp: this.start, - endTimestamp: this.end, - }; - }, - rangeFormatted(format = 'MMM Do YY, hh:mm A') { - return this.range.start.format(format) + ' - ' + this.range.end.format(format); - }, - toTimestampstwo() { - return { - startTimestamp: this.start / 1000, - endTimestamp: this.end / 1000, - }; - }, - } -}); \ No newline at end of file +export default Record( + { + start: 0, + end: 0, + rangeName: CUSTOM_RANGE, + range: moment.range(), + }, + { + fromJS: (period) => { + if (!period.rangeName || period.rangeName === CUSTOM_RANGE) { + const range = moment.range( + moment(period.start || 0), + moment(period.end || 0) + ); + return { + ...period, + range, + start: range.start.unix() * 1000, + end: range.end.unix() * 1000, + }; + } + const range = getRange(period.rangeName); + return { + ...period, + range, + start: range.start.unix() * 1000, + end: range.end.unix() * 1000, + }; + }, + // fromFilter: filter => { + // const range = getRange(filter.rangeName); + // return { + // start: range.start.unix() * 1000, + // end: range.end.unix() * 1000, + // rangeName: filter.rangeName, + // } + // }, + methods: { + toJSON() { + return { + startDate: this.start, + endDate: this.end, + rangeName: this.rangeName, + rangeValue: this.rangeName, + }; + }, + toTimestamps() { + return { + startTimestamp: this.start, + endTimestamp: this.end, + }; + }, + rangeFormatted(format = "MMM Do YY, hh:mm A") { + return ( + this.range.start.format(format) + + " - " + + this.range.end.format(format) + ); + }, + toTimestampstwo() { + return { + startTimestamp: this.start / 1000, + endTimestamp: this.end / 1000, + }; + }, + }, + } +);