@optifye/dashboard-core 6.1.6 → 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 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;
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;
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) {
@@ -4057,7 +4060,14 @@ var useLeaderboardMetrics = (lineId, topCount = 10) => {
4057
4060
  try {
4058
4061
  const currentShiftDetails = getCurrentShift(defaultTimezone, shiftConfig);
4059
4062
  const operationalDate = getOperationalDate(defaultTimezone, new Date(currentShiftDetails.date));
4060
- 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).gt("efficiency", 0).order("efficiency", { ascending: false }).limit(topCount);
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);
4061
4071
  if (fetchError) throw fetchError;
4062
4072
  const rankedData = (data || []).map((entry, index) => ({
4063
4073
  workspace_name: entry.workspace_name,
@@ -4610,14 +4620,20 @@ var useRealtimeLineMetrics = ({
4610
4620
  const companyId = entityConfig.companyId;
4611
4621
  const metricsTablePrefix = getMetricsTablePrefix(companyId || "");
4612
4622
  const metricsTable = `${metricsTablePrefix}_${(companyId || "").replace(/-/g, "_")}`;
4613
- const { data: workspaceData, error: workspaceError } = await supabase.from(metricsTable).select(`
4614
- line_id,
4615
- workspace_id,
4616
- workspace_name,
4617
- efficiency,
4618
- total_output,
4619
- total_day_output
4620
- `).in("line_id", targetLineIds).eq("shift_id", shiftId).eq("date", date);
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 };
4621
4637
  if (workspaceError) {
4622
4638
  console.error("Error fetching workspace metrics for factory view:", workspaceError);
4623
4639
  }
@@ -4669,13 +4685,15 @@ var useRealtimeLineMetrics = ({
4669
4685
  const companyId = entityConfig.companyId;
4670
4686
  const metricsTablePrefix = getMetricsTablePrefix(companyId || "");
4671
4687
  const metricsTable = `${metricsTablePrefix}_${(companyId || "").replace(/-/g, "_")}`;
4672
- const { data: workspaceData, error: workspaceError } = await supabase.from(metricsTable).select(`
4673
- workspace_id,
4674
- workspace_name,
4675
- efficiency,
4676
- total_output,
4677
- total_day_output
4678
- `).eq("line_id", lineIdRef.current).eq("shift_id", shiftId).eq("date", date);
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 };
4679
4697
  if (workspaceError) {
4680
4698
  console.error("Error fetching workspace metrics:", workspaceError);
4681
4699
  }
@@ -6124,6 +6142,19 @@ var useAllWorkspaceMetrics = (options) => {
6124
6142
  queryShiftId,
6125
6143
  metricsTable
6126
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
+ }
6127
6158
  const { data, error: fetchError } = await supabase.from(metricsTable).select(`
6128
6159
  workspace_name,
6129
6160
  total_output,
@@ -6135,7 +6166,7 @@ var useAllWorkspaceMetrics = (options) => {
6135
6166
  trend_score,
6136
6167
  line_id,
6137
6168
  total_day_output
6138
- `).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 });
6139
6170
  if (fetchError) throw fetchError;
6140
6171
  const transformedData = (data || []).map((item) => ({
6141
6172
  company_id: entityConfig.companyId || "unknown",
@@ -30243,15 +30274,22 @@ var LeaderboardDetailView = React19.memo(({
30243
30274
  className = ""
30244
30275
  }) => {
30245
30276
  const navigation = useNavigation();
30277
+ const entityConfig = useEntityConfig();
30246
30278
  const [sortAscending, setSortAscending] = React19.useState(false);
30279
+ const configuredLineNames = React19.useMemo(() => {
30280
+ return getAllLineDisplayNames(entityConfig);
30281
+ }, [entityConfig]);
30247
30282
  const getLineName = React19.useCallback((lineId2) => {
30283
+ if (configuredLineNames[lineId2]) {
30284
+ return configuredLineNames[lineId2];
30285
+ }
30248
30286
  if (lineNames[lineId2]) {
30249
30287
  return lineNames[lineId2];
30250
30288
  }
30251
30289
  if (lineId2 === line1Id) return "Line 1";
30252
30290
  if (lineId2 === line2Id) return "Line 2";
30253
- return lineId2;
30254
- }, [lineNames, line1Id, line2Id]);
30291
+ return `Line ${lineId2.substring(0, 8)}`;
30292
+ }, [configuredLineNames, lineNames, line1Id, line2Id]);
30255
30293
  const handleSortToggle = React19.useCallback(() => {
30256
30294
  setSortAscending(!sortAscending);
30257
30295
  }, [sortAscending]);
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) {
@@ -4028,7 +4031,14 @@ var useLeaderboardMetrics = (lineId, topCount = 10) => {
4028
4031
  try {
4029
4032
  const currentShiftDetails = getCurrentShift(defaultTimezone, shiftConfig);
4030
4033
  const operationalDate = getOperationalDate(defaultTimezone, new Date(currentShiftDetails.date));
4031
- 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).gt("efficiency", 0).order("efficiency", { ascending: false }).limit(topCount);
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);
4032
4042
  if (fetchError) throw fetchError;
4033
4043
  const rankedData = (data || []).map((entry, index) => ({
4034
4044
  workspace_name: entry.workspace_name,
@@ -4581,14 +4591,20 @@ var useRealtimeLineMetrics = ({
4581
4591
  const companyId = entityConfig.companyId;
4582
4592
  const metricsTablePrefix = getMetricsTablePrefix(companyId || "");
4583
4593
  const metricsTable = `${metricsTablePrefix}_${(companyId || "").replace(/-/g, "_")}`;
4584
- const { data: workspaceData, error: workspaceError } = await supabase.from(metricsTable).select(`
4585
- line_id,
4586
- workspace_id,
4587
- workspace_name,
4588
- efficiency,
4589
- total_output,
4590
- total_day_output
4591
- `).in("line_id", targetLineIds).eq("shift_id", shiftId).eq("date", date);
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 };
4592
4608
  if (workspaceError) {
4593
4609
  console.error("Error fetching workspace metrics for factory view:", workspaceError);
4594
4610
  }
@@ -4640,13 +4656,15 @@ var useRealtimeLineMetrics = ({
4640
4656
  const companyId = entityConfig.companyId;
4641
4657
  const metricsTablePrefix = getMetricsTablePrefix(companyId || "");
4642
4658
  const metricsTable = `${metricsTablePrefix}_${(companyId || "").replace(/-/g, "_")}`;
4643
- const { data: workspaceData, error: workspaceError } = await supabase.from(metricsTable).select(`
4644
- workspace_id,
4645
- workspace_name,
4646
- efficiency,
4647
- total_output,
4648
- total_day_output
4649
- `).eq("line_id", lineIdRef.current).eq("shift_id", shiftId).eq("date", date);
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 };
4650
4668
  if (workspaceError) {
4651
4669
  console.error("Error fetching workspace metrics:", workspaceError);
4652
4670
  }
@@ -6095,6 +6113,19 @@ var useAllWorkspaceMetrics = (options) => {
6095
6113
  queryShiftId,
6096
6114
  metricsTable
6097
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
+ }
6098
6129
  const { data, error: fetchError } = await supabase.from(metricsTable).select(`
6099
6130
  workspace_name,
6100
6131
  total_output,
@@ -6106,7 +6137,7 @@ var useAllWorkspaceMetrics = (options) => {
6106
6137
  trend_score,
6107
6138
  line_id,
6108
6139
  total_day_output
6109
- `).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 });
6110
6141
  if (fetchError) throw fetchError;
6111
6142
  const transformedData = (data || []).map((item) => ({
6112
6143
  company_id: entityConfig.companyId || "unknown",
@@ -30214,15 +30245,22 @@ var LeaderboardDetailView = memo(({
30214
30245
  className = ""
30215
30246
  }) => {
30216
30247
  const navigation = useNavigation();
30248
+ const entityConfig = useEntityConfig();
30217
30249
  const [sortAscending, setSortAscending] = useState(false);
30250
+ const configuredLineNames = useMemo(() => {
30251
+ return getAllLineDisplayNames(entityConfig);
30252
+ }, [entityConfig]);
30218
30253
  const getLineName = useCallback((lineId2) => {
30254
+ if (configuredLineNames[lineId2]) {
30255
+ return configuredLineNames[lineId2];
30256
+ }
30219
30257
  if (lineNames[lineId2]) {
30220
30258
  return lineNames[lineId2];
30221
30259
  }
30222
30260
  if (lineId2 === line1Id) return "Line 1";
30223
30261
  if (lineId2 === line2Id) return "Line 2";
30224
- return lineId2;
30225
- }, [lineNames, line1Id, line2Id]);
30262
+ return `Line ${lineId2.substring(0, 8)}`;
30263
+ }, [configuredLineNames, lineNames, line1Id, line2Id]);
30226
30264
  const handleSortToggle = useCallback(() => {
30227
30265
  setSortAscending(!sortAscending);
30228
30266
  }, [sortAscending]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optifye/dashboard-core",
3
- "version": "6.1.6",
3
+ "version": "6.1.7",
4
4
  "description": "Reusable UI & logic for Optifye dashboard",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",