Skip to content

Commit 6c4a56e

Browse files
Copilothotlong
andcommitted
refactor: extract duplicated ViewSwitcher callbacks into reusable handlers
Address code review feedback: - Extract onCreateView and onViewAction into handleCreateView/handleViewAction - Replace `any` type with `{ id: string; type: string }` in view matching - Both PluginObjectView instances now reference the extracted callbacks Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent d2cb8b8 commit 6c4a56e

1 file changed

Lines changed: 19 additions & 18 deletions

File tree

apps/console/src/components/ObjectView.tsx

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,21 @@ export function ObjectView({ dataSource, objects, onEdit, onRowClick }: any) {
372372
}
373373
};
374374

375+
// ViewSwitcher callbacks — wired to both PluginObjectView instances
376+
const handleCreateView = useCallback(() => {
377+
setViewConfigPanelMode('create');
378+
setShowViewConfigPanel(true);
379+
}, []);
380+
381+
const handleViewAction = useCallback((actionType: string, viewType: string) => {
382+
if (actionType === 'settings') {
383+
const matchedView = views.find((v: { id: string; type: string }) => v.type === viewType);
384+
if (matchedView) handleViewChange(matchedView.id);
385+
setViewConfigPanelMode('edit');
386+
setShowViewConfigPanel(true);
387+
}
388+
}, [views, handleViewChange]);
389+
375390
// Action system for toolbar operations
376391
const [refreshKey, setRefreshKey] = useState(0);
377392
const actions = useObjectActions({
@@ -821,15 +836,8 @@ export function ObjectView({ dataSource, objects, onEdit, onRowClick }: any) {
821836
navOverlay.handleClick(record);
822837
})}
823838
renderListView={renderListView}
824-
onCreateView={() => { setViewConfigPanelMode('create'); setShowViewConfigPanel(true); }}
825-
onViewAction={(actionType: string, viewType: string) => {
826-
if (actionType === 'settings') {
827-
const matchedView = views.find((v: any) => v.type === viewType);
828-
if (matchedView) handleViewChange(matchedView.id);
829-
setViewConfigPanelMode('edit');
830-
setShowViewConfigPanel(true);
831-
}
832-
}}
839+
onCreateView={handleCreateView}
840+
onViewAction={handleViewAction}
833841
/>
834842
</div>
835843
{typeof recordCount === 'number' && (
@@ -866,15 +874,8 @@ export function ObjectView({ dataSource, objects, onEdit, onRowClick }: any) {
866874
navOverlay.handleClick(record);
867875
})}
868876
renderListView={renderListView}
869-
onCreateView={() => { setViewConfigPanelMode('create'); setShowViewConfigPanel(true); }}
870-
onViewAction={(actionType: string, viewType: string) => {
871-
if (actionType === 'settings') {
872-
const matchedView = views.find((v: any) => v.type === viewType);
873-
if (matchedView) handleViewChange(matchedView.id);
874-
setViewConfigPanelMode('edit');
875-
setShowViewConfigPanel(true);
876-
}
877-
}}
877+
onCreateView={handleCreateView}
878+
onViewAction={handleViewAction}
878879
/>
879880
</div>
880881
{/* Record count footer removed — ListView already renders record-count-bar */}

0 commit comments

Comments
 (0)