@powerhousedao/common 2.5.0-staging.0 → 2.5.0-staging.1
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.
- package/dist/editors/styles.css +4 -1
- package/dist/hooks/useTimelineItems.d.ts +22 -5
- package/dist/hooks/useTimelineItems.d.ts.map +1 -1
- package/dist/hooks/useTimelineItems.js +71 -76
- package/dist/hooks/useTimelineItems.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -9
package/dist/editors/styles.css
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! tailwindcss v4.1.
|
|
1
|
+
/*! tailwindcss v4.1.10 | MIT License | https://tailwindcss.com */
|
|
2
2
|
@layer properties;
|
|
3
3
|
@layer theme, base, components, utilities;
|
|
4
4
|
@layer theme {
|
|
@@ -2218,6 +2218,9 @@
|
|
|
2218
2218
|
.cursor-pointer {
|
|
2219
2219
|
cursor: pointer;
|
|
2220
2220
|
}
|
|
2221
|
+
.cursor-wait {
|
|
2222
|
+
cursor: wait;
|
|
2223
|
+
}
|
|
2221
2224
|
.resize {
|
|
2222
2225
|
resize: both;
|
|
2223
2226
|
}
|
|
@@ -1,8 +1,25 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
type
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { type UseAnalyticsQueryResult } from "@powerhousedao/reactor-browser/analytics";
|
|
2
|
+
type BarItem = {
|
|
3
|
+
id: string;
|
|
4
|
+
type: "bar";
|
|
5
|
+
addSize: 0 | 1 | 2 | 3 | 4;
|
|
6
|
+
delSize: 0 | 1 | 2 | 3 | 4;
|
|
7
|
+
additions: number;
|
|
8
|
+
deletions: number;
|
|
9
|
+
timestamp: string;
|
|
10
|
+
startDate: Date;
|
|
11
|
+
endDate: Date;
|
|
12
|
+
revision?: number;
|
|
5
13
|
};
|
|
6
|
-
|
|
14
|
+
type DividerItem = {
|
|
15
|
+
id: string;
|
|
16
|
+
type: "divider";
|
|
17
|
+
revision?: number;
|
|
18
|
+
startDate?: Date;
|
|
19
|
+
endDate?: Date;
|
|
20
|
+
};
|
|
21
|
+
type TimelineItem = BarItem | DividerItem;
|
|
22
|
+
export type UseTimelineItemsResult = UseAnalyticsQueryResult<TimelineItem[]>;
|
|
23
|
+
export declare const useTimelineItems: (documentId?: string, startTimestamp?: string) => UseTimelineItemsResult;
|
|
7
24
|
export {};
|
|
8
25
|
//# sourceMappingURL=useTimelineItems.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTimelineItems.d.ts","sourceRoot":"","sources":["../../hooks/useTimelineItems.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"useTimelineItems.d.ts","sourceRoot":"","sources":["../../hooks/useTimelineItems.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,uBAAuB,EAE7B,MAAM,0CAA0C,CAAC;AAWlD,KAAK,OAAO,GAAG;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,KAAK,CAAC;IACZ,OAAO,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC3B,OAAO,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,IAAI,CAAC;IAChB,OAAO,EAAE,IAAI,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,WAAW,GAAG;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,IAAI,CAAC;IACjB,OAAO,CAAC,EAAE,IAAI,CAAC;CAChB,CAAC;AAEF,KAAK,YAAY,GAAG,OAAO,GAAG,WAAW,CAAC;AAwF1C,MAAM,MAAM,sBAAsB,GAAG,uBAAuB,CAAC,YAAY,EAAE,CAAC,CAAC;AAE7E,eAAO,MAAM,gBAAgB,GAC3B,aAAa,MAAM,EACnB,iBAAiB,MAAM,KACtB,sBAuBF,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { AnalyticsGranularity, AnalyticsPath, DateTime, useAnalyticsQuery, } from "@powerhousedao/reactor-browser/analytics";
|
|
2
|
-
import { useMemo } from "react";
|
|
3
2
|
const getBarSize = (value) => {
|
|
4
3
|
if (value <= 0)
|
|
5
4
|
return 0;
|
|
@@ -11,11 +10,79 @@ const getBarSize = (value) => {
|
|
|
11
10
|
return 3;
|
|
12
11
|
return 4;
|
|
13
12
|
};
|
|
13
|
+
function addItemsDividers(items) {
|
|
14
|
+
if (!items.length)
|
|
15
|
+
return [];
|
|
16
|
+
const result = [];
|
|
17
|
+
items.forEach((item, index) => {
|
|
18
|
+
result.push(item);
|
|
19
|
+
// Check if there's a next item and if they're not in consecutive hours
|
|
20
|
+
if (index < items.length - 1) {
|
|
21
|
+
const currentDate = new Date(item.startDate);
|
|
22
|
+
const nextDate = new Date(items[index + 1].startDate);
|
|
23
|
+
const currentHour = currentDate.getHours();
|
|
24
|
+
const nextHour = nextDate.getHours();
|
|
25
|
+
// Get day parts (without time) for comparison
|
|
26
|
+
const currentDay = currentDate.toDateString();
|
|
27
|
+
const nextDay = nextDate.toDateString();
|
|
28
|
+
// If different days or non-consecutive hours on the same day
|
|
29
|
+
if (currentDay !== nextDay ||
|
|
30
|
+
(currentDay === nextDay && Math.abs(nextHour - currentHour) > 1)) {
|
|
31
|
+
result.push({
|
|
32
|
+
id: `divider-${item.id}-${items[index + 1].id}`,
|
|
33
|
+
type: "divider",
|
|
34
|
+
revision: 0,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
function metricsToItems(metrics) {
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
43
|
+
if (!metrics)
|
|
44
|
+
return [];
|
|
45
|
+
const items = metrics
|
|
46
|
+
.sort((a, b) => {
|
|
47
|
+
const aDate = new Date(a.start);
|
|
48
|
+
const bDate = new Date(b.start);
|
|
49
|
+
return aDate.getTime() - bDate.getTime();
|
|
50
|
+
})
|
|
51
|
+
.filter((result) => {
|
|
52
|
+
return result.rows.every((row) => row.value > 0);
|
|
53
|
+
})
|
|
54
|
+
.map((result) => {
|
|
55
|
+
const { additions, deletions } = result.rows.reduce((acc, row) => {
|
|
56
|
+
if (row.dimensions.changes.path === "changes/add") {
|
|
57
|
+
acc.additions += row.value;
|
|
58
|
+
}
|
|
59
|
+
else if (row.dimensions.changes.path ===
|
|
60
|
+
"changes/remove") {
|
|
61
|
+
acc.deletions += row.value;
|
|
62
|
+
}
|
|
63
|
+
return acc;
|
|
64
|
+
}, { additions: 0, deletions: 0 });
|
|
65
|
+
const startDate = new Date(result.start);
|
|
66
|
+
return {
|
|
67
|
+
id: startDate.toISOString(),
|
|
68
|
+
type: "bar",
|
|
69
|
+
addSize: getBarSize(additions),
|
|
70
|
+
delSize: getBarSize(deletions),
|
|
71
|
+
additions,
|
|
72
|
+
deletions,
|
|
73
|
+
timestamp: startDate.toISOString(),
|
|
74
|
+
startDate: startDate,
|
|
75
|
+
endDate: new Date(result.end),
|
|
76
|
+
revision: 0,
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
return addItemsDividers(items);
|
|
80
|
+
}
|
|
14
81
|
export const useTimelineItems = (documentId, startTimestamp) => {
|
|
15
82
|
const start = startTimestamp
|
|
16
83
|
? DateTime.fromISO(startTimestamp)
|
|
17
84
|
: DateTime.now().startOf("day");
|
|
18
|
-
|
|
85
|
+
return useAnalyticsQuery({
|
|
19
86
|
start,
|
|
20
87
|
end: DateTime.now().endOf("day"),
|
|
21
88
|
granularity: AnalyticsGranularity.Hourly,
|
|
@@ -27,80 +94,8 @@ export const useTimelineItems = (documentId, startTimestamp) => {
|
|
|
27
94
|
lod: {
|
|
28
95
|
changes: 2,
|
|
29
96
|
},
|
|
30
|
-
|
|
97
|
+
}, {
|
|
98
|
+
select: metricsToItems,
|
|
31
99
|
});
|
|
32
|
-
// memoize the mapped result to avoid recalculation on rerenders
|
|
33
|
-
const mappedResult = useMemo(() => {
|
|
34
|
-
if (!diffResult)
|
|
35
|
-
return [];
|
|
36
|
-
return diffResult
|
|
37
|
-
.sort((a, b) => {
|
|
38
|
-
const aDate = new Date(a.start);
|
|
39
|
-
const bDate = new Date(b.start);
|
|
40
|
-
return aDate.getTime() - bDate.getTime();
|
|
41
|
-
})
|
|
42
|
-
.filter((result) => {
|
|
43
|
-
return result.rows.every((row) => row.value > 0);
|
|
44
|
-
})
|
|
45
|
-
.map((result) => {
|
|
46
|
-
const { additions, deletions } = result.rows.reduce((acc, row) => {
|
|
47
|
-
if (row.dimensions.changes.path ===
|
|
48
|
-
"changes/add") {
|
|
49
|
-
acc.additions += row.value;
|
|
50
|
-
}
|
|
51
|
-
else if (row.dimensions.changes.path ===
|
|
52
|
-
"changes/remove") {
|
|
53
|
-
acc.deletions += row.value;
|
|
54
|
-
}
|
|
55
|
-
return acc;
|
|
56
|
-
}, { additions: 0, deletions: 0 });
|
|
57
|
-
const startDate = new Date(result.start);
|
|
58
|
-
return {
|
|
59
|
-
id: startDate.toISOString(),
|
|
60
|
-
type: "bar",
|
|
61
|
-
addSize: getBarSize(additions),
|
|
62
|
-
delSize: getBarSize(deletions),
|
|
63
|
-
additions,
|
|
64
|
-
deletions,
|
|
65
|
-
timestamp: startDate.toISOString(),
|
|
66
|
-
startDate: startDate,
|
|
67
|
-
endDate: new Date(result.end),
|
|
68
|
-
revision: 0,
|
|
69
|
-
};
|
|
70
|
-
});
|
|
71
|
-
}, [diffResult]);
|
|
72
|
-
// memoize the divider insertion to avoid recalculation
|
|
73
|
-
const resultWithDividers = useMemo(() => {
|
|
74
|
-
if (!mappedResult.length)
|
|
75
|
-
return [];
|
|
76
|
-
const result = [];
|
|
77
|
-
mappedResult.forEach((item, index) => {
|
|
78
|
-
result.push(item);
|
|
79
|
-
// Check if there's a next item and if they're not in consecutive hours
|
|
80
|
-
if (index < mappedResult.length - 1) {
|
|
81
|
-
const currentDate = new Date(item.startDate);
|
|
82
|
-
const nextDate = new Date(mappedResult[index + 1].startDate);
|
|
83
|
-
const currentHour = currentDate.getHours();
|
|
84
|
-
const nextHour = nextDate.getHours();
|
|
85
|
-
// Get day parts (without time) for comparison
|
|
86
|
-
const currentDay = currentDate.toDateString();
|
|
87
|
-
const nextDay = nextDate.toDateString();
|
|
88
|
-
// If different days or non-consecutive hours on the same day
|
|
89
|
-
if (currentDay !== nextDay ||
|
|
90
|
-
(currentDay === nextDay && Math.abs(nextHour - currentHour) > 1)) {
|
|
91
|
-
result.push({
|
|
92
|
-
id: `divider-${item.id}-${mappedResult[index + 1].id}`,
|
|
93
|
-
type: "divider",
|
|
94
|
-
revision: 0,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
return result;
|
|
100
|
-
}, [mappedResult]);
|
|
101
|
-
return {
|
|
102
|
-
isLoading,
|
|
103
|
-
data: resultWithDividers,
|
|
104
|
-
};
|
|
105
100
|
};
|
|
106
101
|
//# sourceMappingURL=useTimelineItems.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTimelineItems.js","sourceRoot":"","sources":["../../hooks/useTimelineItems.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useTimelineItems.js","sourceRoot":"","sources":["../../hooks/useTimelineItems.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,QAAQ,EAGR,iBAAiB,GAClB,MAAM,0CAA0C,CAAC;AAElD,MAAM,UAAU,GAAG,CAAC,K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