npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@density/reports

v17.0.2

Published

Density reports used to display data across all of our digital products

Downloads

5

Readme

Density Reports

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

Getting started

git clone [email protected]: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: "[email protected]",
    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>