@optifye/dashboard-core 6.1.5 → 6.1.7
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 +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +91 -29
- package/dist/index.mjs +91 -29
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -682,6 +682,7 @@ interface SimpleLine {
|
|
|
682
682
|
factory_name: string;
|
|
683
683
|
company_id: string;
|
|
684
684
|
company_name: string;
|
|
685
|
+
enable: boolean;
|
|
685
686
|
}
|
|
686
687
|
interface WorkspaceMonthlyMetric {
|
|
687
688
|
date: string;
|
|
@@ -759,6 +760,7 @@ interface Workspace {
|
|
|
759
760
|
action_pph_threshold: number | null;
|
|
760
761
|
action_cycle_time: number | null;
|
|
761
762
|
action_total_day_output: number | null;
|
|
763
|
+
enable: boolean;
|
|
762
764
|
}
|
|
763
765
|
interface ActionThreshold {
|
|
764
766
|
line_id: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -682,6 +682,7 @@ interface SimpleLine {
|
|
|
682
682
|
factory_name: string;
|
|
683
683
|
company_id: string;
|
|
684
684
|
company_name: string;
|
|
685
|
+
enable: boolean;
|
|
685
686
|
}
|
|
686
687
|
interface WorkspaceMonthlyMetric {
|
|
687
688
|
date: string;
|
|
@@ -759,6 +760,7 @@ interface Workspace {
|
|
|
759
760
|
action_pph_threshold: number | null;
|
|
760
761
|
action_cycle_time: number | null;
|
|
761
762
|
action_total_day_output: number | null;
|
|
763
|
+
enable: boolean;
|
|
762
764
|
}
|
|
763
765
|
interface ActionThreshold {
|
|
764
766
|
line_id: string;
|
package/dist/index.js
CHANGED
|
@@ -948,8 +948,9 @@ var dashboardService = {
|
|
|
948
948
|
factory_id,
|
|
949
949
|
factories!lines_factory_id_fkey(factory_name),
|
|
950
950
|
company_id,
|
|
951
|
-
companies!lines_company_id_fkey(company_name:name)
|
|
952
|
-
|
|
951
|
+
companies!lines_company_id_fkey(company_name:name),
|
|
952
|
+
enable
|
|
953
|
+
`).eq("enable", true);
|
|
953
954
|
if (companyId) {
|
|
954
955
|
query = query.eq("company_id", companyId);
|
|
955
956
|
}
|
|
@@ -965,7 +966,9 @@ var dashboardService = {
|
|
|
965
966
|
factory_id: line.factory_id,
|
|
966
967
|
factory_name: line.factories?.factory_name ?? "N/A",
|
|
967
968
|
company_id: line.company_id,
|
|
968
|
-
company_name: line.companies?.company_name ?? "N/A"
|
|
969
|
+
company_name: line.companies?.company_name ?? "N/A",
|
|
970
|
+
enable: line.enable ?? true
|
|
971
|
+
// Default to true if not specified
|
|
969
972
|
}));
|
|
970
973
|
return transformedLines;
|
|
971
974
|
} catch (err) {
|
|
@@ -1547,7 +1550,7 @@ var workspaceService = {
|
|
|
1547
1550
|
const config = _getDashboardConfigInstance();
|
|
1548
1551
|
const dbConfig = config?.databaseConfig;
|
|
1549
1552
|
const workspacesTable = getTable3(dbConfig, "workspaces");
|
|
1550
|
-
const { data, error } = await supabase.from(workspacesTable).select("id, line_id, workspace_id, action_id, action_pph_threshold, action_cycle_time, action_total_day_output").eq("line_id", lineId).order("workspace_id", { ascending: true });
|
|
1553
|
+
const { data, error } = await supabase.from(workspacesTable).select("id, line_id, workspace_id, action_id, action_pph_threshold, action_cycle_time, action_total_day_output, enable").eq("line_id", lineId).order("workspace_id", { ascending: true });
|
|
1551
1554
|
if (error) {
|
|
1552
1555
|
console.error(`Error fetching workspaces from ${workspacesTable}:`, error);
|
|
1553
1556
|
throw error;
|
|
@@ -1568,7 +1571,7 @@ var workspaceService = {
|
|
|
1568
1571
|
const dbConfig = config?.databaseConfig;
|
|
1569
1572
|
const workspacesTable = getTable3(dbConfig, "workspaces");
|
|
1570
1573
|
console.log("\u{1F504} Using workspaces table:", workspacesTable);
|
|
1571
|
-
let query = supabase.from(workspacesTable).select("workspace_id, display_name, line_id");
|
|
1574
|
+
let query = supabase.from(workspacesTable).select("workspace_id, display_name, line_id, enable");
|
|
1572
1575
|
console.log("\u{1F504} Supabase query created, about to add filters...");
|
|
1573
1576
|
if (lineId) {
|
|
1574
1577
|
query = query.eq("line_id", lineId);
|
|
@@ -1587,10 +1590,10 @@ var workspaceService = {
|
|
|
1587
1590
|
console.log("Raw workspace data from Supabase:", data);
|
|
1588
1591
|
const displayNamesMap = /* @__PURE__ */ new Map();
|
|
1589
1592
|
(data || []).forEach((workspace) => {
|
|
1590
|
-
if (workspace.workspace_id && workspace.display_name) {
|
|
1593
|
+
if (workspace.workspace_id && workspace.display_name && workspace.enable === true) {
|
|
1591
1594
|
const displayName = workspace.display_name.trim();
|
|
1592
1595
|
displayNamesMap.set(workspace.workspace_id, displayName);
|
|
1593
|
-
console.log(`\u2705 Mapped: ${workspace.workspace_id} -> ${displayName}`);
|
|
1596
|
+
console.log(`\u2705 Mapped: ${workspace.workspace_id} -> ${displayName} (enabled: ${workspace.enable})`);
|
|
1594
1597
|
}
|
|
1595
1598
|
});
|
|
1596
1599
|
console.log("Final display names map:", Array.from(displayNamesMap.entries()));
|
|
@@ -3726,6 +3729,14 @@ var useLineWorkspaceMetrics = (lineId, options) => {
|
|
|
3726
3729
|
queryShiftId,
|
|
3727
3730
|
metricsTable
|
|
3728
3731
|
});
|
|
3732
|
+
const workspaces2 = await workspaceService.getWorkspaces(lineId);
|
|
3733
|
+
const enabledWorkspaceIds = workspaces2.filter((ws) => ws.enable === true).map((ws) => ws.id);
|
|
3734
|
+
if (enabledWorkspaceIds.length === 0) {
|
|
3735
|
+
setWorkspaces([]);
|
|
3736
|
+
setInitialized(true);
|
|
3737
|
+
setLoading(false);
|
|
3738
|
+
return;
|
|
3739
|
+
}
|
|
3729
3740
|
const { data, error: fetchError } = await supabase.from(metricsTable).select(`
|
|
3730
3741
|
workspace_name,
|
|
3731
3742
|
total_output,
|
|
@@ -3737,7 +3748,7 @@ var useLineWorkspaceMetrics = (lineId, options) => {
|
|
|
3737
3748
|
trend_score,
|
|
3738
3749
|
line_id,
|
|
3739
3750
|
total_day_output
|
|
3740
|
-
`).eq("date", queryDate).eq("shift_id", queryShiftId).eq("line_id", lineId).order("workspace_name", { ascending: true });
|
|
3751
|
+
`).eq("date", queryDate).eq("shift_id", queryShiftId).eq("line_id", lineId).in("workspace_id", enabledWorkspaceIds).order("workspace_name", { ascending: true });
|
|
3741
3752
|
if (fetchError) throw fetchError;
|
|
3742
3753
|
const transformedData = (data || []).map((item) => ({
|
|
3743
3754
|
company_id: entityConfig.companyId || "unknown",
|
|
@@ -4049,7 +4060,14 @@ var useLeaderboardMetrics = (lineId, topCount = 10) => {
|
|
|
4049
4060
|
try {
|
|
4050
4061
|
const currentShiftDetails = getCurrentShift(defaultTimezone, shiftConfig);
|
|
4051
4062
|
const operationalDate = getOperationalDate(defaultTimezone, new Date(currentShiftDetails.date));
|
|
4052
|
-
const
|
|
4063
|
+
const workspaces = await workspaceService.getWorkspaces(lineId);
|
|
4064
|
+
const enabledWorkspaceIds = workspaces.filter((ws) => ws.enable === true).map((ws) => ws.id);
|
|
4065
|
+
if (enabledWorkspaceIds.length === 0) {
|
|
4066
|
+
setTopPerformers([]);
|
|
4067
|
+
setIsLoading(false);
|
|
4068
|
+
return;
|
|
4069
|
+
}
|
|
4070
|
+
const { data, error: fetchError } = await supabase.from(companySpecificMetricsTable).select(`workspace_name,total_output,avg_pph,efficiency,workspace_id`).eq("date", operationalDate).eq("shift_id", currentShiftDetails.shiftId).eq("line_id", lineId).in("workspace_id", enabledWorkspaceIds).gt("efficiency", 0).order("efficiency", { ascending: false }).limit(topCount);
|
|
4053
4071
|
if (fetchError) throw fetchError;
|
|
4054
4072
|
const rankedData = (data || []).map((entry, index) => ({
|
|
4055
4073
|
workspace_name: entry.workspace_name,
|
|
@@ -4191,7 +4209,22 @@ var useDashboardMetrics = ({ onLineMetricsUpdate, lineId }) => {
|
|
|
4191
4209
|
throw new Error("No target line IDs available for fetching metrics.");
|
|
4192
4210
|
}
|
|
4193
4211
|
const isFactoryView = currentLineIdToUse === (entityConfig.factoryViewId || "factory");
|
|
4194
|
-
let
|
|
4212
|
+
let enabledWorkspaceIds = [];
|
|
4213
|
+
for (const targetLineId of targetLineIds) {
|
|
4214
|
+
const workspaces = await workspaceService.getWorkspaces(targetLineId);
|
|
4215
|
+
const enabledIds = workspaces.filter((ws) => ws.enable === true).map((ws) => ws.id);
|
|
4216
|
+
enabledWorkspaceIds.push(...enabledIds);
|
|
4217
|
+
}
|
|
4218
|
+
if (enabledWorkspaceIds.length === 0) {
|
|
4219
|
+
const newMetricsState2 = {
|
|
4220
|
+
workspaceMetrics: [],
|
|
4221
|
+
lineMetrics: []
|
|
4222
|
+
};
|
|
4223
|
+
setMetrics(newMetricsState2);
|
|
4224
|
+
setCache(currentLineIdToUse, newMetricsState2);
|
|
4225
|
+
return;
|
|
4226
|
+
}
|
|
4227
|
+
let workspaceQuery = supabase.from(companySpecificMetricsTable).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("date", operationalDate).eq("shift_id", currentShiftDetails.shiftId).in("workspace_id", enabledWorkspaceIds);
|
|
4195
4228
|
if (!isFactoryView) {
|
|
4196
4229
|
workspaceQuery = workspaceQuery.in("line_id", targetLineIds);
|
|
4197
4230
|
}
|
|
@@ -4587,14 +4620,20 @@ var useRealtimeLineMetrics = ({
|
|
|
4587
4620
|
const companyId = entityConfig.companyId;
|
|
4588
4621
|
const metricsTablePrefix = getMetricsTablePrefix(companyId || "");
|
|
4589
4622
|
const metricsTable = `${metricsTablePrefix}_${(companyId || "").replace(/-/g, "_")}`;
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4623
|
+
let enabledWorkspaceIds = [];
|
|
4624
|
+
for (const lineId2 of targetLineIds) {
|
|
4625
|
+
const workspaces = await workspaceService.getWorkspaces(lineId2);
|
|
4626
|
+
const enabledIds = workspaces.filter((ws) => ws.enable === true).map((ws) => ws.id);
|
|
4627
|
+
enabledWorkspaceIds.push(...enabledIds);
|
|
4628
|
+
}
|
|
4629
|
+
const { data: workspaceData, error: workspaceError } = enabledWorkspaceIds.length > 0 ? await supabase.from(metricsTable).select(`
|
|
4630
|
+
line_id,
|
|
4631
|
+
workspace_id,
|
|
4632
|
+
workspace_name,
|
|
4633
|
+
efficiency,
|
|
4634
|
+
total_output,
|
|
4635
|
+
total_day_output
|
|
4636
|
+
`).in("line_id", targetLineIds).in("workspace_id", enabledWorkspaceIds).eq("shift_id", shiftId).eq("date", date) : { data: [], error: null };
|
|
4598
4637
|
if (workspaceError) {
|
|
4599
4638
|
console.error("Error fetching workspace metrics for factory view:", workspaceError);
|
|
4600
4639
|
}
|
|
@@ -4646,13 +4685,15 @@ var useRealtimeLineMetrics = ({
|
|
|
4646
4685
|
const companyId = entityConfig.companyId;
|
|
4647
4686
|
const metricsTablePrefix = getMetricsTablePrefix(companyId || "");
|
|
4648
4687
|
const metricsTable = `${metricsTablePrefix}_${(companyId || "").replace(/-/g, "_")}`;
|
|
4649
|
-
const
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4688
|
+
const workspaces = await workspaceService.getWorkspaces(lineIdRef.current);
|
|
4689
|
+
const enabledWorkspaceIds = workspaces.filter((ws) => ws.enable === true).map((ws) => ws.id);
|
|
4690
|
+
const { data: workspaceData, error: workspaceError } = enabledWorkspaceIds.length > 0 ? await supabase.from(metricsTable).select(`
|
|
4691
|
+
workspace_id,
|
|
4692
|
+
workspace_name,
|
|
4693
|
+
efficiency,
|
|
4694
|
+
total_output,
|
|
4695
|
+
total_day_output
|
|
4696
|
+
`).eq("line_id", lineIdRef.current).in("workspace_id", enabledWorkspaceIds).eq("shift_id", shiftId).eq("date", date) : { data: [], error: null };
|
|
4656
4697
|
if (workspaceError) {
|
|
4657
4698
|
console.error("Error fetching workspace metrics:", workspaceError);
|
|
4658
4699
|
}
|
|
@@ -6101,6 +6142,19 @@ var useAllWorkspaceMetrics = (options) => {
|
|
|
6101
6142
|
queryShiftId,
|
|
6102
6143
|
metricsTable
|
|
6103
6144
|
});
|
|
6145
|
+
const configuredLineIds = getConfiguredLineIds(entityConfig);
|
|
6146
|
+
let enabledWorkspaceIds = [];
|
|
6147
|
+
for (const lineId of configuredLineIds) {
|
|
6148
|
+
const workspaces2 = await workspaceService.getWorkspaces(lineId);
|
|
6149
|
+
const enabledIds = workspaces2.filter((ws) => ws.enable === true).map((ws) => ws.id);
|
|
6150
|
+
enabledWorkspaceIds.push(...enabledIds);
|
|
6151
|
+
}
|
|
6152
|
+
if (enabledWorkspaceIds.length === 0) {
|
|
6153
|
+
setWorkspaces([]);
|
|
6154
|
+
setInitialized(true);
|
|
6155
|
+
setLoading(false);
|
|
6156
|
+
return;
|
|
6157
|
+
}
|
|
6104
6158
|
const { data, error: fetchError } = await supabase.from(metricsTable).select(`
|
|
6105
6159
|
workspace_name,
|
|
6106
6160
|
total_output,
|
|
@@ -6112,7 +6166,7 @@ var useAllWorkspaceMetrics = (options) => {
|
|
|
6112
6166
|
trend_score,
|
|
6113
6167
|
line_id,
|
|
6114
6168
|
total_day_output
|
|
6115
|
-
`).eq("date", queryDate).eq("shift_id", queryShiftId).order("efficiency", { ascending: false });
|
|
6169
|
+
`).eq("date", queryDate).eq("shift_id", queryShiftId).in("workspace_id", enabledWorkspaceIds).order("efficiency", { ascending: false });
|
|
6116
6170
|
if (fetchError) throw fetchError;
|
|
6117
6171
|
const transformedData = (data || []).map((item) => ({
|
|
6118
6172
|
company_id: entityConfig.companyId || "unknown",
|
|
@@ -30220,15 +30274,22 @@ var LeaderboardDetailView = React19.memo(({
|
|
|
30220
30274
|
className = ""
|
|
30221
30275
|
}) => {
|
|
30222
30276
|
const navigation = useNavigation();
|
|
30277
|
+
const entityConfig = useEntityConfig();
|
|
30223
30278
|
const [sortAscending, setSortAscending] = React19.useState(false);
|
|
30279
|
+
const configuredLineNames = React19.useMemo(() => {
|
|
30280
|
+
return getAllLineDisplayNames(entityConfig);
|
|
30281
|
+
}, [entityConfig]);
|
|
30224
30282
|
const getLineName = React19.useCallback((lineId2) => {
|
|
30283
|
+
if (configuredLineNames[lineId2]) {
|
|
30284
|
+
return configuredLineNames[lineId2];
|
|
30285
|
+
}
|
|
30225
30286
|
if (lineNames[lineId2]) {
|
|
30226
30287
|
return lineNames[lineId2];
|
|
30227
30288
|
}
|
|
30228
30289
|
if (lineId2 === line1Id) return "Line 1";
|
|
30229
30290
|
if (lineId2 === line2Id) return "Line 2";
|
|
30230
|
-
return lineId2
|
|
30231
|
-
}, [lineNames, line1Id, line2Id]);
|
|
30291
|
+
return `Line ${lineId2.substring(0, 8)}`;
|
|
30292
|
+
}, [configuredLineNames, lineNames, line1Id, line2Id]);
|
|
30232
30293
|
const handleSortToggle = React19.useCallback(() => {
|
|
30233
30294
|
setSortAscending(!sortAscending);
|
|
30234
30295
|
}, [sortAscending]);
|
|
@@ -32656,12 +32717,13 @@ var TargetsView = ({
|
|
|
32656
32717
|
}
|
|
32657
32718
|
try {
|
|
32658
32719
|
const workspacesData = await workspaceService.getWorkspaces(lineId);
|
|
32720
|
+
const enabledWorkspaces = workspacesData.filter((ws) => ws.enable === true);
|
|
32659
32721
|
const actionThresholds = await workspaceService.getActionThresholds(
|
|
32660
32722
|
lineId,
|
|
32661
32723
|
currentDate,
|
|
32662
32724
|
selectedShift
|
|
32663
32725
|
);
|
|
32664
|
-
const mappedWorkspaces =
|
|
32726
|
+
const mappedWorkspaces = enabledWorkspaces.map((ws) => {
|
|
32665
32727
|
const threshold = actionThresholds.find((t) => t.workspace_id === ws.id);
|
|
32666
32728
|
return {
|
|
32667
32729
|
id: ws.id,
|
package/dist/index.mjs
CHANGED
|
@@ -919,8 +919,9 @@ var dashboardService = {
|
|
|
919
919
|
factory_id,
|
|
920
920
|
factories!lines_factory_id_fkey(factory_name),
|
|
921
921
|
company_id,
|
|
922
|
-
companies!lines_company_id_fkey(company_name:name)
|
|
923
|
-
|
|
922
|
+
companies!lines_company_id_fkey(company_name:name),
|
|
923
|
+
enable
|
|
924
|
+
`).eq("enable", true);
|
|
924
925
|
if (companyId) {
|
|
925
926
|
query = query.eq("company_id", companyId);
|
|
926
927
|
}
|
|
@@ -936,7 +937,9 @@ var dashboardService = {
|
|
|
936
937
|
factory_id: line.factory_id,
|
|
937
938
|
factory_name: line.factories?.factory_name ?? "N/A",
|
|
938
939
|
company_id: line.company_id,
|
|
939
|
-
company_name: line.companies?.company_name ?? "N/A"
|
|
940
|
+
company_name: line.companies?.company_name ?? "N/A",
|
|
941
|
+
enable: line.enable ?? true
|
|
942
|
+
// Default to true if not specified
|
|
940
943
|
}));
|
|
941
944
|
return transformedLines;
|
|
942
945
|
} catch (err) {
|
|
@@ -1518,7 +1521,7 @@ var workspaceService = {
|
|
|
1518
1521
|
const config = _getDashboardConfigInstance();
|
|
1519
1522
|
const dbConfig = config?.databaseConfig;
|
|
1520
1523
|
const workspacesTable = getTable3(dbConfig, "workspaces");
|
|
1521
|
-
const { data, error } = await supabase.from(workspacesTable).select("id, line_id, workspace_id, action_id, action_pph_threshold, action_cycle_time, action_total_day_output").eq("line_id", lineId).order("workspace_id", { ascending: true });
|
|
1524
|
+
const { data, error } = await supabase.from(workspacesTable).select("id, line_id, workspace_id, action_id, action_pph_threshold, action_cycle_time, action_total_day_output, enable").eq("line_id", lineId).order("workspace_id", { ascending: true });
|
|
1522
1525
|
if (error) {
|
|
1523
1526
|
console.error(`Error fetching workspaces from ${workspacesTable}:`, error);
|
|
1524
1527
|
throw error;
|
|
@@ -1539,7 +1542,7 @@ var workspaceService = {
|
|
|
1539
1542
|
const dbConfig = config?.databaseConfig;
|
|
1540
1543
|
const workspacesTable = getTable3(dbConfig, "workspaces");
|
|
1541
1544
|
console.log("\u{1F504} Using workspaces table:", workspacesTable);
|
|
1542
|
-
let query = supabase.from(workspacesTable).select("workspace_id, display_name, line_id");
|
|
1545
|
+
let query = supabase.from(workspacesTable).select("workspace_id, display_name, line_id, enable");
|
|
1543
1546
|
console.log("\u{1F504} Supabase query created, about to add filters...");
|
|
1544
1547
|
if (lineId) {
|
|
1545
1548
|
query = query.eq("line_id", lineId);
|
|
@@ -1558,10 +1561,10 @@ var workspaceService = {
|
|
|
1558
1561
|
console.log("Raw workspace data from Supabase:", data);
|
|
1559
1562
|
const displayNamesMap = /* @__PURE__ */ new Map();
|
|
1560
1563
|
(data || []).forEach((workspace) => {
|
|
1561
|
-
if (workspace.workspace_id && workspace.display_name) {
|
|
1564
|
+
if (workspace.workspace_id && workspace.display_name && workspace.enable === true) {
|
|
1562
1565
|
const displayName = workspace.display_name.trim();
|
|
1563
1566
|
displayNamesMap.set(workspace.workspace_id, displayName);
|
|
1564
|
-
console.log(`\u2705 Mapped: ${workspace.workspace_id} -> ${displayName}`);
|
|
1567
|
+
console.log(`\u2705 Mapped: ${workspace.workspace_id} -> ${displayName} (enabled: ${workspace.enable})`);
|
|
1565
1568
|
}
|
|
1566
1569
|
});
|
|
1567
1570
|
console.log("Final display names map:", Array.from(displayNamesMap.entries()));
|
|
@@ -3697,6 +3700,14 @@ var useLineWorkspaceMetrics = (lineId, options) => {
|
|
|
3697
3700
|
queryShiftId,
|
|
3698
3701
|
metricsTable
|
|
3699
3702
|
});
|
|
3703
|
+
const workspaces2 = await workspaceService.getWorkspaces(lineId);
|
|
3704
|
+
const enabledWorkspaceIds = workspaces2.filter((ws) => ws.enable === true).map((ws) => ws.id);
|
|
3705
|
+
if (enabledWorkspaceIds.length === 0) {
|
|
3706
|
+
setWorkspaces([]);
|
|
3707
|
+
setInitialized(true);
|
|
3708
|
+
setLoading(false);
|
|
3709
|
+
return;
|
|
3710
|
+
}
|
|
3700
3711
|
const { data, error: fetchError } = await supabase.from(metricsTable).select(`
|
|
3701
3712
|
workspace_name,
|
|
3702
3713
|
total_output,
|
|
@@ -3708,7 +3719,7 @@ var useLineWorkspaceMetrics = (lineId, options) => {
|
|
|
3708
3719
|
trend_score,
|
|
3709
3720
|
line_id,
|
|
3710
3721
|
total_day_output
|
|
3711
|
-
`).eq("date", queryDate).eq("shift_id", queryShiftId).eq("line_id", lineId).order("workspace_name", { ascending: true });
|
|
3722
|
+
`).eq("date", queryDate).eq("shift_id", queryShiftId).eq("line_id", lineId).in("workspace_id", enabledWorkspaceIds).order("workspace_name", { ascending: true });
|
|
3712
3723
|
if (fetchError) throw fetchError;
|
|
3713
3724
|
const transformedData = (data || []).map((item) => ({
|
|
3714
3725
|
company_id: entityConfig.companyId || "unknown",
|
|
@@ -4020,7 +4031,14 @@ var useLeaderboardMetrics = (lineId, topCount = 10) => {
|
|
|
4020
4031
|
try {
|
|
4021
4032
|
const currentShiftDetails = getCurrentShift(defaultTimezone, shiftConfig);
|
|
4022
4033
|
const operationalDate = getOperationalDate(defaultTimezone, new Date(currentShiftDetails.date));
|
|
4023
|
-
const
|
|
4034
|
+
const workspaces = await workspaceService.getWorkspaces(lineId);
|
|
4035
|
+
const enabledWorkspaceIds = workspaces.filter((ws) => ws.enable === true).map((ws) => ws.id);
|
|
4036
|
+
if (enabledWorkspaceIds.length === 0) {
|
|
4037
|
+
setTopPerformers([]);
|
|
4038
|
+
setIsLoading(false);
|
|
4039
|
+
return;
|
|
4040
|
+
}
|
|
4041
|
+
const { data, error: fetchError } = await supabase.from(companySpecificMetricsTable).select(`workspace_name,total_output,avg_pph,efficiency,workspace_id`).eq("date", operationalDate).eq("shift_id", currentShiftDetails.shiftId).eq("line_id", lineId).in("workspace_id", enabledWorkspaceIds).gt("efficiency", 0).order("efficiency", { ascending: false }).limit(topCount);
|
|
4024
4042
|
if (fetchError) throw fetchError;
|
|
4025
4043
|
const rankedData = (data || []).map((entry, index) => ({
|
|
4026
4044
|
workspace_name: entry.workspace_name,
|
|
@@ -4162,7 +4180,22 @@ var useDashboardMetrics = ({ onLineMetricsUpdate, lineId }) => {
|
|
|
4162
4180
|
throw new Error("No target line IDs available for fetching metrics.");
|
|
4163
4181
|
}
|
|
4164
4182
|
const isFactoryView = currentLineIdToUse === (entityConfig.factoryViewId || "factory");
|
|
4165
|
-
let
|
|
4183
|
+
let enabledWorkspaceIds = [];
|
|
4184
|
+
for (const targetLineId of targetLineIds) {
|
|
4185
|
+
const workspaces = await workspaceService.getWorkspaces(targetLineId);
|
|
4186
|
+
const enabledIds = workspaces.filter((ws) => ws.enable === true).map((ws) => ws.id);
|
|
4187
|
+
enabledWorkspaceIds.push(...enabledIds);
|
|
4188
|
+
}
|
|
4189
|
+
if (enabledWorkspaceIds.length === 0) {
|
|
4190
|
+
const newMetricsState2 = {
|
|
4191
|
+
workspaceMetrics: [],
|
|
4192
|
+
lineMetrics: []
|
|
4193
|
+
};
|
|
4194
|
+
setMetrics(newMetricsState2);
|
|
4195
|
+
setCache(currentLineIdToUse, newMetricsState2);
|
|
4196
|
+
return;
|
|
4197
|
+
}
|
|
4198
|
+
let workspaceQuery = supabase.from(companySpecificMetricsTable).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("date", operationalDate).eq("shift_id", currentShiftDetails.shiftId).in("workspace_id", enabledWorkspaceIds);
|
|
4166
4199
|
if (!isFactoryView) {
|
|
4167
4200
|
workspaceQuery = workspaceQuery.in("line_id", targetLineIds);
|
|
4168
4201
|
}
|
|
@@ -4558,14 +4591,20 @@ var useRealtimeLineMetrics = ({
|
|
|
4558
4591
|
const companyId = entityConfig.companyId;
|
|
4559
4592
|
const metricsTablePrefix = getMetricsTablePrefix(companyId || "");
|
|
4560
4593
|
const metricsTable = `${metricsTablePrefix}_${(companyId || "").replace(/-/g, "_")}`;
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4594
|
+
let enabledWorkspaceIds = [];
|
|
4595
|
+
for (const lineId2 of targetLineIds) {
|
|
4596
|
+
const workspaces = await workspaceService.getWorkspaces(lineId2);
|
|
4597
|
+
const enabledIds = workspaces.filter((ws) => ws.enable === true).map((ws) => ws.id);
|
|
4598
|
+
enabledWorkspaceIds.push(...enabledIds);
|
|
4599
|
+
}
|
|
4600
|
+
const { data: workspaceData, error: workspaceError } = enabledWorkspaceIds.length > 0 ? await supabase.from(metricsTable).select(`
|
|
4601
|
+
line_id,
|
|
4602
|
+
workspace_id,
|
|
4603
|
+
workspace_name,
|
|
4604
|
+
efficiency,
|
|
4605
|
+
total_output,
|
|
4606
|
+
total_day_output
|
|
4607
|
+
`).in("line_id", targetLineIds).in("workspace_id", enabledWorkspaceIds).eq("shift_id", shiftId).eq("date", date) : { data: [], error: null };
|
|
4569
4608
|
if (workspaceError) {
|
|
4570
4609
|
console.error("Error fetching workspace metrics for factory view:", workspaceError);
|
|
4571
4610
|
}
|
|
@@ -4617,13 +4656,15 @@ var useRealtimeLineMetrics = ({
|
|
|
4617
4656
|
const companyId = entityConfig.companyId;
|
|
4618
4657
|
const metricsTablePrefix = getMetricsTablePrefix(companyId || "");
|
|
4619
4658
|
const metricsTable = `${metricsTablePrefix}_${(companyId || "").replace(/-/g, "_")}`;
|
|
4620
|
-
const
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4659
|
+
const workspaces = await workspaceService.getWorkspaces(lineIdRef.current);
|
|
4660
|
+
const enabledWorkspaceIds = workspaces.filter((ws) => ws.enable === true).map((ws) => ws.id);
|
|
4661
|
+
const { data: workspaceData, error: workspaceError } = enabledWorkspaceIds.length > 0 ? await supabase.from(metricsTable).select(`
|
|
4662
|
+
workspace_id,
|
|
4663
|
+
workspace_name,
|
|
4664
|
+
efficiency,
|
|
4665
|
+
total_output,
|
|
4666
|
+
total_day_output
|
|
4667
|
+
`).eq("line_id", lineIdRef.current).in("workspace_id", enabledWorkspaceIds).eq("shift_id", shiftId).eq("date", date) : { data: [], error: null };
|
|
4627
4668
|
if (workspaceError) {
|
|
4628
4669
|
console.error("Error fetching workspace metrics:", workspaceError);
|
|
4629
4670
|
}
|
|
@@ -6072,6 +6113,19 @@ var useAllWorkspaceMetrics = (options) => {
|
|
|
6072
6113
|
queryShiftId,
|
|
6073
6114
|
metricsTable
|
|
6074
6115
|
});
|
|
6116
|
+
const configuredLineIds = getConfiguredLineIds(entityConfig);
|
|
6117
|
+
let enabledWorkspaceIds = [];
|
|
6118
|
+
for (const lineId of configuredLineIds) {
|
|
6119
|
+
const workspaces2 = await workspaceService.getWorkspaces(lineId);
|
|
6120
|
+
const enabledIds = workspaces2.filter((ws) => ws.enable === true).map((ws) => ws.id);
|
|
6121
|
+
enabledWorkspaceIds.push(...enabledIds);
|
|
6122
|
+
}
|
|
6123
|
+
if (enabledWorkspaceIds.length === 0) {
|
|
6124
|
+
setWorkspaces([]);
|
|
6125
|
+
setInitialized(true);
|
|
6126
|
+
setLoading(false);
|
|
6127
|
+
return;
|
|
6128
|
+
}
|
|
6075
6129
|
const { data, error: fetchError } = await supabase.from(metricsTable).select(`
|
|
6076
6130
|
workspace_name,
|
|
6077
6131
|
total_output,
|
|
@@ -6083,7 +6137,7 @@ var useAllWorkspaceMetrics = (options) => {
|
|
|
6083
6137
|
trend_score,
|
|
6084
6138
|
line_id,
|
|
6085
6139
|
total_day_output
|
|
6086
|
-
`).eq("date", queryDate).eq("shift_id", queryShiftId).order("efficiency", { ascending: false });
|
|
6140
|
+
`).eq("date", queryDate).eq("shift_id", queryShiftId).in("workspace_id", enabledWorkspaceIds).order("efficiency", { ascending: false });
|
|
6087
6141
|
if (fetchError) throw fetchError;
|
|
6088
6142
|
const transformedData = (data || []).map((item) => ({
|
|
6089
6143
|
company_id: entityConfig.companyId || "unknown",
|
|
@@ -30191,15 +30245,22 @@ var LeaderboardDetailView = memo(({
|
|
|
30191
30245
|
className = ""
|
|
30192
30246
|
}) => {
|
|
30193
30247
|
const navigation = useNavigation();
|
|
30248
|
+
const entityConfig = useEntityConfig();
|
|
30194
30249
|
const [sortAscending, setSortAscending] = useState(false);
|
|
30250
|
+
const configuredLineNames = useMemo(() => {
|
|
30251
|
+
return getAllLineDisplayNames(entityConfig);
|
|
30252
|
+
}, [entityConfig]);
|
|
30195
30253
|
const getLineName = useCallback((lineId2) => {
|
|
30254
|
+
if (configuredLineNames[lineId2]) {
|
|
30255
|
+
return configuredLineNames[lineId2];
|
|
30256
|
+
}
|
|
30196
30257
|
if (lineNames[lineId2]) {
|
|
30197
30258
|
return lineNames[lineId2];
|
|
30198
30259
|
}
|
|
30199
30260
|
if (lineId2 === line1Id) return "Line 1";
|
|
30200
30261
|
if (lineId2 === line2Id) return "Line 2";
|
|
30201
|
-
return lineId2
|
|
30202
|
-
}, [lineNames, line1Id, line2Id]);
|
|
30262
|
+
return `Line ${lineId2.substring(0, 8)}`;
|
|
30263
|
+
}, [configuredLineNames, lineNames, line1Id, line2Id]);
|
|
30203
30264
|
const handleSortToggle = useCallback(() => {
|
|
30204
30265
|
setSortAscending(!sortAscending);
|
|
30205
30266
|
}, [sortAscending]);
|
|
@@ -32627,12 +32688,13 @@ var TargetsView = ({
|
|
|
32627
32688
|
}
|
|
32628
32689
|
try {
|
|
32629
32690
|
const workspacesData = await workspaceService.getWorkspaces(lineId);
|
|
32691
|
+
const enabledWorkspaces = workspacesData.filter((ws) => ws.enable === true);
|
|
32630
32692
|
const actionThresholds = await workspaceService.getActionThresholds(
|
|
32631
32693
|
lineId,
|
|
32632
32694
|
currentDate,
|
|
32633
32695
|
selectedShift
|
|
32634
32696
|
);
|
|
32635
|
-
const mappedWorkspaces =
|
|
32697
|
+
const mappedWorkspaces = enabledWorkspaces.map((ws) => {
|
|
32636
32698
|
const threshold = actionThresholds.find((t) => t.workspace_id === ws.id);
|
|
32637
32699
|
return {
|
|
32638
32700
|
id: ws.id,
|