Skip to content

Commit

Permalink
Merge pull request #981 from DeepBlueCLtd/952_user_show_history_does_…
Browse files Browse the repository at this point in the history
…not_filter_result

user show history doesn't filter results issue resolved
  • Loading branch information
IanMayo authored Jan 9, 2024
2 parents 25abc08 + 7c72bff commit afe9c86
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
25 changes: 9 additions & 16 deletions src/resources/users/UserShow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -364,25 +364,11 @@ const UserShowComp = ({
export default function UserShow(): React.ReactElement {
const [record, setRecord] = useState<User>()
const { hasAccess } = useCanAccess()
const [filteredData, setFilteredData] = useState<Audit[]>([])
const hasWriteAccess = hasAccess(R_USERS, { write: true })
const { isLoading, data } = useGetList<Audit>(R_AUDIT, {})
const { isLoading } = useGetList<Audit>(R_AUDIT, {})
const audit = useAudit()
const navigate = useNavigate()

useEffect(() => {
if (data != null)
setFilteredData(
data.filter((audit) => {
return (
audit.user === record?.id ||
audit.subjectId === record?.id ||
(audit.dataId === record?.id && audit.resource === R_USERS)
)
})
)
}, [data, record, isLoading])

if (isLoading) return <Loading />

return (
Expand All @@ -394,7 +380,14 @@ export default function UserShow(): React.ReactElement {
<EditButton />
<HistoryButton
onClick={() => {
navigate('/audit', { state: { data: filteredData } })
if (record) {
navigate(
`/audit?filter=${JSON.stringify({
resource: constants.R_USERS,
dataId: record.id ?? ''
})}`
)
}
}}
/>
</TopToolbar>
Expand Down
9 changes: 6 additions & 3 deletions src/resources/users/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react'
import React, { useEffect, useState } from 'react'
import { Create, Edit, useEditContext, useRedirect } from 'react-admin'
import UserForm from './UserForm'
import * as constants from '../../constants'
Expand Down Expand Up @@ -54,8 +54,11 @@ interface EditValType {

const EditVal = ({ setPrev }: EditValType): React.ReactElement => {
const { record } = useEditContext()
console.log(record)
setPrev(record)

useEffect(() => {
setPrev(record as User)
}, [record, setPrev])

return <UserForm isEdit />
}

Expand Down

0 comments on commit afe9c86

Please sign in to comment.