# purefacts-widgets

> This project is a library containing React widgets that can be re-used in PureReporting NextGen applications.

Latest version **1.0.0** (published 2023-10-25) · 0 weekly downloads

## Install

```sh
npm install purefacts-widgets
pnpm add purefacts-widgets
yarn add purefacts-widgets
bun add purefacts-widgets
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2023-10-25 |
| First published | 2023-10-25 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 24 |
| Unpacked size | 4.1 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | tsejerome |
| Keywords | Purefacts, Widgets, Component |

## Links

- npm: https://www.npmjs.com/package/purefacts-widgets
- npm.io page: https://npm.io/package/purefacts-widgets

## Dependencies (24)

- [react](https://npm.io/package/react.md) ^18.1.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [moment](https://npm.io/package/moment.md) ^2.29.1
- [numeral](https://npm.io/package/numeral.md) ^2.0.6
- [ts-node](https://npm.io/package/ts-node.md) ^10.4.0
- [date-fns](https://npm.io/package/date-fns.md) ^2.27.0
- [recharts](https://npm.io/package/recharts.md) ^1.8.5
- [react-dom](https://npm.io/package/react-dom.md) ^18.1.0
- [prop-types](https://npm.io/package/prop-types.md) ^15.6.0
- [typescript](https://npm.io/package/typescript.md) ^4.1.2
- [web-vitals](https://npm.io/package/web-vitals.md) ^1.0.1
- [roboto-sass](https://npm.io/package/roboto-sass.md) ^1.0.4
- [glob-promise](https://npm.io/package/glob-promise.md) ^3.4.0
- [react-select](https://npm.io/package/react-select.md) ^5.2.1
- [react-feather](https://npm.io/package/react-feather.md) ^2.0.9
- [react-scripts](https://npm.io/package/react-scripts.md) 5.0.1
- [@babel/polyfill](https://npm.io/package/@babel/polyfill.md) ^7.12.1
- [guid-typescript](https://npm.io/package/guid-typescript.md) ^1.0.9
- [moment-timezone](https://npm.io/package/moment-timezone.md) ^0.5.33
- [react-json-view](https://npm.io/package/react-json-view.md) ^1.21.3
- [react-router-dom](https://npm.io/package/react-router-dom.md) ^5.3.0
- [@date-io/date-fns](https://npm.io/package/@date-io/date-fns.md) ^1.3.13
- [rollup-plugin-copy](https://npm.io/package/rollup-plugin-copy.md) ^3.4.0
- [@rollup/plugin-replace](https://npm.io/package/@rollup/plugin-replace.md) ^4.0.0

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2023-10-25

## README

# Overview

This project is a library containing React widgets that can be re-used in PureReporting NextGen applications.

Two important things to take notice of:

- To publish this project as an NPM package into a dummy repository, this project uses `verdaccio`. See below on how to use it (there are links and resources available to you to become familiar with this tool). And yes, you can use any non-public repository running locally or in PureFacts, but we recommend this Verdaccio & cover only that one in the tutorials below.

- To test the components without needing a host app, we use `React Storybook` components. Again there are links and resources provided below.

## A note about creating components

Please create components using command line - for example:

```
npx generate-react-cli component AssetGraph
npx generate-react-cli component --path=src/components/test HelloWorld
```

We use this plugin to make sure the syntax of components are the same. This keeps this project clean and consistent.

If you are familiar with Angular, you know that Angular command line client helps Angular developers maintain their code and keep it clean; however, there are just too many flavours and tools to do the equivalent job in React world. Here we are using this tool: https://github.com/arminbro/generate-react-cli

**Remark:**
Using this plugin allows us to add storybook templates by default. That and more are all configured inside `generate-react-cli.json` (something you should know by now if you had studied their doc in above link).

# Installing Verdaccio

Verdaccio is a dummy local repository that we can use to test. The idea is to publish this package into your local repo, and to install it in your host app.

For example, after publishing this package into your local verdaccio instance, you can install it into our _PureReporting Nextgen UI_ app.

Verdaccio is well documented and your best friend is the YouTUBE video found in their readme. Please see this link: https://verdaccio.org/ and click on _docs_ on top menu.

# Using React Storybook To Test

React Storybook allows developers of plugins and components to test their plugins right there.

As you know, if you are developing a library such as this one, your time would be wasted if you were to compile the plugin, publish the npm, update the plugin in host, and refresh just to see your change.

That's why Storybook is useful.

I think this video does a great job explaining what Storybook is all about. Please review this tutorial fully. https://www.youtube.com/watch?v=FUKpWgRyPlU&t=932s

# Storybook (AKA @storybook/react) is currently broken on `6.4`

The version has been temporarily set to `6.3` until https://github.com/storybookjs/storybook/issues/16880 is fixed

# Using Snapshot testing

Snapshot testing is used to confirm that the output of a component for a given props stays the same. To create a new snapshot test (Or to update the old one, when you know that the new snapshot state is correct).

```
npm run update-snapshots
```

There are 2 major ways to do snapshot testing. [enzyme](https://github.com/enzymejs/enzyme) and [react-test-renderer](https://reactjs.org/docs/test-renderer.html).

The different is that `react-test-renderer` only tests the `HTML` outputted by a given component,
but `enzyme` allows you to compare more detailed things.

A good example of the difference, when testing is testing anything with `recharts`. The output of `recharts` will not show up with `react-test-renderer`, so we cannot test what we made.

With `enzyme`, we can see the `props` which have been given to `recharts`, so we can at least be sure the props we passed to `recharts` did not change.

# How to use some of the more advanced hooks

## `useMemo` and merging default parameters

A perfect useCase for `useMemo` is this

```
const Component = props => {
  const propsMergedWithDefault = useMemo(() => {
      return merge(props, defaultProps);
    }, [props]
  )
  // ...
}
```

Which can replace the unclear and incorrect following pattern

```
const Component => props => {
    const [propsMergedWithDefault, setPropsMergedWithDefault] = useState(defaultProps);
    // ...
    useEffect(() => {
      setPropsMergedWithDefault(merge(props, defaultProps)
    }, [props])
}
```

## Jest and snapshot tests

`npm run test-jst` will execute all tests. Many of these are snapshot tests which will check that your changes didn't change a component in an indesired way. If you changed a component on _purpose_, then use `npm run update-snapshots` and commit the changed files.

---
_Source: https://npm.io/package/purefacts-widgets · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
