mirror of
https://github.com/nowcommunity/nowdatabase.git
synced 2026-10-12 19:13:52 +03:00
change tableUrl to an array
This commit is contained in:
@@ -30,7 +30,7 @@ export const SimpleTable = <T extends MRT_RowData, ParentType extends MRT_RowDat
|
|||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
|
||||||
const location = useLocation()
|
const location = useLocation()
|
||||||
const { setTableUrl } = usePageContext()
|
const { previousTableUrls, setPreviousTableUrls } = usePageContext()
|
||||||
const [searchParams] = useSearchParams()
|
const [searchParams] = useSearchParams()
|
||||||
|
|
||||||
const linkToDetails = ({ row }: { row: MRT_Row<T> }) => {
|
const linkToDetails = ({ row }: { row: MRT_Row<T> }) => {
|
||||||
@@ -45,7 +45,7 @@ export const SimpleTable = <T extends MRT_RowData, ParentType extends MRT_RowDat
|
|||||||
renderRowActions: linkToDetails,
|
renderRowActions: linkToDetails,
|
||||||
muiTableBodyRowProps: ({ row }: { row: MRT_Row<T> }) => ({
|
muiTableBodyRowProps: ({ row }: { row: MRT_Row<T> }) => ({
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
setTableUrl(`${location.pathname}?tab=${searchParams.get('tab')}`)
|
setPreviousTableUrls([...previousTableUrls, `${location.pathname}?tab=${searchParams.get('tab')}`])
|
||||||
navigate(`/${url}/${row.original[idFieldName]}`)
|
navigate(`/${url}/${row.original[idFieldName]}`)
|
||||||
},
|
},
|
||||||
sx: {
|
sx: {
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ export const ErrorBox = <T,>() => {
|
|||||||
|
|
||||||
export const ReturnButton = () => {
|
export const ReturnButton = () => {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const { tableUrl } = usePageContext()
|
const { setPreviousTableUrls, previousTableUrls } = usePageContext()
|
||||||
const { mode, setMode } = useDetailContext()
|
const { mode, setMode } = useDetailContext()
|
||||||
|
|
||||||
if (mode.staging) {
|
if (mode.staging) {
|
||||||
@@ -222,7 +222,17 @@ export const ReturnButton = () => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<Button onClick={() => navigate(tableUrl, { relative: 'path' })}>
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
if (previousTableUrls.length > 0) {
|
||||||
|
const previousTableUrl = previousTableUrls[previousTableUrls.length - 1]
|
||||||
|
const newUrls = [...previousTableUrls]
|
||||||
|
newUrls.splice(-1)
|
||||||
|
setPreviousTableUrls(newUrls)
|
||||||
|
navigate(previousTableUrl, { relative: 'path' })
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
<ArrowBackIcon color="primary" style={{ marginRight: '0.2em' }} />
|
<ArrowBackIcon color="primary" style={{ marginRight: '0.2em' }} />
|
||||||
Return to table
|
Return to table
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ export type PageContextType<T> = {
|
|||||||
setIdList: (ids: string[]) => void
|
setIdList: (ids: string[]) => void
|
||||||
idFieldName: string
|
idFieldName: string
|
||||||
viewName: string
|
viewName: string
|
||||||
tableUrl: string
|
previousTableUrls: string[]
|
||||||
setTableUrl: (newUrl: string) => void
|
setPreviousTableUrls: (newPreviousTableUrls: string[]) => void
|
||||||
createTitle: (data: T) => string
|
createTitle: (data: T) => string
|
||||||
createSubtitle: (data: T) => string
|
createSubtitle: (data: T) => string
|
||||||
editRights: EditRights
|
editRights: EditRights
|
||||||
@@ -47,12 +47,13 @@ export const PageContextProvider = <T extends object>({
|
|||||||
editRights: EditRights
|
editRights: EditRights
|
||||||
}) => {
|
}) => {
|
||||||
const [idList, setIdList] = useState<string[]>([])
|
const [idList, setIdList] = useState<string[]>([])
|
||||||
const [tableUrl, setTableUrl] = useState<string>(`/${viewName}`)
|
const [previousTableUrls, setPreviousTableUrls] = useState<string[]>([`/${viewName}`])
|
||||||
// TODO: replace with some default values from variables
|
// TODO: replace with some default values from variables
|
||||||
const [sqlLimit, setSqlLimit] = useState<number>(defaultPagination.pageSize)
|
const [sqlLimit, setSqlLimit] = useState<number>(defaultPagination.pageSize)
|
||||||
const [sqlOffset, setSqlOffset] = useState<number>(0)
|
const [sqlOffset, setSqlOffset] = useState<number>(0)
|
||||||
const [sqlColumnFilters, setSqlColumnFilters] = useState<MRT_ColumnFiltersState>([])
|
const [sqlColumnFilters, setSqlColumnFilters] = useState<MRT_ColumnFiltersState>([])
|
||||||
const [sqlOrderBy, setSqlOrderBy] = useState<MRT_SortingState>([])
|
const [sqlOrderBy, setSqlOrderBy] = useState<MRT_SortingState>([])
|
||||||
|
console.log(previousTableUrls)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageContext.Provider
|
<PageContext.Provider
|
||||||
@@ -62,8 +63,8 @@ export const PageContextProvider = <T extends object>({
|
|||||||
idFieldName,
|
idFieldName,
|
||||||
setIdList: (newIdList: string[]) => setIdList(newIdList),
|
setIdList: (newIdList: string[]) => setIdList(newIdList),
|
||||||
viewName,
|
viewName,
|
||||||
tableUrl,
|
previousTableUrls,
|
||||||
setTableUrl: (newUrl: string) => setTableUrl(newUrl),
|
setPreviousTableUrls,
|
||||||
createTitle: (data: unknown) => createTitle(data as T),
|
createTitle: (data: unknown) => createTitle(data as T),
|
||||||
createSubtitle: (data: unknown) => createSubtitle(data as T),
|
createSubtitle: (data: unknown) => createSubtitle(data as T),
|
||||||
sqlLimit,
|
sqlLimit,
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { Box, Button, Tooltip, Typography } from '@mui/material'
|
import { Box, Button, Tooltip, Typography } from '@mui/material'
|
||||||
import { MRT_RowData, MRT_Row } from 'material-react-table'
|
import { MRT_RowData, MRT_Row } from 'material-react-table'
|
||||||
import { useNavigate } from 'react-router-dom'
|
import { useNavigate, useSearchParams } from 'react-router-dom'
|
||||||
import ManageSearchIcon from '@mui/icons-material/ManageSearch'
|
import ManageSearchIcon from '@mui/icons-material/ManageSearch'
|
||||||
import PolicyIcon from '@mui/icons-material/Policy'
|
import PolicyIcon from '@mui/icons-material/Policy'
|
||||||
import AddCircleOutlineIcon from '@mui/icons-material/AddCircleOutline'
|
import AddCircleOutlineIcon from '@mui/icons-material/AddCircleOutline'
|
||||||
|
import { usePageContext } from '../Page'
|
||||||
|
|
||||||
export const ActionComponent = <T extends MRT_RowData>({
|
export const ActionComponent = <T extends MRT_RowData>({
|
||||||
row,
|
row,
|
||||||
@@ -21,6 +22,8 @@ export const ActionComponent = <T extends MRT_RowData>({
|
|||||||
tableRowAction?: (row: T) => void
|
tableRowAction?: (row: T) => void
|
||||||
}) => {
|
}) => {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
const { previousTableUrls, setPreviousTableUrls } = usePageContext()
|
||||||
|
const [searchParams] = useSearchParams()
|
||||||
|
|
||||||
const id = row.original[idFieldName]
|
const id = row.original[idFieldName]
|
||||||
|
|
||||||
@@ -57,6 +60,7 @@ export const ActionComponent = <T extends MRT_RowData>({
|
|||||||
event.stopPropagation()
|
event.stopPropagation()
|
||||||
tableRowAction(row.original)
|
tableRowAction(row.original)
|
||||||
} else {
|
} else {
|
||||||
|
setPreviousTableUrls([...previousTableUrls, `${location.pathname}?tab=${searchParams.get('tab')}`])
|
||||||
navigate(`/${url}/${id}`)
|
navigate(`/${url}/${id}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,15 @@ export const TableView = <T extends MRT_RowData>({
|
|||||||
isFetching: boolean
|
isFetching: boolean
|
||||||
}) => {
|
}) => {
|
||||||
const location = useLocation()
|
const location = useLocation()
|
||||||
const { editRights, setSqlLimit, setSqlOffset, setSqlColumnFilters, setSqlOrderBy } = usePageContext()
|
const {
|
||||||
|
editRights,
|
||||||
|
setSqlLimit,
|
||||||
|
setSqlOffset,
|
||||||
|
setSqlColumnFilters,
|
||||||
|
setSqlOrderBy,
|
||||||
|
previousTableUrls,
|
||||||
|
setPreviousTableUrls,
|
||||||
|
} = usePageContext()
|
||||||
const [columnFilters, setColumnFilters] = useState<MRT_ColumnFiltersState>([])
|
const [columnFilters, setColumnFilters] = useState<MRT_ColumnFiltersState>([])
|
||||||
const [sorting, setSorting] = useState<MRT_SortingState>([])
|
const [sorting, setSorting] = useState<MRT_SortingState>([])
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
@@ -80,7 +88,7 @@ export const TableView = <T extends MRT_RowData>({
|
|||||||
selectorFn ? defaultPaginationSmall : defaultPagination
|
selectorFn ? defaultPaginationSmall : defaultPagination
|
||||||
)
|
)
|
||||||
const user = useUser()
|
const user = useUser()
|
||||||
const { setIdList, setTableUrl } = usePageContext<T>()
|
const { setIdList } = usePageContext<T>()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setSqlLimit(pagination.pageSize)
|
setSqlLimit(pagination.pageSize)
|
||||||
@@ -122,6 +130,13 @@ export const TableView = <T extends MRT_RowData>({
|
|||||||
|
|
||||||
const muiTableBodyRowProps = ({ row }: { row: MRT_Row<T> }) => ({
|
const muiTableBodyRowProps = ({ row }: { row: MRT_Row<T> }) => ({
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
|
const columnFilterToUrl = `columnfilters=${JSON.stringify(columnFilters)}`
|
||||||
|
const sortingToUrl = `sorting=${JSON.stringify(sorting)}`
|
||||||
|
const paginationToUrl = `pagination=${JSON.stringify(pagination)}`
|
||||||
|
setPreviousTableUrls([
|
||||||
|
...previousTableUrls,
|
||||||
|
`${location.pathname}?&${columnFilterToUrl}&${sortingToUrl}&${paginationToUrl}`,
|
||||||
|
])
|
||||||
navigate(`/${url}/${row.original[idFieldName]}`)
|
navigate(`/${url}/${row.original[idFieldName]}`)
|
||||||
},
|
},
|
||||||
sx: {
|
sx: {
|
||||||
@@ -211,7 +226,6 @@ export const TableView = <T extends MRT_RowData>({
|
|||||||
const columnFilterToUrl = `columnfilters=${JSON.stringify(columnFilters)}`
|
const columnFilterToUrl = `columnfilters=${JSON.stringify(columnFilters)}`
|
||||||
const sortingToUrl = `sorting=${JSON.stringify(sorting)}`
|
const sortingToUrl = `sorting=${JSON.stringify(sorting)}`
|
||||||
const paginationToUrl = `pagination=${JSON.stringify(pagination)}`
|
const paginationToUrl = `pagination=${JSON.stringify(pagination)}`
|
||||||
setTableUrl(`${location.pathname}?&${columnFilterToUrl}&${sortingToUrl}&${paginationToUrl}`)
|
|
||||||
navigate(`${location.pathname}?&${columnFilterToUrl}&${sortingToUrl}&${paginationToUrl}`, {
|
navigate(`${location.pathname}?&${columnFilterToUrl}&${sortingToUrl}&${paginationToUrl}`, {
|
||||||
replace: true,
|
replace: true,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user