@optifye/dashboard-core 6.11.46 → 6.11.48
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/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +148 -56
- package/dist/index.mjs +148 -56
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -6667,7 +6667,9 @@ declare const filterDataByDateKeyRange: <T extends {
|
|
|
6667
6667
|
*/
|
|
6668
6668
|
declare const getShiftWorkDurationSeconds: (shiftConfig: ShiftConfig | null | undefined, shiftId: number) => number | null;
|
|
6669
6669
|
/**
|
|
6670
|
-
* Determines the
|
|
6670
|
+
* Determines the active shift when one exists. Otherwise stays on the current
|
|
6671
|
+
* local calendar date and returns either the most recently completed shift from
|
|
6672
|
+
* today or, if none has completed yet, the next upcoming shift from today.
|
|
6671
6673
|
* Prefers DB-driven shift definitions (shiftConfig.shifts), falls back to legacy day/night config.
|
|
6672
6674
|
*
|
|
6673
6675
|
* @param timezone - IANA timezone string (e.g., 'Asia/Kolkata') from config.
|
|
@@ -6679,7 +6681,7 @@ declare const getCurrentShift: (timezone: string, shiftConfig?: ShiftConfig | nu
|
|
|
6679
6681
|
/**
|
|
6680
6682
|
* Determines the currently active shift for a line if one exists.
|
|
6681
6683
|
* Unlike getCurrentShift(), this returns null during schedule gaps instead of
|
|
6682
|
-
*
|
|
6684
|
+
* choosing any same-day fallback shift.
|
|
6683
6685
|
*/
|
|
6684
6686
|
declare const getActiveShift: (timezone: string, shiftConfig?: ShiftConfig | null, now?: Date) => CurrentShiftResult | null;
|
|
6685
6687
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -6667,7 +6667,9 @@ declare const filterDataByDateKeyRange: <T extends {
|
|
|
6667
6667
|
*/
|
|
6668
6668
|
declare const getShiftWorkDurationSeconds: (shiftConfig: ShiftConfig | null | undefined, shiftId: number) => number | null;
|
|
6669
6669
|
/**
|
|
6670
|
-
* Determines the
|
|
6670
|
+
* Determines the active shift when one exists. Otherwise stays on the current
|
|
6671
|
+
* local calendar date and returns either the most recently completed shift from
|
|
6672
|
+
* today or, if none has completed yet, the next upcoming shift from today.
|
|
6671
6673
|
* Prefers DB-driven shift definitions (shiftConfig.shifts), falls back to legacy day/night config.
|
|
6672
6674
|
*
|
|
6673
6675
|
* @param timezone - IANA timezone string (e.g., 'Asia/Kolkata') from config.
|
|
@@ -6679,7 +6681,7 @@ declare const getCurrentShift: (timezone: string, shiftConfig?: ShiftConfig | nu
|
|
|
6679
6681
|
/**
|
|
6680
6682
|
* Determines the currently active shift for a line if one exists.
|
|
6681
6683
|
* Unlike getCurrentShift(), this returns null during schedule gaps instead of
|
|
6682
|
-
*
|
|
6684
|
+
* choosing any same-day fallback shift.
|
|
6683
6685
|
*/
|
|
6684
6686
|
declare const getActiveShift: (timezone: string, shiftConfig?: ShiftConfig | null, now?: Date) => CurrentShiftResult | null;
|
|
6685
6687
|
/**
|
package/dist/index.js
CHANGED
|
@@ -3626,12 +3626,81 @@ var determineActiveShiftFromDefinitions = (timezone, shifts, now4 = /* @__PURE__
|
|
|
3626
3626
|
}
|
|
3627
3627
|
return null;
|
|
3628
3628
|
};
|
|
3629
|
-
var
|
|
3630
|
-
const
|
|
3631
|
-
|
|
3629
|
+
var buildSameDayShiftOccurrence = (timezone, shift, now4 = /* @__PURE__ */ new Date()) => {
|
|
3630
|
+
const zonedNow = dateFnsTz.toZonedTime(now4, timezone);
|
|
3631
|
+
zonedNow.getHours() * 60 + zonedNow.getMinutes();
|
|
3632
|
+
const startMinutes = parseTimeToMinutes(shift.startTime);
|
|
3633
|
+
const durationMinutes = calculateDurationMinutes(shift.startTime, shift.endTime);
|
|
3634
|
+
if (!Number.isFinite(startMinutes) || !Number.isFinite(durationMinutes) || durationMinutes <= 0) {
|
|
3635
|
+
return null;
|
|
3636
|
+
}
|
|
3637
|
+
const occurrenceStart = new Date(zonedNow);
|
|
3638
|
+
occurrenceStart.setHours(0, 0, 0, 0);
|
|
3639
|
+
occurrenceStart.setHours(Math.floor(startMinutes / 60), startMinutes % 60, 0, 0);
|
|
3640
|
+
const occurrenceEnd = new Date(occurrenceStart.getTime() + durationMinutes * 60 * 1e3);
|
|
3641
|
+
return {
|
|
3642
|
+
shift,
|
|
3643
|
+
operationalDate: dateFns.format(occurrenceStart, "yyyy-MM-dd"),
|
|
3644
|
+
occurrenceStart,
|
|
3645
|
+
occurrenceEnd
|
|
3646
|
+
};
|
|
3647
|
+
};
|
|
3648
|
+
var determineCurrentOrPreviousShiftFromDefinitions = (timezone, shifts, now4 = /* @__PURE__ */ new Date()) => {
|
|
3649
|
+
const activeShift = determineActiveShiftFromDefinitions(timezone, shifts, now4);
|
|
3632
3650
|
if (activeShift) {
|
|
3633
3651
|
return activeShift;
|
|
3634
3652
|
}
|
|
3653
|
+
const sameDayOccurrences = shifts.map((shift) => buildSameDayShiftOccurrence(timezone, shift, now4)).filter((occurrence) => occurrence !== null);
|
|
3654
|
+
if (!sameDayOccurrences.length) {
|
|
3655
|
+
return null;
|
|
3656
|
+
}
|
|
3657
|
+
const zonedNow = dateFnsTz.toZonedTime(now4, timezone);
|
|
3658
|
+
const completedOccurrences = sameDayOccurrences.filter(
|
|
3659
|
+
(occurrence) => occurrence.occurrenceEnd.getTime() <= zonedNow.getTime()
|
|
3660
|
+
);
|
|
3661
|
+
let chosenOccurrence;
|
|
3662
|
+
if (completedOccurrences.length > 0) {
|
|
3663
|
+
chosenOccurrence = completedOccurrences.reduce((best, candidate) => {
|
|
3664
|
+
if (candidate.occurrenceEnd.getTime() > best.occurrenceEnd.getTime()) {
|
|
3665
|
+
return candidate;
|
|
3666
|
+
}
|
|
3667
|
+
if (candidate.occurrenceEnd.getTime() === best.occurrenceEnd.getTime() && candidate.shift.shiftId > best.shift.shiftId) {
|
|
3668
|
+
return candidate;
|
|
3669
|
+
}
|
|
3670
|
+
return best;
|
|
3671
|
+
});
|
|
3672
|
+
} else {
|
|
3673
|
+
const upcomingOccurrences = sameDayOccurrences.filter(
|
|
3674
|
+
(occurrence) => occurrence.occurrenceStart.getTime() > zonedNow.getTime()
|
|
3675
|
+
);
|
|
3676
|
+
if (!upcomingOccurrences.length) {
|
|
3677
|
+
return null;
|
|
3678
|
+
}
|
|
3679
|
+
chosenOccurrence = upcomingOccurrences.reduce((best, candidate) => {
|
|
3680
|
+
if (candidate.occurrenceStart.getTime() < best.occurrenceStart.getTime()) {
|
|
3681
|
+
return candidate;
|
|
3682
|
+
}
|
|
3683
|
+
if (candidate.occurrenceStart.getTime() === best.occurrenceStart.getTime() && candidate.shift.shiftId < best.shift.shiftId) {
|
|
3684
|
+
return candidate;
|
|
3685
|
+
}
|
|
3686
|
+
return best;
|
|
3687
|
+
});
|
|
3688
|
+
}
|
|
3689
|
+
return {
|
|
3690
|
+
shiftId: chosenOccurrence.shift.shiftId,
|
|
3691
|
+
shiftName: chosenOccurrence.shift.shiftName,
|
|
3692
|
+
startTime: chosenOccurrence.shift.startTime,
|
|
3693
|
+
endTime: chosenOccurrence.shift.endTime,
|
|
3694
|
+
timezone,
|
|
3695
|
+
date: chosenOccurrence.operationalDate
|
|
3696
|
+
};
|
|
3697
|
+
};
|
|
3698
|
+
var getCurrentShift = (timezone, shiftConfig, now4 = /* @__PURE__ */ new Date()) => {
|
|
3699
|
+
const { shifts, timezone: effectiveTz } = normalizeShiftDefinitions(timezone, shiftConfig);
|
|
3700
|
+
const resolvedShift = determineCurrentOrPreviousShiftFromDefinitions(effectiveTz, shifts, now4);
|
|
3701
|
+
if (resolvedShift) {
|
|
3702
|
+
return resolvedShift;
|
|
3703
|
+
}
|
|
3635
3704
|
const fallbackShift = shifts[0];
|
|
3636
3705
|
return {
|
|
3637
3706
|
shiftId: fallbackShift.shiftId,
|
|
@@ -4006,7 +4075,7 @@ var dashboardService = {
|
|
|
4006
4075
|
const factoryViewId = entityConfig.factoryViewId ?? "factory";
|
|
4007
4076
|
const defaultTimezone = dateTimeConfig.defaultTimezone;
|
|
4008
4077
|
const currentShiftResult = getCurrentShift(defaultTimezone, shiftConfig);
|
|
4009
|
-
const queryDate = dateProp ||
|
|
4078
|
+
const queryDate = dateProp || currentShiftResult.date;
|
|
4010
4079
|
const queryShiftId = shiftProp ?? currentShiftResult.shiftId;
|
|
4011
4080
|
const lineId = lineIdInput;
|
|
4012
4081
|
let query = supabase.from(metricsTable).select("company_id,line_id,shift_id,date,workspace_id,workspace_name,total_output,avg_pph,performance_score,avg_cycle_time,trend_score,ideal_output,efficiency,total_day_output").eq("shift_id", queryShiftId).eq("date", queryDate);
|
|
@@ -4055,7 +4124,7 @@ var dashboardService = {
|
|
|
4055
4124
|
const metricsTable = `${metricsTablePrefixStr}_${companyId.replace(/-/g, "_")}`;
|
|
4056
4125
|
const defaultTimezone = dateTimeConfig.defaultTimezone;
|
|
4057
4126
|
const currentShiftResult = getCurrentShift(defaultTimezone, shiftConfig);
|
|
4058
|
-
const queryDate = dateProp ||
|
|
4127
|
+
const queryDate = dateProp || currentShiftResult.date;
|
|
4059
4128
|
const queryShiftId = shiftIdProp !== void 0 ? shiftIdProp : currentShiftResult.shiftId;
|
|
4060
4129
|
try {
|
|
4061
4130
|
const { data, error } = await supabase.from(metricsTable).select("*").eq("workspace_id", workspaceUuid).eq("date", queryDate).eq("shift_id", queryShiftId).maybeSingle();
|
|
@@ -4364,7 +4433,7 @@ var dashboardService = {
|
|
|
4364
4433
|
const defaultTimezone = dateTimeConfig.defaultTimezone;
|
|
4365
4434
|
const lineIdToQuery = lineIdInput || factoryViewId;
|
|
4366
4435
|
const currentShiftResult = getCurrentShift(defaultTimezone, shiftConfig);
|
|
4367
|
-
const queryDate = dateProp ||
|
|
4436
|
+
const queryDate = dateProp || currentShiftResult.date;
|
|
4368
4437
|
const queryShiftId = shiftProp !== void 0 ? shiftProp : currentShiftResult.shiftId;
|
|
4369
4438
|
try {
|
|
4370
4439
|
if (lineIdToQuery === factoryViewId) {
|
|
@@ -12488,8 +12557,8 @@ var useWorkspaceDetailedMetrics = (workspaceId, date, shiftId, options) => {
|
|
|
12488
12557
|
return;
|
|
12489
12558
|
}
|
|
12490
12559
|
const channels = [];
|
|
12491
|
-
const operationalDate = operationalDateFromKey || date || getOperationalDate(defaultTimezone);
|
|
12492
12560
|
const currentShift = getCurrentShift(defaultTimezone, shiftConfig);
|
|
12561
|
+
const operationalDate = operationalDateFromKey || date || currentShift.date;
|
|
12493
12562
|
const queryShiftId = operationalShiftIdFromKey ?? shiftId ?? currentShift.shiftId;
|
|
12494
12563
|
fetchMetrics();
|
|
12495
12564
|
if (!realtimeEnabled) {
|
|
@@ -12845,14 +12914,16 @@ var useLineWorkspaceMetrics = (lineId, options) => {
|
|
|
12845
12914
|
const [loading, setLoading] = React143.useState(true);
|
|
12846
12915
|
const [error, setError] = React143.useState(null);
|
|
12847
12916
|
const [initialized, setInitialized] = React143.useState(false);
|
|
12848
|
-
const
|
|
12917
|
+
const currentShift = React143.useMemo(() => {
|
|
12849
12918
|
const effectiveTimezone = timezone || dateTimeConfig.defaultTimezone || "Asia/Kolkata";
|
|
12850
|
-
|
|
12919
|
+
return getCurrentShift(effectiveTimezone, shiftConfig);
|
|
12920
|
+
}, [timezone, dateTimeConfig.defaultTimezone, shiftConfig]);
|
|
12921
|
+
const queryShiftId = React143.useMemo(() => {
|
|
12851
12922
|
return options?.initialShiftId !== void 0 ? options.initialShiftId : currentShift.shiftId;
|
|
12852
|
-
}, [options?.initialShiftId,
|
|
12923
|
+
}, [options?.initialShiftId, currentShift.shiftId]);
|
|
12853
12924
|
const queryDate = React143.useMemo(() => {
|
|
12854
|
-
return options?.initialDate ||
|
|
12855
|
-
}, [options?.initialDate,
|
|
12925
|
+
return options?.initialDate || currentShift.date;
|
|
12926
|
+
}, [options?.initialDate, currentShift.date]);
|
|
12856
12927
|
const metricsTable = React143.useMemo(() => {
|
|
12857
12928
|
const companyId = entityConfig.companyId;
|
|
12858
12929
|
if (!companyId) return "";
|
|
@@ -13076,10 +13147,9 @@ var useLineDetailedMetrics = (lineIdFromProp) => {
|
|
|
13076
13147
|
setError(null);
|
|
13077
13148
|
try {
|
|
13078
13149
|
const currentShiftDetails = getCurrentShift(defaultTimezone, shiftConfig);
|
|
13079
|
-
const operationalDate = getOperationalDate(defaultTimezone, new Date(currentShiftDetails.date));
|
|
13080
13150
|
const data = await dashboardService.getDetailedLineInfo(
|
|
13081
13151
|
lineIdToUse,
|
|
13082
|
-
|
|
13152
|
+
currentShiftDetails.date,
|
|
13083
13153
|
currentShiftDetails.shiftId
|
|
13084
13154
|
);
|
|
13085
13155
|
setLineData(data);
|
|
@@ -13103,7 +13173,7 @@ var useLineDetailedMetrics = (lineIdFromProp) => {
|
|
|
13103
13173
|
}
|
|
13104
13174
|
fetchData();
|
|
13105
13175
|
const currentShiftDetails = getCurrentShift(defaultTimezone, shiftConfig);
|
|
13106
|
-
const operationalDate =
|
|
13176
|
+
const operationalDate = currentShiftDetails.date;
|
|
13107
13177
|
const currentShiftId = currentShiftDetails.shiftId;
|
|
13108
13178
|
let filterString = "";
|
|
13109
13179
|
let targetLineIdsForSubscription = [];
|
|
@@ -14868,7 +14938,7 @@ var useRealtimeLineMetrics = ({
|
|
|
14868
14938
|
() => urlShiftId !== void 0 ? urlShiftId : currentShift.shiftId,
|
|
14869
14939
|
[urlShiftId, currentShift.shiftId]
|
|
14870
14940
|
);
|
|
14871
|
-
const date = React143.useMemo(() => urlDate ||
|
|
14941
|
+
const date = React143.useMemo(() => urlDate || currentShift.date, [urlDate, currentShift.date]);
|
|
14872
14942
|
const fetchData = React143.useCallback(async () => {
|
|
14873
14943
|
try {
|
|
14874
14944
|
if (!lineIdRef.current || isFetchingRef.current || enabled === false) return;
|
|
@@ -14999,7 +15069,7 @@ var useRealtimeLineMetrics = ({
|
|
|
14999
15069
|
const companyId = entityConfig.companyId;
|
|
15000
15070
|
const metricsTablePrefix = getMetricsTablePrefix();
|
|
15001
15071
|
const metricsTable = `${metricsTablePrefix}_${(companyId || "").replace(/-/g, "_")}`;
|
|
15002
|
-
const currentDate = urlDate ||
|
|
15072
|
+
const currentDate = urlDate || currentShift.date;
|
|
15003
15073
|
const filter2 = `line_id=in.(${filteredLineIds.join(",")})`;
|
|
15004
15074
|
const lineMetricsChannel = supabase.channel(`line-metrics-${timestamp}`).on(
|
|
15005
15075
|
"postgres_changes",
|
|
@@ -17684,8 +17754,11 @@ var useAllWorkspaceMetrics = (options) => {
|
|
|
17684
17754
|
if (shiftGroups.length > 0) {
|
|
17685
17755
|
return shiftGroups[0].date;
|
|
17686
17756
|
}
|
|
17687
|
-
return
|
|
17688
|
-
|
|
17757
|
+
return getCurrentShift(
|
|
17758
|
+
timezone || dateTimeConfig.defaultTimezone || "Asia/Kolkata",
|
|
17759
|
+
staticShiftConfig
|
|
17760
|
+
).date;
|
|
17761
|
+
}, [options?.initialDate, shiftGroups, timezone, dateTimeConfig.defaultTimezone, staticShiftConfig]);
|
|
17689
17762
|
const metricsTable = React143.useMemo(() => {
|
|
17690
17763
|
const companyId = entityConfig.companyId;
|
|
17691
17764
|
if (!companyId) return "";
|
|
@@ -51949,11 +52022,11 @@ var getWorkspaceStyles = (position, isPlaceholder = false) => {
|
|
|
51949
52022
|
${isPlaceholder ? "cursor-default" : ""}`;
|
|
51950
52023
|
};
|
|
51951
52024
|
var formatPercentRange = (min, max) => {
|
|
51952
|
-
const
|
|
52025
|
+
const format10 = (value) => Number.isInteger(value) ? `${value}` : value.toFixed(1);
|
|
51953
52026
|
if (min >= 100 || max >= 100) {
|
|
51954
|
-
return `${
|
|
52027
|
+
return `${format10(min)}+%`;
|
|
51955
52028
|
}
|
|
51956
|
-
return `${
|
|
52029
|
+
return `${format10(min)}-${format10(max)}%`;
|
|
51957
52030
|
};
|
|
51958
52031
|
var Legend5 = ({
|
|
51959
52032
|
useBottleneckLabel = false,
|
|
@@ -60386,8 +60459,7 @@ var FactoryView = ({
|
|
|
60386
60459
|
setLoading(false);
|
|
60387
60460
|
return;
|
|
60388
60461
|
}
|
|
60389
|
-
const { shiftId } = getCurrentShift(timezone, shiftConfig);
|
|
60390
|
-
const date = getOperationalDate(timezone);
|
|
60462
|
+
const { shiftId, date } = getCurrentShift(timezone, shiftConfig);
|
|
60391
60463
|
const hourlyDataPromises = effectiveLineIds.map(
|
|
60392
60464
|
(lineId) => supabase.from("line_hourly_metrics").select("hour, efficiency").eq("line_id", lineId).eq("shift_id", shiftId).eq("date", date).order("hour", { ascending: false }).limit(5)
|
|
60393
60465
|
);
|
|
@@ -60960,6 +61032,7 @@ var useLiveMonitorBootstrap = ({
|
|
|
60960
61032
|
[normalizedLineIds]
|
|
60961
61033
|
);
|
|
60962
61034
|
const [state, setState] = React143.useState(() => createEmptyState());
|
|
61035
|
+
const [rawState, setRawState] = React143.useState(null);
|
|
60963
61036
|
const [isLoading, setIsLoading] = React143.useState(false);
|
|
60964
61037
|
const [error, setError] = React143.useState(null);
|
|
60965
61038
|
const activeRequestIdRef = React143.useRef(0);
|
|
@@ -60990,62 +61063,80 @@ var useLiveMonitorBootstrap = ({
|
|
|
60990
61063
|
if (requestId !== activeRequestIdRef.current) {
|
|
60991
61064
|
return;
|
|
60992
61065
|
}
|
|
61066
|
+
setRawState({
|
|
61067
|
+
requestKey,
|
|
61068
|
+
normalizedLineIds,
|
|
61069
|
+
response
|
|
61070
|
+
});
|
|
61071
|
+
} catch (fetchError) {
|
|
61072
|
+
if (requestId !== activeRequestIdRef.current) {
|
|
61073
|
+
return;
|
|
61074
|
+
}
|
|
61075
|
+
setError(fetchError instanceof Error ? fetchError : new Error("Failed to load live monitor bootstrap"));
|
|
61076
|
+
} finally {
|
|
61077
|
+
if (requestId === activeRequestIdRef.current) {
|
|
61078
|
+
setIsLoading(false);
|
|
61079
|
+
}
|
|
61080
|
+
}
|
|
61081
|
+
}, [
|
|
61082
|
+
enabled,
|
|
61083
|
+
supabase,
|
|
61084
|
+
resolvedCompanyId,
|
|
61085
|
+
normalizedLineIds,
|
|
61086
|
+
requestKey
|
|
61087
|
+
]);
|
|
61088
|
+
React143.useEffect(() => {
|
|
61089
|
+
if (!enabled || !rawState || !resolvedCompanyId) {
|
|
61090
|
+
return;
|
|
61091
|
+
}
|
|
61092
|
+
try {
|
|
60993
61093
|
const workspaceMetrics = transformMonitorWorkspaceMetrics({
|
|
60994
|
-
rows: response.workspace_metrics || [],
|
|
61094
|
+
rows: rawState.response.workspace_metrics || [],
|
|
60995
61095
|
companyId: resolvedCompanyId,
|
|
60996
61096
|
workspaceConfig: effectiveWorkspaceConfig,
|
|
60997
61097
|
appTimezone: effectiveTimezone,
|
|
60998
|
-
lineMetrics: response.line_metrics || [],
|
|
61098
|
+
lineMetrics: rawState.response.line_metrics || [],
|
|
60999
61099
|
resolveShiftConfig: (lineId) => lineShiftConfigs?.get(lineId) || fallbackShiftConfig,
|
|
61000
61100
|
shouldOverrideShiftType: (lineId) => Boolean(lineShiftConfigs?.get(lineId)),
|
|
61001
61101
|
fallbackShiftConfig
|
|
61002
61102
|
});
|
|
61003
|
-
const activeBreaks = transformActiveBreaks(response.active_breaks_by_line);
|
|
61004
|
-
const metadata = normalizeMetadata(response.metadata);
|
|
61103
|
+
const activeBreaks = transformActiveBreaks(rawState.response.active_breaks_by_line);
|
|
61104
|
+
const metadata = normalizeMetadata(rawState.response.metadata);
|
|
61005
61105
|
const workspaceIds = workspaceMetrics.map((metric) => metric.workspace_uuid).filter((workspaceId) => Boolean(workspaceId));
|
|
61006
|
-
const videoStreamsByWorkspaceId = response.video_streams_by_workspace_id || {};
|
|
61106
|
+
const videoStreamsByWorkspaceId = rawState.response.video_streams_by_workspace_id || {};
|
|
61007
61107
|
if (metadata.idleTimeVlmByLine) {
|
|
61008
61108
|
hydrateFromBackend(metadata.idleTimeVlmByLine);
|
|
61009
61109
|
}
|
|
61010
61110
|
workspaceService.primeWorkspaceVideoStreamsCache({
|
|
61011
61111
|
streams: videoStreamsByWorkspaceId,
|
|
61012
61112
|
workspaceIds,
|
|
61013
|
-
lineIds: normalizedLineIds
|
|
61113
|
+
lineIds: rawState.normalizedLineIds
|
|
61014
61114
|
});
|
|
61015
61115
|
setState({
|
|
61016
|
-
requestKey,
|
|
61017
|
-
resolvedScope: response.resolved_scope || [],
|
|
61018
|
-
scopeKey: response.scope_key || null,
|
|
61019
|
-
lines: response.lines || [],
|
|
61116
|
+
requestKey: rawState.requestKey,
|
|
61117
|
+
resolvedScope: rawState.response.resolved_scope || [],
|
|
61118
|
+
scopeKey: rawState.response.scope_key || null,
|
|
61119
|
+
lines: rawState.response.lines || [],
|
|
61020
61120
|
workspaceMetrics,
|
|
61021
|
-
lineMetrics: response.line_metrics || [],
|
|
61022
|
-
kpiTrend: response.kpi_trend || null,
|
|
61121
|
+
lineMetrics: rawState.response.line_metrics || [],
|
|
61122
|
+
kpiTrend: rawState.response.kpi_trend || null,
|
|
61023
61123
|
activeBreaks,
|
|
61024
61124
|
videoStreamsByWorkspaceId,
|
|
61025
|
-
efficiencyLegend: response.efficiency_legend || null,
|
|
61125
|
+
efficiencyLegend: rawState.response.efficiency_legend || null,
|
|
61026
61126
|
metadata
|
|
61027
61127
|
});
|
|
61028
|
-
} catch (
|
|
61029
|
-
|
|
61030
|
-
return;
|
|
61031
|
-
}
|
|
61032
|
-
setError(fetchError instanceof Error ? fetchError : new Error("Failed to load live monitor bootstrap"));
|
|
61033
|
-
} finally {
|
|
61034
|
-
if (requestId === activeRequestIdRef.current) {
|
|
61035
|
-
setIsLoading(false);
|
|
61036
|
-
}
|
|
61128
|
+
} catch (processingError) {
|
|
61129
|
+
setError(processingError instanceof Error ? processingError : new Error("Failed to process live monitor bootstrap"));
|
|
61037
61130
|
}
|
|
61038
61131
|
}, [
|
|
61039
61132
|
enabled,
|
|
61040
|
-
|
|
61133
|
+
rawState,
|
|
61041
61134
|
resolvedCompanyId,
|
|
61042
|
-
normalizedLineIds,
|
|
61043
|
-
requestKey,
|
|
61044
|
-
hydrateFromBackend,
|
|
61045
61135
|
effectiveWorkspaceConfig,
|
|
61046
61136
|
effectiveTimezone,
|
|
61047
61137
|
lineShiftConfigs,
|
|
61048
|
-
fallbackShiftConfig
|
|
61138
|
+
fallbackShiftConfig,
|
|
61139
|
+
hydrateFromBackend
|
|
61049
61140
|
]);
|
|
61050
61141
|
React143.useEffect(() => {
|
|
61051
61142
|
if (!enabled) {
|
|
@@ -61054,6 +61145,7 @@ var useLiveMonitorBootstrap = ({
|
|
|
61054
61145
|
}
|
|
61055
61146
|
if (!resolvedCompanyId || normalizedLineIds.length === 0 || !supabase) {
|
|
61056
61147
|
setState(createEmptyState());
|
|
61148
|
+
setRawState(null);
|
|
61057
61149
|
setIsLoading(false);
|
|
61058
61150
|
setError(null);
|
|
61059
61151
|
return;
|
|
@@ -62927,8 +63019,8 @@ var useLineDetailPageData = ({
|
|
|
62927
63019
|
[urlShiftId, currentShift]
|
|
62928
63020
|
);
|
|
62929
63021
|
const queryDate = React143.useMemo(
|
|
62930
|
-
() => urlDate || getOperationalDate(timezone),
|
|
62931
|
-
[urlDate, timezone]
|
|
63022
|
+
() => urlDate || currentShift?.date || getOperationalDate(timezone),
|
|
63023
|
+
[urlDate, currentShift?.date, timezone]
|
|
62932
63024
|
);
|
|
62933
63025
|
const [detailResponse, setDetailResponse] = React143.useState(null);
|
|
62934
63026
|
const [loading, setLoading] = React143.useState(true);
|
|
@@ -65664,7 +65756,7 @@ var formatDateKey2 = (dateKey, timezone, options) => {
|
|
|
65664
65756
|
return dateKey;
|
|
65665
65757
|
}
|
|
65666
65758
|
};
|
|
65667
|
-
var LeaderboardCountdown = ({ targetDate, format:
|
|
65759
|
+
var LeaderboardCountdown = ({ targetDate, format: format10, finishedLabel = "Finished", placeholder = "--", onFinished }) => {
|
|
65668
65760
|
const [time2, setTime] = React143.useState("");
|
|
65669
65761
|
const hasFinishedRef = React143.useRef(false);
|
|
65670
65762
|
React143.useEffect(() => {
|
|
@@ -65686,7 +65778,7 @@ var LeaderboardCountdown = ({ targetDate, format: format9, finishedLabel = "Fini
|
|
|
65686
65778
|
}
|
|
65687
65779
|
return;
|
|
65688
65780
|
}
|
|
65689
|
-
if (
|
|
65781
|
+
if (format10 === "days") {
|
|
65690
65782
|
const days = Math.floor(diff / (1e3 * 60 * 60 * 24));
|
|
65691
65783
|
const hours = Math.floor(diff % (1e3 * 60 * 60 * 24) / (1e3 * 60 * 60));
|
|
65692
65784
|
setTime(`${days} days ${hours} hours`);
|
|
@@ -65701,7 +65793,7 @@ var LeaderboardCountdown = ({ targetDate, format: format9, finishedLabel = "Fini
|
|
|
65701
65793
|
tick();
|
|
65702
65794
|
const interval = setInterval(tick, 1e3);
|
|
65703
65795
|
return () => clearInterval(interval);
|
|
65704
|
-
}, [targetDate,
|
|
65796
|
+
}, [targetDate, format10, finishedLabel, placeholder, onFinished]);
|
|
65705
65797
|
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: time2 });
|
|
65706
65798
|
};
|
|
65707
65799
|
var LinesLeaderboard = ({
|
package/dist/index.mjs
CHANGED
|
@@ -3597,12 +3597,81 @@ var determineActiveShiftFromDefinitions = (timezone, shifts, now4 = /* @__PURE__
|
|
|
3597
3597
|
}
|
|
3598
3598
|
return null;
|
|
3599
3599
|
};
|
|
3600
|
-
var
|
|
3601
|
-
const
|
|
3602
|
-
|
|
3600
|
+
var buildSameDayShiftOccurrence = (timezone, shift, now4 = /* @__PURE__ */ new Date()) => {
|
|
3601
|
+
const zonedNow = toZonedTime(now4, timezone);
|
|
3602
|
+
zonedNow.getHours() * 60 + zonedNow.getMinutes();
|
|
3603
|
+
const startMinutes = parseTimeToMinutes(shift.startTime);
|
|
3604
|
+
const durationMinutes = calculateDurationMinutes(shift.startTime, shift.endTime);
|
|
3605
|
+
if (!Number.isFinite(startMinutes) || !Number.isFinite(durationMinutes) || durationMinutes <= 0) {
|
|
3606
|
+
return null;
|
|
3607
|
+
}
|
|
3608
|
+
const occurrenceStart = new Date(zonedNow);
|
|
3609
|
+
occurrenceStart.setHours(0, 0, 0, 0);
|
|
3610
|
+
occurrenceStart.setHours(Math.floor(startMinutes / 60), startMinutes % 60, 0, 0);
|
|
3611
|
+
const occurrenceEnd = new Date(occurrenceStart.getTime() + durationMinutes * 60 * 1e3);
|
|
3612
|
+
return {
|
|
3613
|
+
shift,
|
|
3614
|
+
operationalDate: format(occurrenceStart, "yyyy-MM-dd"),
|
|
3615
|
+
occurrenceStart,
|
|
3616
|
+
occurrenceEnd
|
|
3617
|
+
};
|
|
3618
|
+
};
|
|
3619
|
+
var determineCurrentOrPreviousShiftFromDefinitions = (timezone, shifts, now4 = /* @__PURE__ */ new Date()) => {
|
|
3620
|
+
const activeShift = determineActiveShiftFromDefinitions(timezone, shifts, now4);
|
|
3603
3621
|
if (activeShift) {
|
|
3604
3622
|
return activeShift;
|
|
3605
3623
|
}
|
|
3624
|
+
const sameDayOccurrences = shifts.map((shift) => buildSameDayShiftOccurrence(timezone, shift, now4)).filter((occurrence) => occurrence !== null);
|
|
3625
|
+
if (!sameDayOccurrences.length) {
|
|
3626
|
+
return null;
|
|
3627
|
+
}
|
|
3628
|
+
const zonedNow = toZonedTime(now4, timezone);
|
|
3629
|
+
const completedOccurrences = sameDayOccurrences.filter(
|
|
3630
|
+
(occurrence) => occurrence.occurrenceEnd.getTime() <= zonedNow.getTime()
|
|
3631
|
+
);
|
|
3632
|
+
let chosenOccurrence;
|
|
3633
|
+
if (completedOccurrences.length > 0) {
|
|
3634
|
+
chosenOccurrence = completedOccurrences.reduce((best, candidate) => {
|
|
3635
|
+
if (candidate.occurrenceEnd.getTime() > best.occurrenceEnd.getTime()) {
|
|
3636
|
+
return candidate;
|
|
3637
|
+
}
|
|
3638
|
+
if (candidate.occurrenceEnd.getTime() === best.occurrenceEnd.getTime() && candidate.shift.shiftId > best.shift.shiftId) {
|
|
3639
|
+
return candidate;
|
|
3640
|
+
}
|
|
3641
|
+
return best;
|
|
3642
|
+
});
|
|
3643
|
+
} else {
|
|
3644
|
+
const upcomingOccurrences = sameDayOccurrences.filter(
|
|
3645
|
+
(occurrence) => occurrence.occurrenceStart.getTime() > zonedNow.getTime()
|
|
3646
|
+
);
|
|
3647
|
+
if (!upcomingOccurrences.length) {
|
|
3648
|
+
return null;
|
|
3649
|
+
}
|
|
3650
|
+
chosenOccurrence = upcomingOccurrences.reduce((best, candidate) => {
|
|
3651
|
+
if (candidate.occurrenceStart.getTime() < best.occurrenceStart.getTime()) {
|
|
3652
|
+
return candidate;
|
|
3653
|
+
}
|
|
3654
|
+
if (candidate.occurrenceStart.getTime() === best.occurrenceStart.getTime() && candidate.shift.shiftId < best.shift.shiftId) {
|
|
3655
|
+
return candidate;
|
|
3656
|
+
}
|
|
3657
|
+
return best;
|
|
3658
|
+
});
|
|
3659
|
+
}
|
|
3660
|
+
return {
|
|
3661
|
+
shiftId: chosenOccurrence.shift.shiftId,
|
|
3662
|
+
shiftName: chosenOccurrence.shift.shiftName,
|
|
3663
|
+
startTime: chosenOccurrence.shift.startTime,
|
|
3664
|
+
endTime: chosenOccurrence.shift.endTime,
|
|
3665
|
+
timezone,
|
|
3666
|
+
date: chosenOccurrence.operationalDate
|
|
3667
|
+
};
|
|
3668
|
+
};
|
|
3669
|
+
var getCurrentShift = (timezone, shiftConfig, now4 = /* @__PURE__ */ new Date()) => {
|
|
3670
|
+
const { shifts, timezone: effectiveTz } = normalizeShiftDefinitions(timezone, shiftConfig);
|
|
3671
|
+
const resolvedShift = determineCurrentOrPreviousShiftFromDefinitions(effectiveTz, shifts, now4);
|
|
3672
|
+
if (resolvedShift) {
|
|
3673
|
+
return resolvedShift;
|
|
3674
|
+
}
|
|
3606
3675
|
const fallbackShift = shifts[0];
|
|
3607
3676
|
return {
|
|
3608
3677
|
shiftId: fallbackShift.shiftId,
|
|
@@ -3977,7 +4046,7 @@ var dashboardService = {
|
|
|
3977
4046
|
const factoryViewId = entityConfig.factoryViewId ?? "factory";
|
|
3978
4047
|
const defaultTimezone = dateTimeConfig.defaultTimezone;
|
|
3979
4048
|
const currentShiftResult = getCurrentShift(defaultTimezone, shiftConfig);
|
|
3980
|
-
const queryDate = dateProp ||
|
|
4049
|
+
const queryDate = dateProp || currentShiftResult.date;
|
|
3981
4050
|
const queryShiftId = shiftProp ?? currentShiftResult.shiftId;
|
|
3982
4051
|
const lineId = lineIdInput;
|
|
3983
4052
|
let query = supabase.from(metricsTable).select("company_id,line_id,shift_id,date,workspace_id,workspace_name,total_output,avg_pph,performance_score,avg_cycle_time,trend_score,ideal_output,efficiency,total_day_output").eq("shift_id", queryShiftId).eq("date", queryDate);
|
|
@@ -4026,7 +4095,7 @@ var dashboardService = {
|
|
|
4026
4095
|
const metricsTable = `${metricsTablePrefixStr}_${companyId.replace(/-/g, "_")}`;
|
|
4027
4096
|
const defaultTimezone = dateTimeConfig.defaultTimezone;
|
|
4028
4097
|
const currentShiftResult = getCurrentShift(defaultTimezone, shiftConfig);
|
|
4029
|
-
const queryDate = dateProp ||
|
|
4098
|
+
const queryDate = dateProp || currentShiftResult.date;
|
|
4030
4099
|
const queryShiftId = shiftIdProp !== void 0 ? shiftIdProp : currentShiftResult.shiftId;
|
|
4031
4100
|
try {
|
|
4032
4101
|
const { data, error } = await supabase.from(metricsTable).select("*").eq("workspace_id", workspaceUuid).eq("date", queryDate).eq("shift_id", queryShiftId).maybeSingle();
|
|
@@ -4335,7 +4404,7 @@ var dashboardService = {
|
|
|
4335
4404
|
const defaultTimezone = dateTimeConfig.defaultTimezone;
|
|
4336
4405
|
const lineIdToQuery = lineIdInput || factoryViewId;
|
|
4337
4406
|
const currentShiftResult = getCurrentShift(defaultTimezone, shiftConfig);
|
|
4338
|
-
const queryDate = dateProp ||
|
|
4407
|
+
const queryDate = dateProp || currentShiftResult.date;
|
|
4339
4408
|
const queryShiftId = shiftProp !== void 0 ? shiftProp : currentShiftResult.shiftId;
|
|
4340
4409
|
try {
|
|
4341
4410
|
if (lineIdToQuery === factoryViewId) {
|
|
@@ -12459,8 +12528,8 @@ var useWorkspaceDetailedMetrics = (workspaceId, date, shiftId, options) => {
|
|
|
12459
12528
|
return;
|
|
12460
12529
|
}
|
|
12461
12530
|
const channels = [];
|
|
12462
|
-
const operationalDate = operationalDateFromKey || date || getOperationalDate(defaultTimezone);
|
|
12463
12531
|
const currentShift = getCurrentShift(defaultTimezone, shiftConfig);
|
|
12532
|
+
const operationalDate = operationalDateFromKey || date || currentShift.date;
|
|
12464
12533
|
const queryShiftId = operationalShiftIdFromKey ?? shiftId ?? currentShift.shiftId;
|
|
12465
12534
|
fetchMetrics();
|
|
12466
12535
|
if (!realtimeEnabled) {
|
|
@@ -12816,14 +12885,16 @@ var useLineWorkspaceMetrics = (lineId, options) => {
|
|
|
12816
12885
|
const [loading, setLoading] = useState(true);
|
|
12817
12886
|
const [error, setError] = useState(null);
|
|
12818
12887
|
const [initialized, setInitialized] = useState(false);
|
|
12819
|
-
const
|
|
12888
|
+
const currentShift = useMemo(() => {
|
|
12820
12889
|
const effectiveTimezone = timezone || dateTimeConfig.defaultTimezone || "Asia/Kolkata";
|
|
12821
|
-
|
|
12890
|
+
return getCurrentShift(effectiveTimezone, shiftConfig);
|
|
12891
|
+
}, [timezone, dateTimeConfig.defaultTimezone, shiftConfig]);
|
|
12892
|
+
const queryShiftId = useMemo(() => {
|
|
12822
12893
|
return options?.initialShiftId !== void 0 ? options.initialShiftId : currentShift.shiftId;
|
|
12823
|
-
}, [options?.initialShiftId,
|
|
12894
|
+
}, [options?.initialShiftId, currentShift.shiftId]);
|
|
12824
12895
|
const queryDate = useMemo(() => {
|
|
12825
|
-
return options?.initialDate ||
|
|
12826
|
-
}, [options?.initialDate,
|
|
12896
|
+
return options?.initialDate || currentShift.date;
|
|
12897
|
+
}, [options?.initialDate, currentShift.date]);
|
|
12827
12898
|
const metricsTable = useMemo(() => {
|
|
12828
12899
|
const companyId = entityConfig.companyId;
|
|
12829
12900
|
if (!companyId) return "";
|
|
@@ -13047,10 +13118,9 @@ var useLineDetailedMetrics = (lineIdFromProp) => {
|
|
|
13047
13118
|
setError(null);
|
|
13048
13119
|
try {
|
|
13049
13120
|
const currentShiftDetails = getCurrentShift(defaultTimezone, shiftConfig);
|
|
13050
|
-
const operationalDate = getOperationalDate(defaultTimezone, new Date(currentShiftDetails.date));
|
|
13051
13121
|
const data = await dashboardService.getDetailedLineInfo(
|
|
13052
13122
|
lineIdToUse,
|
|
13053
|
-
|
|
13123
|
+
currentShiftDetails.date,
|
|
13054
13124
|
currentShiftDetails.shiftId
|
|
13055
13125
|
);
|
|
13056
13126
|
setLineData(data);
|
|
@@ -13074,7 +13144,7 @@ var useLineDetailedMetrics = (lineIdFromProp) => {
|
|
|
13074
13144
|
}
|
|
13075
13145
|
fetchData();
|
|
13076
13146
|
const currentShiftDetails = getCurrentShift(defaultTimezone, shiftConfig);
|
|
13077
|
-
const operationalDate =
|
|
13147
|
+
const operationalDate = currentShiftDetails.date;
|
|
13078
13148
|
const currentShiftId = currentShiftDetails.shiftId;
|
|
13079
13149
|
let filterString = "";
|
|
13080
13150
|
let targetLineIdsForSubscription = [];
|
|
@@ -14839,7 +14909,7 @@ var useRealtimeLineMetrics = ({
|
|
|
14839
14909
|
() => urlShiftId !== void 0 ? urlShiftId : currentShift.shiftId,
|
|
14840
14910
|
[urlShiftId, currentShift.shiftId]
|
|
14841
14911
|
);
|
|
14842
|
-
const date = useMemo(() => urlDate ||
|
|
14912
|
+
const date = useMemo(() => urlDate || currentShift.date, [urlDate, currentShift.date]);
|
|
14843
14913
|
const fetchData = useCallback(async () => {
|
|
14844
14914
|
try {
|
|
14845
14915
|
if (!lineIdRef.current || isFetchingRef.current || enabled === false) return;
|
|
@@ -14970,7 +15040,7 @@ var useRealtimeLineMetrics = ({
|
|
|
14970
15040
|
const companyId = entityConfig.companyId;
|
|
14971
15041
|
const metricsTablePrefix = getMetricsTablePrefix();
|
|
14972
15042
|
const metricsTable = `${metricsTablePrefix}_${(companyId || "").replace(/-/g, "_")}`;
|
|
14973
|
-
const currentDate = urlDate ||
|
|
15043
|
+
const currentDate = urlDate || currentShift.date;
|
|
14974
15044
|
const filter2 = `line_id=in.(${filteredLineIds.join(",")})`;
|
|
14975
15045
|
const lineMetricsChannel = supabase.channel(`line-metrics-${timestamp}`).on(
|
|
14976
15046
|
"postgres_changes",
|
|
@@ -17655,8 +17725,11 @@ var useAllWorkspaceMetrics = (options) => {
|
|
|
17655
17725
|
if (shiftGroups.length > 0) {
|
|
17656
17726
|
return shiftGroups[0].date;
|
|
17657
17727
|
}
|
|
17658
|
-
return
|
|
17659
|
-
|
|
17728
|
+
return getCurrentShift(
|
|
17729
|
+
timezone || dateTimeConfig.defaultTimezone || "Asia/Kolkata",
|
|
17730
|
+
staticShiftConfig
|
|
17731
|
+
).date;
|
|
17732
|
+
}, [options?.initialDate, shiftGroups, timezone, dateTimeConfig.defaultTimezone, staticShiftConfig]);
|
|
17660
17733
|
const metricsTable = useMemo(() => {
|
|
17661
17734
|
const companyId = entityConfig.companyId;
|
|
17662
17735
|
if (!companyId) return "";
|
|
@@ -51920,11 +51993,11 @@ var getWorkspaceStyles = (position, isPlaceholder = false) => {
|
|
|
51920
51993
|
${isPlaceholder ? "cursor-default" : ""}`;
|
|
51921
51994
|
};
|
|
51922
51995
|
var formatPercentRange = (min, max) => {
|
|
51923
|
-
const
|
|
51996
|
+
const format10 = (value) => Number.isInteger(value) ? `${value}` : value.toFixed(1);
|
|
51924
51997
|
if (min >= 100 || max >= 100) {
|
|
51925
|
-
return `${
|
|
51998
|
+
return `${format10(min)}+%`;
|
|
51926
51999
|
}
|
|
51927
|
-
return `${
|
|
52000
|
+
return `${format10(min)}-${format10(max)}%`;
|
|
51928
52001
|
};
|
|
51929
52002
|
var Legend5 = ({
|
|
51930
52003
|
useBottleneckLabel = false,
|
|
@@ -60357,8 +60430,7 @@ var FactoryView = ({
|
|
|
60357
60430
|
setLoading(false);
|
|
60358
60431
|
return;
|
|
60359
60432
|
}
|
|
60360
|
-
const { shiftId } = getCurrentShift(timezone, shiftConfig);
|
|
60361
|
-
const date = getOperationalDate(timezone);
|
|
60433
|
+
const { shiftId, date } = getCurrentShift(timezone, shiftConfig);
|
|
60362
60434
|
const hourlyDataPromises = effectiveLineIds.map(
|
|
60363
60435
|
(lineId) => supabase.from("line_hourly_metrics").select("hour, efficiency").eq("line_id", lineId).eq("shift_id", shiftId).eq("date", date).order("hour", { ascending: false }).limit(5)
|
|
60364
60436
|
);
|
|
@@ -60931,6 +61003,7 @@ var useLiveMonitorBootstrap = ({
|
|
|
60931
61003
|
[normalizedLineIds]
|
|
60932
61004
|
);
|
|
60933
61005
|
const [state, setState] = useState(() => createEmptyState());
|
|
61006
|
+
const [rawState, setRawState] = useState(null);
|
|
60934
61007
|
const [isLoading, setIsLoading] = useState(false);
|
|
60935
61008
|
const [error, setError] = useState(null);
|
|
60936
61009
|
const activeRequestIdRef = useRef(0);
|
|
@@ -60961,62 +61034,80 @@ var useLiveMonitorBootstrap = ({
|
|
|
60961
61034
|
if (requestId !== activeRequestIdRef.current) {
|
|
60962
61035
|
return;
|
|
60963
61036
|
}
|
|
61037
|
+
setRawState({
|
|
61038
|
+
requestKey,
|
|
61039
|
+
normalizedLineIds,
|
|
61040
|
+
response
|
|
61041
|
+
});
|
|
61042
|
+
} catch (fetchError) {
|
|
61043
|
+
if (requestId !== activeRequestIdRef.current) {
|
|
61044
|
+
return;
|
|
61045
|
+
}
|
|
61046
|
+
setError(fetchError instanceof Error ? fetchError : new Error("Failed to load live monitor bootstrap"));
|
|
61047
|
+
} finally {
|
|
61048
|
+
if (requestId === activeRequestIdRef.current) {
|
|
61049
|
+
setIsLoading(false);
|
|
61050
|
+
}
|
|
61051
|
+
}
|
|
61052
|
+
}, [
|
|
61053
|
+
enabled,
|
|
61054
|
+
supabase,
|
|
61055
|
+
resolvedCompanyId,
|
|
61056
|
+
normalizedLineIds,
|
|
61057
|
+
requestKey
|
|
61058
|
+
]);
|
|
61059
|
+
useEffect(() => {
|
|
61060
|
+
if (!enabled || !rawState || !resolvedCompanyId) {
|
|
61061
|
+
return;
|
|
61062
|
+
}
|
|
61063
|
+
try {
|
|
60964
61064
|
const workspaceMetrics = transformMonitorWorkspaceMetrics({
|
|
60965
|
-
rows: response.workspace_metrics || [],
|
|
61065
|
+
rows: rawState.response.workspace_metrics || [],
|
|
60966
61066
|
companyId: resolvedCompanyId,
|
|
60967
61067
|
workspaceConfig: effectiveWorkspaceConfig,
|
|
60968
61068
|
appTimezone: effectiveTimezone,
|
|
60969
|
-
lineMetrics: response.line_metrics || [],
|
|
61069
|
+
lineMetrics: rawState.response.line_metrics || [],
|
|
60970
61070
|
resolveShiftConfig: (lineId) => lineShiftConfigs?.get(lineId) || fallbackShiftConfig,
|
|
60971
61071
|
shouldOverrideShiftType: (lineId) => Boolean(lineShiftConfigs?.get(lineId)),
|
|
60972
61072
|
fallbackShiftConfig
|
|
60973
61073
|
});
|
|
60974
|
-
const activeBreaks = transformActiveBreaks(response.active_breaks_by_line);
|
|
60975
|
-
const metadata = normalizeMetadata(response.metadata);
|
|
61074
|
+
const activeBreaks = transformActiveBreaks(rawState.response.active_breaks_by_line);
|
|
61075
|
+
const metadata = normalizeMetadata(rawState.response.metadata);
|
|
60976
61076
|
const workspaceIds = workspaceMetrics.map((metric) => metric.workspace_uuid).filter((workspaceId) => Boolean(workspaceId));
|
|
60977
|
-
const videoStreamsByWorkspaceId = response.video_streams_by_workspace_id || {};
|
|
61077
|
+
const videoStreamsByWorkspaceId = rawState.response.video_streams_by_workspace_id || {};
|
|
60978
61078
|
if (metadata.idleTimeVlmByLine) {
|
|
60979
61079
|
hydrateFromBackend(metadata.idleTimeVlmByLine);
|
|
60980
61080
|
}
|
|
60981
61081
|
workspaceService.primeWorkspaceVideoStreamsCache({
|
|
60982
61082
|
streams: videoStreamsByWorkspaceId,
|
|
60983
61083
|
workspaceIds,
|
|
60984
|
-
lineIds: normalizedLineIds
|
|
61084
|
+
lineIds: rawState.normalizedLineIds
|
|
60985
61085
|
});
|
|
60986
61086
|
setState({
|
|
60987
|
-
requestKey,
|
|
60988
|
-
resolvedScope: response.resolved_scope || [],
|
|
60989
|
-
scopeKey: response.scope_key || null,
|
|
60990
|
-
lines: response.lines || [],
|
|
61087
|
+
requestKey: rawState.requestKey,
|
|
61088
|
+
resolvedScope: rawState.response.resolved_scope || [],
|
|
61089
|
+
scopeKey: rawState.response.scope_key || null,
|
|
61090
|
+
lines: rawState.response.lines || [],
|
|
60991
61091
|
workspaceMetrics,
|
|
60992
|
-
lineMetrics: response.line_metrics || [],
|
|
60993
|
-
kpiTrend: response.kpi_trend || null,
|
|
61092
|
+
lineMetrics: rawState.response.line_metrics || [],
|
|
61093
|
+
kpiTrend: rawState.response.kpi_trend || null,
|
|
60994
61094
|
activeBreaks,
|
|
60995
61095
|
videoStreamsByWorkspaceId,
|
|
60996
|
-
efficiencyLegend: response.efficiency_legend || null,
|
|
61096
|
+
efficiencyLegend: rawState.response.efficiency_legend || null,
|
|
60997
61097
|
metadata
|
|
60998
61098
|
});
|
|
60999
|
-
} catch (
|
|
61000
|
-
|
|
61001
|
-
return;
|
|
61002
|
-
}
|
|
61003
|
-
setError(fetchError instanceof Error ? fetchError : new Error("Failed to load live monitor bootstrap"));
|
|
61004
|
-
} finally {
|
|
61005
|
-
if (requestId === activeRequestIdRef.current) {
|
|
61006
|
-
setIsLoading(false);
|
|
61007
|
-
}
|
|
61099
|
+
} catch (processingError) {
|
|
61100
|
+
setError(processingError instanceof Error ? processingError : new Error("Failed to process live monitor bootstrap"));
|
|
61008
61101
|
}
|
|
61009
61102
|
}, [
|
|
61010
61103
|
enabled,
|
|
61011
|
-
|
|
61104
|
+
rawState,
|
|
61012
61105
|
resolvedCompanyId,
|
|
61013
|
-
normalizedLineIds,
|
|
61014
|
-
requestKey,
|
|
61015
|
-
hydrateFromBackend,
|
|
61016
61106
|
effectiveWorkspaceConfig,
|
|
61017
61107
|
effectiveTimezone,
|
|
61018
61108
|
lineShiftConfigs,
|
|
61019
|
-
fallbackShiftConfig
|
|
61109
|
+
fallbackShiftConfig,
|
|
61110
|
+
hydrateFromBackend
|
|
61020
61111
|
]);
|
|
61021
61112
|
useEffect(() => {
|
|
61022
61113
|
if (!enabled) {
|
|
@@ -61025,6 +61116,7 @@ var useLiveMonitorBootstrap = ({
|
|
|
61025
61116
|
}
|
|
61026
61117
|
if (!resolvedCompanyId || normalizedLineIds.length === 0 || !supabase) {
|
|
61027
61118
|
setState(createEmptyState());
|
|
61119
|
+
setRawState(null);
|
|
61028
61120
|
setIsLoading(false);
|
|
61029
61121
|
setError(null);
|
|
61030
61122
|
return;
|
|
@@ -62898,8 +62990,8 @@ var useLineDetailPageData = ({
|
|
|
62898
62990
|
[urlShiftId, currentShift]
|
|
62899
62991
|
);
|
|
62900
62992
|
const queryDate = useMemo(
|
|
62901
|
-
() => urlDate || getOperationalDate(timezone),
|
|
62902
|
-
[urlDate, timezone]
|
|
62993
|
+
() => urlDate || currentShift?.date || getOperationalDate(timezone),
|
|
62994
|
+
[urlDate, currentShift?.date, timezone]
|
|
62903
62995
|
);
|
|
62904
62996
|
const [detailResponse, setDetailResponse] = useState(null);
|
|
62905
62997
|
const [loading, setLoading] = useState(true);
|
|
@@ -65635,7 +65727,7 @@ var formatDateKey2 = (dateKey, timezone, options) => {
|
|
|
65635
65727
|
return dateKey;
|
|
65636
65728
|
}
|
|
65637
65729
|
};
|
|
65638
|
-
var LeaderboardCountdown = ({ targetDate, format:
|
|
65730
|
+
var LeaderboardCountdown = ({ targetDate, format: format10, finishedLabel = "Finished", placeholder = "--", onFinished }) => {
|
|
65639
65731
|
const [time2, setTime] = useState("");
|
|
65640
65732
|
const hasFinishedRef = useRef(false);
|
|
65641
65733
|
useEffect(() => {
|
|
@@ -65657,7 +65749,7 @@ var LeaderboardCountdown = ({ targetDate, format: format9, finishedLabel = "Fini
|
|
|
65657
65749
|
}
|
|
65658
65750
|
return;
|
|
65659
65751
|
}
|
|
65660
|
-
if (
|
|
65752
|
+
if (format10 === "days") {
|
|
65661
65753
|
const days = Math.floor(diff / (1e3 * 60 * 60 * 24));
|
|
65662
65754
|
const hours = Math.floor(diff % (1e3 * 60 * 60 * 24) / (1e3 * 60 * 60));
|
|
65663
65755
|
setTime(`${days} days ${hours} hours`);
|
|
@@ -65672,7 +65764,7 @@ var LeaderboardCountdown = ({ targetDate, format: format9, finishedLabel = "Fini
|
|
|
65672
65764
|
tick();
|
|
65673
65765
|
const interval = setInterval(tick, 1e3);
|
|
65674
65766
|
return () => clearInterval(interval);
|
|
65675
|
-
}, [targetDate,
|
|
65767
|
+
}, [targetDate, format10, finishedLabel, placeholder, onFinished]);
|
|
65676
65768
|
return /* @__PURE__ */ jsx(Fragment, { children: time2 });
|
|
65677
65769
|
};
|
|
65678
65770
|
var LinesLeaderboard = ({
|