Skip to content

Commit 46b969f

Browse files
Copilothotlong
andcommitted
feat: wire allowCreateView/viewActions from ObjectViewSchema to ViewSwitcher
- Add allowCreateView and viewActions to ObjectViewSchema (types) - Add onCreateView and onViewAction props to engine ObjectViewProps - Wire allowCreateView/viewActions in viewSwitcherSchema builder - Pass onCreateView/onViewAction callbacks to ViewSwitcher rendering - Console ObjectView: pass allowCreateView=isAdmin and viewActions - Console ObjectView: wire onCreateView/onViewAction to both PluginObjectView instances Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 277bbcb commit 46b969f

3 files changed

Lines changed: 57 additions & 2 deletions

File tree

apps/console/src/components/ObjectView.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,13 @@ export function ObjectView({ dataSource, objects, onEdit, onRowClick }: any) {
652652
showSort: activeView?.showSort !== false,
653653
showCreate: false, // We render our own create button in the header
654654
showRefresh: true,
655+
allowCreateView: isAdmin,
656+
viewActions: isAdmin ? [
657+
{ type: 'settings' as const },
658+
{ type: 'share' as const },
659+
{ type: 'duplicate' as const },
660+
{ type: 'delete' as const },
661+
] : [],
655662
onNavigate: (recordId: string | number, mode: 'view' | 'edit') => {
656663
if (mode === 'edit') {
657664
onEdit?.({ _id: recordId, id: recordId });
@@ -663,7 +670,7 @@ export function ObjectView({ dataSource, objects, onEdit, onRowClick }: any) {
663670
}
664671
}
665672
},
666-
}), [objectDef.name, onEdit, activeView?.showSearch, activeView?.showFilters, activeView?.showSort, navigate, viewId]);
673+
}), [objectDef.name, onEdit, activeView?.showSearch, activeView?.showFilters, activeView?.showSort, navigate, viewId, isAdmin]);
667674

668675
return (
669676
<div className="h-full flex flex-col bg-background min-w-0 overflow-hidden">
@@ -814,6 +821,15 @@ export function ObjectView({ dataSource, objects, onEdit, onRowClick }: any) {
814821
navOverlay.handleClick(record);
815822
})}
816823
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+
}}
817833
/>
818834
</div>
819835
{typeof recordCount === 'number' && (
@@ -850,6 +866,15 @@ export function ObjectView({ dataSource, objects, onEdit, onRowClick }: any) {
850866
navOverlay.handleClick(record);
851867
})}
852868
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+
}}
853878
/>
854879
</div>
855880
{/* Record count footer removed — ListView already renders record-count-bar */}

packages/plugin-view/src/ObjectView.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,16 @@ export interface ObjectViewProps {
141141
* Toolbar addon: extra elements to render in the toolbar (e.g., MetadataToggle)
142142
*/
143143
toolbarAddon?: React.ReactNode;
144+
145+
/**
146+
* Callback when the "+" create view button is clicked in ViewSwitcher.
147+
*/
148+
onCreateView?: () => void;
149+
150+
/**
151+
* Callback when a per-view action is triggered in ViewSwitcher.
152+
*/
153+
onViewAction?: (action: string, viewType: ViewType) => void;
144154
}
145155

146156
type FormMode = 'create' | 'edit' | 'view';
@@ -205,6 +215,8 @@ export const ObjectView: React.FC<ObjectViewProps> = ({
205215
onEdit: onEditProp,
206216
renderListView,
207217
toolbarAddon,
218+
onCreateView,
219+
onViewAction,
208220
}) => {
209221
const [objectSchema, setObjectSchema] = useState<Record<string, unknown> | null>(null);
210222
const [isFormOpen, setIsFormOpen] = useState(false);
@@ -501,8 +513,10 @@ export const ObjectView: React.FC<ObjectViewProps> = ({
501513
icon: iconMap[v.type] || 'table',
502514
};
503515
}),
516+
allowCreateView: schema.allowCreateView,
517+
viewActions: schema.viewActions,
504518
};
505-
}, [hasMultiView, viewsPropResolved, activeView, schema.objectName]);
519+
}, [hasMultiView, viewsPropResolved, activeView, schema.objectName, schema.allowCreateView, schema.viewActions]);
506520

507521
// Handle view type change from ViewSwitcher → map back to view ID
508522
const handleViewTypeChange = useCallback((viewType: ViewType) => {
@@ -955,6 +969,8 @@ export const ObjectView: React.FC<ObjectViewProps> = ({
955969
<ViewSwitcher
956970
schema={viewSwitcherSchema}
957971
onViewChange={handleViewTypeChange}
972+
onCreateView={onCreateView}
973+
onViewAction={onViewAction}
958974
className="overflow-x-auto"
959975
/>
960976
)}

packages/types/src/objectql.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,20 @@ export interface ObjectViewSchema extends BaseSchema {
10671067
* View tab bar UX configuration (inline add, context menu, overflow, indicators).
10681068
*/
10691069
viewTabBar?: ViewTabBarConfig;
1070+
1071+
/**
1072+
* Show "+" button in ViewSwitcher to create a new view.
1073+
* Typically gated on admin permission.
1074+
*/
1075+
allowCreateView?: boolean;
1076+
1077+
/**
1078+
* Per-view action icons shown in ViewSwitcher (e.g., share, settings, duplicate, delete).
1079+
*/
1080+
viewActions?: Array<{
1081+
type: 'share' | 'settings' | 'duplicate' | 'delete';
1082+
icon?: string;
1083+
}>;
10701084
}
10711085

10721086
/**

0 commit comments

Comments
 (0)