refactor(base): rename baseId to pageId in client components

This commit is contained in:
Philipinho
2026-04-27 01:44:11 +01:00
parent 3e9f26a8dd
commit f56af5e6b4
12 changed files with 56 additions and 56 deletions
@@ -42,15 +42,15 @@ import { BaseTableSkeleton } from "@/features/base/components/base-table-skeleto
import classes from "@/features/base/styles/grid.module.css"; import classes from "@/features/base/styles/grid.module.css";
type BaseTableProps = { type BaseTableProps = {
baseId: string; pageId: string;
}; };
export function BaseTable({ baseId }: BaseTableProps) { export function BaseTable({ pageId }: BaseTableProps) {
const { t } = useTranslation(); const { t } = useTranslation();
// Subscribe to the base's realtime room so other clients' edits, // Subscribe to the base's realtime room so other clients' edits,
// schema changes, and async-job completions reconcile into our cache. // schema changes, and async-job completions reconcile into our cache.
useBaseSocket(baseId); useBaseSocket(pageId);
const { data: base, isLoading: baseLoading, error: baseError } = useBaseQuery(baseId); const { data: base, isLoading: baseLoading, error: baseError } = useBaseQuery(pageId);
const [activeViewId, setActiveViewId] = useAtom(activeViewIdAtom) as unknown as [string | null, (val: string | null) => void]; const [activeViewId, setActiveViewId] = useAtom(activeViewIdAtom) as unknown as [string | null, (val: string | null) => void];
@@ -72,7 +72,7 @@ export function BaseTable({ baseId }: BaseTableProps) {
buildPromotedConfig, buildPromotedConfig,
} = useViewDraft({ } = useViewDraft({
userId: currentUser?.user.id, userId: currentUser?.user.id,
baseId, pageId,
viewId: activeView?.id, viewId: activeView?.id,
baselineFilter: activeView?.config?.filter, baselineFilter: activeView?.config?.filter,
baselineSorts: activeView?.config?.sorts, baselineSorts: activeView?.config?.sorts,
@@ -119,7 +119,7 @@ export function BaseTable({ baseId }: BaseTableProps) {
// active view's config resolves — doubling network traffic on every // active view's config resolves — doubling network traffic on every
// base open for any view that has sort or filter. // base open for any view that has sort or filter.
const { data: rowsData, isLoading: rowsLoading, fetchNextPage, hasNextPage, isFetchingNextPage } = const { data: rowsData, isLoading: rowsLoading, fetchNextPage, hasNextPage, isFetchingNextPage } =
useBaseRowsQuery(base ? baseId : undefined, activeFilter, activeSorts); useBaseRowsQuery(base ? pageId : undefined, activeFilter, activeSorts);
// Fire the count request alongside the rows query. Not rendered yet — // Fire the count request alongside the rows query. Not rendered yet —
// this mounts the query so its cache is warm for when the toolbar // this mounts the query so its cache is warm for when the toolbar
@@ -129,7 +129,7 @@ export function BaseTable({ baseId }: BaseTableProps) {
// filter and fire with baseline-only (or nothing). // filter and fire with baseline-only (or nothing).
const canFetchCount = !!base && !!currentUser; const canFetchCount = !!base && !!currentUser;
useBaseRowsCountQuery( useBaseRowsCountQuery(
canFetchCount ? baseId : undefined, canFetchCount ? pageId : undefined,
activeFilter, activeFilter,
); );
@@ -148,7 +148,7 @@ export function BaseTable({ baseId }: BaseTableProps) {
const { clear: clearSelection } = useRowSelection(); const { clear: clearSelection } = useRowSelection();
useEffect(() => { useEffect(() => {
clearSelection(); clearSelection();
}, [baseId, activeView?.id, clearSelection]); }, [pageId, activeView?.id, clearSelection]);
const rows = useMemo(() => { const rows = useMemo(() => {
const flat = flattenRows(rowsData); const flat = flattenRows(rowsData);
@@ -175,16 +175,16 @@ export function BaseTable({ baseId }: BaseTableProps) {
(rowId: string, propertyId: string, value: unknown) => { (rowId: string, propertyId: string, value: unknown) => {
updateRowMutation.mutate({ updateRowMutation.mutate({
rowId, rowId,
baseId, pageId,
cells: { [propertyId]: value }, cells: { [propertyId]: value },
}); });
}, },
[baseId, updateRowMutation], [pageId, updateRowMutation],
); );
const handleAddRow = useCallback(() => { const handleAddRow = useCallback(() => {
createRowMutation.mutate({ baseId }); createRowMutation.mutate({ pageId });
}, [baseId, createRowMutation]); }, [pageId, createRowMutation]);
const handleViewChange = useCallback( const handleViewChange = useCallback(
(viewId: string) => { (viewId: string) => {
@@ -195,11 +195,11 @@ export function BaseTable({ baseId }: BaseTableProps) {
const handleAddView = useCallback(() => { const handleAddView = useCallback(() => {
createViewMutation.mutate({ createViewMutation.mutate({
baseId, pageId,
name: t("New view"), name: t("New view"),
type: "table", type: "table",
}); });
}, [baseId, createViewMutation, t]); }, [pageId, createViewMutation, t]);
const handleColumnReorder = useCallback( const handleColumnReorder = useCallback(
(activeId: string, overId: string) => { (activeId: string, overId: string) => {
@@ -242,7 +242,7 @@ export function BaseTable({ baseId }: BaseTableProps) {
try { try {
await updateViewMutation.mutateAsync({ await updateViewMutation.mutateAsync({
viewId: activeView.id, viewId: activeView.id,
baseId: base.id, pageId: base.id,
config, config,
}); });
resetDraft(); resetDraft();
@@ -288,14 +288,14 @@ export function BaseTable({ baseId }: BaseTableProps) {
reorderRowMutation.mutate({ reorderRowMutation.mutate({
rowId, rowId,
baseId, pageId,
position: newPosition, position: newPosition,
}); });
} catch { } catch {
// Position computation failed — skip silently // Position computation failed — skip silently
} }
}, },
[rows, baseId, reorderRowMutation], [rows, pageId, reorderRowMutation],
); );
if (baseLoading || rowsLoading) { if (baseLoading || rowsLoading) {
@@ -338,7 +338,7 @@ export function BaseTable({ baseId }: BaseTableProps) {
properties={base.properties} properties={base.properties}
onCellUpdate={handleCellUpdate} onCellUpdate={handleCellUpdate}
onAddRow={handleAddRow} onAddRow={handleAddRow}
baseId={baseId} pageId={pageId}
onColumnReorder={handleColumnReorder} onColumnReorder={handleColumnReorder}
onResizeEnd={handleResizeEnd} onResizeEnd={handleResizeEnd}
onRowReorder={handleRowReorder} onRowReorder={handleRowReorder}
@@ -163,7 +163,7 @@ export function BaseToolbar({
<ViewTabs <ViewTabs
views={views} views={views}
activeViewId={activeView?.id} activeViewId={activeView?.id}
baseId={base.id} pageId={base.id}
onViewChange={onViewChange} onViewChange={onViewChange}
onAddView={onAddView} onAddView={onAddView}
/> />
@@ -72,7 +72,7 @@ export function CellFile({
try { try {
const formData = new FormData(); const formData = new FormData();
formData.append("file", file); formData.append("file", file);
formData.append("baseId", property.baseId); formData.append("pageId", property.pageId);
const res = await api.post<FileValue>( const res = await api.post<FileValue>(
"/bases/files/upload", "/bases/files/upload",
@@ -98,7 +98,7 @@ export function CellFile({
setUploading(false); setUploading(false);
onCommit(newFiles.length > 0 ? newFiles : null); onCommit(newFiles.length > 0 ? newFiles : null);
}, },
[files, property.baseId, onCommit], [files, property.pageId, onCommit],
); );
const handleKeyDown = useCallback( const handleKeyDown = useCallback(
@@ -105,7 +105,7 @@ export function CellMultiSelect({
const newChoices = [...choices, newChoice]; const newChoices = [...choices, newChoice];
updatePropertyMutation.mutate({ updatePropertyMutation.mutate({
propertyId: property.id, propertyId: property.id,
baseId: property.baseId, pageId: property.pageId,
typeOptions: { typeOptions: {
...typeOptions, ...typeOptions,
choices: newChoices, choices: newChoices,
@@ -44,7 +44,7 @@ export function CellPage({
onCancel, onCancel,
}: CellPageProps) { }: CellPageProps) {
const pageId = parsePageId(value); const pageId = parsePageId(value);
const { data: base } = useBaseQuery(property.baseId); const { data: base } = useBaseQuery(property.pageId);
const ids = useMemo(() => (pageId ? [pageId] : []), [pageId]); const ids = useMemo(() => (pageId ? [pageId] : []), [pageId]);
const { pages } = useResolvedPages(ids); const { pages } = useResolvedPages(ids);
@@ -102,7 +102,7 @@ export function CellSelect({
const newChoices = [...choices, newChoice]; const newChoices = [...choices, newChoice];
updatePropertyMutation.mutate({ updatePropertyMutation.mutate({
propertyId: property.id, propertyId: property.id,
baseId: property.baseId, pageId: property.pageId,
typeOptions: { typeOptions: {
...typeOptions, ...typeOptions,
choices: newChoices, choices: newChoices,
@@ -37,7 +37,7 @@ type GridContainerProps = {
properties: IBaseProperty[]; properties: IBaseProperty[];
onCellUpdate: (rowId: string, propertyId: string, value: unknown) => void; onCellUpdate: (rowId: string, propertyId: string, value: unknown) => void;
onAddRow?: () => void; onAddRow?: () => void;
baseId?: string; pageId?: string;
onColumnReorder?: (columnId: string, overColumnId: string) => void; onColumnReorder?: (columnId: string, overColumnId: string) => void;
onResizeEnd?: () => void; onResizeEnd?: () => void;
onRowReorder?: (rowId: string, targetRowId: string, position: "above" | "below") => void; onRowReorder?: (rowId: string, targetRowId: string, position: "above" | "below") => void;
@@ -51,7 +51,7 @@ export function GridContainer({
properties, properties,
onCellUpdate, onCellUpdate,
onAddRow, onAddRow,
baseId, pageId,
onColumnReorder, onColumnReorder,
onResizeEnd, onResizeEnd,
onRowReorder, onRowReorder,
@@ -72,7 +72,7 @@ export function GridContainer({
const closeRequestCounterRef = useRef(0); const closeRequestCounterRef = useRef(0);
const { selectionCount, clear: clearSelection } = useRowSelection(); const { selectionCount, clear: clearSelection } = useRowSelection();
const { deleteSelected } = useDeleteSelectedRows(baseId ?? ""); const { deleteSelected } = useDeleteSelectedRows(pageId ?? "");
useEffect(() => { useEffect(() => {
const handleMouseDown = (e: MouseEvent) => { const handleMouseDown = (e: MouseEvent) => {
@@ -134,7 +134,7 @@ export function GridContainer({
useEffect(() => { useEffect(() => {
const el = scrollRef.current; const el = scrollRef.current;
if (!el || !baseId) return; if (!el || !pageId) return;
const handler = (e: KeyboardEvent) => { const handler = (e: KeyboardEvent) => {
if (editingCell) return; if (editingCell) return;
const active = document.activeElement as HTMLElement | null; const active = document.activeElement as HTMLElement | null;
@@ -154,13 +154,13 @@ export function GridContainer({
}; };
el.addEventListener("keydown", handler); el.addEventListener("keydown", handler);
return () => el.removeEventListener("keydown", handler); return () => el.removeEventListener("keydown", handler);
}, [editingCell, selectionCount, clearSelection, deleteSelected, baseId]); }, [editingCell, selectionCount, clearSelection, deleteSelected, pageId]);
const gridTemplateColumns = useMemo(() => { const gridTemplateColumns = useMemo(() => {
const visibleColumns = table.getVisibleLeafColumns(); const visibleColumns = table.getVisibleLeafColumns();
const columnWidths = visibleColumns.map((col) => `${col.getSize()}px`); const columnWidths = visibleColumns.map((col) => `${col.getSize()}px`);
return columnWidths.join(" ") + (baseId ? " 40px" : ""); return columnWidths.join(" ") + (pageId ? " 40px" : "");
}, [table, table.getState().columnSizing, table.getState().columnVisibility, table.getState().columnOrder, baseId]); }, [table, table.getState().columnSizing, table.getState().columnVisibility, table.getState().columnOrder, pageId]);
const totalHeight = virtualizer.getTotalSize(); const totalHeight = virtualizer.getTotalSize();
@@ -252,7 +252,7 @@ export function GridContainer({
> >
<GridHeader <GridHeader
table={table} table={table}
baseId={baseId} pageId={pageId}
columnOrder={table.getState().columnOrder} columnOrder={table.getState().columnOrder}
columnVisibility={table.getState().columnVisibility} columnVisibility={table.getState().columnVisibility}
properties={properties} properties={properties}
@@ -298,7 +298,7 @@ export function GridContainer({
)} )}
<AddRowButton onClick={handleAddRow} /> <AddRowButton onClick={handleAddRow} />
{baseId && <SelectionActionBar baseId={baseId} />} {pageId && <SelectionActionBar pageId={pageId} />}
</div> </div>
</div> </div>
</DndContext> </DndContext>
@@ -7,7 +7,7 @@ import classes from "@/features/base/styles/grid.module.css";
type GridHeaderProps = { type GridHeaderProps = {
table: Table<IBaseRow>; table: Table<IBaseRow>;
baseId?: string; pageId?: string;
// Passed explicitly to break memo when columns change // Passed explicitly to break memo when columns change
// (table ref is stable from useReactTable, so memo won't fire without these) // (table ref is stable from useReactTable, so memo won't fire without these)
columnOrder: ColumnOrderState; columnOrder: ColumnOrderState;
@@ -19,7 +19,7 @@ type GridHeaderProps = {
export const GridHeader = memo(function GridHeader({ export const GridHeader = memo(function GridHeader({
table, table,
baseId, pageId,
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
columnOrder: _columnOrder, columnOrder: _columnOrder,
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -45,9 +45,9 @@ export const GridHeader = memo(function GridHeader({
loadedRowIds={loadedRowIds} loadedRowIds={loadedRowIds}
/> />
))} ))}
{baseId && ( {pageId && (
<CreatePropertyPopover <CreatePropertyPopover
baseId={baseId} pageId={pageId}
properties={properties} properties={properties}
onPropertyCreated={onPropertyCreated} onPropertyCreated={onPropertyCreated}
/> />
@@ -7,15 +7,15 @@ import { useDeleteSelectedRows } from "@/features/base/hooks/use-delete-selected
import classes from "@/features/base/styles/grid.module.css"; import classes from "@/features/base/styles/grid.module.css";
type SelectionActionBarProps = { type SelectionActionBarProps = {
baseId: string; pageId: string;
}; };
export const SelectionActionBar = memo(function SelectionActionBar({ export const SelectionActionBar = memo(function SelectionActionBar({
baseId, pageId,
}: SelectionActionBarProps) { }: SelectionActionBarProps) {
const { t } = useTranslation(); const { t } = useTranslation();
const { selectionCount, clear } = useRowSelection(); const { selectionCount, clear } = useRowSelection();
const { deleteSelected, isPending } = useDeleteSelectedRows(baseId); const { deleteSelected, isPending } = useDeleteSelectedRows(pageId);
const isOpen = selectionCount > 0; const isOpen = selectionCount > 0;
@@ -25,7 +25,7 @@ import { FormulaEditor } from "../formula/formula-editor";
import classes from "@/features/base/styles/grid.module.css"; import classes from "@/features/base/styles/grid.module.css";
type CreatePropertyPopoverProps = { type CreatePropertyPopoverProps = {
baseId: string; pageId: string;
properties?: IBaseProperty[]; properties?: IBaseProperty[];
onPropertyCreated?: () => void; onPropertyCreated?: () => void;
}; };
@@ -44,7 +44,7 @@ const typesWithOptions = new Set<BasePropertyType>([
"person", "person",
]); ]);
export function CreatePropertyPopover({ baseId, properties, onPropertyCreated }: CreatePropertyPopoverProps) { export function CreatePropertyPopover({ pageId, properties, onPropertyCreated }: CreatePropertyPopoverProps) {
const { t } = useTranslation(); const { t } = useTranslation();
const [opened, setOpened] = useState(false); const [opened, setOpened] = useState(false);
const [panel, setPanel] = useState<Panel>("typePicker"); const [panel, setPanel] = useState<Panel>("typePicker");
@@ -141,7 +141,7 @@ export function CreatePropertyPopover({ baseId, properties, onPropertyCreated }:
const finalName = name.trim() || fallbackName; const finalName = name.trim() || fallbackName;
createPropertyMutation.mutate( createPropertyMutation.mutate(
{ {
baseId, pageId,
name: finalName, name: finalName,
type: selectedType, type: selectedType,
typeOptions: Object.keys(typeOptions).length > 0 typeOptions: Object.keys(typeOptions).length > 0
@@ -155,7 +155,7 @@ export function CreatePropertyPopover({ baseId, properties, onPropertyCreated }:
}, },
); );
handleClose(); handleClose();
}, [selectedType, nameTaken, name, fallbackName, typeOptions, baseId, createPropertyMutation, handleClose, onPropertyCreated]); }, [selectedType, nameTaken, name, fallbackName, typeOptions, pageId, createPropertyMutation, handleClose, onPropertyCreated]);
const handleBackToTypePicker = useCallback(() => { const handleBackToTypePicker = useCallback(() => {
setPanel("typePicker"); setPanel("typePicker");
@@ -198,7 +198,7 @@ export function CreatePropertyPopover({ baseId, properties, onPropertyCreated }:
const syntheticProperty: IBaseProperty = useMemo(() => ({ const syntheticProperty: IBaseProperty = useMemo(() => ({
id: "", id: "",
baseId, pageId,
name: name || "", name: name || "",
type: selectedType ?? "text", type: selectedType ?? "text",
position: "", position: "",
@@ -207,7 +207,7 @@ export function CreatePropertyPopover({ baseId, properties, onPropertyCreated }:
workspaceId: "", workspaceId: "",
createdAt: "", createdAt: "",
updatedAt: "", updatedAt: "",
}), [baseId, name, selectedType, typeOptions]); }), [pageId, name, selectedType, typeOptions]);
const TypeIcon = selectedTypeIcon; const TypeIcon = selectedTypeIcon;
const showOptions = selectedType && typesWithOptions.has(selectedType); const showOptions = selectedType && typesWithOptions.has(selectedType);
@@ -279,7 +279,7 @@ export function CreatePropertyPopover({ baseId, properties, onPropertyCreated }:
if (nameTaken) return; if (nameTaken) return;
createPropertyMutation.mutate( createPropertyMutation.mutate(
{ {
baseId, pageId,
name: name.trim() || fallbackName, name: name.trim() || fallbackName,
type: "formula", type: "formula",
typeOptions: { typeOptions: {
@@ -94,7 +94,7 @@ export function PropertyMenuContent({
if (trimmed && trimmed !== property.name) { if (trimmed && trimmed !== property.name) {
updatePropertyMutation.mutate({ updatePropertyMutation.mutate({
propertyId: property.id, propertyId: property.id,
baseId: property.baseId, pageId: property.pageId,
name: trimmed, name: trimmed,
}); });
} }
@@ -138,7 +138,7 @@ export function PropertyMenuContent({
(typeOptions: Record<string, unknown>) => { (typeOptions: Record<string, unknown>) => {
updatePropertyMutation.mutate({ updatePropertyMutation.mutate({
propertyId: property.id, propertyId: property.id,
baseId: property.baseId, pageId: property.pageId,
typeOptions, typeOptions,
}); });
setOptionsDirty(false); setOptionsDirty(false);
@@ -149,7 +149,7 @@ export function PropertyMenuContent({
const handleDelete = useCallback(() => { const handleDelete = useCallback(() => {
deletePropertyMutation.mutate({ deletePropertyMutation.mutate({
propertyId: property.id, propertyId: property.id,
baseId: property.baseId, pageId: property.pageId,
}); });
onClose(); onClose();
}, [property, deletePropertyMutation, onClose]); }, [property, deletePropertyMutation, onClose]);
@@ -22,7 +22,7 @@ import cellClasses from "@/features/base/styles/cells.module.css";
type ViewTabsProps = { type ViewTabsProps = {
views: IBaseView[]; views: IBaseView[];
activeViewId: string | undefined; activeViewId: string | undefined;
baseId: string; pageId: string;
onViewChange: (viewId: string) => void; onViewChange: (viewId: string) => void;
onAddView?: () => void; onAddView?: () => void;
}; };
@@ -30,7 +30,7 @@ type ViewTabsProps = {
export function ViewTabs({ export function ViewTabs({
views, views,
activeViewId, activeViewId,
baseId, pageId,
onViewChange, onViewChange,
onAddView, onAddView,
}: ViewTabsProps) { }: ViewTabsProps) {
@@ -56,12 +56,12 @@ export function ViewTabs({
if (trimmed && view && trimmed !== view.name) { if (trimmed && view && trimmed !== view.name) {
updateViewMutation.mutate({ updateViewMutation.mutate({
viewId: editingViewId, viewId: editingViewId,
baseId, pageId,
name: trimmed, name: trimmed,
}); });
} }
setEditingViewId(null); setEditingViewId(null);
}, [editingViewId, editingName, views, baseId, updateViewMutation]); }, [editingViewId, editingName, views, pageId, updateViewMutation]);
const handleRenameKeyDown = useCallback( const handleRenameKeyDown = useCallback(
(e: React.KeyboardEvent) => { (e: React.KeyboardEvent) => {
@@ -80,13 +80,13 @@ export function ViewTabs({
const handleDelete = useCallback( const handleDelete = useCallback(
(viewId: string) => { (viewId: string) => {
if (views.length <= 1) return; if (views.length <= 1) return;
deleteViewMutation.mutate({ viewId, baseId }); deleteViewMutation.mutate({ viewId, pageId });
if (viewId === activeViewId && views.length > 1) { if (viewId === activeViewId && views.length > 1) {
const remaining = views.filter((v) => v.id !== viewId); const remaining = views.filter((v) => v.id !== viewId);
onViewChange(remaining[0].id); onViewChange(remaining[0].id);
} }
}, },
[views, baseId, activeViewId, deleteViewMutation, onViewChange], [views, pageId, activeViewId, deleteViewMutation, onViewChange],
); );
return ( return (