oolib 2.174.0 → 2.175.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,9 @@
1
- export function getEmptyStatesConfig({ preset, title, contentTypeTitle, commaSeparatedTags }: {
1
+ export function getEmptyStatesConfig({ preset, title, contentTypeTitle, commaSeparatedTags, localize }: {
2
2
  preset: any;
3
3
  title: any;
4
4
  contentTypeTitle: any;
5
5
  commaSeparatedTags: any;
6
+ localize: any;
6
7
  }): {
7
8
  align: string;
8
9
  image: {
@@ -13,7 +14,7 @@ export function getEmptyStatesConfig({ preset, title, contentTypeTitle, commaSep
13
14
  };
14
15
  };
15
16
  title: string;
16
- subtitle: string;
17
+ subtitle: any;
17
18
  imageSize?: undefined;
18
19
  button?: undefined;
19
20
  link?: undefined;
@@ -28,7 +29,7 @@ export function getEmptyStatesConfig({ preset, title, contentTypeTitle, commaSep
28
29
  };
29
30
  imageSize: number;
30
31
  title: string;
31
- subtitle: string;
32
+ subtitle: any;
32
33
  button?: undefined;
33
34
  link?: undefined;
34
35
  } | {
@@ -78,7 +79,7 @@ export function getEmptyStatesConfig({ preset, title, contentTypeTitle, commaSep
78
79
  height?: undefined;
79
80
  };
80
81
  };
81
- title: string;
82
+ title: any;
82
83
  subtitle: string;
83
84
  link: {
84
85
  text: string;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getEmptyStatesConfig = void 0;
4
4
  var getEmptyStatesConfig = function (_a) {
5
- var preset = _a.preset, title = _a.title, contentTypeTitle = _a.contentTypeTitle, commaSeparatedTags = _a.commaSeparatedTags;
5
+ var preset = _a.preset, title = _a.title, contentTypeTitle = _a.contentTypeTitle, commaSeparatedTags = _a.commaSeparatedTags, localize = _a.localize;
6
6
  switch (preset) {
7
7
  case "multipleCollectionsListing":
8
8
  return {
@@ -15,7 +15,7 @@ var getEmptyStatesConfig = function (_a) {
15
15
  },
16
16
  },
17
17
  title: "No tags added",
18
- subtitle: "Publishing under ".concat(commaSeparatedTags, " shows all tagged content here, You can edit published content in future, when required."),
18
+ subtitle: localize("Publishing under <word1 : ".concat(commaSeparatedTags, "> shows all tagged content here, You can edit published content in future, when required.")),
19
19
  };
20
20
  case "multiplePublishingListing":
21
21
  return {
@@ -41,7 +41,7 @@ var getEmptyStatesConfig = function (_a) {
41
41
  },
42
42
  },
43
43
  title: "No ".concat(contentTypeTitle === null || contentTypeTitle === void 0 ? void 0 : contentTypeTitle.toLowerCase(), " Added"),
44
- subtitle: "Publishing under ".concat(contentTypeTitle === null || contentTypeTitle === void 0 ? void 0 : contentTypeTitle.toLowerCase(), " shows your content here, You can edit published content in future, when required."),
44
+ subtitle: localize("Publishing under <word1 : ".concat(contentTypeTitle === null || contentTypeTitle === void 0 ? void 0 : contentTypeTitle.toLowerCase(), "> shows your content here, You can edit published content in future, when required.")),
45
45
  };
46
46
  case "singleCollectionsListing":
47
47
  return {
@@ -55,7 +55,7 @@ var getEmptyStatesConfig = function (_a) {
55
55
  },
56
56
  imageSize: 80,
57
57
  title: "No ".concat(contentTypeTitle === null || contentTypeTitle === void 0 ? void 0 : contentTypeTitle.toLowerCase(), " Added"),
58
- subtitle: "Publishing under ".concat(contentTypeTitle === null || contentTypeTitle === void 0 ? void 0 : contentTypeTitle.toLowerCase(), " shows your content here, You can edit published content in future, when required."),
58
+ subtitle: localize("Publishing under <word1 : ".concat(contentTypeTitle === null || contentTypeTitle === void 0 ? void 0 : contentTypeTitle.toLowerCase(), "> shows your content here, You can edit published content in future, when required.")),
59
59
  };
60
60
  case "profileListing":
61
61
  return {
@@ -202,7 +202,7 @@ var getEmptyStatesConfig = function (_a) {
202
202
  opacity: 0.6,
203
203
  },
204
204
  },
205
- title: "Cant find any content for ".concat(contentTypeTitle),
205
+ title: localize("Cant find any content for <word1 : ".concat(contentTypeTitle, ">")),
206
206
  subtitle: "Sorry we couldn’t find any matches for this. Please make sure the words are spelled correctly",
207
207
  link: {
208
208
  // onClick: action,
@@ -7,14 +7,17 @@ exports.EmptyStates = void 0;
7
7
  var react_1 = __importDefault(require("react"));
8
8
  var EmptyStatesRenderer_1 = require("./comps/EmptyStatesRenderer");
9
9
  var config_1 = require("./config");
10
+ var utilsOolib_1 = require("../../utilsOolib");
10
11
  var EmptyStates = function (_a) {
11
12
  var _b = _a.preset, preset = _b === void 0 ? "multiplePublishingListing" : _b, contentTypeTitle = _a.contentTypeTitle, titleProp = _a.title, tags = _a.tags, onClick = _a.onClick;
12
13
  var commaSeparatedTags = tags === null || tags === void 0 ? void 0 : tags.map(function (item) { return item.toLowerCase(); }).join(",");
14
+ var localize = (0, utilsOolib_1.useLocale)();
13
15
  var _c = (0, config_1.getEmptyStatesConfig)({
14
16
  preset: preset,
15
17
  contentTypeTitle: contentTypeTitle,
16
18
  commaSeparatedTags: commaSeparatedTags,
17
- title: titleProp
19
+ title: titleProp,
20
+ localize: localize
18
21
  }), image = _c.image, title = _c.title, subtitle = _c.subtitle, link = _c.link, button = _c.button, align = _c.align;
19
22
  return (react_1.default.createElement(EmptyStatesRenderer_1.EmptyStatesRenderer, { image: image, align: align, title: title, subtitle: subtitle, link: link, button: button, onClick: onClick, preset: preset }));
20
23
  };
@@ -65,7 +65,7 @@ var BarChart = function (args) {
65
65
  react_1.default.createElement(BarChart_1.BarChart, { data: [
66
66
  {
67
67
  display: "Logged In Once",
68
- stack1: 60,
68
+ // stack1: 60,
69
69
  stack2: 20,
70
70
  stack3: 40,
71
71
  stack4: 10,
@@ -125,7 +125,14 @@ var BarChart = function (args) {
125
125
  "stack4",
126
126
  "stack5",
127
127
  "stack6",
128
- ],
128
+ ], tooltipLabelsMapping: {
129
+ stack1: 'Stack 1',
130
+ stack2: 'Stack 2',
131
+ stack3: 'Stack 3',
132
+ stack4: 'Stack 4',
133
+ stack5: 'Stack 5',
134
+ stack6: 'Stack 6',
135
+ },
129
136
  // valuePath="stack1"
130
137
  labelPath: "display", title: "This is a Stacked BarChart", onClick: handleBarClick,
131
138
  // showPercent={true}
@@ -135,7 +142,7 @@ var BarChart = function (args) {
135
142
  react_1.default.createElement(BarChart_1.BarChart, { data: [
136
143
  {
137
144
  display: "Logged In Once",
138
- stack1: 60,
145
+ // stack1: 60,
139
146
  stack2: 20,
140
147
  stack3: 40,
141
148
  stack4: 10,
@@ -7,7 +7,7 @@ var getTotalCount = function (_a) {
7
7
  var total = 0;
8
8
  for (var _i = 0, data_1 = data; _i < data_1.length; _i++) {
9
9
  var d = data_1[_i];
10
- var count = (0, _EXPORTS_1.getVal)(d, countPath);
10
+ var count = (0, _EXPORTS_1.getVal)(d, countPath) || 0; // fallback to 0, cuz sometimes backend systems return 'undefined' if the count of data against a field is non-existent / zero
11
11
  total += count;
12
12
  }
13
13
  return total;
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ import { TooltipProps } from 'recharts';
3
+ import { LabelData } from '../CustomizedLabel';
4
+ interface CustomTooltipProps extends TooltipProps<number, string> {
5
+ value?: LabelData[];
6
+ showPercent?: boolean;
7
+ }
8
+ declare const CustomTooltip: React.FC<CustomTooltipProps>;
9
+ export default CustomTooltip;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var react_1 = __importDefault(require("react"));
7
+ var Typo2_1 = require("../../../Typo2");
8
+ var __1 = require("../../../../..");
9
+ var CustomTooltip = function (props) {
10
+ var _a, _b;
11
+ var active = props.active, payload = props.payload, value = props.value, showPercent = props.showPercent;
12
+ if (!active || !payload || !payload.length)
13
+ return null;
14
+ // Calculate position - align with the right side of the bars
15
+ var style = {
16
+ position: 'absolute',
17
+ left: "".concat(((_a = props === null || props === void 0 ? void 0 : props.coordinate) === null || _a === void 0 ? void 0 : _a.x) || 0, "px"),
18
+ top: "".concat(((_b = props === null || props === void 0 ? void 0 : props.coordinate) === null || _b === void 0 ? void 0 : _b.y) || 0, "px"),
19
+ transform: 'translateX(10px)', // Small offset from the bars
20
+ backgroundColor: 'white',
21
+ border: "1px solid ".concat(__1.colors2.grey10),
22
+ borderRadius: '6px',
23
+ padding: '8px',
24
+ boxShadow: '0 2px 4px rgba(0,0,0,0.1)',
25
+ zIndex: 1000,
26
+ width: 'max-content',
27
+ maxWidth: '200px',
28
+ display: 'flex',
29
+ flexDirection: 'column',
30
+ gap: '0.5rem'
31
+ };
32
+ return (react_1.default.createElement("div", { style: style }, value.map(function (entry, index) { return (react_1.default.createElement("div", { key: index, style: {
33
+ display: 'flex',
34
+ alignItems: 'center',
35
+ gap: '0.5rem'
36
+ } },
37
+ react_1.default.createElement("div", { style: {
38
+ flex: '0 0 auto',
39
+ width: '1.2rem',
40
+ height: '1.2rem',
41
+ borderRadius: '0.2rem',
42
+ backgroundColor: entry.color,
43
+ display: 'flex',
44
+ gap: '0.5rem',
45
+ alignItems: 'center'
46
+ } }),
47
+ react_1.default.createElement(Typo2_1.UI_CAPTION_BOLD_DF, { style: { flex: '0 0 auto', } }, showPercent ? entry.percentage + '%' : entry.count),
48
+ react_1.default.createElement(Typo2_1.UI_CAPTION_DF, { style: { flex: '0 0 auto', } }, entry.tooltipLabel))); })));
49
+ };
50
+ exports.default = CustomTooltip;
@@ -1,13 +1,14 @@
1
1
  import React from "react";
2
2
  import { BaseConfigs, DebugControls } from "../..";
3
- interface LabelData {
3
+ export interface LabelData {
4
4
  percentage: number;
5
5
  count: number;
6
6
  name: string;
7
7
  dataIndex: number;
8
8
  color: string;
9
+ tooltipLabel?: string;
9
10
  }
10
- type CustomizedLabelValue = LabelData | LabelData[];
11
+ export type CustomizedLabelValue = LabelData | LabelData[];
11
12
  interface CustomizedLabelProps {
12
13
  y?: number | string;
13
14
  width?: number | string;
@@ -18,6 +18,9 @@ export interface DebugControls {
18
18
  export interface BarChartProps {
19
19
  data: any;
20
20
  valuePath: string | string[];
21
+ tooltipLabelsMapping: {
22
+ [key: string]: string;
23
+ };
21
24
  labelPath: string;
22
25
  onClick?: (name: string) => void;
23
26
  valueSuffix?: string;
@@ -52,6 +52,9 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
52
52
  }
53
53
  return to.concat(ar || Array.prototype.slice.call(from));
54
54
  };
55
+ var __importDefault = (this && this.__importDefault) || function (mod) {
56
+ return (mod && mod.__esModule) ? mod : { "default": mod };
57
+ };
55
58
  Object.defineProperty(exports, "__esModule", { value: true });
56
59
  exports.BarChart = void 0;
57
60
  var react_1 = __importStar(require("react"));
@@ -60,21 +63,22 @@ var _EXPORTS_1 = require("../../../utils/_EXPORTS");
60
63
  var getTotalCount_1 = require("../../../utils/getTotalCount");
61
64
  var CustomizedLabel_1 = require("./comps/CustomizedLabel");
62
65
  var colors_1 = require("../../themes/colors");
66
+ var CustomTooltip_1 = __importDefault(require("./comps/CustomTooltip"));
63
67
  var usePrepareData = function (_a) {
64
- var _data = _a._data, labelPath = _a.labelPath, valuePath = _a.valuePath, isBreakdown = _a.isBreakdown, showPercent = _a.showPercent;
68
+ var _data = _a._data, labelPath = _a.labelPath, valuePath = _a.valuePath, tooltipLabelsMapping = _a.tooltipLabelsMapping, isBreakdown = _a.isBreakdown, showPercent = _a.showPercent;
65
69
  return (0, react_1.useMemo)(function () {
66
70
  var finalData = __spreadArray([], _data, true);
67
71
  var totalCount = !isBreakdown
68
72
  ? (0, getTotalCount_1.getTotalCount)({ data: finalData, countPath: valuePath })
69
73
  : finalData.map(function (d) {
70
74
  var valueSum = valuePath
71
- .map(function (path) { return (0, _EXPORTS_1.getVal)(d, path); })
75
+ .map(function (path) { return (0, _EXPORTS_1.getVal)(d, path) || 0; }) // fallback to 0, cuz sometimes backend systems return 'undefined' if the count of data against a field is non-existent / zero
72
76
  .reduce(function (acc, curr) { return acc + curr; }, 0);
73
77
  return valueSum;
74
78
  });
75
79
  finalData = finalData.map(function (d, index) {
76
80
  if (!isBreakdown) {
77
- var count = (0, _EXPORTS_1.getVal)(d, valuePath);
81
+ var count = (0, _EXPORTS_1.getVal)(d, valuePath) || 0; // fallback to 0, cuz sometimes backend systems return 'undefined' if the count of data against a field is non-existent / zero
78
82
  return {
79
83
  labels: __assign(__assign({}, (showPercent
80
84
  ? { percentage: (0, _EXPORTS_1.getPercentage)(count, totalCount) }
@@ -82,11 +86,11 @@ var usePrepareData = function (_a) {
82
86
  };
83
87
  }
84
88
  return valuePath.map(function (path, i) {
85
- var count = (0, _EXPORTS_1.getVal)(d, path);
89
+ var count = (0, _EXPORTS_1.getVal)(d, path) || 0;
86
90
  return {
87
91
  labels: __assign(__assign({}, (showPercent
88
92
  ? { percentage: (0, _EXPORTS_1.getPercentage)(count, totalCount[index]) }
89
- : {})), { count: count, name: (0, _EXPORTS_1.getVal)(d, labelPath) }),
93
+ : {})), { count: count, tooltipLabel: (tooltipLabelsMapping === null || tooltipLabelsMapping === void 0 ? void 0 : tooltipLabelsMapping[path]) || path, name: (0, _EXPORTS_1.getVal)(d, labelPath) }),
90
94
  };
91
95
  });
92
96
  });
@@ -178,29 +182,27 @@ var barConfigs = {
178
182
  getDataKey: function (stackIndex) { return "".concat(stackIndex, ".labels.count"); },
179
183
  getStackId: function (stackIndex, breakdownDisplayType //replaced breakdownDisplayType
180
184
  ) { return (breakdownDisplayType === "stacked" ? "stack" : "stack-".concat(stackIndex)); },
181
- getCellFill: function (colorIdx, stackIndex, dataVizColors) {
182
- return dataVizColors[(colorIdx + stackIndex) % dataVizColors.length];
183
- },
185
+ getCellFill: function (colorIdx, stackIndex, dataVizColors) { return dataVizColors[(colorIdx + stackIndex) % dataVizColors.length]; },
184
186
  },
185
187
  isNotBreakdown: {
186
188
  getBarRadius: function () { return _base_configs.barRadius; },
187
189
  getDataKey: function () { return "labels.count"; },
188
190
  getStackId: function () { return undefined; },
189
- getCellFill: function (colorIdx, _stackIndex, dataVizColors) {
190
- return dataVizColors[colorIdx];
191
- },
191
+ getCellFill: function (colorIdx, _stackIndex, dataVizColors) { return dataVizColors[colorIdx]; },
192
192
  },
193
193
  };
194
194
  var BarChart = function (_a) {
195
- var _data = _a.data, valuePath = _a.valuePath, _b = _a.labelPath, labelPath = _b === void 0 ? "name" : _b, onClick = _a.onClick, _c = _a.breakdownDisplayType, breakdownDisplayType = _c === void 0 ? "grouped" : _c, _d = _a.showCount, showCount = _d === void 0 ? true : _d, _e = _a.showPercent, showPercent = _e === void 0 ? true : _e, _f = _a.colorIdx, colorIdx = _f === void 0 ? 0 : _f;
195
+ var _data = _a.data, valuePath = _a.valuePath, tooltipLabelsMapping = _a.tooltipLabelsMapping, _b = _a.labelPath, labelPath = _b === void 0 ? "name" : _b, onClick = _a.onClick, _c = _a.breakdownDisplayType, breakdownDisplayType = _c === void 0 ? "grouped" : _c, _d = _a.showCount, showCount = _d === void 0 ? true : _d, _e = _a.showPercent, showPercent = _e === void 0 ? true : _e, _f = _a.colorIdx, colorIdx = _f === void 0 ? 0 : _f;
196
196
  var isBreakdown = Array.isArray(valuePath);
197
197
  var data = usePrepareData({
198
198
  _data: _data,
199
199
  labelPath: labelPath,
200
200
  valuePath: valuePath,
201
+ tooltipLabelsMapping: tooltipLabelsMapping,
201
202
  isBreakdown: isBreakdown,
202
- showPercent: showPercent
203
+ showPercent: showPercent,
203
204
  });
205
+ console.log({ data: data });
204
206
  var _g = (0, react_1.useState)(undefined), activeBar = _g[0], setActiveBar = _g[1];
205
207
  // menu options for grouped and stacked
206
208
  var renderBar = function (stackIndex, lastIndex) {
@@ -236,7 +238,7 @@ var BarChart = function (_a) {
236
238
  },
237
239
  }
238
240
  : {})))); } })),
239
- data.map(function (d, index) { return (react_1.default.createElement(recharts_1.Cell, { y: (!isBreakdown || breakdownDisplayType === "stacked")
241
+ data.map(function (d, index) { return (react_1.default.createElement(recharts_1.Cell, { y: !isBreakdown || breakdownDisplayType === "stacked"
240
242
  ? CALC_SINGLE_BAR_SECTION_Y_POS(index) + CHART_OFFSET_TOP
241
243
  : CALC_GROUPED_BAR_SECTION_Y_POS(index, stackIndex, data[0].length) + CHART_OFFSET_TOP, key: "cell-".concat(index, "-").concat(stackIndex), opacity: 1, height: _base_configs.barHeight, fill: activeConfig.getCellFill(colorIdx, stackIndex, colors_1.dataVizColors) })); }))));
242
244
  };
@@ -261,6 +263,14 @@ var BarChart = function (_a) {
261
263
  } },
262
264
  react_1.default.createElement(recharts_1.XAxis, { hide: true, type: "number" }),
263
265
  react_1.default.createElement(recharts_1.YAxis, { hide: true, type: "category" }),
266
+ isBreakdown && (react_1.default.createElement(recharts_1.Tooltip, { content: function (props) {
267
+ var _a;
268
+ return (react_1.default.createElement(CustomTooltip_1.default, __assign({}, props, { showPercent: showPercent,
269
+ // god knows why the dataindex gets stored against props.label.
270
+ // this is some internal recharts thing for tooltips specifically.
271
+ // we dont do this.
272
+ value: (_a = data[props.label]) === null || _a === void 0 ? void 0 : _a.map(function (item, idx) { return (__assign(__assign({}, item.labels), { color: colors_1.dataVizColors[(colorIdx + idx) % colors_1.dataVizColors.length] })); }) })));
273
+ }, cursor: false, allowEscapeViewBox: { x: true, y: true } })),
264
274
  isBreakdown
265
275
  ? data[0].map(function (_, stackIndex) {
266
276
  return renderBar(stackIndex, data[0].length - 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oolib",
3
- "version": "2.174.0",
3
+ "version": "2.175.0",
4
4
  "description": " OKE Component Library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",