chore: edit grid row

This commit is contained in:
ascarbek 2023-03-31 19:51:30 +06:00
parent ac2a0c5b91
commit 75f7b9765d
4 changed files with 46 additions and 19 deletions

View File

@ -7,13 +7,24 @@ import { GridAddRow } from '../GridTableRows/GridAddRow';
import { GridTableRows } from '../GridTableRows/GridTableRows'; import { GridTableRows } from '../GridTableRows/GridTableRows';
import { GridTitle } from '../GridTitle/GridTitle'; import { GridTitle } from '../GridTitle/GridTitle';
import { GridToolbar } from '../GridToolbar/GridToolbar'; import { GridToolbar } from '../GridToolbar/GridToolbar';
import { EditRow } from '$app/components/_shared/EditRow/EditRow';
import { useState } from 'react';
import { RowInfo } from '$app/stores/effects/database/row/row_cache';
export const Grid = ({ viewId }: { viewId: string }) => { export const Grid = ({ viewId }: { viewId: string }) => {
const { controller, rows, groups } = useDatabase(viewId, ViewLayoutTypePB.Grid); const { controller, rows, groups } = useDatabase(viewId, ViewLayoutTypePB.Grid);
const [showGridRow, setShowGridRow] = useState(false);
const [boardRowInfo, setBoardRowInfo] = useState<RowInfo>();
const onOpenRow = (rowInfo: RowInfo) => {
setBoardRowInfo(rowInfo);
setShowGridRow(true);
};
return ( return (
controller && controller &&
groups && ( groups && (
<>
<div className='mx-auto mt-8 flex flex-col gap-8 px-8'> <div className='mx-auto mt-8 flex flex-col gap-8 px-8'>
<div className='flex w-full items-center justify-between'> <div className='flex w-full items-center justify-between'>
<GridTitle /> <GridTitle />
@ -24,7 +35,7 @@ export const Grid = ({ viewId }: { viewId: string }) => {
<div className='flex flex-col gap-4'> <div className='flex flex-col gap-4'>
<table className='w-full table-fixed text-sm'> <table className='w-full table-fixed text-sm'>
<GridTableHeader /> <GridTableHeader />
<GridTableRows allRows={rows} viewId={viewId} controller={controller} /> <GridTableRows onOpenRow={onOpenRow} allRows={rows} viewId={viewId} controller={controller} />
</table> </table>
<GridAddRow /> <GridAddRow />
@ -32,6 +43,15 @@ export const Grid = ({ viewId }: { viewId: string }) => {
<GridTableCount /> <GridTableCount />
</div> </div>
{showGridRow && boardRowInfo && (
<EditRow
onClose={() => setShowGridRow(false)}
viewId={viewId}
controller={controller}
rowInfo={boardRowInfo}
></EditRow>
)}
</>
) )
); );
}; };

View File

@ -7,13 +7,15 @@ export const GridTableCell = ({
cellIdentifier, cellIdentifier,
cellCache, cellCache,
fieldController, fieldController,
onClick,
}: { }: {
cellIdentifier: CellIdentifier; cellIdentifier: CellIdentifier;
cellCache: CellCache; cellCache: CellCache;
fieldController: FieldController; fieldController: FieldController;
onClick: () => void;
}) => { }) => {
return ( return (
<div className='w-full rounded-lg border border-transparent group-active:bg-main-accent'> <div onClick={() => onClick()} className='w-full rounded-lg border border-transparent group-active:bg-main-accent'>
<BoardCell cellIdentifier={cellIdentifier} cellCache={cellCache} fieldController={fieldController} /> <BoardCell cellIdentifier={cellIdentifier} cellCache={cellCache} fieldController={fieldController} />
</div> </div>
); );

View File

@ -7,10 +7,12 @@ export const GridTableRow = ({
viewId, viewId,
controller, controller,
row, row,
onOpenRow,
}: { }: {
viewId: string; viewId: string;
controller: DatabaseController; controller: DatabaseController;
row: RowInfo; row: RowInfo;
onOpenRow: (rowId: RowInfo) => void;
}) => { }) => {
const { cells } = useRow(viewId, controller, row); const { cells } = useRow(viewId, controller, row);
@ -21,6 +23,7 @@ export const GridTableRow = ({
return ( return (
<td className='m-0 border border-l-0 border-shade-6 p-0 ' key={cellIndex}> <td className='m-0 border border-l-0 border-shade-6 p-0 ' key={cellIndex}>
<GridTableCell <GridTableCell
onClick={() => onOpenRow(row)}
key={cellIndex} key={cellIndex}
cellIdentifier={cell.cellIdentifier} cellIdentifier={cell.cellIdentifier}
cellCache={controller.databaseViewCache.getRowCache().getCellCache()} cellCache={controller.databaseViewCache.getRowCache().getCellCache()}

View File

@ -5,15 +5,17 @@ export const GridTableRows = ({
viewId, viewId,
controller, controller,
allRows, allRows,
onOpenRow,
}: { }: {
viewId: string; viewId: string;
controller: DatabaseController; controller: DatabaseController;
allRows: readonly RowInfo[]; allRows: readonly RowInfo[];
onOpenRow: (rowId: RowInfo) => void;
}) => { }) => {
return ( return (
<tbody> <tbody>
{allRows.map((row, i) => { {allRows.map((row, i) => {
return <GridTableRow row={row} key={i} viewId={viewId} controller={controller} />; return <GridTableRow onOpenRow={onOpenRow} row={row} key={i} viewId={viewId} controller={controller} />;
})} })}
</tbody> </tbody>
); );