Skip to content

Commit

Permalink
project values come from configData
Browse files Browse the repository at this point in the history
  • Loading branch information
TahaKhanAbdalli committed Jan 4, 2024
1 parent 614ca3e commit 2903bf3
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 68 deletions.
21 changes: 9 additions & 12 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,7 @@ export const ITEM_SAVE = 'item_save'
export const CHANGE_PASSWORD_EVENT = 'change_password'


export const availableResources = [
R_USERS,
R_ITEMS,
R_BATCHES,
R_DESTRUCTION,
R_VAULT_LOCATION,
R_DISPATCH,
R_PROJECTS,
R_MEDIA_TYPE,
R_PLATFORMS
]

export const cosmeticLabels = {
[R_USERS]: 'User',
[R_ITEMS]: 'Item',
Expand All @@ -129,5 +119,12 @@ export const cosmeticLabels = {
[R_DISPATCH]: 'Dispatch',
[R_PROJECTS]: 'Project',
[R_MEDIA_TYPE]: 'Media Type',
[R_PLATFORMS]: 'Platform'
[R_PLATFORMS]: 'Platform',
[R_ORGANISATION]: 'Organization',
[R_CAT_CAVE]: 'Cat Cave',
[R_CAT_CODE]: 'Cat Code',
[R_CAT_HANDLE]: 'Cat Handle',
[R_DEPARTMENT]: 'Department',
[R_PROTECTIVE_MARKING]: 'Protective Marking',

}
133 changes: 77 additions & 56 deletions src/resources/audit/AuditList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,29 @@ import SourceField from '../../components/SourceField'
import SourceInput from '../../components/SourceInput'
import StyledTopToolbar from '../../components/StyledTopToolbar'
import { useLocation } from 'react-router-dom'
import { useConfigData } from '../../utils/useConfigData'

interface Props {
label: string
source: string
}
export const availableResources = [
constants.R_USERS,
constants.R_ITEMS,
constants.R_BATCHES,
constants.R_DESTRUCTION,
constants.R_VAULT_LOCATION,
constants.R_DISPATCH,
constants.R_PROJECTS,
constants.R_MEDIA_TYPE,
constants.R_PLATFORMS,
constants.R_ORGANISATION,
constants.R_CAT_CAVE,
constants.R_CAT_CODE,
constants.R_CAT_HANDLE,
constants.R_DEPARTMENT,
constants.R_PROTECTIVE_MARKING
]

const SecurityRelatedFilter = ({
label,
Expand All @@ -43,60 +61,7 @@ const SecurityRelatedFilter = ({

return <Chip sx={{ marginBottom: 1 }} label={label} />
}

const yourListOfResources = constants.availableResources.map((resource) => ({
id: resource,
name: constants.cosmeticLabels[
resource as keyof typeof constants.cosmeticLabels
]
}))

const choices = ActivityTypes.map((v) => ({ name: v.label, id: v.label }))
const filters = [
<DateTimeInput
key='startDate'
source='dateTime_gte'
label='After'
alwaysOn={true}
/>,
<DateTimeInput key='endDate' source='dateTime_lte' label='Before' />,
<AutocompleteArrayInput
source='label'
choices={choices}
key='Activity Type'
label='Activity Type'
/>,
<SourceInput
reference={constants.R_USERS}
source='user'
key='user'
label='User'
/>,
<SelectInput
source='resource'
key='resource'
label='Resource'
choices={yourListOfResources}
/>,

<SecurityRelatedFilter
source='securityRelated'
key='securityRelated'
label='Security Related'
/>,
<DateFilter key='createdAt' source='dateTime' label='Created At' />,
<NumberInput
key='data'
source='dataId'
label='Subject (expert users only)'
/>,
<NumberInput
key='subject'
source='subjectId'
label='Object (expert users only)'
/>
]

const resourcesRefKey: Record<string, string> = {
[constants.R_BATCHES]: 'batchNumber',
[constants.R_ITEMS]: 'itemNumber',
Expand Down Expand Up @@ -221,6 +186,61 @@ export default function AuditList({
: 'simple-audit-list'
const filteredData = location.state?.filter

const ConfigData = useConfigData()
const yourListOfResources = availableResources.map((resource) => ({
id: resource,
name:
resource === constants.R_PROJECTS
? ConfigData?.projectName
: constants.cosmeticLabels[
resource as keyof typeof constants.cosmeticLabels
]
}))

const filters = [
<DateTimeInput
key='startDate'
source='dateTime_gte'
label='After'
alwaysOn={true}
/>,
<DateTimeInput key='endDate' source='dateTime_lte' label='Before' />,
<AutocompleteArrayInput
source='label'
choices={choices}
key='Activity Type'
label='Activity Type'
/>,
<SourceInput
reference={constants.R_USERS}
source='user'
key='user'
label='User'
/>,
<SelectInput
choices={yourListOfResources}
source='resource'
key='resource'
label='Resource'
/>,

<SecurityRelatedFilter
source='securityRelated'
key='securityRelated'
label='Security Related'
/>,
<DateFilter key='createdAt' source='dateTime' label='Created At' />,
<NumberInput
key='data'
source='dataId'
label='Subject (expert users only)'
/>,
<NumberInput
key='subject'
source='subjectId'
label='Object (expert users only)'
/>
]
return (
<List
perPage={25}
Expand Down Expand Up @@ -269,9 +289,10 @@ export default function AuditList({
label='Resource'
render={(record) => (
<span>
{constants.cosmeticLabels[
record.resource as keyof typeof constants.cosmeticLabels
] || record.resource}
{String(
yourListOfResources.find((r) => r.id === record.resource)
?.name || record.resource
)}
</span>
)}
/>
Expand Down

0 comments on commit 2903bf3

Please sign in to comment.