@izumisy-tailor/tailor-data-viewer 0.1.9 → 0.1.10

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@izumisy-tailor/tailor-data-viewer",
3
3
  "private": false,
4
- "version": "0.1.9",
4
+ "version": "0.1.10",
5
5
  "type": "module",
6
6
  "description": "Flexible data viewer component for Tailor Platform",
7
7
  "files": [
@@ -1,4 +1,4 @@
1
- import { useState, useCallback } from "react";
1
+ import { useState, useCallback, useEffect, useRef } from "react";
2
2
  import { Plus, X } from "lucide-react";
3
3
  import { Card, CardContent, CardHeader, CardTitle } from "./ui/card";
4
4
  import { Button } from "./ui/button";
@@ -57,27 +57,13 @@ export function DataViewer({
57
57
  initialViewId,
58
58
  }: DataViewerProps) {
59
59
  const allTables = Object.values(tableMetadata);
60
- const { getViewById } = useSavedViews();
60
+ const { getViewById, isLoading } = useSavedViews();
61
61
 
62
- // Tab management - initialize with saved view if provided
62
+ // Track if we've already initialized from the saved view
63
+ const initializedFromViewRef = useRef(false);
64
+
65
+ // Tab management - start with empty tab, will apply saved view after loading
63
66
  const [tabs, setTabs] = useState<Tab[]>(() => {
64
- if (initialViewId) {
65
- const view = getViewById(initialViewId);
66
- if (view) {
67
- const table = tableMetadata[view.tableName];
68
- if (table) {
69
- return [
70
- {
71
- id: generateTabId(),
72
- label: view.name,
73
- table,
74
- isLocked: true,
75
- initialView: view,
76
- },
77
- ];
78
- }
79
- }
80
- }
81
67
  return [
82
68
  {
83
69
  id: generateTabId(),
@@ -89,6 +75,31 @@ export function DataViewer({
89
75
  });
90
76
  const [activeTabId, setActiveTabId] = useState<string>(tabs[0].id);
91
77
 
78
+ // Apply saved view after views are loaded from store
79
+ useEffect(() => {
80
+ // Skip if no initialViewId, already initialized, or still loading
81
+ if (!initialViewId || initializedFromViewRef.current || isLoading) {
82
+ return;
83
+ }
84
+
85
+ const view = getViewById(initialViewId);
86
+ if (view) {
87
+ const table = tableMetadata[view.tableName];
88
+ if (table) {
89
+ initializedFromViewRef.current = true;
90
+ const newTab: Tab = {
91
+ id: generateTabId(),
92
+ label: view.name,
93
+ table,
94
+ isLocked: true,
95
+ initialView: view,
96
+ };
97
+ setTabs([newTab]);
98
+ setActiveTabId(newTab.id);
99
+ }
100
+ }
101
+ }, [initialViewId, isLoading, getViewById, tableMetadata]);
102
+
92
103
  const handleAddTab = useCallback(() => {
93
104
  const newTab: Tab = {
94
105
  id: generateTabId(),