@optifye/dashboard-core 6.0.7 → 6.0.8

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 CHANGED
@@ -2083,19 +2083,19 @@ interface UseWorkspaceDisplayNamesReturn {
2083
2083
  * loading states, error handling, and caching. It automatically fetches workspace display names
2084
2084
  * on mount and provides utility methods for accessing individual workspace names.
2085
2085
  *
2086
- * @param {string} [companyId] - Optional company ID to filter workspaces
2087
2086
  * @param {string} [lineId] - Optional line ID to filter workspaces
2087
+ * @param {string} [companyId] - Optional company ID to filter workspaces
2088
2088
  * @returns {UseWorkspaceDisplayNamesReturn} An object containing display names, loading state, error, and utility functions
2089
2089
  *
2090
2090
  * @example
2091
- * const { displayNames, loading, error, getDisplayName } = useWorkspaceDisplayNames();
2091
+ * const { displayNames, loading, error } = useWorkspaceDisplayNames(lineId);
2092
2092
  *
2093
2093
  * if (loading) return <div>Loading...</div>;
2094
2094
  * if (error) return <div>Error: {error.message}</div>;
2095
2095
  *
2096
- * const workspaceName = getDisplayName('WS01'); // Returns display name or fallback
2096
+ * const workspaceName = displayNames['WS01'] || 'WS01'; // Returns display name or fallback
2097
2097
  */
2098
- declare const useWorkspaceDisplayNames: (companyId?: string, lineId?: string) => UseWorkspaceDisplayNamesReturn;
2098
+ declare const useWorkspaceDisplayNames: (lineId?: string, companyId?: string) => UseWorkspaceDisplayNamesReturn;
2099
2099
  /**
2100
2100
  * @hook useWorkspaceDisplayName
2101
2101
  * @summary Hook for fetching a single workspace display name
@@ -2103,17 +2103,17 @@ declare const useWorkspaceDisplayNames: (companyId?: string, lineId?: string) =>
2103
2103
  * loading state and error handling. It's useful when you only need one workspace name.
2104
2104
  *
2105
2105
  * @param {string} workspaceId - The workspace ID to fetch the display name for
2106
- * @param {string} [companyId] - Optional company ID to filter workspaces
2107
2106
  * @param {string} [lineId] - Optional line ID to filter workspaces
2107
+ * @param {string} [companyId] - Optional company ID to filter workspaces
2108
2108
  * @returns {object} An object containing displayName, loading state, error, and refetch function
2109
2109
  *
2110
2110
  * @example
2111
- * const { displayName, loading, error } = useWorkspaceDisplayName('WS01');
2111
+ * const { displayName, loading, error } = useWorkspaceDisplayName('WS01', lineId);
2112
2112
  *
2113
2113
  * if (loading) return <span>Loading...</span>;
2114
2114
  * return <span>{displayName}</span>;
2115
2115
  */
2116
- declare const useWorkspaceDisplayName: (workspaceId: string, companyId?: string, lineId?: string) => {
2116
+ declare const useWorkspaceDisplayName: (workspaceId: string, lineId?: string, companyId?: string) => {
2117
2117
  displayName: string;
2118
2118
  loading: boolean;
2119
2119
  error: Error | null;
@@ -2126,20 +2126,20 @@ declare const useWorkspaceDisplayName: (workspaceId: string, companyId?: string,
2126
2126
  * as a Record<string, string> for easy lookup. Useful when you need names for a specific set of workspaces.
2127
2127
  *
2128
2128
  * @param {string[]} workspaceIds - Array of workspace IDs to fetch display names for
2129
- * @param {string} [companyId] - Optional company ID to filter workspaces
2130
2129
  * @param {string} [lineId] - Optional line ID to filter workspaces
2130
+ * @param {string} [companyId] - Optional company ID to filter workspaces
2131
2131
  * @returns {object} An object containing displayNamesMap, loading state, error, and refetch function
2132
2132
  *
2133
2133
  * @example
2134
- * const { displayNamesMap, loading } = useWorkspaceDisplayNamesMap(['WS01', 'WS02', 'WS03']);
2134
+ * const { displayNames, loading } = useWorkspaceDisplayNamesMap(['WS01', 'WS02', 'WS03'], lineId);
2135
2135
  *
2136
2136
  * if (!loading) {
2137
2137
  * workspaceIds.forEach(id => {
2138
- * console.log(`${id}: ${displayNamesMap[id]}`);
2138
+ * console.log(`${id}: ${displayNames[id]}`);
2139
2139
  * });
2140
2140
  * }
2141
2141
  */
2142
- declare const useWorkspaceDisplayNamesMap: (workspaceIds: string[], companyId?: string, lineId?: string) => {
2142
+ declare const useWorkspaceDisplayNamesMap: (workspaceIds: string[], lineId?: string, companyId?: string) => {
2143
2143
  displayNames: Record<string, string>;
2144
2144
  loading: boolean;
2145
2145
  error: Error | null;
@@ -2957,10 +2957,14 @@ declare const forceRefreshWorkspaceDisplayNames: (lineId?: string) => Promise<vo
2957
2957
  /**
2958
2958
  * Gets workspace display name synchronously
2959
2959
  * If not initialized, triggers lazy initialization and returns workspace ID
2960
+ * @param workspaceId - The workspace ID to get display name for
2961
+ * @param lineId - Optional line ID to filter workspaces by line
2960
2962
  */
2961
2963
  declare const getWorkspaceDisplayName: (workspaceId: string, lineId?: string) => string;
2962
2964
  /**
2963
2965
  * Short version of workspace display name (synchronous version for backward compatibility)
2966
+ * @param workspaceId - The workspace ID to get display name for
2967
+ * @param lineId - Optional line ID to filter workspaces by line
2964
2968
  */
2965
2969
  declare const getShortWorkspaceDisplayName: (workspaceId: string, lineId?: string) => string;
2966
2970
  /**
package/dist/index.d.ts CHANGED
@@ -2083,19 +2083,19 @@ interface UseWorkspaceDisplayNamesReturn {
2083
2083
  * loading states, error handling, and caching. It automatically fetches workspace display names
2084
2084
  * on mount and provides utility methods for accessing individual workspace names.
2085
2085
  *
2086
- * @param {string} [companyId] - Optional company ID to filter workspaces
2087
2086
  * @param {string} [lineId] - Optional line ID to filter workspaces
2087
+ * @param {string} [companyId] - Optional company ID to filter workspaces
2088
2088
  * @returns {UseWorkspaceDisplayNamesReturn} An object containing display names, loading state, error, and utility functions
2089
2089
  *
2090
2090
  * @example
2091
- * const { displayNames, loading, error, getDisplayName } = useWorkspaceDisplayNames();
2091
+ * const { displayNames, loading, error } = useWorkspaceDisplayNames(lineId);
2092
2092
  *
2093
2093
  * if (loading) return <div>Loading...</div>;
2094
2094
  * if (error) return <div>Error: {error.message}</div>;
2095
2095
  *
2096
- * const workspaceName = getDisplayName('WS01'); // Returns display name or fallback
2096
+ * const workspaceName = displayNames['WS01'] || 'WS01'; // Returns display name or fallback
2097
2097
  */
2098
- declare const useWorkspaceDisplayNames: (companyId?: string, lineId?: string) => UseWorkspaceDisplayNamesReturn;
2098
+ declare const useWorkspaceDisplayNames: (lineId?: string, companyId?: string) => UseWorkspaceDisplayNamesReturn;
2099
2099
  /**
2100
2100
  * @hook useWorkspaceDisplayName
2101
2101
  * @summary Hook for fetching a single workspace display name
@@ -2103,17 +2103,17 @@ declare const useWorkspaceDisplayNames: (companyId?: string, lineId?: string) =>
2103
2103
  * loading state and error handling. It's useful when you only need one workspace name.
2104
2104
  *
2105
2105
  * @param {string} workspaceId - The workspace ID to fetch the display name for
2106
- * @param {string} [companyId] - Optional company ID to filter workspaces
2107
2106
  * @param {string} [lineId] - Optional line ID to filter workspaces
2107
+ * @param {string} [companyId] - Optional company ID to filter workspaces
2108
2108
  * @returns {object} An object containing displayName, loading state, error, and refetch function
2109
2109
  *
2110
2110
  * @example
2111
- * const { displayName, loading, error } = useWorkspaceDisplayName('WS01');
2111
+ * const { displayName, loading, error } = useWorkspaceDisplayName('WS01', lineId);
2112
2112
  *
2113
2113
  * if (loading) return <span>Loading...</span>;
2114
2114
  * return <span>{displayName}</span>;
2115
2115
  */
2116
- declare const useWorkspaceDisplayName: (workspaceId: string, companyId?: string, lineId?: string) => {
2116
+ declare const useWorkspaceDisplayName: (workspaceId: string, lineId?: string, companyId?: string) => {
2117
2117
  displayName: string;
2118
2118
  loading: boolean;
2119
2119
  error: Error | null;
@@ -2126,20 +2126,20 @@ declare const useWorkspaceDisplayName: (workspaceId: string, companyId?: string,
2126
2126
  * as a Record<string, string> for easy lookup. Useful when you need names for a specific set of workspaces.
2127
2127
  *
2128
2128
  * @param {string[]} workspaceIds - Array of workspace IDs to fetch display names for
2129
- * @param {string} [companyId] - Optional company ID to filter workspaces
2130
2129
  * @param {string} [lineId] - Optional line ID to filter workspaces
2130
+ * @param {string} [companyId] - Optional company ID to filter workspaces
2131
2131
  * @returns {object} An object containing displayNamesMap, loading state, error, and refetch function
2132
2132
  *
2133
2133
  * @example
2134
- * const { displayNamesMap, loading } = useWorkspaceDisplayNamesMap(['WS01', 'WS02', 'WS03']);
2134
+ * const { displayNames, loading } = useWorkspaceDisplayNamesMap(['WS01', 'WS02', 'WS03'], lineId);
2135
2135
  *
2136
2136
  * if (!loading) {
2137
2137
  * workspaceIds.forEach(id => {
2138
- * console.log(`${id}: ${displayNamesMap[id]}`);
2138
+ * console.log(`${id}: ${displayNames[id]}`);
2139
2139
  * });
2140
2140
  * }
2141
2141
  */
2142
- declare const useWorkspaceDisplayNamesMap: (workspaceIds: string[], companyId?: string, lineId?: string) => {
2142
+ declare const useWorkspaceDisplayNamesMap: (workspaceIds: string[], lineId?: string, companyId?: string) => {
2143
2143
  displayNames: Record<string, string>;
2144
2144
  loading: boolean;
2145
2145
  error: Error | null;
@@ -2957,10 +2957,14 @@ declare const forceRefreshWorkspaceDisplayNames: (lineId?: string) => Promise<vo
2957
2957
  /**
2958
2958
  * Gets workspace display name synchronously
2959
2959
  * If not initialized, triggers lazy initialization and returns workspace ID
2960
+ * @param workspaceId - The workspace ID to get display name for
2961
+ * @param lineId - Optional line ID to filter workspaces by line
2960
2962
  */
2961
2963
  declare const getWorkspaceDisplayName: (workspaceId: string, lineId?: string) => string;
2962
2964
  /**
2963
2965
  * Short version of workspace display name (synchronous version for backward compatibility)
2966
+ * @param workspaceId - The workspace ID to get display name for
2967
+ * @param lineId - Optional line ID to filter workspaces by line
2964
2968
  */
2965
2969
  declare const getShortWorkspaceDisplayName: (workspaceId: string, lineId?: string) => string;
2966
2970
  /**
package/dist/index.js CHANGED
@@ -4613,20 +4613,13 @@ var useRealtimeLineMetrics = ({
4613
4613
  workspaceData: workspaceData?.length
4614
4614
  });
4615
4615
  }
4616
- let avgEfficiency = 0;
4617
- if (workspaceData && workspaceData.length > 0) {
4618
- const activeWorkspaces = workspaceData.filter((w) => w.efficiency >= 10);
4619
- if (activeWorkspaces.length > 0) {
4620
- const totalEfficiency = activeWorkspaces.reduce((sum, workspace) => sum + (workspace.efficiency || 0), 0);
4621
- avgEfficiency = totalEfficiency / activeWorkspaces.length;
4622
- }
4623
- }
4616
+ const avgEfficiency = metricsData.reduce((sum, m) => sum + (m.avg_efficiency || 0), 0) / metricsData.length;
4624
4617
  const combinedMetrics = {
4625
4618
  line_id: factoryViewId,
4626
4619
  shift_id: shiftId,
4627
4620
  date,
4628
4621
  factory_id: firstLine.factory_id,
4629
- avg_efficiency: avgEfficiency > 0 ? avgEfficiency : metricsData.reduce((sum, m) => sum + (m.avg_efficiency || 0), 0) / metricsData.length,
4622
+ avg_efficiency: avgEfficiency,
4630
4623
  avg_cycle_time: metricsData.reduce((sum, m) => sum + (m.avg_cycle_time || 0), 0) / metricsData.length,
4631
4624
  current_output: metricsData.reduce((sum, m) => sum + (m.current_output || 0), 0),
4632
4625
  ideal_output: metricsData.reduce((sum, m) => sum + (m.ideal_output || 0), 0),
@@ -4678,22 +4671,14 @@ var useRealtimeLineMetrics = ({
4678
4671
  workspaceData: workspaceData?.length
4679
4672
  });
4680
4673
  }
4681
- let avgEfficiency = 0;
4682
- if (workspaceData && workspaceData.length > 0) {
4683
- const activeWorkspaces = workspaceData.filter((w) => w.efficiency >= 10);
4684
- if (activeWorkspaces.length > 0) {
4685
- const totalEfficiency = activeWorkspaces.reduce((sum, workspace) => sum + (workspace.efficiency || 0), 0);
4686
- avgEfficiency = totalEfficiency / activeWorkspaces.length;
4687
- }
4688
- }
4689
4674
  if (!metricsData) {
4690
4675
  setMetrics({
4691
4676
  line_id: lineIdRef.current,
4692
4677
  shift_id: shiftId,
4693
4678
  date,
4694
4679
  factory_id: "",
4695
- avg_efficiency: avgEfficiency,
4696
- // Use calculated workspace average
4680
+ avg_efficiency: 0,
4681
+ // Default to 0 when no data
4697
4682
  avg_cycle_time: 0,
4698
4683
  current_output: 0,
4699
4684
  ideal_output: 0,
@@ -4712,7 +4697,6 @@ var useRealtimeLineMetrics = ({
4712
4697
  } else {
4713
4698
  setMetrics({
4714
4699
  ...metricsData,
4715
- avg_efficiency: avgEfficiency > 0 ? avgEfficiency : metricsData.avg_efficiency,
4716
4700
  poorest_performing_workspaces: poorestPerformingWorkspaces
4717
4701
  });
4718
4702
  }
@@ -5561,6 +5545,7 @@ console.log("\u{1F504} workspaceDisplayNames.ts module loaded");
5561
5545
  var runtimeWorkspaceDisplayNames = {};
5562
5546
  var isInitialized = false;
5563
5547
  var isInitializing = false;
5548
+ var initializedWithLineIds = [];
5564
5549
  function getCurrentLineIds() {
5565
5550
  try {
5566
5551
  const config = _getDashboardConfigInstance();
@@ -5592,28 +5577,29 @@ async function initializeWorkspaceDisplayNames(explicitLineId) {
5592
5577
  targetLineIds = getCurrentLineIds();
5593
5578
  }
5594
5579
  console.log("\u{1F504} Target line IDs for workspace filtering:", targetLineIds);
5595
- const allDisplayNamesMap = /* @__PURE__ */ new Map();
5580
+ runtimeWorkspaceDisplayNames = {};
5596
5581
  if (targetLineIds.length > 0) {
5597
5582
  for (const lineId of targetLineIds) {
5598
5583
  console.log(`\u{1F504} Fetching workspaces for line: ${lineId}`);
5599
5584
  const lineDisplayNamesMap = await workspaceService.getWorkspaceDisplayNames(void 0, lineId);
5585
+ runtimeWorkspaceDisplayNames[lineId] = {};
5600
5586
  lineDisplayNamesMap.forEach((displayName, workspaceId) => {
5601
- allDisplayNamesMap.set(workspaceId, displayName);
5587
+ runtimeWorkspaceDisplayNames[lineId][workspaceId] = displayName;
5602
5588
  });
5589
+ console.log(`\u2705 Stored ${lineDisplayNamesMap.size} workspaces for line ${lineId}`);
5603
5590
  }
5604
5591
  } else {
5605
5592
  console.warn("\u26A0\uFE0F No line IDs found, fetching all workspaces (less efficient)");
5606
5593
  const allWorkspacesMap = await workspaceService.getWorkspaceDisplayNames();
5594
+ runtimeWorkspaceDisplayNames["global"] = {};
5607
5595
  allWorkspacesMap.forEach((displayName, workspaceId) => {
5608
- allDisplayNamesMap.set(workspaceId, displayName);
5596
+ runtimeWorkspaceDisplayNames["global"][workspaceId] = displayName;
5609
5597
  });
5610
5598
  }
5611
- runtimeWorkspaceDisplayNames = {};
5612
- allDisplayNamesMap.forEach((displayName, workspaceId) => {
5613
- runtimeWorkspaceDisplayNames[workspaceId] = displayName;
5614
- });
5615
5599
  isInitialized = true;
5600
+ initializedWithLineIds = targetLineIds;
5616
5601
  console.log("\u2705 Workspace display names initialized from Supabase:", runtimeWorkspaceDisplayNames);
5602
+ console.log("\u2705 Initialized with line IDs:", initializedWithLineIds);
5617
5603
  } catch (error) {
5618
5604
  console.error("\u274C Failed to initialize workspace display names from Supabase:", error);
5619
5605
  } finally {
@@ -5623,7 +5609,20 @@ async function initializeWorkspaceDisplayNames(explicitLineId) {
5623
5609
  var preInitializeWorkspaceDisplayNames = async (lineId) => {
5624
5610
  console.log("\u{1F504} preInitializeWorkspaceDisplayNames called for lineId:", lineId);
5625
5611
  if (isInitialized || isInitializing) {
5626
- console.log("\u{1F504} Already initialized or initializing, skipping pre-init");
5612
+ console.log("\u{1F504} Already initialized or initializing");
5613
+ if (lineId && !runtimeWorkspaceDisplayNames[lineId]) {
5614
+ console.log(`\u{1F504} Line ${lineId} not in cache, fetching...`);
5615
+ try {
5616
+ const lineDisplayNamesMap = await workspaceService.getWorkspaceDisplayNames(void 0, lineId);
5617
+ runtimeWorkspaceDisplayNames[lineId] = {};
5618
+ lineDisplayNamesMap.forEach((displayName, workspaceId) => {
5619
+ runtimeWorkspaceDisplayNames[lineId][workspaceId] = displayName;
5620
+ });
5621
+ console.log(`\u2705 Added ${lineDisplayNamesMap.size} workspaces for line ${lineId}`);
5622
+ } catch (error) {
5623
+ console.error(`\u274C Failed to fetch workspaces for line ${lineId}:`, error);
5624
+ }
5625
+ }
5627
5626
  return;
5628
5627
  }
5629
5628
  await initializeWorkspaceDisplayNames(lineId);
@@ -5636,45 +5635,91 @@ var forceRefreshWorkspaceDisplayNames = async (lineId) => {
5636
5635
  console.log("\u{1F504} Module loaded, will initialize lazily when first function is called");
5637
5636
  var getWorkspaceDisplayName = (workspaceId, lineId) => {
5638
5637
  if (!isInitialized && !isInitializing) {
5639
- console.log(`\u{1F504} [DEBUG] getWorkspaceDisplayName(${workspaceId}) - Not initialized, triggering lazy init...`);
5638
+ console.log(`\u{1F504} [DEBUG] getWorkspaceDisplayName(${workspaceId}, lineId: ${lineId}) - Not initialized, triggering lazy init...`);
5640
5639
  } else if (isInitializing) {
5641
- console.log(`\u{1F504} [DEBUG] getWorkspaceDisplayName(${workspaceId}) - Currently initializing...`);
5640
+ console.log(`\u{1F504} [DEBUG] getWorkspaceDisplayName(${workspaceId}, lineId: ${lineId}) - Currently initializing...`);
5642
5641
  }
5643
5642
  if (!isInitialized && !isInitializing) {
5644
- console.log("\u{1F504} Lazy initialization triggered by getWorkspaceDisplayName");
5643
+ console.log("\u{1F504} Lazy initialization triggered by getWorkspaceDisplayName with lineId:", lineId);
5645
5644
  initializeWorkspaceDisplayNames(lineId).catch((error) => {
5646
5645
  console.error("\u274C Lazy initialization failed:", error);
5647
5646
  });
5648
5647
  }
5649
- const displayName = runtimeWorkspaceDisplayNames[workspaceId];
5648
+ if (isInitialized && lineId && !runtimeWorkspaceDisplayNames[lineId]) {
5649
+ console.log(`\u{1F504} Line ${lineId} not in cache, fetching its workspaces...`);
5650
+ workspaceService.getWorkspaceDisplayNames(void 0, lineId).then((lineDisplayNamesMap) => {
5651
+ runtimeWorkspaceDisplayNames[lineId] = {};
5652
+ lineDisplayNamesMap.forEach((displayName2, workspaceId2) => {
5653
+ runtimeWorkspaceDisplayNames[lineId][workspaceId2] = displayName2;
5654
+ });
5655
+ console.log(`\u2705 Added ${lineDisplayNamesMap.size} workspaces for line ${lineId} to cache`);
5656
+ }).catch((error) => {
5657
+ console.error(`\u274C Failed to fetch workspaces for line ${lineId}:`, error);
5658
+ });
5659
+ }
5660
+ let displayName;
5661
+ if (lineId && runtimeWorkspaceDisplayNames[lineId]) {
5662
+ displayName = runtimeWorkspaceDisplayNames[lineId][workspaceId];
5663
+ } else if (!lineId) {
5664
+ for (const cachedLineId of Object.keys(runtimeWorkspaceDisplayNames)) {
5665
+ if (runtimeWorkspaceDisplayNames[cachedLineId][workspaceId]) {
5666
+ displayName = runtimeWorkspaceDisplayNames[cachedLineId][workspaceId];
5667
+ console.warn(`\u26A0\uFE0F No lineId provided for ${workspaceId}, found in line ${cachedLineId}`);
5668
+ break;
5669
+ }
5670
+ }
5671
+ }
5650
5672
  if (displayName) {
5651
- console.log(`getWorkspaceDisplayName(${workspaceId}) -> ${displayName} (from Supabase)`);
5673
+ console.log(`getWorkspaceDisplayName(${workspaceId}, lineId: ${lineId}) -> ${displayName} (from Supabase)`);
5652
5674
  return displayName;
5653
5675
  } else {
5654
5676
  if (isInitialized) {
5655
- console.log(`getWorkspaceDisplayName(${workspaceId}) -> ${workspaceId} (not found in Supabase data)`);
5677
+ console.log(`getWorkspaceDisplayName(${workspaceId}, lineId: ${lineId}) -> ${workspaceId} (not found in Supabase data)`);
5656
5678
  } else {
5657
- console.log(`getWorkspaceDisplayName(${workspaceId}) -> ${workspaceId} (Supabase not initialized yet)`);
5679
+ console.log(`getWorkspaceDisplayName(${workspaceId}, lineId: ${lineId}) -> ${workspaceId} (Supabase not initialized yet)`);
5658
5680
  }
5659
5681
  return workspaceId;
5660
5682
  }
5661
5683
  };
5662
5684
  var getShortWorkspaceDisplayName = (workspaceId, lineId) => {
5663
5685
  if (!isInitialized && !isInitializing) {
5664
- console.log("\u{1F504} Lazy initialization triggered by getShortWorkspaceDisplayName");
5686
+ console.log("\u{1F504} Lazy initialization triggered by getShortWorkspaceDisplayName with lineId:", lineId);
5665
5687
  initializeWorkspaceDisplayNames(lineId).catch((error) => {
5666
5688
  console.error("\u274C Lazy initialization failed:", error);
5667
5689
  });
5668
5690
  }
5669
- const displayName = runtimeWorkspaceDisplayNames[workspaceId];
5691
+ if (isInitialized && lineId && !runtimeWorkspaceDisplayNames[lineId]) {
5692
+ console.log(`\u{1F504} Line ${lineId} not in cache, fetching its workspaces...`);
5693
+ workspaceService.getWorkspaceDisplayNames(void 0, lineId).then((lineDisplayNamesMap) => {
5694
+ runtimeWorkspaceDisplayNames[lineId] = {};
5695
+ lineDisplayNamesMap.forEach((displayName2, workspaceId2) => {
5696
+ runtimeWorkspaceDisplayNames[lineId][workspaceId2] = displayName2;
5697
+ });
5698
+ console.log(`\u2705 Added ${lineDisplayNamesMap.size} workspaces for line ${lineId} to cache`);
5699
+ }).catch((error) => {
5700
+ console.error(`\u274C Failed to fetch workspaces for line ${lineId}:`, error);
5701
+ });
5702
+ }
5703
+ let displayName;
5704
+ if (lineId && runtimeWorkspaceDisplayNames[lineId]) {
5705
+ displayName = runtimeWorkspaceDisplayNames[lineId][workspaceId];
5706
+ } else if (!lineId) {
5707
+ for (const cachedLineId of Object.keys(runtimeWorkspaceDisplayNames)) {
5708
+ if (runtimeWorkspaceDisplayNames[cachedLineId][workspaceId]) {
5709
+ displayName = runtimeWorkspaceDisplayNames[cachedLineId][workspaceId];
5710
+ console.warn(`\u26A0\uFE0F No lineId provided for ${workspaceId}, found in line ${cachedLineId}`);
5711
+ break;
5712
+ }
5713
+ }
5714
+ }
5670
5715
  if (displayName) {
5671
- console.log(`getShortWorkspaceDisplayName(${workspaceId}) -> ${displayName} (from Supabase)`);
5716
+ console.log(`getShortWorkspaceDisplayName(${workspaceId}, lineId: ${lineId}) -> ${displayName} (from Supabase)`);
5672
5717
  return displayName;
5673
5718
  } else {
5674
5719
  if (isInitialized) {
5675
- console.log(`getShortWorkspaceDisplayName(${workspaceId}) -> ${workspaceId} (not found in Supabase data)`);
5720
+ console.log(`getShortWorkspaceDisplayName(${workspaceId}, lineId: ${lineId}) -> ${workspaceId} (not found in Supabase data)`);
5676
5721
  } else {
5677
- console.log(`getShortWorkspaceDisplayName(${workspaceId}) -> ${workspaceId} (Supabase not initialized yet)`);
5722
+ console.log(`getShortWorkspaceDisplayName(${workspaceId}, lineId: ${lineId}) -> ${workspaceId} (Supabase not initialized yet)`);
5678
5723
  }
5679
5724
  return workspaceId;
5680
5725
  }
@@ -5695,7 +5740,14 @@ var getAllWorkspaceDisplayNamesAsync = async (companyId, lineId) => {
5695
5740
  while (isInitializing) {
5696
5741
  await new Promise((resolve) => setTimeout(resolve, 100));
5697
5742
  }
5698
- return { ...runtimeWorkspaceDisplayNames };
5743
+ if (lineId && runtimeWorkspaceDisplayNames[lineId]) {
5744
+ return { ...runtimeWorkspaceDisplayNames[lineId] };
5745
+ }
5746
+ const allNames = {};
5747
+ Object.values(runtimeWorkspaceDisplayNames).forEach((lineNames) => {
5748
+ Object.assign(allNames, lineNames);
5749
+ });
5750
+ return allNames;
5699
5751
  };
5700
5752
  var getWorkspaceDisplayNamesMap = async (workspaceIds, companyId, lineId) => {
5701
5753
  const allNames = await getAllWorkspaceDisplayNamesAsync(companyId, lineId);
@@ -5724,10 +5776,11 @@ var clearWorkspaceDisplayNamesCache = () => {
5724
5776
  runtimeWorkspaceDisplayNames = {};
5725
5777
  isInitialized = false;
5726
5778
  isInitializing = false;
5779
+ initializedWithLineIds = [];
5727
5780
  };
5728
5781
 
5729
5782
  // src/lib/hooks/useWorkspaceDisplayNames.ts
5730
- var useWorkspaceDisplayNames = (companyId, lineId) => {
5783
+ var useWorkspaceDisplayNames = (lineId, companyId) => {
5731
5784
  const [displayNames, setDisplayNames] = React19.useState({});
5732
5785
  const [loading, setLoading] = React19.useState(true);
5733
5786
  const [error, setError] = React19.useState(null);
@@ -5753,7 +5806,7 @@ var useWorkspaceDisplayNames = (companyId, lineId) => {
5753
5806
  refetch: fetchDisplayNames
5754
5807
  };
5755
5808
  };
5756
- var useWorkspaceDisplayName = (workspaceId, companyId, lineId) => {
5809
+ var useWorkspaceDisplayName = (workspaceId, lineId, companyId) => {
5757
5810
  const [displayName, setDisplayName] = React19.useState(workspaceId);
5758
5811
  const [loading, setLoading] = React19.useState(true);
5759
5812
  const [error, setError] = React19.useState(null);
@@ -5780,7 +5833,7 @@ var useWorkspaceDisplayName = (workspaceId, companyId, lineId) => {
5780
5833
  refetch: fetchDisplayName
5781
5834
  };
5782
5835
  };
5783
- var useWorkspaceDisplayNamesMap = (workspaceIds, companyId, lineId) => {
5836
+ var useWorkspaceDisplayNamesMap = (workspaceIds, lineId, companyId) => {
5784
5837
  const [displayNames, setDisplayNames] = React19.useState({});
5785
5838
  const [loading, setLoading] = React19.useState(true);
5786
5839
  const [error, setError] = React19.useState(null);
@@ -18491,7 +18544,7 @@ var VideoCard = React19__namespace.default.memo(({
18491
18544
  onFatalError: onFatalError ?? (() => throttledReloadDashboard())
18492
18545
  });
18493
18546
  }
18494
- const displayName = getWorkspaceDisplayName(workspace.workspace_name);
18547
+ const displayName = getWorkspaceDisplayName(workspace.workspace_name, workspace.line_id);
18495
18548
  const getEfficiencyOverlayColor = (efficiency) => {
18496
18549
  if (efficiency >= 80) {
18497
18550
  return "bg-[#00D654]/25";
@@ -18748,7 +18801,7 @@ var VideoGridView = React19__namespace.default.memo(({
18748
18801
  efficiency: workspace.efficiency,
18749
18802
  action_count: workspace.action_count
18750
18803
  });
18751
- const displayName = getWorkspaceDisplayName(workspace.workspace_name);
18804
+ const displayName = getWorkspaceDisplayName(workspace.workspace_name, workspace.line_id);
18752
18805
  const navParams = getWorkspaceNavigationParams(workspaceId, displayName);
18753
18806
  router$1.push(`/workspace/${workspaceId}${navParams}`);
18754
18807
  }, [router$1]);
@@ -20223,7 +20276,7 @@ var LineMonthlyHistory = ({
20223
20276
  className: "block hover:bg-gray-50 transition-colors rounded-lg w-full text-left",
20224
20277
  children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between py-3 px-2 border-b border-gray-100 last:border-b-0", children: [
20225
20278
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "font-medium text-gray-900", children: [
20226
- getWorkspaceDisplayName(workspace.workspace_name),
20279
+ getWorkspaceDisplayName(workspace.workspace_name, lineId),
20227
20280
  workspace.avg_efficiency !== void 0 && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "ml-2 text-sm text-gray-500", children: [
20228
20281
  "(",
20229
20282
  workspace.avg_efficiency.toFixed(1),
@@ -20807,7 +20860,7 @@ var LinePdfGenerator = ({
20807
20860
  doc.setFillColor(252, 252, 252);
20808
20861
  doc.roundedRect(20, yPos - 5, 170, 8, 1, 1, "F");
20809
20862
  }
20810
- const workspaceName = getWorkspaceDisplayName(ws.workspace_name);
20863
+ const workspaceName = getWorkspaceDisplayName(ws.workspace_name, lineInfo.line_id);
20811
20864
  const maxWidth = 55;
20812
20865
  const truncatedName = workspaceName.length > 25 ? workspaceName.substring(0, 22) + "..." : workspaceName;
20813
20866
  doc.text(truncatedName, 25, yPos);
@@ -21488,7 +21541,7 @@ var WorkspacePdfGenerator = ({ workspace, className }) => {
21488
21541
  doc.setFontSize(22);
21489
21542
  doc.setFont("helvetica", "normal");
21490
21543
  doc.setTextColor(40, 40, 40);
21491
- doc.text(getWorkspaceDisplayName(workspace.workspace_name), 20, 52);
21544
+ doc.text(getWorkspaceDisplayName(workspace.workspace_name, workspace.line_id), 20, 52);
21492
21545
  doc.setFontSize(13);
21493
21546
  doc.setFont("helvetica", "normal");
21494
21547
  doc.setTextColor(60, 60, 60);
@@ -23957,7 +24010,7 @@ var WorkspaceGridItem = React19__namespace.default.memo(({
23957
24010
  const handleClick = React19.useCallback((e) => {
23958
24011
  e.preventDefault();
23959
24012
  if (isInactive) return;
23960
- const displayName = getWorkspaceDisplayName(data.workspace_name);
24013
+ const displayName = getWorkspaceDisplayName(data.workspace_name, data.line_id);
23961
24014
  const navParams = getWorkspaceNavigationParams(data.workspace_id, displayName);
23962
24015
  navigate(`/workspace/${data.workspace_id}${navParams}`, {
23963
24016
  trackingEvent: {
@@ -24005,7 +24058,7 @@ var WorkspaceGridItem = React19__namespace.default.memo(({
24005
24058
  onClick: handleClick,
24006
24059
  className: `${styles2} ${colorClass} ${isBottleneck ? "ring-2 ring-red-500/70" : ""} ${isVeryLowEfficiency ? "ring-2 ring-red-500/50" : ""} ${isInactive ? "bg-gray-200" : ""} shadow-lg`,
24007
24060
  "aria-label": isInactive ? `Inactive workspace ${workspaceNumber}` : `View details for workspace ${workspaceNumber}`,
24008
- title: isInactive ? `Inactive: ${getWorkspaceDisplayName(data.workspace_name)}` : getWorkspaceDisplayName(data.workspace_name),
24061
+ title: isInactive ? `Inactive: ${getWorkspaceDisplayName(data.workspace_name, data.line_id)}` : getWorkspaceDisplayName(data.workspace_name, data.line_id),
24009
24062
  children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: `font-semibold tracking-wide text-[min(4vw,2rem)] uppercase ${isInactive ? "text-gray-400" : "text-white"} drop-shadow-sm`, children: workspaceNumber })
24010
24063
  }
24011
24064
  ),
@@ -28820,6 +28873,7 @@ var MetricCards = React19.memo(({ lineInfo }) => {
28820
28873
  MetricCards.displayName = "MetricCards";
28821
28874
  var BottomSection = React19.memo(({
28822
28875
  lineInfo,
28876
+ lineId,
28823
28877
  workspaceData,
28824
28878
  sortedByEfficiency,
28825
28879
  hourlyOutputData,
@@ -28877,7 +28931,7 @@ var BottomSection = React19.memo(({
28877
28931
  return null;
28878
28932
  }
28879
28933
  const clickHandler = () => handleWorkspaceClick(ws, index);
28880
- const displayName = getWorkspaceDisplayName(ws.workspace_name);
28934
+ const displayName = getWorkspaceDisplayName(ws.workspace_name, lineId);
28881
28935
  const navParams = wsUuid ? getWorkspaceNavigationParams2(wsUuid, displayName) : "";
28882
28936
  const dateShiftParams = urlDate ? `&date=${urlDate}&shift=${urlShift || "0"}` : "";
28883
28937
  const returnToParam = `&returnTo=${encodeURIComponent(`/kpis/${lineInfo?.line_id}`)}`;
@@ -28911,7 +28965,7 @@ var BottomSection = React19.memo(({
28911
28965
  // Fallback to sorted workspaces if no poorest performing workspaces provided
28912
28966
  sortedByEfficiency.map((ws, index) => {
28913
28967
  const clickHandler = () => handleWorkspaceClick(ws, index);
28914
- const displayName = getWorkspaceDisplayName(ws.workspace_name);
28968
+ const displayName = getWorkspaceDisplayName(ws.workspace_name, lineId);
28915
28969
  const navParams = ws.workspace_uuid ? getWorkspaceNavigationParams2(ws.workspace_uuid, displayName) : "";
28916
28970
  const dateShiftParams = urlDate ? `&date=${urlDate}&shift=${urlShift || "0"}` : "";
28917
28971
  const returnToParam = `&returnTo=${encodeURIComponent(`/kpis/${lineInfo?.line_id}`)}`;
@@ -29408,6 +29462,7 @@ var KPIDetailView = ({
29408
29462
  BottomSection,
29409
29463
  {
29410
29464
  lineInfo,
29465
+ lineId,
29411
29466
  workspaceData: workspaces || [],
29412
29467
  sortedByEfficiency,
29413
29468
  hourlyOutputData,
@@ -29510,6 +29565,7 @@ var KPIDetailView = ({
29510
29565
  BottomSection,
29511
29566
  {
29512
29567
  lineInfo,
29568
+ lineId,
29513
29569
  workspaceData: workspaces || [],
29514
29570
  sortedByEfficiency,
29515
29571
  hourlyOutputData,
@@ -29528,34 +29584,10 @@ var KPIDetailView = ({
29528
29584
  var KPIDetailView_default = KPIDetailView;
29529
29585
  var LineCard = ({ line, onClick }) => {
29530
29586
  const { kpis, isLoading, error } = useLineKPIs({ lineId: line.id });
29531
- const shiftConfig = useShiftConfig();
29532
- const dateTimeConfig = useDateTimeConfig();
29533
29587
  const isOnTrack = React19__namespace.default.useMemo(() => {
29534
29588
  if (!kpis) return null;
29535
- const currentTime = /* @__PURE__ */ new Date();
29536
- const timezone = dateTimeConfig.defaultTimezone || "Asia/Kolkata";
29537
- const currentShiftDetails = getCurrentShift(timezone, shiftConfig);
29538
- const shiftStartTime = currentShiftDetails.shiftId === 0 ? shiftConfig.dayShift?.startTime || "06:00" : shiftConfig.nightShift?.startTime || "18:00";
29539
- const shiftEndTime = currentShiftDetails.shiftId === 0 ? shiftConfig.dayShift?.endTime || "14:00" : shiftConfig.nightShift?.endTime || "02:00";
29540
- const [startHour, startMin] = shiftStartTime.split(":").map(Number);
29541
- const [endHour, endMin] = shiftEndTime.split(":").map(Number);
29542
- const shiftStart = /* @__PURE__ */ new Date();
29543
- shiftStart.setHours(startHour, startMin, 0, 0);
29544
- const shiftEnd = /* @__PURE__ */ new Date();
29545
- shiftEnd.setHours(endHour, endMin, 0, 0);
29546
- if (endHour < startHour) {
29547
- if (currentTime.getHours() < endHour) {
29548
- shiftStart.setDate(shiftStart.getDate() - 1);
29549
- } else {
29550
- shiftEnd.setDate(shiftEnd.getDate() + 1);
29551
- }
29552
- }
29553
- const totalShiftMinutes = (shiftEnd.getTime() - shiftStart.getTime()) / (1e3 * 60);
29554
- const elapsedMinutes = (currentTime.getTime() - shiftStart.getTime()) / (1e3 * 60);
29555
- const shiftProgress = Math.max(0, Math.min(1, elapsedMinutes / totalShiftMinutes));
29556
- const outputProgress = kpis.outputProgress.current / kpis.outputProgress.target;
29557
- return outputProgress >= shiftProgress - 0.05;
29558
- }, [kpis, shiftConfig, dateTimeConfig]);
29589
+ return kpis.efficiency.value > 90;
29590
+ }, [kpis]);
29559
29591
  return /* @__PURE__ */ jsxRuntime.jsxs(
29560
29592
  motion.div,
29561
29593
  {
@@ -29871,7 +29903,7 @@ var MobileWorkspaceCard = React19.memo(({
29871
29903
  getMedalIcon(rank)
29872
29904
  ] }),
29873
29905
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
29874
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-semibold text-gray-900", children: getWorkspaceDisplayName(workspace.workspace_name) }),
29906
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-semibold text-gray-900", children: getWorkspaceDisplayName(workspace.workspace_name, workspace.line_id) }),
29875
29907
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-gray-500", children: getLineName(workspace.line_id) })
29876
29908
  ] })
29877
29909
  ] }),
@@ -29921,7 +29953,7 @@ var DesktopWorkspaceRow = React19.memo(({
29921
29953
  /* @__PURE__ */ jsxRuntime.jsx("span", { children: index + 1 }),
29922
29954
  getMedalIcon(index + 1)
29923
29955
  ] }) }),
29924
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-3 py-2.5 sm:p-4 text-sm sm:text-base whitespace-nowrap", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-medium", children: getWorkspaceDisplayName(workspace.workspace_name) }) }),
29956
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-3 py-2.5 sm:p-4 text-sm sm:text-base whitespace-nowrap", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-medium", children: getWorkspaceDisplayName(workspace.workspace_name, workspace.line_id) }) }),
29925
29957
  /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-3 py-2.5 sm:p-4 text-sm sm:text-base whitespace-nowrap", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-medium", children: getLineName(workspace.line_id) }) }),
29926
29958
  /* @__PURE__ */ jsxRuntime.jsxs("td", { className: "px-3 py-2.5 sm:p-4 text-sm sm:text-base font-medium whitespace-nowrap", children: [
29927
29959
  (workspace.efficiency || 0).toFixed(1),
@@ -30038,7 +30070,7 @@ var LeaderboardDetailView = React19.memo(({
30038
30070
  action_count: workspace.action_count,
30039
30071
  action_threshold: workspace.action_threshold
30040
30072
  });
30041
- const displayName = getWorkspaceDisplayName(workspace.workspace_name);
30073
+ const displayName = getWorkspaceDisplayName(workspace.workspace_name, workspace.line_id);
30042
30074
  const navParams = workspace.workspace_uuid ? getWorkspaceNavigationParams(workspace.workspace_uuid, displayName) : "";
30043
30075
  const returnToParam = `&returnTo=${encodeURIComponent(`/leaderboard`)}`;
30044
30076
  if (onWorkspaceClick) {
@@ -31266,8 +31298,8 @@ var calculateDayOutput = (pph, shiftHours, breaks = []) => {
31266
31298
  const realWorkHours = shiftHours - totalBreakHours;
31267
31299
  return Math.round(pph * realWorkHours);
31268
31300
  };
31269
- var formatWorkspaceName = (name) => {
31270
- return getWorkspaceDisplayName(name);
31301
+ var formatWorkspaceName = (name, lineId) => {
31302
+ return getWorkspaceDisplayName(name, lineId);
31271
31303
  };
31272
31304
  var getStoredLineState2 = (lineId) => {
31273
31305
  try {
@@ -31295,6 +31327,7 @@ var BulkConfigureModal = ({
31295
31327
  isOpen,
31296
31328
  onClose,
31297
31329
  lineWorkspaces,
31330
+ lineNames,
31298
31331
  onSave,
31299
31332
  selectedShift
31300
31333
  }) => {
@@ -31445,10 +31478,7 @@ var BulkConfigureModal = ({
31445
31478
  className: "block w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm\n shadow-sm focus:border-blue-500 focus:ring-blue-500 \n transition-all duration-200 hover:border-blue-400\n appearance-none bg-no-repeat bg-right pr-10\n hover:bg-blue-50/50",
31446
31479
  children: [
31447
31480
  /* @__PURE__ */ jsxRuntime.jsx("option", { value: "", children: "Select a line" }),
31448
- Object.entries(lineWorkspaces).map(([lineId, line]) => /* @__PURE__ */ jsxRuntime.jsxs("option", { value: lineId, className: "py-2", children: [
31449
- lineId,
31450
- " "
31451
- ] }, lineId))
31481
+ Object.entries(lineWorkspaces).map(([lineId, line]) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: lineId, className: "py-2", children: lineNames[lineId] || lineId }, lineId))
31452
31482
  ]
31453
31483
  }
31454
31484
  )
@@ -31506,7 +31536,7 @@ var BulkConfigureModal = ({
31506
31536
  className: "rounded border-gray-300 text-blue-600 focus:ring-blue-500"
31507
31537
  }
31508
31538
  ),
31509
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: `text-sm ${selectedWorkspaces.includes(workspace.id) ? "text-blue-900 font-medium" : "text-gray-900"}`, children: formatWorkspaceName(workspace.name) })
31539
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: `text-sm ${selectedWorkspaces.includes(workspace.id) ? "text-blue-900 font-medium" : "text-gray-900"}`, children: formatWorkspaceName(workspace.name, selectedLine) })
31510
31540
  ]
31511
31541
  },
31512
31542
  workspace.id
@@ -32193,7 +32223,7 @@ var TargetsViewUI = ({
32193
32223
  {
32194
32224
  className: "px-6 py-4 hover:bg-gray-50 transition-all duration-200",
32195
32225
  children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-12 gap-6 items-center", children: [
32196
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "col-span-2", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-medium text-gray-900", children: formatWorkspaceName(workspace.name) }) }),
32226
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "col-span-2", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-medium text-gray-900", children: formatWorkspaceName(workspace.name, lineId) }) }),
32197
32227
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "col-span-2", children: /* @__PURE__ */ jsxRuntime.jsxs(
32198
32228
  "select",
32199
32229
  {
@@ -32203,7 +32233,7 @@ var TargetsViewUI = ({
32203
32233
  onActionTypeChange(lineId, workspace.id, newActionType);
32204
32234
  },
32205
32235
  className: "w-full p-2 border border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm",
32206
- "aria-label": `Action type for ${formatWorkspaceName(workspace.name)}`,
32236
+ "aria-label": `Action type for ${formatWorkspaceName(workspace.name, lineId)}`,
32207
32237
  children: [
32208
32238
  /* @__PURE__ */ jsxRuntime.jsx("option", { value: "assembly", className: "py-2", children: "Assembly" }),
32209
32239
  /* @__PURE__ */ jsxRuntime.jsx("option", { value: "packaging", className: "py-2", children: "Packaging" })
@@ -32262,6 +32292,7 @@ var TargetsViewUI = ({
32262
32292
  isOpen: isBulkConfigureOpen,
32263
32293
  onClose: onToggleBulkConfigure,
32264
32294
  lineWorkspaces,
32295
+ lineNames,
32265
32296
  onSave: onBulkConfigure,
32266
32297
  selectedShift
32267
32298
  }
package/dist/index.mjs CHANGED
@@ -4584,20 +4584,13 @@ var useRealtimeLineMetrics = ({
4584
4584
  workspaceData: workspaceData?.length
4585
4585
  });
4586
4586
  }
4587
- let avgEfficiency = 0;
4588
- if (workspaceData && workspaceData.length > 0) {
4589
- const activeWorkspaces = workspaceData.filter((w) => w.efficiency >= 10);
4590
- if (activeWorkspaces.length > 0) {
4591
- const totalEfficiency = activeWorkspaces.reduce((sum, workspace) => sum + (workspace.efficiency || 0), 0);
4592
- avgEfficiency = totalEfficiency / activeWorkspaces.length;
4593
- }
4594
- }
4587
+ const avgEfficiency = metricsData.reduce((sum, m) => sum + (m.avg_efficiency || 0), 0) / metricsData.length;
4595
4588
  const combinedMetrics = {
4596
4589
  line_id: factoryViewId,
4597
4590
  shift_id: shiftId,
4598
4591
  date,
4599
4592
  factory_id: firstLine.factory_id,
4600
- avg_efficiency: avgEfficiency > 0 ? avgEfficiency : metricsData.reduce((sum, m) => sum + (m.avg_efficiency || 0), 0) / metricsData.length,
4593
+ avg_efficiency: avgEfficiency,
4601
4594
  avg_cycle_time: metricsData.reduce((sum, m) => sum + (m.avg_cycle_time || 0), 0) / metricsData.length,
4602
4595
  current_output: metricsData.reduce((sum, m) => sum + (m.current_output || 0), 0),
4603
4596
  ideal_output: metricsData.reduce((sum, m) => sum + (m.ideal_output || 0), 0),
@@ -4649,22 +4642,14 @@ var useRealtimeLineMetrics = ({
4649
4642
  workspaceData: workspaceData?.length
4650
4643
  });
4651
4644
  }
4652
- let avgEfficiency = 0;
4653
- if (workspaceData && workspaceData.length > 0) {
4654
- const activeWorkspaces = workspaceData.filter((w) => w.efficiency >= 10);
4655
- if (activeWorkspaces.length > 0) {
4656
- const totalEfficiency = activeWorkspaces.reduce((sum, workspace) => sum + (workspace.efficiency || 0), 0);
4657
- avgEfficiency = totalEfficiency / activeWorkspaces.length;
4658
- }
4659
- }
4660
4645
  if (!metricsData) {
4661
4646
  setMetrics({
4662
4647
  line_id: lineIdRef.current,
4663
4648
  shift_id: shiftId,
4664
4649
  date,
4665
4650
  factory_id: "",
4666
- avg_efficiency: avgEfficiency,
4667
- // Use calculated workspace average
4651
+ avg_efficiency: 0,
4652
+ // Default to 0 when no data
4668
4653
  avg_cycle_time: 0,
4669
4654
  current_output: 0,
4670
4655
  ideal_output: 0,
@@ -4683,7 +4668,6 @@ var useRealtimeLineMetrics = ({
4683
4668
  } else {
4684
4669
  setMetrics({
4685
4670
  ...metricsData,
4686
- avg_efficiency: avgEfficiency > 0 ? avgEfficiency : metricsData.avg_efficiency,
4687
4671
  poorest_performing_workspaces: poorestPerformingWorkspaces
4688
4672
  });
4689
4673
  }
@@ -5532,6 +5516,7 @@ console.log("\u{1F504} workspaceDisplayNames.ts module loaded");
5532
5516
  var runtimeWorkspaceDisplayNames = {};
5533
5517
  var isInitialized = false;
5534
5518
  var isInitializing = false;
5519
+ var initializedWithLineIds = [];
5535
5520
  function getCurrentLineIds() {
5536
5521
  try {
5537
5522
  const config = _getDashboardConfigInstance();
@@ -5563,28 +5548,29 @@ async function initializeWorkspaceDisplayNames(explicitLineId) {
5563
5548
  targetLineIds = getCurrentLineIds();
5564
5549
  }
5565
5550
  console.log("\u{1F504} Target line IDs for workspace filtering:", targetLineIds);
5566
- const allDisplayNamesMap = /* @__PURE__ */ new Map();
5551
+ runtimeWorkspaceDisplayNames = {};
5567
5552
  if (targetLineIds.length > 0) {
5568
5553
  for (const lineId of targetLineIds) {
5569
5554
  console.log(`\u{1F504} Fetching workspaces for line: ${lineId}`);
5570
5555
  const lineDisplayNamesMap = await workspaceService.getWorkspaceDisplayNames(void 0, lineId);
5556
+ runtimeWorkspaceDisplayNames[lineId] = {};
5571
5557
  lineDisplayNamesMap.forEach((displayName, workspaceId) => {
5572
- allDisplayNamesMap.set(workspaceId, displayName);
5558
+ runtimeWorkspaceDisplayNames[lineId][workspaceId] = displayName;
5573
5559
  });
5560
+ console.log(`\u2705 Stored ${lineDisplayNamesMap.size} workspaces for line ${lineId}`);
5574
5561
  }
5575
5562
  } else {
5576
5563
  console.warn("\u26A0\uFE0F No line IDs found, fetching all workspaces (less efficient)");
5577
5564
  const allWorkspacesMap = await workspaceService.getWorkspaceDisplayNames();
5565
+ runtimeWorkspaceDisplayNames["global"] = {};
5578
5566
  allWorkspacesMap.forEach((displayName, workspaceId) => {
5579
- allDisplayNamesMap.set(workspaceId, displayName);
5567
+ runtimeWorkspaceDisplayNames["global"][workspaceId] = displayName;
5580
5568
  });
5581
5569
  }
5582
- runtimeWorkspaceDisplayNames = {};
5583
- allDisplayNamesMap.forEach((displayName, workspaceId) => {
5584
- runtimeWorkspaceDisplayNames[workspaceId] = displayName;
5585
- });
5586
5570
  isInitialized = true;
5571
+ initializedWithLineIds = targetLineIds;
5587
5572
  console.log("\u2705 Workspace display names initialized from Supabase:", runtimeWorkspaceDisplayNames);
5573
+ console.log("\u2705 Initialized with line IDs:", initializedWithLineIds);
5588
5574
  } catch (error) {
5589
5575
  console.error("\u274C Failed to initialize workspace display names from Supabase:", error);
5590
5576
  } finally {
@@ -5594,7 +5580,20 @@ async function initializeWorkspaceDisplayNames(explicitLineId) {
5594
5580
  var preInitializeWorkspaceDisplayNames = async (lineId) => {
5595
5581
  console.log("\u{1F504} preInitializeWorkspaceDisplayNames called for lineId:", lineId);
5596
5582
  if (isInitialized || isInitializing) {
5597
- console.log("\u{1F504} Already initialized or initializing, skipping pre-init");
5583
+ console.log("\u{1F504} Already initialized or initializing");
5584
+ if (lineId && !runtimeWorkspaceDisplayNames[lineId]) {
5585
+ console.log(`\u{1F504} Line ${lineId} not in cache, fetching...`);
5586
+ try {
5587
+ const lineDisplayNamesMap = await workspaceService.getWorkspaceDisplayNames(void 0, lineId);
5588
+ runtimeWorkspaceDisplayNames[lineId] = {};
5589
+ lineDisplayNamesMap.forEach((displayName, workspaceId) => {
5590
+ runtimeWorkspaceDisplayNames[lineId][workspaceId] = displayName;
5591
+ });
5592
+ console.log(`\u2705 Added ${lineDisplayNamesMap.size} workspaces for line ${lineId}`);
5593
+ } catch (error) {
5594
+ console.error(`\u274C Failed to fetch workspaces for line ${lineId}:`, error);
5595
+ }
5596
+ }
5598
5597
  return;
5599
5598
  }
5600
5599
  await initializeWorkspaceDisplayNames(lineId);
@@ -5607,45 +5606,91 @@ var forceRefreshWorkspaceDisplayNames = async (lineId) => {
5607
5606
  console.log("\u{1F504} Module loaded, will initialize lazily when first function is called");
5608
5607
  var getWorkspaceDisplayName = (workspaceId, lineId) => {
5609
5608
  if (!isInitialized && !isInitializing) {
5610
- console.log(`\u{1F504} [DEBUG] getWorkspaceDisplayName(${workspaceId}) - Not initialized, triggering lazy init...`);
5609
+ console.log(`\u{1F504} [DEBUG] getWorkspaceDisplayName(${workspaceId}, lineId: ${lineId}) - Not initialized, triggering lazy init...`);
5611
5610
  } else if (isInitializing) {
5612
- console.log(`\u{1F504} [DEBUG] getWorkspaceDisplayName(${workspaceId}) - Currently initializing...`);
5611
+ console.log(`\u{1F504} [DEBUG] getWorkspaceDisplayName(${workspaceId}, lineId: ${lineId}) - Currently initializing...`);
5613
5612
  }
5614
5613
  if (!isInitialized && !isInitializing) {
5615
- console.log("\u{1F504} Lazy initialization triggered by getWorkspaceDisplayName");
5614
+ console.log("\u{1F504} Lazy initialization triggered by getWorkspaceDisplayName with lineId:", lineId);
5616
5615
  initializeWorkspaceDisplayNames(lineId).catch((error) => {
5617
5616
  console.error("\u274C Lazy initialization failed:", error);
5618
5617
  });
5619
5618
  }
5620
- const displayName = runtimeWorkspaceDisplayNames[workspaceId];
5619
+ if (isInitialized && lineId && !runtimeWorkspaceDisplayNames[lineId]) {
5620
+ console.log(`\u{1F504} Line ${lineId} not in cache, fetching its workspaces...`);
5621
+ workspaceService.getWorkspaceDisplayNames(void 0, lineId).then((lineDisplayNamesMap) => {
5622
+ runtimeWorkspaceDisplayNames[lineId] = {};
5623
+ lineDisplayNamesMap.forEach((displayName2, workspaceId2) => {
5624
+ runtimeWorkspaceDisplayNames[lineId][workspaceId2] = displayName2;
5625
+ });
5626
+ console.log(`\u2705 Added ${lineDisplayNamesMap.size} workspaces for line ${lineId} to cache`);
5627
+ }).catch((error) => {
5628
+ console.error(`\u274C Failed to fetch workspaces for line ${lineId}:`, error);
5629
+ });
5630
+ }
5631
+ let displayName;
5632
+ if (lineId && runtimeWorkspaceDisplayNames[lineId]) {
5633
+ displayName = runtimeWorkspaceDisplayNames[lineId][workspaceId];
5634
+ } else if (!lineId) {
5635
+ for (const cachedLineId of Object.keys(runtimeWorkspaceDisplayNames)) {
5636
+ if (runtimeWorkspaceDisplayNames[cachedLineId][workspaceId]) {
5637
+ displayName = runtimeWorkspaceDisplayNames[cachedLineId][workspaceId];
5638
+ console.warn(`\u26A0\uFE0F No lineId provided for ${workspaceId}, found in line ${cachedLineId}`);
5639
+ break;
5640
+ }
5641
+ }
5642
+ }
5621
5643
  if (displayName) {
5622
- console.log(`getWorkspaceDisplayName(${workspaceId}) -> ${displayName} (from Supabase)`);
5644
+ console.log(`getWorkspaceDisplayName(${workspaceId}, lineId: ${lineId}) -> ${displayName} (from Supabase)`);
5623
5645
  return displayName;
5624
5646
  } else {
5625
5647
  if (isInitialized) {
5626
- console.log(`getWorkspaceDisplayName(${workspaceId}) -> ${workspaceId} (not found in Supabase data)`);
5648
+ console.log(`getWorkspaceDisplayName(${workspaceId}, lineId: ${lineId}) -> ${workspaceId} (not found in Supabase data)`);
5627
5649
  } else {
5628
- console.log(`getWorkspaceDisplayName(${workspaceId}) -> ${workspaceId} (Supabase not initialized yet)`);
5650
+ console.log(`getWorkspaceDisplayName(${workspaceId}, lineId: ${lineId}) -> ${workspaceId} (Supabase not initialized yet)`);
5629
5651
  }
5630
5652
  return workspaceId;
5631
5653
  }
5632
5654
  };
5633
5655
  var getShortWorkspaceDisplayName = (workspaceId, lineId) => {
5634
5656
  if (!isInitialized && !isInitializing) {
5635
- console.log("\u{1F504} Lazy initialization triggered by getShortWorkspaceDisplayName");
5657
+ console.log("\u{1F504} Lazy initialization triggered by getShortWorkspaceDisplayName with lineId:", lineId);
5636
5658
  initializeWorkspaceDisplayNames(lineId).catch((error) => {
5637
5659
  console.error("\u274C Lazy initialization failed:", error);
5638
5660
  });
5639
5661
  }
5640
- const displayName = runtimeWorkspaceDisplayNames[workspaceId];
5662
+ if (isInitialized && lineId && !runtimeWorkspaceDisplayNames[lineId]) {
5663
+ console.log(`\u{1F504} Line ${lineId} not in cache, fetching its workspaces...`);
5664
+ workspaceService.getWorkspaceDisplayNames(void 0, lineId).then((lineDisplayNamesMap) => {
5665
+ runtimeWorkspaceDisplayNames[lineId] = {};
5666
+ lineDisplayNamesMap.forEach((displayName2, workspaceId2) => {
5667
+ runtimeWorkspaceDisplayNames[lineId][workspaceId2] = displayName2;
5668
+ });
5669
+ console.log(`\u2705 Added ${lineDisplayNamesMap.size} workspaces for line ${lineId} to cache`);
5670
+ }).catch((error) => {
5671
+ console.error(`\u274C Failed to fetch workspaces for line ${lineId}:`, error);
5672
+ });
5673
+ }
5674
+ let displayName;
5675
+ if (lineId && runtimeWorkspaceDisplayNames[lineId]) {
5676
+ displayName = runtimeWorkspaceDisplayNames[lineId][workspaceId];
5677
+ } else if (!lineId) {
5678
+ for (const cachedLineId of Object.keys(runtimeWorkspaceDisplayNames)) {
5679
+ if (runtimeWorkspaceDisplayNames[cachedLineId][workspaceId]) {
5680
+ displayName = runtimeWorkspaceDisplayNames[cachedLineId][workspaceId];
5681
+ console.warn(`\u26A0\uFE0F No lineId provided for ${workspaceId}, found in line ${cachedLineId}`);
5682
+ break;
5683
+ }
5684
+ }
5685
+ }
5641
5686
  if (displayName) {
5642
- console.log(`getShortWorkspaceDisplayName(${workspaceId}) -> ${displayName} (from Supabase)`);
5687
+ console.log(`getShortWorkspaceDisplayName(${workspaceId}, lineId: ${lineId}) -> ${displayName} (from Supabase)`);
5643
5688
  return displayName;
5644
5689
  } else {
5645
5690
  if (isInitialized) {
5646
- console.log(`getShortWorkspaceDisplayName(${workspaceId}) -> ${workspaceId} (not found in Supabase data)`);
5691
+ console.log(`getShortWorkspaceDisplayName(${workspaceId}, lineId: ${lineId}) -> ${workspaceId} (not found in Supabase data)`);
5647
5692
  } else {
5648
- console.log(`getShortWorkspaceDisplayName(${workspaceId}) -> ${workspaceId} (Supabase not initialized yet)`);
5693
+ console.log(`getShortWorkspaceDisplayName(${workspaceId}, lineId: ${lineId}) -> ${workspaceId} (Supabase not initialized yet)`);
5649
5694
  }
5650
5695
  return workspaceId;
5651
5696
  }
@@ -5666,7 +5711,14 @@ var getAllWorkspaceDisplayNamesAsync = async (companyId, lineId) => {
5666
5711
  while (isInitializing) {
5667
5712
  await new Promise((resolve) => setTimeout(resolve, 100));
5668
5713
  }
5669
- return { ...runtimeWorkspaceDisplayNames };
5714
+ if (lineId && runtimeWorkspaceDisplayNames[lineId]) {
5715
+ return { ...runtimeWorkspaceDisplayNames[lineId] };
5716
+ }
5717
+ const allNames = {};
5718
+ Object.values(runtimeWorkspaceDisplayNames).forEach((lineNames) => {
5719
+ Object.assign(allNames, lineNames);
5720
+ });
5721
+ return allNames;
5670
5722
  };
5671
5723
  var getWorkspaceDisplayNamesMap = async (workspaceIds, companyId, lineId) => {
5672
5724
  const allNames = await getAllWorkspaceDisplayNamesAsync(companyId, lineId);
@@ -5695,10 +5747,11 @@ var clearWorkspaceDisplayNamesCache = () => {
5695
5747
  runtimeWorkspaceDisplayNames = {};
5696
5748
  isInitialized = false;
5697
5749
  isInitializing = false;
5750
+ initializedWithLineIds = [];
5698
5751
  };
5699
5752
 
5700
5753
  // src/lib/hooks/useWorkspaceDisplayNames.ts
5701
- var useWorkspaceDisplayNames = (companyId, lineId) => {
5754
+ var useWorkspaceDisplayNames = (lineId, companyId) => {
5702
5755
  const [displayNames, setDisplayNames] = useState({});
5703
5756
  const [loading, setLoading] = useState(true);
5704
5757
  const [error, setError] = useState(null);
@@ -5724,7 +5777,7 @@ var useWorkspaceDisplayNames = (companyId, lineId) => {
5724
5777
  refetch: fetchDisplayNames
5725
5778
  };
5726
5779
  };
5727
- var useWorkspaceDisplayName = (workspaceId, companyId, lineId) => {
5780
+ var useWorkspaceDisplayName = (workspaceId, lineId, companyId) => {
5728
5781
  const [displayName, setDisplayName] = useState(workspaceId);
5729
5782
  const [loading, setLoading] = useState(true);
5730
5783
  const [error, setError] = useState(null);
@@ -5751,7 +5804,7 @@ var useWorkspaceDisplayName = (workspaceId, companyId, lineId) => {
5751
5804
  refetch: fetchDisplayName
5752
5805
  };
5753
5806
  };
5754
- var useWorkspaceDisplayNamesMap = (workspaceIds, companyId, lineId) => {
5807
+ var useWorkspaceDisplayNamesMap = (workspaceIds, lineId, companyId) => {
5755
5808
  const [displayNames, setDisplayNames] = useState({});
5756
5809
  const [loading, setLoading] = useState(true);
5757
5810
  const [error, setError] = useState(null);
@@ -18462,7 +18515,7 @@ var VideoCard = React19__default.memo(({
18462
18515
  onFatalError: onFatalError ?? (() => throttledReloadDashboard())
18463
18516
  });
18464
18517
  }
18465
- const displayName = getWorkspaceDisplayName(workspace.workspace_name);
18518
+ const displayName = getWorkspaceDisplayName(workspace.workspace_name, workspace.line_id);
18466
18519
  const getEfficiencyOverlayColor = (efficiency) => {
18467
18520
  if (efficiency >= 80) {
18468
18521
  return "bg-[#00D654]/25";
@@ -18719,7 +18772,7 @@ var VideoGridView = React19__default.memo(({
18719
18772
  efficiency: workspace.efficiency,
18720
18773
  action_count: workspace.action_count
18721
18774
  });
18722
- const displayName = getWorkspaceDisplayName(workspace.workspace_name);
18775
+ const displayName = getWorkspaceDisplayName(workspace.workspace_name, workspace.line_id);
18723
18776
  const navParams = getWorkspaceNavigationParams(workspaceId, displayName);
18724
18777
  router.push(`/workspace/${workspaceId}${navParams}`);
18725
18778
  }, [router]);
@@ -20194,7 +20247,7 @@ var LineMonthlyHistory = ({
20194
20247
  className: "block hover:bg-gray-50 transition-colors rounded-lg w-full text-left",
20195
20248
  children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between py-3 px-2 border-b border-gray-100 last:border-b-0", children: [
20196
20249
  /* @__PURE__ */ jsxs("div", { className: "font-medium text-gray-900", children: [
20197
- getWorkspaceDisplayName(workspace.workspace_name),
20250
+ getWorkspaceDisplayName(workspace.workspace_name, lineId),
20198
20251
  workspace.avg_efficiency !== void 0 && /* @__PURE__ */ jsxs("span", { className: "ml-2 text-sm text-gray-500", children: [
20199
20252
  "(",
20200
20253
  workspace.avg_efficiency.toFixed(1),
@@ -20778,7 +20831,7 @@ var LinePdfGenerator = ({
20778
20831
  doc.setFillColor(252, 252, 252);
20779
20832
  doc.roundedRect(20, yPos - 5, 170, 8, 1, 1, "F");
20780
20833
  }
20781
- const workspaceName = getWorkspaceDisplayName(ws.workspace_name);
20834
+ const workspaceName = getWorkspaceDisplayName(ws.workspace_name, lineInfo.line_id);
20782
20835
  const maxWidth = 55;
20783
20836
  const truncatedName = workspaceName.length > 25 ? workspaceName.substring(0, 22) + "..." : workspaceName;
20784
20837
  doc.text(truncatedName, 25, yPos);
@@ -21459,7 +21512,7 @@ var WorkspacePdfGenerator = ({ workspace, className }) => {
21459
21512
  doc.setFontSize(22);
21460
21513
  doc.setFont("helvetica", "normal");
21461
21514
  doc.setTextColor(40, 40, 40);
21462
- doc.text(getWorkspaceDisplayName(workspace.workspace_name), 20, 52);
21515
+ doc.text(getWorkspaceDisplayName(workspace.workspace_name, workspace.line_id), 20, 52);
21463
21516
  doc.setFontSize(13);
21464
21517
  doc.setFont("helvetica", "normal");
21465
21518
  doc.setTextColor(60, 60, 60);
@@ -23928,7 +23981,7 @@ var WorkspaceGridItem = React19__default.memo(({
23928
23981
  const handleClick = useCallback((e) => {
23929
23982
  e.preventDefault();
23930
23983
  if (isInactive) return;
23931
- const displayName = getWorkspaceDisplayName(data.workspace_name);
23984
+ const displayName = getWorkspaceDisplayName(data.workspace_name, data.line_id);
23932
23985
  const navParams = getWorkspaceNavigationParams(data.workspace_id, displayName);
23933
23986
  navigate(`/workspace/${data.workspace_id}${navParams}`, {
23934
23987
  trackingEvent: {
@@ -23976,7 +24029,7 @@ var WorkspaceGridItem = React19__default.memo(({
23976
24029
  onClick: handleClick,
23977
24030
  className: `${styles2} ${colorClass} ${isBottleneck ? "ring-2 ring-red-500/70" : ""} ${isVeryLowEfficiency ? "ring-2 ring-red-500/50" : ""} ${isInactive ? "bg-gray-200" : ""} shadow-lg`,
23978
24031
  "aria-label": isInactive ? `Inactive workspace ${workspaceNumber}` : `View details for workspace ${workspaceNumber}`,
23979
- title: isInactive ? `Inactive: ${getWorkspaceDisplayName(data.workspace_name)}` : getWorkspaceDisplayName(data.workspace_name),
24032
+ title: isInactive ? `Inactive: ${getWorkspaceDisplayName(data.workspace_name, data.line_id)}` : getWorkspaceDisplayName(data.workspace_name, data.line_id),
23980
24033
  children: /* @__PURE__ */ jsx("div", { className: `font-semibold tracking-wide text-[min(4vw,2rem)] uppercase ${isInactive ? "text-gray-400" : "text-white"} drop-shadow-sm`, children: workspaceNumber })
23981
24034
  }
23982
24035
  ),
@@ -28791,6 +28844,7 @@ var MetricCards = memo(({ lineInfo }) => {
28791
28844
  MetricCards.displayName = "MetricCards";
28792
28845
  var BottomSection = memo(({
28793
28846
  lineInfo,
28847
+ lineId,
28794
28848
  workspaceData,
28795
28849
  sortedByEfficiency,
28796
28850
  hourlyOutputData,
@@ -28848,7 +28902,7 @@ var BottomSection = memo(({
28848
28902
  return null;
28849
28903
  }
28850
28904
  const clickHandler = () => handleWorkspaceClick(ws, index);
28851
- const displayName = getWorkspaceDisplayName(ws.workspace_name);
28905
+ const displayName = getWorkspaceDisplayName(ws.workspace_name, lineId);
28852
28906
  const navParams = wsUuid ? getWorkspaceNavigationParams2(wsUuid, displayName) : "";
28853
28907
  const dateShiftParams = urlDate ? `&date=${urlDate}&shift=${urlShift || "0"}` : "";
28854
28908
  const returnToParam = `&returnTo=${encodeURIComponent(`/kpis/${lineInfo?.line_id}`)}`;
@@ -28882,7 +28936,7 @@ var BottomSection = memo(({
28882
28936
  // Fallback to sorted workspaces if no poorest performing workspaces provided
28883
28937
  sortedByEfficiency.map((ws, index) => {
28884
28938
  const clickHandler = () => handleWorkspaceClick(ws, index);
28885
- const displayName = getWorkspaceDisplayName(ws.workspace_name);
28939
+ const displayName = getWorkspaceDisplayName(ws.workspace_name, lineId);
28886
28940
  const navParams = ws.workspace_uuid ? getWorkspaceNavigationParams2(ws.workspace_uuid, displayName) : "";
28887
28941
  const dateShiftParams = urlDate ? `&date=${urlDate}&shift=${urlShift || "0"}` : "";
28888
28942
  const returnToParam = `&returnTo=${encodeURIComponent(`/kpis/${lineInfo?.line_id}`)}`;
@@ -29379,6 +29433,7 @@ var KPIDetailView = ({
29379
29433
  BottomSection,
29380
29434
  {
29381
29435
  lineInfo,
29436
+ lineId,
29382
29437
  workspaceData: workspaces || [],
29383
29438
  sortedByEfficiency,
29384
29439
  hourlyOutputData,
@@ -29481,6 +29536,7 @@ var KPIDetailView = ({
29481
29536
  BottomSection,
29482
29537
  {
29483
29538
  lineInfo,
29539
+ lineId,
29484
29540
  workspaceData: workspaces || [],
29485
29541
  sortedByEfficiency,
29486
29542
  hourlyOutputData,
@@ -29499,34 +29555,10 @@ var KPIDetailView = ({
29499
29555
  var KPIDetailView_default = KPIDetailView;
29500
29556
  var LineCard = ({ line, onClick }) => {
29501
29557
  const { kpis, isLoading, error } = useLineKPIs({ lineId: line.id });
29502
- const shiftConfig = useShiftConfig();
29503
- const dateTimeConfig = useDateTimeConfig();
29504
29558
  const isOnTrack = React19__default.useMemo(() => {
29505
29559
  if (!kpis) return null;
29506
- const currentTime = /* @__PURE__ */ new Date();
29507
- const timezone = dateTimeConfig.defaultTimezone || "Asia/Kolkata";
29508
- const currentShiftDetails = getCurrentShift(timezone, shiftConfig);
29509
- const shiftStartTime = currentShiftDetails.shiftId === 0 ? shiftConfig.dayShift?.startTime || "06:00" : shiftConfig.nightShift?.startTime || "18:00";
29510
- const shiftEndTime = currentShiftDetails.shiftId === 0 ? shiftConfig.dayShift?.endTime || "14:00" : shiftConfig.nightShift?.endTime || "02:00";
29511
- const [startHour, startMin] = shiftStartTime.split(":").map(Number);
29512
- const [endHour, endMin] = shiftEndTime.split(":").map(Number);
29513
- const shiftStart = /* @__PURE__ */ new Date();
29514
- shiftStart.setHours(startHour, startMin, 0, 0);
29515
- const shiftEnd = /* @__PURE__ */ new Date();
29516
- shiftEnd.setHours(endHour, endMin, 0, 0);
29517
- if (endHour < startHour) {
29518
- if (currentTime.getHours() < endHour) {
29519
- shiftStart.setDate(shiftStart.getDate() - 1);
29520
- } else {
29521
- shiftEnd.setDate(shiftEnd.getDate() + 1);
29522
- }
29523
- }
29524
- const totalShiftMinutes = (shiftEnd.getTime() - shiftStart.getTime()) / (1e3 * 60);
29525
- const elapsedMinutes = (currentTime.getTime() - shiftStart.getTime()) / (1e3 * 60);
29526
- const shiftProgress = Math.max(0, Math.min(1, elapsedMinutes / totalShiftMinutes));
29527
- const outputProgress = kpis.outputProgress.current / kpis.outputProgress.target;
29528
- return outputProgress >= shiftProgress - 0.05;
29529
- }, [kpis, shiftConfig, dateTimeConfig]);
29560
+ return kpis.efficiency.value > 90;
29561
+ }, [kpis]);
29530
29562
  return /* @__PURE__ */ jsxs(
29531
29563
  motion.div,
29532
29564
  {
@@ -29842,7 +29874,7 @@ var MobileWorkspaceCard = memo(({
29842
29874
  getMedalIcon(rank)
29843
29875
  ] }),
29844
29876
  /* @__PURE__ */ jsxs("div", { children: [
29845
- /* @__PURE__ */ jsx("div", { className: "font-semibold text-gray-900", children: getWorkspaceDisplayName(workspace.workspace_name) }),
29877
+ /* @__PURE__ */ jsx("div", { className: "font-semibold text-gray-900", children: getWorkspaceDisplayName(workspace.workspace_name, workspace.line_id) }),
29846
29878
  /* @__PURE__ */ jsx("div", { className: "text-xs text-gray-500", children: getLineName(workspace.line_id) })
29847
29879
  ] })
29848
29880
  ] }),
@@ -29892,7 +29924,7 @@ var DesktopWorkspaceRow = memo(({
29892
29924
  /* @__PURE__ */ jsx("span", { children: index + 1 }),
29893
29925
  getMedalIcon(index + 1)
29894
29926
  ] }) }),
29895
- /* @__PURE__ */ jsx("td", { className: "px-3 py-2.5 sm:p-4 text-sm sm:text-base whitespace-nowrap", children: /* @__PURE__ */ jsx("div", { className: "font-medium", children: getWorkspaceDisplayName(workspace.workspace_name) }) }),
29927
+ /* @__PURE__ */ jsx("td", { className: "px-3 py-2.5 sm:p-4 text-sm sm:text-base whitespace-nowrap", children: /* @__PURE__ */ jsx("div", { className: "font-medium", children: getWorkspaceDisplayName(workspace.workspace_name, workspace.line_id) }) }),
29896
29928
  /* @__PURE__ */ jsx("td", { className: "px-3 py-2.5 sm:p-4 text-sm sm:text-base whitespace-nowrap", children: /* @__PURE__ */ jsx("div", { className: "font-medium", children: getLineName(workspace.line_id) }) }),
29897
29929
  /* @__PURE__ */ jsxs("td", { className: "px-3 py-2.5 sm:p-4 text-sm sm:text-base font-medium whitespace-nowrap", children: [
29898
29930
  (workspace.efficiency || 0).toFixed(1),
@@ -30009,7 +30041,7 @@ var LeaderboardDetailView = memo(({
30009
30041
  action_count: workspace.action_count,
30010
30042
  action_threshold: workspace.action_threshold
30011
30043
  });
30012
- const displayName = getWorkspaceDisplayName(workspace.workspace_name);
30044
+ const displayName = getWorkspaceDisplayName(workspace.workspace_name, workspace.line_id);
30013
30045
  const navParams = workspace.workspace_uuid ? getWorkspaceNavigationParams(workspace.workspace_uuid, displayName) : "";
30014
30046
  const returnToParam = `&returnTo=${encodeURIComponent(`/leaderboard`)}`;
30015
30047
  if (onWorkspaceClick) {
@@ -31237,8 +31269,8 @@ var calculateDayOutput = (pph, shiftHours, breaks = []) => {
31237
31269
  const realWorkHours = shiftHours - totalBreakHours;
31238
31270
  return Math.round(pph * realWorkHours);
31239
31271
  };
31240
- var formatWorkspaceName = (name) => {
31241
- return getWorkspaceDisplayName(name);
31272
+ var formatWorkspaceName = (name, lineId) => {
31273
+ return getWorkspaceDisplayName(name, lineId);
31242
31274
  };
31243
31275
  var getStoredLineState2 = (lineId) => {
31244
31276
  try {
@@ -31266,6 +31298,7 @@ var BulkConfigureModal = ({
31266
31298
  isOpen,
31267
31299
  onClose,
31268
31300
  lineWorkspaces,
31301
+ lineNames,
31269
31302
  onSave,
31270
31303
  selectedShift
31271
31304
  }) => {
@@ -31416,10 +31449,7 @@ var BulkConfigureModal = ({
31416
31449
  className: "block w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm\n shadow-sm focus:border-blue-500 focus:ring-blue-500 \n transition-all duration-200 hover:border-blue-400\n appearance-none bg-no-repeat bg-right pr-10\n hover:bg-blue-50/50",
31417
31450
  children: [
31418
31451
  /* @__PURE__ */ jsx("option", { value: "", children: "Select a line" }),
31419
- Object.entries(lineWorkspaces).map(([lineId, line]) => /* @__PURE__ */ jsxs("option", { value: lineId, className: "py-2", children: [
31420
- lineId,
31421
- " "
31422
- ] }, lineId))
31452
+ Object.entries(lineWorkspaces).map(([lineId, line]) => /* @__PURE__ */ jsx("option", { value: lineId, className: "py-2", children: lineNames[lineId] || lineId }, lineId))
31423
31453
  ]
31424
31454
  }
31425
31455
  )
@@ -31477,7 +31507,7 @@ var BulkConfigureModal = ({
31477
31507
  className: "rounded border-gray-300 text-blue-600 focus:ring-blue-500"
31478
31508
  }
31479
31509
  ),
31480
- /* @__PURE__ */ jsx("span", { className: `text-sm ${selectedWorkspaces.includes(workspace.id) ? "text-blue-900 font-medium" : "text-gray-900"}`, children: formatWorkspaceName(workspace.name) })
31510
+ /* @__PURE__ */ jsx("span", { className: `text-sm ${selectedWorkspaces.includes(workspace.id) ? "text-blue-900 font-medium" : "text-gray-900"}`, children: formatWorkspaceName(workspace.name, selectedLine) })
31481
31511
  ]
31482
31512
  },
31483
31513
  workspace.id
@@ -32164,7 +32194,7 @@ var TargetsViewUI = ({
32164
32194
  {
32165
32195
  className: "px-6 py-4 hover:bg-gray-50 transition-all duration-200",
32166
32196
  children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-12 gap-6 items-center", children: [
32167
- /* @__PURE__ */ jsx("div", { className: "col-span-2", children: /* @__PURE__ */ jsx("span", { className: "font-medium text-gray-900", children: formatWorkspaceName(workspace.name) }) }),
32197
+ /* @__PURE__ */ jsx("div", { className: "col-span-2", children: /* @__PURE__ */ jsx("span", { className: "font-medium text-gray-900", children: formatWorkspaceName(workspace.name, lineId) }) }),
32168
32198
  /* @__PURE__ */ jsx("div", { className: "col-span-2", children: /* @__PURE__ */ jsxs(
32169
32199
  "select",
32170
32200
  {
@@ -32174,7 +32204,7 @@ var TargetsViewUI = ({
32174
32204
  onActionTypeChange(lineId, workspace.id, newActionType);
32175
32205
  },
32176
32206
  className: "w-full p-2 border border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm",
32177
- "aria-label": `Action type for ${formatWorkspaceName(workspace.name)}`,
32207
+ "aria-label": `Action type for ${formatWorkspaceName(workspace.name, lineId)}`,
32178
32208
  children: [
32179
32209
  /* @__PURE__ */ jsx("option", { value: "assembly", className: "py-2", children: "Assembly" }),
32180
32210
  /* @__PURE__ */ jsx("option", { value: "packaging", className: "py-2", children: "Packaging" })
@@ -32233,6 +32263,7 @@ var TargetsViewUI = ({
32233
32263
  isOpen: isBulkConfigureOpen,
32234
32264
  onClose: onToggleBulkConfigure,
32235
32265
  lineWorkspaces,
32266
+ lineNames,
32236
32267
  onSave: onBulkConfigure,
32237
32268
  selectedShift
32238
32269
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optifye/dashboard-core",
3
- "version": "6.0.7",
3
+ "version": "6.0.8",
4
4
  "description": "Reusable UI & logic for Optifye dashboard",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",