@optifye/dashboard-core 6.11.47 → 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 +101 -29
- package/dist/index.mjs +101 -29
- 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
|
);
|
|
@@ -62947,8 +63019,8 @@ var useLineDetailPageData = ({
|
|
|
62947
63019
|
[urlShiftId, currentShift]
|
|
62948
63020
|
);
|
|
62949
63021
|
const queryDate = React143.useMemo(
|
|
62950
|
-
() => urlDate || getOperationalDate(timezone),
|
|
62951
|
-
[urlDate, timezone]
|
|
63022
|
+
() => urlDate || currentShift?.date || getOperationalDate(timezone),
|
|
63023
|
+
[urlDate, currentShift?.date, timezone]
|
|
62952
63024
|
);
|
|
62953
63025
|
const [detailResponse, setDetailResponse] = React143.useState(null);
|
|
62954
63026
|
const [loading, setLoading] = React143.useState(true);
|
|
@@ -65684,7 +65756,7 @@ var formatDateKey2 = (dateKey, timezone, options) => {
|
|
|
65684
65756
|
return dateKey;
|
|
65685
65757
|
}
|
|
65686
65758
|
};
|
|
65687
|
-
var LeaderboardCountdown = ({ targetDate, format:
|
|
65759
|
+
var LeaderboardCountdown = ({ targetDate, format: format10, finishedLabel = "Finished", placeholder = "--", onFinished }) => {
|
|
65688
65760
|
const [time2, setTime] = React143.useState("");
|
|
65689
65761
|
const hasFinishedRef = React143.useRef(false);
|
|
65690
65762
|
React143.useEffect(() => {
|
|
@@ -65706,7 +65778,7 @@ var LeaderboardCountdown = ({ targetDate, format: format9, finishedLabel = "Fini
|
|
|
65706
65778
|
}
|
|
65707
65779
|
return;
|
|
65708
65780
|
}
|
|
65709
|
-
if (
|
|
65781
|
+
if (format10 === "days") {
|
|
65710
65782
|
const days = Math.floor(diff / (1e3 * 60 * 60 * 24));
|
|
65711
65783
|
const hours = Math.floor(diff % (1e3 * 60 * 60 * 24) / (1e3 * 60 * 60));
|
|
65712
65784
|
setTime(`${days} days ${hours} hours`);
|
|
@@ -65721,7 +65793,7 @@ var LeaderboardCountdown = ({ targetDate, format: format9, finishedLabel = "Fini
|
|
|
65721
65793
|
tick();
|
|
65722
65794
|
const interval = setInterval(tick, 1e3);
|
|
65723
65795
|
return () => clearInterval(interval);
|
|
65724
|
-
}, [targetDate,
|
|
65796
|
+
}, [targetDate, format10, finishedLabel, placeholder, onFinished]);
|
|
65725
65797
|
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: time2 });
|
|
65726
65798
|
};
|
|
65727
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
|
);
|
|
@@ -62918,8 +62990,8 @@ var useLineDetailPageData = ({
|
|
|
62918
62990
|
[urlShiftId, currentShift]
|
|
62919
62991
|
);
|
|
62920
62992
|
const queryDate = useMemo(
|
|
62921
|
-
() => urlDate || getOperationalDate(timezone),
|
|
62922
|
-
[urlDate, timezone]
|
|
62993
|
+
() => urlDate || currentShift?.date || getOperationalDate(timezone),
|
|
62994
|
+
[urlDate, currentShift?.date, timezone]
|
|
62923
62995
|
);
|
|
62924
62996
|
const [detailResponse, setDetailResponse] = useState(null);
|
|
62925
62997
|
const [loading, setLoading] = useState(true);
|
|
@@ -65655,7 +65727,7 @@ var formatDateKey2 = (dateKey, timezone, options) => {
|
|
|
65655
65727
|
return dateKey;
|
|
65656
65728
|
}
|
|
65657
65729
|
};
|
|
65658
|
-
var LeaderboardCountdown = ({ targetDate, format:
|
|
65730
|
+
var LeaderboardCountdown = ({ targetDate, format: format10, finishedLabel = "Finished", placeholder = "--", onFinished }) => {
|
|
65659
65731
|
const [time2, setTime] = useState("");
|
|
65660
65732
|
const hasFinishedRef = useRef(false);
|
|
65661
65733
|
useEffect(() => {
|
|
@@ -65677,7 +65749,7 @@ var LeaderboardCountdown = ({ targetDate, format: format9, finishedLabel = "Fini
|
|
|
65677
65749
|
}
|
|
65678
65750
|
return;
|
|
65679
65751
|
}
|
|
65680
|
-
if (
|
|
65752
|
+
if (format10 === "days") {
|
|
65681
65753
|
const days = Math.floor(diff / (1e3 * 60 * 60 * 24));
|
|
65682
65754
|
const hours = Math.floor(diff % (1e3 * 60 * 60 * 24) / (1e3 * 60 * 60));
|
|
65683
65755
|
setTime(`${days} days ${hours} hours`);
|
|
@@ -65692,7 +65764,7 @@ var LeaderboardCountdown = ({ targetDate, format: format9, finishedLabel = "Fini
|
|
|
65692
65764
|
tick();
|
|
65693
65765
|
const interval = setInterval(tick, 1e3);
|
|
65694
65766
|
return () => clearInterval(interval);
|
|
65695
|
-
}, [targetDate,
|
|
65767
|
+
}, [targetDate, format10, finishedLabel, placeholder, onFinished]);
|
|
65696
65768
|
return /* @__PURE__ */ jsx(Fragment, { children: time2 });
|
|
65697
65769
|
};
|
|
65698
65770
|
var LinesLeaderboard = ({
|