17.0.2 • Published 2 years ago

@density/reports v17.0.2

Weekly downloads
105
License
MIT
Repository
github
Last release
2 years ago

Density Reports

A collection of reports used to display data across all of our digital products.

Getting started

git clone git@github.com:densityco/reports.git
cd reports/
npm install
npm start

Rendering a report

This package exports by default a React component (originally from the dashboard) that can be used to render a report:

import Report from '@density/reports';

<Report
  report={{
    id: "rpt_xxx",
    type: "DAILY_PEAKS",
    creator_email: "engineering@density.io",
    name: "Custom report name",
    settings: {
      hello: "world"
    },
  }}
  reportData={{
    state: "COMPLETE",
    data: {
      calculationResults: "go here"
    },
  }}

  // Props to control exactly how this report looks when rendered:

  // Render this report in "expanded mode", optimizing graphics for a large format
  expanded={false}
  // Set to true when a report is being rendered in a digest email
  email={false}

  // Optionally hide the border of the report if it's being rendered in a context that provides a
  // border already
  hideBorder={true}

  // Hide the csv action on the action bar at the bottom of the report
  hideCsvAction={true}
  // Hide the expand action on the action bar if it should be hidden in a specific context
  hideExpandAction={true}

  // Props that allow the report to interact with the application it is within:
  onOpenReportExpandedModal={report => {
    console.log('Called when "expand" button is clicked on a report.');
    console.log('If report cannot be expanded, this callback is never called.');
  }}
  onCsvExportError={error => {
    console.error('An error occured while exporting a csv from a report:', error);
    console.error('A toast or other sort of error alert should be shown in the application.');
  }}
/>

Creating a new report

There are two ways to go about this, the easy way, and the hard way

The Easy Way

Use a nifty script:

npm run make-report

The Hard Way

  1. Make a copy of an existing report, such as TotalVisits:
cp -R src/reports/TotalVisits src/reports/MyReport
  1. Add the new report to the central reports list, located at src/reports.js:
/* ... */
import MyReport from './reports/MyReport/index';

/* ... */
import myReport from './reports/MyReport/calculations';

/* ... */

const REPORTS = {
  /* ... */

  MY_REPORT: { // `MY_REPORT` is the enum value defined in the Core API's `Report` type field
    component: MyReport,
    calculations: myReport,
    /* there are other keys too, look at the other reports for details */
  },

  /* ... */
};
  1. Finally, update the interactive story in src/MyReport/story.js to point to the new report:
.add('Interactive', () => (
  <ReportTester
    name="My Report Example"
    type="MY_REPORT"
  />
))

Report Calculation Schema

A report calculation function accepts two parameters and must return a promise that resolves to an object.

type ReportCalculationFunction = (report: DensityReport, opts: DensityReportOptions) => Promise<object>;

type DensityReport = {
  id: string;
  name: string;
  settings: string;
  /* ... */
}

type DensityReportOptions = {
  date: Moment; // A moment representing "now", in utc. This permits reports to be run for any time period, including in the past!
  week_start: string; // A weekday for the report week to start on. Default is "Sunday".
  client: any; // An axios client used to make AJAX requests.
  slow: boolean; // A flag representing if the report calculations should run specifying the "?slow=true" flag, which bypasses the new reporting database.
}

// CSV calculation function schema
type DensityCalculatedCsv = {
  fileName: string,
  contents: string,
};
type DensityCsvCalculationFunction = (report: DensityReport, calculationResult: ReturnType<ReportCalculationFunction>) => Promise<DensityCalculatedCsv>
17.0.2

2 years ago

17.0.1

2 years ago

17.0.0

2 years ago

16.3.7

3 years ago

16.3.6

3 years ago

16.3.5

3 years ago

16.3.4

3 years ago

16.3.8

3 years ago

16.4.0

3 years ago

16.2.8-cat15

3 years ago

16.2.8-cat10

3 years ago

16.2.8-cat14

3 years ago

16.2.8-cat13

3 years ago

16.2.8-cat12

3 years ago

16.3.2-cat

3 years ago

16.2.8-cat11

3 years ago

16.3.3

3 years ago

16.3.2

3 years ago

16.3.1

3 years ago

16.3.0

3 years ago

16.2.8-cat8

3 years ago

16.2.8-cat9

3 years ago

16.2.8-cat7

3 years ago

16.2.8-cat6

3 years ago

16.2.8-cat4

3 years ago

16.2.8-cat5

3 years ago

16.2.8-cat2

3 years ago

16.2.8-cat3

3 years ago

16.2.8-cat

3 years ago

16.2.8

4 years ago

16.2.7

4 years ago

16.2.6

4 years ago

16.2.6-cat2

4 years ago

16.2.6-cat

4 years ago

16.2.5

4 years ago

16.2.5--cat

4 years ago

16.1.1

4 years ago

16.2.0

4 years ago

16.2.4

4 years ago

16.2.3

4 years ago

16.2.2

4 years ago

16.2.1

4 years ago

16.1.0

4 years ago

16.0.0

4 years ago

16.0.1-test

4 years ago

15.3.0

4 years ago

16.0.0-test

4 years ago

15.2.0

4 years ago

15.1.8

4 years ago

15.1.7

4 years ago

15.1.6

4 years ago

15.1.5

4 years ago

15.1.4

4 years ago

15.1.2

4 years ago

15.1.3

4 years ago

15.1.1

4 years ago

15.1.0

4 years ago

15.0.2

4 years ago

15.0.0

4 years ago

15.0.1

4 years ago

14.2.0

4 years ago

14.2.1

4 years ago

14.2.2

4 years ago

14.1.3

4 years ago

14.1.2

4 years ago

14.1.1

4 years ago

14.1.0

4 years ago

14.0.0

4 years ago

14.0.1

4 years ago

13.1.3

4 years ago

13.1.2

4 years ago

13.1.1

4 years ago

13.1.0

4 years ago

13.0.0

4 years ago

13.0.0-rc.3

4 years ago

13.0.0-rc.4

4 years ago

13.0.0-rc.2

4 years ago

13.0.0-rc.1

4 years ago

13.0.0-0

4 years ago

12.2.0

4 years ago

12.1.4

4 years ago

12.1.3

4 years ago

12.1.2

4 years ago

12.1.1

4 years ago

12.1.0

4 years ago

12.0.1

4 years ago

12.0.0

4 years ago

11.0.2

4 years ago

11.0.1

4 years ago

11.0.0-pre1

4 years ago

11.0.0-pre2

4 years ago

11.0.0

4 years ago

10.0.1

4 years ago

10.0.0

4 years ago

10.0.0-pre1

4 years ago

9.4.5

4 years ago

9.4.4

4 years ago

9.4.3

4 years ago

9.4.2

5 years ago

9.4.1

5 years ago

9.4.0

5 years ago

9.3.1

5 years ago

9.3.0

5 years ago

9.2.0

5 years ago

9.1.4-pre2

5 years ago

9.1.4-pre1

5 years ago

9.1.4

5 years ago

9.1.3

5 years ago

9.1.2

5 years ago

9.1.1-pre1

5 years ago

9.1.1

5 years ago

9.1.0

5 years ago

9.0.2

5 years ago

9.0.1

5 years ago

9.0.0

5 years ago

8.1.1

5 years ago

8.1.0

5 years ago

8.0.8

5 years ago

8.0.7

5 years ago

8.0.6

5 years ago

8.0.5

5 years ago

8.0.5-pre7

5 years ago

8.0.5-pre6

5 years ago

8.0.5-pre5

5 years ago

8.0.5-pre4

5 years ago

8.0.5-pre3

5 years ago

8.0.5-pre2

5 years ago

8.0.5-pre1

5 years ago

8.0.4

5 years ago

8.0.3

5 years ago

8.0.2

5 years ago

8.0.1

5 years ago

8.0.0

5 years ago

8.0.0-pre1

5 years ago

7.0.4

5 years ago

7.0.3

5 years ago

7.0.2

5 years ago

7.0.1

5 years ago

7.0.0

5 years ago

6.4.0

5 years ago

6.4.0-pre6

5 years ago

6.4.0-pre5

5 years ago

6.4.0-pre4

5 years ago

6.4.0-pre3

5 years ago

6.4.0-pre2

5 years ago

6.4.0-pre1

5 years ago

6.3.2

5 years ago

6.3.1

5 years ago

6.3.0

5 years ago

6.3.0-pre1

5 years ago

6.2.1

5 years ago

6.2.0

5 years ago

6.1.0-pre5

5 years ago

6.1.0-pre4

5 years ago

6.1.0-pre3

5 years ago

6.1.0-pre2

5 years ago

6.1.0-pre1

5 years ago

6.0.0

5 years ago

5.5.0

5 years ago

5.5.0-pre5

5 years ago

5.5.0-pre4

5 years ago

5.5.0-pre3

5 years ago

5.5.0-pre2

5 years ago

5.4.3

5 years ago

5.4.2

5 years ago

5.4.1

5 years ago

5.5.0-pre1

5 years ago

5.4.0

5 years ago

5.3.1

5 years ago

5.3.0

5 years ago

5.2.0

5 years ago

5.1.1

5 years ago

5.1.0

5 years ago

5.0.0

5 years ago

4.8.8

5 years ago

4.8.7

5 years ago

4.8.6

5 years ago

4.8.5

5 years ago

4.8.4

5 years ago

4.8.3

5 years ago

4.8.2

5 years ago

4.8.1

5 years ago

4.8.0

5 years ago

4.7.0

5 years ago

4.6.1

5 years ago

4.6.0

5 years ago

4.5.2

5 years ago

4.5.1

5 years ago

4.5.0

5 years ago

4.4.1

5 years ago

4.4.0

5 years ago

4.3.0

5 years ago

4.3.0-pre8

5 years ago

4.3.0-pre7

5 years ago

4.3.0-pre6

5 years ago

4.3.0-pre5

5 years ago

4.3.0-pre4

5 years ago

4.3.0-pre3

5 years ago

4.3.0-pre2

5 years ago

4.3.0-pre

5 years ago

4.2.5

5 years ago

4.2.4

5 years ago

4.2.3

5 years ago

4.2.2

5 years ago

4.2.1

5 years ago

4.2.0

5 years ago

4.1.0

5 years ago

4.0.0

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.1.4

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.5.11

5 years ago

1.5.10

5 years ago

1.5.9

5 years ago

1.5.8

5 years ago

1.5.7

5 years ago

1.5.6

5 years ago

1.5.5

5 years ago

1.5.4

5 years ago

1.5.3

5 years ago

1.5.2

5 years ago

1.5.1

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.3

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.2.0

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago