Skip to content

Commit

Permalink
Issue #388 - removed objectNested
Browse files Browse the repository at this point in the history
- removed lib
- added babel nullish-coalescing-operator and optional-chaining
  • Loading branch information
magsout committed May 14, 2021
1 parent cbe556c commit 5df6951
Show file tree
Hide file tree
Showing 29 changed files with 101 additions and 290 deletions.
49 changes: 29 additions & 20 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,42 @@
"presets": ["next/babel"],
"plugins": [
[
"babel-plugin-inline-react-svg",
{
"svgo": {
"plugins": [
{
"name": "removeViewBox",
"active": false
}
]
}
"babel-plugin-inline-react-svg",
{
"svgo": {
"plugins": [
{
"name": "removeViewBox",
"active": false
}]
}
],
[
"babel-plugin-transform-react-remove-prop-types",
{
"mode": "wrap"
}
]
]
}
],
[
"babel-plugin-transform-react-remove-prop-types",
{
"mode": "wrap"
}
],
"@babel/plugin-proposal-nullish-coalescing-operator",
"@babel/plugin-proposal-optional-chaining"
]
},
"development": {
"presets": ["next/babel"],
"plugins": ["babel-plugin-inline-react-svg"]
"plugins": [
"babel-plugin-inline-react-svg",
"@babel/plugin-proposal-nullish-coalescing-operator",
"@babel/plugin-proposal-optional-chaining"
]
},
"test": {
"presets": ["next/babel"],
"plugins": ["babel-plugin-inline-react-svg"]
"plugins": [
"babel-plugin-inline-react-svg",
"@babel/plugin-proposal-nullish-coalescing-operator",
"@babel/plugin-proposal-optional-chaining"
]
}
}
}
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
},
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.14.2",
"@babel/plugin-proposal-optional-chaining": "^7.14.2",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/preset-env": "^7.14.1",
"@babel/preset-react": "^7.13.13",
Expand Down
4 changes: 2 additions & 2 deletions src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import jsonFetch from "simple-json-fetch";

import { isEmptyObject, toQueryString, ObjectNested } from "../libraries";
import { isEmptyObject, toQueryString } from "../libraries";
import { CONFIG_API, GET, CALLBACK_API, METHODS, POST } from "../constants/Api";

/**
Expand All @@ -27,7 +27,7 @@ const request = (args = {}, callback = CALLBACK_API) => {
...CONFIG_API,
...config,
};
const method = ObjectNested.get(config, "method");
const method = config?.method;

/* methods : get or post */
if ("string" !== typeof method) {
Expand Down
5 changes: 2 additions & 3 deletions src/components/Chart/CommonFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import React from "react";
import PropTypes from "prop-types";

import Input from "../Input";
import { ObjectNested } from "../../libraries";

const CommonFilters = ({ onChange, filters, minFrom, minTo }) => {
return (
Expand All @@ -16,15 +15,15 @@ const CommonFilters = ({ onChange, filters, minFrom, minTo }) => {
name="from"
placeholder="From"
min={minFrom}
value={ObjectNested.get(filters, "from", "")}
value={filters?.from ?? ""}
onChange={onChange}
/>
<Input
type="date"
name="to"
placeholder="To"
min={minTo}
value={ObjectNested.get(filters, "to", "")}
value={filters?.to ?? ""}
onChange={onChange}
/>
</React.Fragment>
Expand Down
8 changes: 3 additions & 5 deletions src/components/SimpleStat/Stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
import React from "react";
import PropTypes from "prop-types";

import { ObjectNested } from "../../libraries";

import classes from "./SimpleStat.module.css";

const Stat = ({ stat }) => {
const label = ObjectNested.get(stat, "label");
const count = ObjectNested.get(stat, "count");
const style = ObjectNested.get(stat, "style");
const label = stat?.label;
const count = stat?.count;
const style = stat?.style;

return (
<div {...(style ? { style } : undefined)} className={classes.stat}>
Expand Down
7 changes: 3 additions & 4 deletions src/containers/ContactReady/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import React from "react";
import LineChart from "../../components/LineChart";
import { CommonFilters } from "../../components/Chart";
import MetricsTemplate from "../MetricsTemplate";
import { ObjectNested } from "../../libraries";
import {
mostAndLeast,
normalize,
Expand All @@ -18,7 +17,7 @@ import { TEMP_MIN_DATE } from "../../constants/Charts";
import Router from "../../routes";

const handleData = (data) => {
const localData = ObjectNested.get(data, "timeline", {});
const localData = data?.timeline ?? {};
return {
globalStats: mostAndLeast(localData),
chart: normalize(localData, "openIssues"),
Expand Down Expand Up @@ -46,9 +45,9 @@ const ContactReady = () => {
<LineChart
title={"Open issues in contactready milestone"}
label={""}
labels={ObjectNested.get(data, "chart.dates", [])}
labels={data?.chart?.dates ?? []}
legend={{ display: false }}
data={ObjectNested.get(data, "chart.openIssues", [])}
data={data?.chart?.openIssues ?? []}
options={{
scales: {
xAxes: [
Expand Down
13 changes: 8 additions & 5 deletions src/containers/Intervention/Filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import PropTypes from "prop-types";

import Input from "../../components/Input";
import Select from "../../components/Select";
import { ObjectNested } from "../../libraries";

const Filters = ({ onChange, filters }) => {
return (
Expand All @@ -16,19 +15,19 @@ const Filters = ({ onChange, filters }) => {
type="date"
name="start"
placeholder="From"
value={ObjectNested.get(filters, "start", "")}
value={filters?.start ?? ""}
onChange={onChange}
/>
<Input
type="date"
name="end"
placeholder="To"
value={ObjectNested.get(filters, "end", "")}
value={filters?.end ?? ""}
onChange={onChange}
/>
<Select
name="distribution"
value={ObjectNested.get(filters, "distribution", "upstream")}
value={filters?.distribution}
onChange={onChange}
optionList={[
{ label: "Upstream", value: "upstream" },
Expand All @@ -40,7 +39,7 @@ const Filters = ({ onChange, filters }) => {
/>
<Select
name="type"
value={ObjectNested.get(filters, "type", "all")}
value={filters?.type}
onChange={onChange}
optionList={[
{ label: "All Interventions", value: "all" },
Expand All @@ -57,13 +56,17 @@ Filters.propTypes = {
filters: PropTypes.shape({
start: PropTypes.string,
end: PropTypes.string,
distribution: PropTypes.string,
type: PropTypes.string,
}),
};

Filters.defaultProps = {
filters: {
start: "",
end: "",
distribution: "upstream",
type: "all",
},
};

Expand Down
5 changes: 2 additions & 3 deletions src/containers/Intervention/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import dayjs from "dayjs";

import LineChart from "../../components/LineChart";
import MetricsTemplate from "../MetricsTemplate";
import { ObjectNested } from "../../libraries";
import { interventionParse } from "../../modules/Intervention";
import Router from "../../routes";

Expand Down Expand Up @@ -39,9 +38,9 @@ const Intervention = () => {
<LineChart
title={"Number of interventions"}
label={""}
labels={ObjectNested.get(data, "dates", [])}
labels={data?.dates ?? []}
legend={{ display: true, position: "bottom" }}
data={ObjectNested.get(data, "counters", [])}
data={data?.counters ?? []}
multiple={true}
options={{
responsive: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import React from "react";
import renderer from "react-test-renderer";

import { ObjectNested } from "../../../libraries";
import { mostAndLeast, normalize } from "../../../modules/Chart";
import LineChart from "../../../components/LineChart";
import Component from "..";
Expand Down Expand Up @@ -54,9 +53,9 @@ it("renders Component default correctly", () => {
title={"Issues Reported per Week"}
fill={true}
label={""}
labels={ObjectNested.get(data, "chart.dates", [])}
labels={data?.chart?.dates ?? []}
legend={{ display: false }}
data={ObjectNested.get(data, "chart.newIssues", [])}
data={data?.chart?.newIssues ?? []}
options={{
scales: {
xAxes: [
Expand Down Expand Up @@ -122,9 +121,9 @@ it("renders Component with custom props", () => {
title={"Issues Reported per Week"}
fill={true}
label={""}
labels={ObjectNested.get(data, "chart.dates", [])}
labels={data?.chart?.dates ?? []}
legend={{ display: false }}
data={ObjectNested.get(data, "chart.newIssues", [])}
data={data?.chart?.newIssues ?? []}
options={{
scales: {
xAxes: [
Expand Down
13 changes: 6 additions & 7 deletions src/containers/MetricsTemplate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import PropTypes from "prop-types";

import request from "../../api";
import {
ObjectNested,
getFiltersFromUrl,
toQueryObject,
pushFiltersToUrl,
Expand Down Expand Up @@ -96,8 +95,8 @@ class MetricsTemplate extends React.Component {
getFormatedDate(filters = {}) {
const { nameFieldDateFrom, nameFieldDateTo } = this.props;
const filterList = [];
const from = ObjectNested.get(filters, nameFieldDateFrom);
const to = ObjectNested.get(filters, nameFieldDateTo);
const from = filters?.[nameFieldDateFrom];
const to = filters?.[nameFieldDateTo];
if (from) {
filterList.push(dayjs(filters.from).format("DD MMMM YYYY"));
}
Expand Down Expand Up @@ -154,9 +153,9 @@ class MetricsTemplate extends React.Component {
this.setState({
isFetching: false,
error: {
message: ObjectNested.get(payload, "message", "Error"),
errors: ObjectNested.get(payload, "errors", []),
code: ObjectNested.get(payload, "code"),
message: payload?.message ?? "Error",
errors: payload?.errors ?? [],
code: payload?.code,
},
});
}
Expand Down Expand Up @@ -190,7 +189,7 @@ class MetricsTemplate extends React.Component {

render() {
const { filters, data } = this.state;
const globalStats = ObjectNested.get(data, "globalStats", []);
const globalStats = data?.globalStats ?? [];
return (
<section>
{this.props.shouldRenderJumbotron && (
Expand Down
7 changes: 3 additions & 4 deletions src/containers/NeedsContact/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import React from "react";
import LineChart from "../../components/LineChart";
import { CommonFilters } from "../../components/Chart";
import MetricsTemplate from "../MetricsTemplate";
import { ObjectNested } from "../../libraries";
import {
mostAndLeast,
normalize,
Expand All @@ -17,7 +16,7 @@ import { TEMP_MIN_DATE } from "../../constants/Charts";
import Router from "../../routes";

const handleData = (data) => {
const localData = ObjectNested.get(data, "timeline", {});
const localData = data?.timeline ?? {};
return {
globalStats: mostAndLeast(localData),
chart: normalize(localData, "openIssues"),
Expand Down Expand Up @@ -45,9 +44,9 @@ const NeedsContact = () => {
<LineChart
title={"Open issues in needscontact milestone"}
label={""}
labels={ObjectNested.get(data, "chart.dates", [])}
labels={data?.chart?.dates ?? []}
legend={{ display: false }}
data={ObjectNested.get(data, "chart.openIssues", [])}
data={data?.chart?.openIssues ?? []}
options={{
scales: {
xAxes: [
Expand Down
7 changes: 3 additions & 4 deletions src/containers/NeedsDiagnosis/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import React from "react";

import LineChart from "../../components/LineChart";
import MetricsTemplate from "../MetricsTemplate";
import { ObjectNested } from "../../libraries";
import { mostAndLeast, normalize } from "../../modules/Chart";
import Router from "../../routes";

const handleData = (data) => {
const localData = ObjectNested.get(data, "timeline", {});
const localData = data?.timeline ?? {};
return {
globalStats: mostAndLeast(localData),
chart: normalize(localData, "openIssues"),
Expand All @@ -29,9 +28,9 @@ const NeedsDiagnosis = () => {
<LineChart
title={"Open issues in needsdiagnosis milestone"}
label={""}
labels={ObjectNested.get(data, "chart.dates", [])}
labels={data?.chart?.dates ?? []}
legend={{ display: false }}
data={ObjectNested.get(data, "chart.openIssues", [])}
data={data?.chart?.openIssues ?? []}
options={{
scales: {
xAxes: [
Expand Down
Loading

0 comments on commit 5df6951

Please sign in to comment.