From 69c0e63ad1932d310d75a28b19dafe781d6a3ba9 Mon Sep 17 00:00:00 2001 From: Miguel Jimenez Esun Date: Wed, 18 Sep 2019 15:48:10 +0200 Subject: [PATCH] fix: Fix error when loading, prettify all codebase --- .eslintrc.js | 48 +-- .prettierrc.js | 6 +- components/account-picker.js | 182 ++++----- components/configure/custom-hostnames.js | 361 ++++++++++-------- components/configure/modal-tag.js | 154 ++++---- components/current-incidents.js | 144 +++---- components/incidents/incident-timline.js | 119 +++--- components/incidents/ind-incident.js | 42 +- components/incidents/ind-updates.js | 41 +- components/status-page.js | 80 ++-- components/summary.js | 95 +++-- components/toolbar.js | 165 ++++---- launchers/status-page/nr1.json | 1 - nerdlets/configure-status-pages/configure.js | 13 +- nerdlets/incident-details/incident-details.js | 2 +- nerdlets/status-page-dashboard/main-page.js | 40 +- package.json | 2 +- popular-status-pages.js | 51 ++- utilities/format-service.js | 27 +- utilities/formatters/google.js | 68 ++-- utilities/formatters/status-page-io.js | 20 +- utilities/nerdlet-storage.js | 136 ++++--- utilities/network.js | 69 ++-- utilities/provider-services.js | 62 +-- 24 files changed, 1057 insertions(+), 871 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 072662c..39042d4 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,29 +1,23 @@ module.exports = { - "env": { - "browser": true, - "es6": true + env: { + browser: true, + es6: true, + }, + extends: ['prettier', 'prettier/react'], + globals: { + Atomics: 'readonly', + SharedArrayBuffer: 'readonly', + }, + parser: 'babel-eslint', + parserOptions: { + ecmaFeatures: { + jsx: true, }, - "extends": [ - "prettier", - "prettier/react", - ], - "globals": { - "Atomics": "readonly", - "SharedArrayBuffer": "readonly" - }, - "parser": "babel-eslint", - "parserOptions": { - "ecmaFeatures": { - "jsx": true - }, - "ecmaVersion": 2018, - "sourceType": "module" - }, - "plugins": [ - "react", - "prettier" - ], - "rules": { - "prettier/prettier": "error" - } -}; \ No newline at end of file + ecmaVersion: 2018, + sourceType: 'module', + }, + plugins: ['react', 'prettier'], + rules: { + 'prettier/prettier': 'error', + }, +}; diff --git a/.prettierrc.js b/.prettierrc.js index 4f2781d..a425d3f 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -1,4 +1,4 @@ module.exports = { - singleQuote: true, - trailingComma: "es5", -}; \ No newline at end of file + singleQuote: true, + trailingComma: 'es5', +}; diff --git a/components/account-picker.js b/components/account-picker.js index ad40d6b..e1b0eb2 100644 --- a/components/account-picker.js +++ b/components/account-picker.js @@ -1,106 +1,112 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { AccountsQuery, Dropdown, DropdownItem, UserStorageMutation, UserStorageQuery } from 'nr1'; - -const USER_ACCOUNT_COLLECTION = 'user_account_collection_v0'; +import { + AccountsQuery, + Dropdown, + DropdownItem, + UserStorageMutation, + UserStorageQuery, +} from 'nr1'; + +const USER_ACCOUNT_COLLECTION = 'user_account_collection_v1'; const USER_SELECTED_ACCOUNT_ID = 'user_account_id'; export default class AccountPicker extends React.Component { - static propTypes = { - hostname: PropTypes.string, - refreshRate: PropTypes.number + static propTypes = { + hostname: PropTypes.string, + refreshRate: PropTypes.number, + }; + + constructor(props) { + super(props); + this.state = { + selectedAccount: { name: '' }, + accounts: [], + filter: '', }; + this.onAccountChange = this.onAccountChange.bind(this); + } - constructor(props) { - super(props); - this.state = { - selectedAccount: { name: '' }, - accounts: [], - filter: '' - } - this.onAccountChange = this.onAccountChange.bind(this); - } - - async componentDidMount() { - const accountsResults = await AccountsQuery.query({}); - - if (accountsResults.data && accountsResults.data) { - const accounts = accountsResults.data; - this.setState({ accounts }); + async componentDidMount() { + const accountsResults = await AccountsQuery.query({}); - let accountId = await this.getLastChoseAccountId(); - if (!accountId) { - accountId = accounts[0].id; - } + if (accountsResults.data && accountsResults.data) { + const accounts = accountsResults.data; + this.setState({ accounts }); - const account = accounts.find(a => a.id === accountId); + let accountId = await this.getLastChoseAccountId(); + if (!accountId) { + accountId = accounts[0].id; + } - if (account) { - this._accountChanged(account); - } - } - } - - async getLastChoseAccountId() { - const userStorageQuery = { - collection: USER_ACCOUNT_COLLECTION, - documentId: USER_SELECTED_ACCOUNT_ID - } - // TODO: Add error handling - const queryResults = await UserStorageQuery.query(userStorageQuery); - return queryResults.data - } + const account = accounts.find(a => a.id === accountId); - async saveOffLastChosenAccountId(accountId) { - const userMutation = { - actionType: UserStorageMutation.ACTION_TYPE.WRITE_DOCUMENT, - collection: USER_ACCOUNT_COLLECTION, - document: accountId, - documentId: USER_SELECTED_ACCOUNT_ID - } - UserStorageMutation.mutate(userMutation); + if (account) { + this._accountChanged(account); + } } + } - async _accountChanged(account){ - const accountId = account.id; - const { accountChangedCallback } = this.props; - this.saveOffLastChosenAccountId(accountId); - if (accountChangedCallback) { - await accountChangedCallback(accountId, this.state.accounts); - } - this.setState({ selectedAccount: account }); + async getLastChoseAccountId() { + const userStorageQuery = { + collection: USER_ACCOUNT_COLLECTION, + documentId: USER_SELECTED_ACCOUNT_ID, + }; + // TODO: Add error handling + const queryResults = await UserStorageQuery.query(userStorageQuery); + return queryResults.data; + } + + async saveOffLastChosenAccountId(accountId) { + const userMutation = { + actionType: UserStorageMutation.ACTION_TYPE.WRITE_DOCUMENT, + collection: USER_ACCOUNT_COLLECTION, + document: { account: accountId }, + documentId: USER_SELECTED_ACCOUNT_ID, + }; + UserStorageMutation.mutate(userMutation); + } + + async _accountChanged(account) { + const accountId = account.id; + const { accountChangedCallback } = this.props; + this.saveOffLastChosenAccountId(accountId); + if (accountChangedCallback) { + await accountChangedCallback(accountId, this.state.accounts); } - - async onAccountChange(account) { - await this._accountChanged(account); + this.setState({ selectedAccount: account }); + } + + async onAccountChange(account) { + await this._accountChanged(account); + } + + render() { + const { accounts, filter, selectedAccount } = this.state; + + let filteredAccounts = [...accounts]; + if (filter && filter.length > 0) { + const re = new RegExp(filter, 'i'); + filteredAccounts = accounts.filter(a => { + return a.name.match(re); + }); } - render() { - const { accounts, filter, selectedAccount } = this.state; - - let filteredAccounts = [...accounts]; - if (filter && filter.length > 0) { - const re = new RegExp(filter, 'i'); - filteredAccounts = accounts.filter(a => { - return a.name.match(re); - }); - } - - return ( - { this.setState({ filter: event.target.value })}} - > - {filteredAccounts.map(a => - this.onAccountChange(a)}> - {a.name} - - )} - - ); - } + return ( + { + this.setState({ filter: event.target.value }); + }} + > + {filteredAccounts.map(a => ( + this.onAccountChange(a)}> + {a.name} + + ))} + + ); + } } - - diff --git a/components/configure/custom-hostnames.js b/components/configure/custom-hostnames.js index a736c85..5460360 100644 --- a/components/configure/custom-hostnames.js +++ b/components/configure/custom-hostnames.js @@ -2,163 +2,220 @@ import React from 'react'; import PropTypes from 'prop-types'; const uuid = require('uuid/v4'); -import { NerdGraphQuery, Button, HeadingText, Icon, TextField, Stack, StackItem } from 'nr1'; +import { + NerdGraphQuery, + Button, + HeadingText, + Icon, + TextField, + Stack, + StackItem, +} from 'nr1'; import { saveHostNamesToNerdStorage } from '../../utilities/nerdlet-storage'; import TagsModal from './modal-tag'; export default class CustomHostNames extends React.Component { - - constructor(props) { - super(props); - this.state = { - hidden: true, - tagHidden: true, - mounted: false, - selectedProvider: 'statusPageIo', - tags: [], - keyObject: {key: props.entityGuid ? props.entityGuid : props.accountId, type: props.entityGuid ? 'entity' : 'account'}, - selectedEditHost: undefined - } - this.addHostName = this.addHostName.bind(this); - this.onTextInputChange = this.onTextInputChange.bind(this); - this.saveAll = this.saveAll.bind(this); - this.onProviderChange = this.onProviderChange.bind(this); - this.onTagModalClose = this.onTagModalClose.bind(this); - this.addDepTypeCallback = this.addDepTypeCallback.bind(this); - } - - addDepTypeCallback() { - this.setState({'tagHidden': false}); - } - - editTags(hostNameObject) { - this.setState({'tagHidden': false, 'selectedEditHost': hostNameObject}) - } - - async addHostName() { - const {addHostNameCallback} = this.props; - const {addHostNameText, selectedProvider, tags} = this.state; - - const hostNameObject = { - id: uuid(), - hostName: addHostNameText, - provider: selectedProvider, - tags: tags - }; - this.setState({'tags': []}); - addHostNameCallback(hostNameObject); - } - - // TODO: Move to nerd store - generateListHostNames() { - const {deleteHostNameCallback, hostNames} = this.props; - - if (!hostNames) return
- return hostNames.map(hostNameObject =>
  • -
    {hostNameObject.hostName}
    -
    - - -
    -
  • ); - } - - _displaySaveMessage() { - this.setState({'showSaved': true}); - setTimeout(()=> this.setState({'showSaved': false}), 2 * 1000); - } - - async saveAll() { - const {hostNames} = this.props; - try { - // const accountsResults = await AccountsQuery.query(); - const accountsResults = await NerdGraphQuery.query({query: "{ actor { accounts { id name } }}"}); - if (accountsResults.data && accountsResults.data.actor && accountsResults.data.actor.accounts) { - accountsResults.data.actor.accounts.forEach(async account=> await saveHostNamesToNerdStorage({key: account.id, type: 'account'}, hostNames) ); - this._displaySaveMessage(); - } - } catch(err) { - console.log(err); - } - } - - onTextInputChange(event) { - this.setState({'addHostNameText': event.target.value}); - } - - onProviderChange(event) { - this.setState({'selectedProvider': event.target.value}) - } - - onTagModalClose(tags) { - this.setState({'tagHidden': true}); - this.setState({'tags': tags}); - } - - render() { - const {keyObject, tagHidden, selectedEditHost, showSaved, selectedProvider} = this.state; - const hostnames = this.generateListHostNames(); - return ( -
    -
    Saved -
    - Custom Host Names -
    -
    -
    - -
    - -
    -
    - -
    -
    -
      - {hostnames} -
    -
    - {keyObject.type === 'account' && - - - - - } -
    -
    + constructor(props) { + super(props); + this.state = { + hidden: true, + tagHidden: true, + mounted: false, + selectedProvider: 'statusPageIo', + tags: [], + keyObject: { + key: props.entityGuid ? props.entityGuid : props.accountId, + type: props.entityGuid ? 'entity' : 'account', + }, + selectedEditHost: undefined, + }; + this.addHostName = this.addHostName.bind(this); + this.onTextInputChange = this.onTextInputChange.bind(this); + this.saveAll = this.saveAll.bind(this); + this.onProviderChange = this.onProviderChange.bind(this); + this.onTagModalClose = this.onTagModalClose.bind(this); + this.addDepTypeCallback = this.addDepTypeCallback.bind(this); + } + + addDepTypeCallback() { + this.setState({ tagHidden: false }); + } + + editTags(hostNameObject) { + this.setState({ tagHidden: false, selectedEditHost: hostNameObject }); + } + + async addHostName() { + const { addHostNameCallback } = this.props; + const { addHostNameText, selectedProvider, tags } = this.state; + + const hostNameObject = { + id: uuid(), + hostName: addHostNameText, + provider: selectedProvider, + tags: tags, + }; + this.setState({ tags: [] }); + addHostNameCallback(hostNameObject); + } + + // TODO: Move to nerd store + generateListHostNames() { + const { deleteHostNameCallback, hostNames } = this.props; + + if (!hostNames) return
    ; + return hostNames.map(hostNameObject => ( +
  • +
    {hostNameObject.hostName}
    +
    + + +
    +
  • + )); + } + + _displaySaveMessage() { + this.setState({ showSaved: true }); + setTimeout(() => this.setState({ showSaved: false }), 2 * 1000); + } + + async saveAll() { + const { hostNames } = this.props; + try { + // const accountsResults = await AccountsQuery.query(); + const accountsResults = await NerdGraphQuery.query({ + query: '{ actor { accounts { id name } }}', + }); + if ( + accountsResults.data && + accountsResults.data.actor && + accountsResults.data.actor.accounts + ) { + accountsResults.data.actor.accounts.forEach( + async account => + await saveHostNamesToNerdStorage( + { key: account.id, type: 'account' }, + hostNames + ) ); + this._displaySaveMessage(); + } + } catch (err) { + console.log(err); } + } + + onTextInputChange(event) { + this.setState({ addHostNameText: event.target.value }); + } + + onProviderChange(event) { + this.setState({ selectedProvider: event.target.value }); + } + + onTagModalClose(tags) { + this.setState({ tagHidden: true }); + this.setState({ tags: tags }); + } + + render() { + const { + keyObject, + tagHidden, + selectedEditHost, + showSaved, + selectedProvider, + } = this.state; + const hostnames = this.generateListHostNames(); + return ( +
    +
    + {' '} + Saved +
    + + {' '} + Custom Host Names + +
    +
    +
    + +
    + +
    +
    + +
    +
    +
      {hostnames}
    +
    + {keyObject.type === 'account' && ( + + + + + + )} +
    +
    + ); + } } diff --git a/components/configure/modal-tag.js b/components/configure/modal-tag.js index 2590edf..78ca45f 100644 --- a/components/configure/modal-tag.js +++ b/components/configure/modal-tag.js @@ -1,73 +1,99 @@ import React from 'react'; -import { Button, HeadingText, Modal, TextField, Stack, StackItem } from 'nr1'; +import { Button, HeadingText, Modal, TextField, Stack, StackItem } from 'nr1'; export default class TagsModal extends React.Component { + constructor(props) { + super(props); + this.state = { + addTagName: '', + tagHidden: props.tagHidden, + tags: props.hostName ? props.hostName.tags : [], + }; + this.addTag = this.addTag.bind(this); + this.deleteTag = this.deleteTag.bind(this); + this.onTextInputChange = this.onTextInputChange.bind(this); + } - constructor(props) { - super(props); - this.state = { - addTagName: '', - tagHidden: props.tagHidden, - tags: props.hostName ? props.hostName.tags : [] - } - this.addTag = this.addTag.bind(this); - this.deleteTag = this.deleteTag.bind(this); - this.onTextInputChange = this.onTextInputChange.bind(this); - } + addTag() { + const { addTagName, tags } = this.state; + tags.push(addTagName.toLowerCase()); + if (!this.props.hostName.tags) this.props.hostName.tags = []; + this.props.hostName.tags.push(addTagName); + this.setState({ tags: tags }); + } - addTag() { - const {addTagName, tags} = this.state; - tags.push(addTagName.toLowerCase()); - if (!this.props.hostName.tags) this.props.hostName.tags = []; - this.props.hostName.tags.push(addTagName) - this.setState({'tags': tags}); - } + deleteTag(tagName) { + const { tags } = this.state; + this.props.hostName.tags.splice( + this.props.hostName.tags.findIndex(tag => tag === tagName), + 1 + ); + tags.splice(tags.findIndex(tag => tag === tagName), 1); + this.setState({ tags: tags }); + } - deleteTag(tagName) { - const {tags} = this.state; - this.props.hostName.tags.splice(this.props.hostName.tags.findIndex(tag => tag === tagName), 1); - tags.splice(tags.findIndex(tag => tag === tagName), 1); - this.setState({'tags': tags}); - } + generateListHostNames() { + if (!this.props.hostName || !this.props.hostName.tags) return
    ; + return this.props.hostName.tags.map(tag => ( +
  • +
    {tag}
    + +
  • + )); + } - generateListHostNames() { - if (!this.props.hostName || !this.props.hostName.tags) return
    - return this.props.hostName.tags.map(tag =>
  • -
    {tag}
    -
  • ); - } + onTextInputChange(event) { + this.setState({ addTagName: event.target.value }); + } - onTextInputChange(event) { - this.setState({'addTagName': event.target.value}); - } - - render() { - const {onClose, hidden} = this.props; - const {tags} = this.state; - return ( - - ); - } + render() { + const { onClose, hidden } = this.props; + const { tags } = this.state; + return ( + + ); + } } diff --git a/components/current-incidents.js b/components/current-incidents.js index 38f5b7b..d0ff1ba 100644 --- a/components/current-incidents.js +++ b/components/current-incidents.js @@ -6,75 +6,85 @@ import { navigation, Button, Stack, StackItem } from 'nr1'; import FormatService from '../utilities/format-service'; export default class CurrentIncidents extends React.Component { - static propTypes = { - hostname: PropTypes.string, - refreshRate: PropTypes.number - }; - - constructor(props) { - super(props); - this.state = { - currentIncidents: undefined - } - this.FormatService = new FormatService(this.props.provider); - this.statusPageNetwork = new Network(this.props.hostname, this.props.refreshRate, this.props.provider); - this.seeMore = this.seeMore.bind(this); - } + static propTypes = { + hostname: PropTypes.string, + refreshRate: PropTypes.number, + }; - seeMore() { - const nerdletWithState = { - id: 'incident-details', - urlState: { - hostname: this.props.hostname, - provider: this.props.provider - } - }; - navigation.openStackedNerdlet(nerdletWithState); - } + constructor(props) { + super(props); + this.state = { + currentIncidents: undefined, + }; + this.FormatService = new FormatService(this.props.provider); + this.statusPageNetwork = new Network( + this.props.hostname, + this.props.refreshRate, + this.props.provider + ); + this.seeMore = this.seeMore.bind(this); + } - componentDidMount() { - this.statusPageNetwork.pollCurrentIncidents(this.setIncidentData.bind(this)); - } + seeMore() { + const nerdletWithState = { + id: 'incident-details', + urlState: { + hostname: this.props.hostname, + provider: this.props.provider, + }, + }; + navigation.openStackedNerdlet(nerdletWithState); + } - setIncidentData(data) { - this.setState({'currentIncidents': this.FormatService.uniformIncidentData(data)}); - } + componentDidMount() { + this.statusPageNetwork.pollCurrentIncidents( + this.setIncidentData.bind(this) + ); + } + setIncidentData(data) { + this.setState({ + currentIncidents: this.FormatService.uniformIncidentData(data), + }); + } - render() { - const {currentIncidents} = this.state; - if (!currentIncidents) return
    ; - this.statusPageNetwork.refreshRateInSeconds = this.props.refreshRate; - const latestIncident = currentIncidents[0]; - // Show first current incident and then add a see more button - return ( - - -

    Latest Incident: - - {latestIncident ? latestIncident.name : 'None'} - -

    -
    - - - - - - - -
    - ) - } -} \ No newline at end of file + render() { + const { currentIncidents } = this.state; + if (!currentIncidents) return
    ; + this.statusPageNetwork.refreshRateInSeconds = this.props.refreshRate; + const latestIncident = currentIncidents[0]; + // Show first current incident and then add a see more button + return ( + + +

    + Latest Incident: + + {latestIncident ? latestIncident.name : 'None'} + +

    +
    + + + + + + + +
    + ); + } +} diff --git a/components/incidents/incident-timline.js b/components/incidents/incident-timline.js index 776df6e..87e144d 100644 --- a/components/incidents/incident-timline.js +++ b/components/incidents/incident-timline.js @@ -1,63 +1,78 @@ -import React from 'react' -import PropTypes from 'prop-types' -import { Timeline, TimelineItem } from 'vertical-timeline-component-for-react' +import React from 'react'; +import PropTypes from 'prop-types'; +import { Timeline, TimelineItem } from 'vertical-timeline-component-for-react'; import IndIncident from './ind-incident'; export default class IncidentTimeline extends React.Component { + static propTypes = { + version: PropTypes.number, + }; - static propTypes = { - version: PropTypes.number - } + static defaultProps = { + version: 1, + }; - static defaultProps = { - version: 1 - } + backgroundColors = { + none: '#10a600', + minor: '#ffda00', + major: '#ea7c00', + critical: '#bd071f', + }; - backgroundColors = { - none: '#10a600', - minor: '#ffda00', - major: '#ea7c00', - critical: '#bd071f' - } - - getTimeLineItems() { - return this.props.incidents.map( (incident, index) => { - const date = new Date(incident.created_at) - return ( - - - - ) + getTimeLineItems() { + return this.props.incidents.map((incident, index) => { + const date = new Date(incident.created_at); + return ( + + + + ); }); - } + } - getTimeLine() { - if (this.props.incidents.length === 0) { - return
    No reported outages
    - } - return ( - {this.getTimeLineItems()} - ); + getTimeLine() { + if (this.props.incidents.length === 0) { + return
    No reported outages
    ; } + return {this.getTimeLineItems()}; + } - render() { - return ( -
    -
    -
    -
    No Impact
    -
    Minor Impact
    -
    Major Impact
    -
    Critical Impact
    -
    -
    - { this.getTimeLine() } + render() { + return ( +
    +
    +
    +
    + {' '} +
    +
    No Impact
    - - ) - } -} \ No newline at end of file +
    + {' '} +
    +
    Minor Impact
    +
    +
    + {' '} +
    +
    Major Impact
    +
    +
    + {' '} +
    +
    Critical Impact
    +
    +
    +
    + {this.getTimeLine()} +
    + ); + } +} diff --git a/components/incidents/ind-incident.js b/components/incidents/ind-incident.js index acb4629..8cd0927 100644 --- a/components/incidents/ind-incident.js +++ b/components/incidents/ind-incident.js @@ -2,28 +2,30 @@ import React from 'react'; import PropTypes from 'prop-types'; import IndUpdates from './ind-updates'; -import {HeadingText} from 'nr1'; +import { HeadingText } from 'nr1'; export default class IndIncident extends React.Component { - static propTypes = { - incident: PropTypes.any - }; + static propTypes = { + incident: PropTypes.any, + }; - generateIncidentUpdates() { - return this.props.incident.incident_updates.map(update => ); - } + generateIncidentUpdates() { + return this.props.incident.incident_updates.map(update => ( + + )); + } - render() { - const {incident} = this.props; - const updates = this.generateIncidentUpdates(); - return ( -
    - {incident.name} -
    -
      - {updates} -
    -
    - ) - } + render() { + const { incident } = this.props; + const updates = this.generateIncidentUpdates(); + return ( +
    + + {incident.name} + +
    +
      {updates}
    +
    + ); + } } diff --git a/components/incidents/ind-updates.js b/components/incidents/ind-updates.js index db1dca5..f73a8d5 100644 --- a/components/incidents/ind-updates.js +++ b/components/incidents/ind-updates.js @@ -1,28 +1,31 @@ import React from 'react'; import PropTypes from 'prop-types'; -import {HeadingText} from 'nr1'; - -const ReactMarkdown = require('react-markdown') +import { HeadingText } from 'nr1'; +const ReactMarkdown = require('react-markdown'); export default class IndUpdates extends React.Component { - static propTypes = { - update: PropTypes.any - }; + static propTypes = { + update: PropTypes.any, + }; - render() { - const {update} = this.props; - const updateDate = new Date(update.created_at); - const statusString = update.status ? `${update.status} @` : ''; + render() { + const { update } = this.props; + const updateDate = new Date(update.created_at); + const statusString = update.status ? `${update.status} @` : ''; - return ( -
  • - {statusString} {updateDate.toLocaleDateString()} {updateDate.toLocaleTimeString()} -
    - -
    -
  • - ) - } + return ( +
  • + + {' '} + {statusString} {updateDate.toLocaleDateString()}{' '} + {updateDate.toLocaleTimeString()}{' '} + +
    + +
    +
  • + ); + } } diff --git a/components/status-page.js b/components/status-page.js index 7cd0799..ab969ab 100644 --- a/components/status-page.js +++ b/components/status-page.js @@ -8,41 +8,57 @@ import FormatService from '../utilities/format-service'; import { Spinner } from 'nr1'; export default class StatusPage extends React.Component { - static propTypes = { - nerdletUrlState: PropTypes.object, - launcherUrlState: PropTypes.object, - width: PropTypes.number, - height: PropTypes.number, - refreshRate: PropTypes.number - }; + static propTypes = { + nerdletUrlState: PropTypes.object, + launcherUrlState: PropTypes.object, + width: PropTypes.number, + height: PropTypes.number, + refreshRate: PropTypes.number, + }; - constructor(props) { - super(props); - this.StatusPageNetwork = new Network(this.props.hostname, this.props.refreshRate, this.props.provider); - this.FormatService = new FormatService(this.props.provider); - this.state = { - statusPageIoSummaryData: undefined - } - } + constructor(props) { + super(props); + this.StatusPageNetwork = new Network( + this.props.hostname, + this.props.refreshRate, + this.props.provider + ); + this.FormatService = new FormatService(this.props.provider); + this.state = { + statusPageIoSummaryData: undefined, + }; + } - async componentDidMount() { - this.StatusPageNetwork.pollSummaryData(this.setSummaryData.bind(this)); - } + async componentDidMount() { + this.StatusPageNetwork.pollSummaryData(this.setSummaryData.bind(this)); + } - setSummaryData(data) { - this.setState({'statusPageIoSummaryData': this.FormatService.uniformSummaryData(data)}); - } + setSummaryData(data) { + this.setState({ + statusPageIoSummaryData: this.FormatService.uniformSummaryData(data), + }); + } - render() { - const { statusPageIoSummaryData } = this.state; - if (!statusPageIoSummaryData) return + render() { + const { statusPageIoSummaryData } = this.state; + if (!statusPageIoSummaryData) return ; - const {provider} = this.props; - return ( -
    - - -
    - ) - } + const { provider } = this.props; + return ( +
    + + +
    + ); + } } diff --git a/components/summary.js b/components/summary.js index 6e28519..34cca67 100644 --- a/components/summary.js +++ b/components/summary.js @@ -6,49 +6,62 @@ import { HeadingText, Spinner, Stack, StackItem } from 'nr1'; import FormatService from '../utilities/format-service'; export default class Summary extends React.Component { - static propTypes = { - hostname: PropTypes.string, - refreshRate: PropTypes.number - }; + static propTypes = { + hostname: PropTypes.string, + refreshRate: PropTypes.number, + }; - constructor(props) { - super(props); - this.StatusPageNetwork = new Network(this.props.hostname, this.props.refreshRate, this.props.provider); - this.FormatService = new FormatService(this.props.provider); - this.state = { - statusPageIoSummaryData: undefined - } - } + constructor(props) { + super(props); + this.StatusPageNetwork = new Network( + this.props.hostname, + this.props.refreshRate, + this.props.provider + ); + this.FormatService = new FormatService(this.props.provider); + this.state = { + statusPageIoSummaryData: undefined, + }; + } - async componentDidMount() { - this.StatusPageNetwork.pollSummaryData(this.setSummaryData.bind(this)); - } + async componentDidMount() { + this.StatusPageNetwork.pollSummaryData(this.setSummaryData.bind(this)); + } - setSummaryData(data) { - this.setState({'statusPageIoSummaryData': this.FormatService.uniformSummaryData(data)}); - } + setSummaryData(data) { + this.setState({ + statusPageIoSummaryData: this.FormatService.uniformSummaryData(data), + }); + } - render() { - const { statusPageIoSummaryData } = this.state; - this.StatusPageNetwork.refreshRateInSeconds = this.props.refreshRate; - if (!statusPageIoSummaryData) return - return ( - - - {statusPageIoSummaryData.name} - - -
    - {statusPageIoSummaryData.description} -
    -
    -
    - ); - } + render() { + const { statusPageIoSummaryData } = this.state; + this.StatusPageNetwork.refreshRateInSeconds = this.props.refreshRate; + if (!statusPageIoSummaryData) return ; + return ( + + + + {statusPageIoSummaryData.name} + + + +
    + {statusPageIoSummaryData.description} +
    +
    +
    + ); + } } diff --git a/components/toolbar.js b/components/toolbar.js index 6f7e8d5..f825c62 100644 --- a/components/toolbar.js +++ b/components/toolbar.js @@ -1,81 +1,110 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { Button, Dropdown, DropdownItem , navigation, Stack, StackItem} from 'nr1'; - +import { + Button, + Dropdown, + DropdownItem, + navigation, + Stack, + StackItem, +} from 'nr1'; import AccountPicker from './account-picker'; export default class Toolbar extends React.Component { + constructor(props) { + super(props); + this.state = { + hidden: true, + mounted: false, + hostNames: [], + }; + this.onEditStatusPageClick = this.onEditStatusPageClick.bind(this); + this.onModalClose = this.onModalClose.bind(this); + this.onModalHideEnd = this.onModalHideEnd.bind(this); + } - constructor(props) { - super(props); - this.state = { - hidden: true, - mounted: false, - hostNames: [] - } - this.onEditStatusPageClick = this.onEditStatusPageClick.bind(this); - this.onModalClose = this.onModalClose.bind(this); - this.onModalHideEnd = this.onModalHideEnd.bind(this); - } - - async onEditStatusPageClick() { - const nerdletWithState = { - id: 'configure-status-pages', - urlState: { - accounts: this.props.accounts, - accountId: this.props.selectedAccountId - } - }; + async onEditStatusPageClick() { + const nerdletWithState = { + id: 'configure-status-pages', + urlState: { + accounts: this.props.accounts, + accountId: this.props.selectedAccountId, + }, + }; - if (this.props.entityGuid) { - nerdletWithState.urlState.entityGuid = this.props.entityGuid; - } - navigation.openStackedNerdlet(nerdletWithState); + if (this.props.entityGuid) { + nerdletWithState.urlState.entityGuid = this.props.entityGuid; } + navigation.openStackedNerdlet(nerdletWithState); + } - onModalClose() { - this.setState({'hidden': true}); - } + onModalClose() { + this.setState({ hidden: true }); + } - onModalHideEnd() { - this.setState({'mounted': false}); - } + onModalHideEnd() { + this.setState({ mounted: false }); + } - render() { - const {entityGuid, onAccountSelected, refreshRateCallback, refreshRate} = this.props; - return ( - - - - 2 - 5 - 10 - 15 - 20 - 25 - - {!entityGuid && } - - - -
    -
    Minor Incident
    -
    Major Incident
    -
    Critical Incident
    -
    -
    -
    - ); - } + render() { + const { + entityGuid, + onAccountSelected, + refreshRateCallback, + refreshRate, + } = this.props; + return ( + + + + 2 + 5 + 10 + 15 + 20 + 25 + + {!entityGuid && ( + + )} + + + +
    +
    + {' '} +
    +
    Minor Incident
    +
    +
    + {' '} +
    +
    Major Incident
    +
    +
    + {' '} +
    +
    Critical Incident
    +
    +
    +
    +
    + ); + } } diff --git a/launchers/status-page/nr1.json b/launchers/status-page/nr1.json index 3032e37..35619ec 100644 --- a/launchers/status-page/nr1.json +++ b/launchers/status-page/nr1.json @@ -3,6 +3,5 @@ "id": "status-page-launcher", "description": "Review all the relevant status pages in your world as track through the incident reports.", "displayName": "Status Pages", - "icon": "interface_operations_alert_s-on", "rootNerdletId": "status-page" } diff --git a/nerdlets/configure-status-pages/configure.js b/nerdlets/configure-status-pages/configure.js index f17397e..6908ff5 100644 --- a/nerdlets/configure-status-pages/configure.js +++ b/nerdlets/configure-status-pages/configure.js @@ -1,7 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -const uuid = require('uuid/v4'); - +import uuid from 'uuid/v4'; import { flatten, uniqBy } from 'lodash'; import { Button, @@ -18,10 +17,10 @@ import { saveHostNamesToNerdStorage, } from '../../utilities/nerdlet-storage'; import { popularSites } from '../../popular-status-pages'; - import StatusPage from '../../components/status-page'; import CustomHostNames from '../../components/configure/custom-hostnames'; -const HOST_NAMES_COLLECTION_KEY = 'host_names_v0'; + +const HOST_NAMES_COLLECTION_KEY = 'host_names_v1'; const HOST_NAMES_DOCUMENT_ID = 'host_names'; const MAX_ACCOUNT_DOC_FIELD_COUNT = 37; // Max size is 200 fields so to be safe we aim for 150 @@ -59,7 +58,9 @@ export default class ConfigureStatusPages extends React.Component { async componentDidMount() { const { keyObject } = this.state; - const accountsResults = await NerdGraphQuery.query({query: "{ actor { accounts { id name } }}"}); + const accountsResults = await NerdGraphQuery.query({ + query: '{ actor { accounts { id name } }}', + }); this.setState({ hostNames: await getHostNamesFromNerdStorage(keyObject) }); if ( accountsResults.data && @@ -149,7 +150,7 @@ export default class ConfigureStatusPages extends React.Component { }; }) ); - } catch(e) { + } catch (e) { console.error(e); } this.setState({ hostNames: hostNames }); diff --git a/nerdlets/incident-details/incident-details.js b/nerdlets/incident-details/incident-details.js index aefbf30..dbd4a3e 100644 --- a/nerdlets/incident-details/incident-details.js +++ b/nerdlets/incident-details/incident-details.js @@ -12,7 +12,7 @@ const REFRESH_RATE = 15; export default class IncidentDetails extends React.Component { static propTypes = { - nerdletUrlState: PropTypes.object + nerdletUrlState: PropTypes.object, }; constructor(props) { diff --git a/nerdlets/status-page-dashboard/main-page.js b/nerdlets/status-page-dashboard/main-page.js index 0f158b5..f2af2e5 100644 --- a/nerdlets/status-page-dashboard/main-page.js +++ b/nerdlets/status-page-dashboard/main-page.js @@ -26,8 +26,6 @@ export default class StatusPageIoMainPage extends React.Component { this.onAccountSelected = this.onAccountSelected.bind(this); this.onRefreshRateSelected = this.onRefreshRateSelected.bind(this); this.setHostNames = this.setHostNames.bind(this); - //! Bad hack - this.pollHosts(); } async componentDidMount() { @@ -38,6 +36,12 @@ export default class StatusPageIoMainPage extends React.Component { }); this.setHostNames(hostNames); } + + this._interval = setInterval(this.pollHosts.bind(this), 15000); + } + + componentWillUnmount() { + clearInterval(this._interval); } setHostNames(hostNames) { @@ -57,25 +61,19 @@ export default class StatusPageIoMainPage extends React.Component { //! This is a hack until there is an message bus between stacked nerdlets async pollHosts() { - setTimeout(async () => { - try { - const hostNames = await getHostNamesFromNerdStorage({ - key: this.state.entityGuid - ? this.state.entityGuid - : this.state.selectedAccountId, - type: this.state.entityGuid ? 'entity' : 'account', - }); - if ( - JSON.stringify(hostNames) !== JSON.stringify(this.state.hostNames) - ) { - this.setHostNames(hostNames); - } - } catch (err) { - console.log(err); - } finally { - this.pollHosts(); + try { + const hostNames = await getHostNamesFromNerdStorage({ + key: this.state.entityGuid + ? this.state.entityGuid + : this.state.selectedAccountId, + type: this.state.entityGuid ? 'entity' : 'account', + }); + if (JSON.stringify(hostNames) !== JSON.stringify(this.state.hostNames)) { + this.setHostNames(hostNames); } - }, 5 * 1000); + } catch (err) { + console.log(err); + } } onRefreshRateSelected(event) { @@ -87,7 +85,7 @@ export default class StatusPageIoMainPage extends React.Component { !this.state.hostNames || (!this.state.selectedAccountId && !this.state.entityGuid) ) { - return ; + return ; } if (this.state.hostNames.length === 0) { return ( diff --git a/package.json b/package.json index 9b56dc5..e9aa974 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "email": "opensource@newrelic.com" }, "scripts": { - "start": "nr1 nerdpack:serve", + "start": "nr1-dev nerdpack:serve", "test": "exit 0", "eslint-check": "eslint nerdlets/", "eslint-fix": "eslint nerdlets/ --fix" diff --git a/popular-status-pages.js b/popular-status-pages.js index 72066c2..2fbabf8 100644 --- a/popular-status-pages.js +++ b/popular-status-pages.js @@ -1,28 +1,25 @@ export const popularSites = { - "providers": [ - "statusPageIo", - "google" - ], - "sites": [ - { - "id": "118f5f49-f709-4247-87cf-87d74a9d035d", - "hostName": "https://status.cloud.google.com", - "provider": "google" - }, - { - "id": "f10f56ce-a9f1-41b7-8795-f3dc552de84b", - "hostName": "https://status.newrelic.com/", - "provider": "statusPageIo" - }, - { - "id": "6bec0401-d3e7-4b64-873b-239afc85b110", - "hostName": "https://jira-software.status.atlassian.com/", - "provider": "statusPageIo" - }, - { - "id": "93f445cf-a248-4c70-9d69-dc5790dbf0cd", - "hostName": "https://www.githubstatus.com/", - "provider": "statusPageIo" - } - ] -} \ No newline at end of file + providers: ['statusPageIo', 'google'], + sites: [ + { + id: '118f5f49-f709-4247-87cf-87d74a9d035d', + hostName: 'https://status.cloud.google.com', + provider: 'google', + }, + { + id: 'f10f56ce-a9f1-41b7-8795-f3dc552de84b', + hostName: 'https://status.newrelic.com/', + provider: 'statusPageIo', + }, + { + id: '6bec0401-d3e7-4b64-873b-239afc85b110', + hostName: 'https://jira-software.status.atlassian.com/', + provider: 'statusPageIo', + }, + { + id: '93f445cf-a248-4c70-9d69-dc5790dbf0cd', + hostName: 'https://www.githubstatus.com/', + provider: 'statusPageIo', + }, + ], +}; diff --git a/utilities/format-service.js b/utilities/format-service.js index 7256aa6..b78937c 100644 --- a/utilities/format-service.js +++ b/utilities/format-service.js @@ -1,18 +1,17 @@ -import { getProvider } from "./provider-services"; +import { getProvider } from './provider-services'; export default class FormatService { + constructor(provider) { + this.provider = getProvider(provider); + } - constructor(provider) { - this.provider = getProvider(provider); - } + uniformSummaryData(data) { + const responseData = data.data; + return this.provider.summaryFormatter(responseData); + } - uniformSummaryData(data) { - const responseData = data.data; - return this.provider.summaryFormatter(responseData); - } - - uniformIncidentData(data) { - const responseData = data.data; - return this.provider.incidentFormatter(responseData); - } -} \ No newline at end of file + uniformIncidentData(data) { + const responseData = data.data; + return this.provider.incidentFormatter(responseData); + } +} diff --git a/utilities/formatters/google.js b/utilities/formatters/google.js index 3d9c60e..64763d6 100644 --- a/utilities/formatters/google.js +++ b/utilities/formatters/google.js @@ -1,36 +1,38 @@ -const GoogleSeverityToKnown ={ - low: 'minor', - medium: 'major', - high: 'critical' -} +const GoogleSeverityToKnown = { + low: 'minor', + medium: 'major', + high: 'critical', +}; -export const googleFormatter = (data) => { - const formattedData = {}; - data = data.sort(incident => incident.begin) - formattedData.name = 'Google Cloud Provider'; - const openIncident = data.find(incident => !incident.end || incident.end === ''); - if (openIncident) { - formattedData.description = 'Ongoing Issues'; - formattedData.indicator = GoogleSeverityToKnown[openIncident.severity] - } else { - formattedData.description = 'All Systems Operational' - formattedData.indicator = 'none'; - } - return formattedData; -} +export const googleFormatter = data => { + const formattedData = {}; + data = data.sort(incident => incident.begin); + formattedData.name = 'Google Cloud Provider'; + const openIncident = data.find( + incident => !incident.end || incident.end === '' + ); + if (openIncident) { + formattedData.description = 'Ongoing Issues'; + formattedData.indicator = GoogleSeverityToKnown[openIncident.severity]; + } else { + formattedData.description = 'All Systems Operational'; + formattedData.indicator = 'none'; + } + return formattedData; +}; -export const googleIncidentFormatter = (data) => { - return data.map(incident => { +export const googleIncidentFormatter = data => { + return data.map(incident => { + return { + name: incident.external_desc, + created_at: incident.created, + impact: GoogleSeverityToKnown[incident.severity], + incident_updates: incident.updates.map(update => { return { - name: incident.external_desc, - created_at: incident.created, - impact: GoogleSeverityToKnown[incident.severity], - incident_updates: incident.updates.map(update => { - return { - created_at: update.created, - body: update.text - } - }) - } - }) -} \ No newline at end of file + created_at: update.created, + body: update.text, + }; + }), + }; + }); +}; diff --git a/utilities/formatters/status-page-io.js b/utilities/formatters/status-page-io.js index ed5bd8f..d4af477 100644 --- a/utilities/formatters/status-page-io.js +++ b/utilities/formatters/status-page-io.js @@ -1,11 +1,11 @@ -export const statusPageIoFormatter = (data) => { - return { - name: data['page']['name'], - description: data['status']['description'], - indicator: data['status']['indicator'] - } -} +export const statusPageIoFormatter = data => { + return { + name: data['page']['name'], + description: data['status']['description'], + indicator: data['status']['indicator'], + }; +}; -export const statusPageIncidentFormatter = (data) => { - return data.incidents; -} \ No newline at end of file +export const statusPageIncidentFormatter = data => { + return data.incidents; +}; diff --git a/utilities/nerdlet-storage.js b/utilities/nerdlet-storage.js index 568c39a..836ac1d 100644 --- a/utilities/nerdlet-storage.js +++ b/utilities/nerdlet-storage.js @@ -1,73 +1,89 @@ +import { + AccountStorageMutation, + AccountStorageQuery, + EntityStorageMutation, + EntityStorageQuery, +} from 'nr1'; -const HOST_NAMES_COLLECTION_KEY = 'host_names_v0' -const HOST_NAMES_DOCUMENT_ID = 'host_names' +const HOST_NAMES_COLLECTION_KEY = 'host_names_v1'; +const HOST_NAMES_DOCUMENT_ID = 'host_names'; -import { AccountStorageMutation, AccountStorageQuery, EntityStorageMutation, EntityStorageQuery } from 'nr1'; - -const _getHostNameFromQueryResults = (queryResults) => { - if (queryResults.data) { - let hostNames = queryResults.data; - if (!hostNames) { - hostNames = []; - } - return hostNames; - }; - return []; -} +const _getHostNameFromQueryResults = queryResults => { + if (queryResults.data) { + let hostNames = queryResults.data; + if (!hostNames) { + hostNames = []; + } + return hostNames; + } + return []; +}; const getHostNameFromAccountStorage = async (accountId, queryProp) => { - queryProp.accountId = accountId; - try { - return _getHostNameFromQueryResults(await AccountStorageQuery.query(queryProp)); - } catch(err) { - console.log(err); - } -} + queryProp.accountId = accountId; + try { + return _getHostNameFromQueryResults( + await AccountStorageQuery.query(queryProp) + ); + } catch (err) { + console.log(err); + } +}; const getHostNameFromEntityStorage = async (entityGuid, queryProp) => { - queryProp.entityGuid = entityGuid; - try { - return _getHostNameFromQueryResults(await EntityStorageQuery.query(queryProp)); - } catch(err) { - console.log(err); - } -} + queryProp.entityGuid = entityGuid; + try { + return _getHostNameFromQueryResults( + await EntityStorageQuery.query(queryProp) + ); + } catch (err) { + console.log(err); + } +}; -const saveHostNamesToAccountStorage = async(accountId, mutationProp) => { - mutationProp.accountId = accountId; - mutationProp.actionType = AccountStorageMutation.ACTION_TYPE.WRITE_DOCUMENT; - return AccountStorageMutation.mutate(mutationProp); -} +const saveHostNamesToAccountStorage = async (accountId, mutationProp) => { + mutationProp.accountId = accountId; + mutationProp.actionType = AccountStorageMutation.ACTION_TYPE.WRITE_DOCUMENT; + return AccountStorageMutation.mutate(mutationProp); +}; -const saveHostNamesToEntityStorage = async(entityGuid, mutationProp) => { - mutationProp.entityGuid = entityGuid; - mutationProp.actionType = EntityStorageMutation.ACTION_TYPE.WRITE_DOCUMENT; - return EntityStorageMutation.mutate(mutationProp); -} +const saveHostNamesToEntityStorage = async (entityGuid, mutationProp) => { + mutationProp.entityGuid = entityGuid; + mutationProp.actionType = EntityStorageMutation.ACTION_TYPE.WRITE_DOCUMENT; + return EntityStorageMutation.mutate(mutationProp); +}; +export const getHostNamesFromNerdStorage = async keyObject => { + const queryProp = { + collection: HOST_NAMES_COLLECTION_KEY, + documentId: HOST_NAMES_DOCUMENT_ID, + }; -export const getHostNamesFromNerdStorage = async (keyObject) => { - const queryProp = { - collection: HOST_NAMES_COLLECTION_KEY, - documentId: HOST_NAMES_DOCUMENT_ID - } - if (keyObject.type === 'account') { - return getHostNameFromAccountStorage(keyObject.key, queryProp); - } else if (keyObject.type === 'entity'){ - return getHostNameFromEntityStorage(keyObject.key, queryProp); - } -} + let result; + + if (keyObject.type === 'account') { + result = await getHostNameFromAccountStorage(keyObject.key, queryProp); + } else if (keyObject.type === 'entity') { + result = await getHostNameFromEntityStorage(keyObject.key, queryProp); + } else { + throw new Error('Invalid keyObject'); + } + + return result.hostNames || []; +}; export const saveHostNamesToNerdStorage = async (keyObject, document) => { - const mutationProp = { - collection: HOST_NAMES_COLLECTION_KEY, - document: document, - documentId: HOST_NAMES_DOCUMENT_ID - } - if (keyObject.type === 'account') { - return saveHostNamesToAccountStorage(keyObject.key, mutationProp); - } else if (keyObject.type === 'entity'){ - return saveHostNamesToEntityStorage(keyObject.key, mutationProp); - } -} + const mutationProp = { + collection: HOST_NAMES_COLLECTION_KEY, + document: { hostNames: document }, + documentId: HOST_NAMES_DOCUMENT_ID, + }; + if (keyObject.type === 'account') { + saveHostNamesToAccountStorage(keyObject.key, mutationProp); + } else if (keyObject.type === 'entity') { + saveHostNamesToEntityStorage(keyObject.key, mutationProp); + } else { + throw new Error('Invalid keyObject'); + } +}; diff --git a/utilities/network.js b/utilities/network.js index ac68fdf..29ec89c 100644 --- a/utilities/network.js +++ b/utilities/network.js @@ -3,41 +3,42 @@ import { getProvider } from './provider-services'; const axios = require('axios'); export default class Network { + constructor(statusPageUrl, refreshRateInSeconds, provider) { + this.statusPageUrl = statusPageUrl; + this.refreshRateInSeconds = refreshRateInSeconds; + this.provider = provider; + } - constructor(statusPageUrl, refreshRateInSeconds, provider) { - this.statusPageUrl = statusPageUrl; - this.refreshRateInSeconds = refreshRateInSeconds; - this.provider = provider; - } + async _fetchAndPopulateData(url, callbackSetterFunction) { + const networkResponse = await axios.get(url); + callbackSetterFunction(networkResponse); + return networkResponse; + } - async _fetchAndPopulateData(url, callbackSetterFunction) { - const networkResponse = await axios.get(url); - callbackSetterFunction(networkResponse); - return networkResponse; - } + _pollData(url, callbackSetterFunction) { + setTimeout(async () => { + try { + this._fetchAndPopulateData(url, callbackSetterFunction); + } catch (err) { + console.error(err); + } finally { + this._pollData(url, callbackSetterFunction); + } + }, this.refreshRateInSeconds * 1000); + } - _pollData(url, callbackSetterFunction) { - setTimeout(async () => { - try { - this._fetchAndPopulateData(url, callbackSetterFunction); - } catch(err) { - console.error(err); - } finally { - this._pollData(url, callbackSetterFunction) - } - }, this.refreshRateInSeconds * 1000); - } + async pollSummaryData(callbackSetterFunction) { + // Populate initial data before we start polling + const url = `${this.statusPageUrl}${getProvider(this.provider).summaryUrl}`; + await this._fetchAndPopulateData(url, callbackSetterFunction); + this._pollData(url, callbackSetterFunction); + } - async pollSummaryData(callbackSetterFunction) { - // Populate initial data before we start polling - const url = `${this.statusPageUrl}${getProvider(this.provider).summaryUrl}`; - await this._fetchAndPopulateData(url, callbackSetterFunction); - this._pollData(url, callbackSetterFunction) - } - - async pollCurrentIncidents(callbackSetterFunction) { - const url = `${this.statusPageUrl}${getProvider(this.provider).incidentUrl}`; - await this._fetchAndPopulateData(url, callbackSetterFunction); - this._pollData(url, callbackSetterFunction) - } -} \ No newline at end of file + async pollCurrentIncidents(callbackSetterFunction) { + const url = `${this.statusPageUrl}${ + getProvider(this.provider).incidentUrl + }`; + await this._fetchAndPopulateData(url, callbackSetterFunction); + this._pollData(url, callbackSetterFunction); + } +} diff --git a/utilities/provider-services.js b/utilities/provider-services.js index 6f6d3bd..348038d 100644 --- a/utilities/provider-services.js +++ b/utilities/provider-services.js @@ -1,34 +1,36 @@ - -import { googleIncidentFormatter, googleFormatter } from "./formatters/google"; -import { statusPageIncidentFormatter, statusPageIoFormatter } from "./formatters/status-page-io"; +import { googleIncidentFormatter, googleFormatter } from './formatters/google'; +import { + statusPageIncidentFormatter, + statusPageIoFormatter, +} from './formatters/status-page-io'; const providers = { - google: { - summaryUrl: '/incidents.json', - incidentUrl: '/incidents.json', - impactMap: { - low: 'minor', - medium: 'major', - high: 'critical' - }, - name: "Google Cloud Provider", - incidentFormatter: googleIncidentFormatter, - summaryFormatter: googleFormatter + google: { + summaryUrl: '/incidents.json', + incidentUrl: '/incidents.json', + impactMap: { + low: 'minor', + medium: 'major', + high: 'critical', + }, + name: 'Google Cloud Provider', + incidentFormatter: googleIncidentFormatter, + summaryFormatter: googleFormatter, + }, + statusPageIo: { + summaryUrl: '/api/v2/summary.json', + incidentUrl: '/api/v2/incidents.json', + impactMap: { + minor: 'minor', + major: 'major', + critical: 'critical', }, - statusPageIo: { - summaryUrl: '/api/v2/summary.json', - incidentUrl: '/api/v2/incidents.json', - impactMap: { - minor: 'minor', - major: 'major', - critical: 'critical' - }, - name: "Google Cloud Provider", - summaryFormatter: statusPageIoFormatter, - incidentFormatter: statusPageIncidentFormatter - } -} + name: 'Google Cloud Provider', + summaryFormatter: statusPageIoFormatter, + incidentFormatter: statusPageIncidentFormatter, + }, +}; -export const getProvider = (providerKey) => { - return providers[providerKey]; -}; \ No newline at end of file +export const getProvider = providerKey => { + return providers[providerKey]; +};