Skip to content

Commit

Permalink
Merge branch 'main' into inactive_user_token_expire
Browse files Browse the repository at this point in the history
  • Loading branch information
IanMayo committed Jan 18, 2024
2 parents 0293f2c + 4a079dc commit f8f1519
Show file tree
Hide file tree
Showing 26 changed files with 309 additions and 148 deletions.
18 changes: 12 additions & 6 deletions src/components/DateFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,9 @@ const getFilter = (value: Values, source: string, format: string): Filter[] => {
return formattedDate
}

const now = formatter(DateTime.now())
const gteKeyName: string = `${source}_gte`
const lteKeyName: string = `${source}_lte`

const todayFilter: Filter = { key: lteKeyName, value: now }

const resetTodayFilter: Filter = { key: source, value: undefined }
const resetGTFilter: Filter = { key: gteKeyName, value: undefined }
const resetLTFilter: Filter = { key: lteKeyName, value: undefined }
Expand All @@ -63,7 +60,10 @@ const getFilter = (value: Values, source: string, format: string): Filter[] => {
case 'past_week':
return [
resetTodayFilter,
todayFilter,
{
key: lteKeyName,
value: DateTime.now().endOf('day').toISO() ?? ''
},
{
key: gteKeyName,
value: minusFromNow('week')
Expand All @@ -72,7 +72,10 @@ const getFilter = (value: Values, source: string, format: string): Filter[] => {
case 'past_month':
return [
resetTodayFilter,
todayFilter,
{
key: lteKeyName,
value: DateTime.now().endOf('day').toISO() ?? ''
},
{
key: gteKeyName,
value: minusFromNow('month')
Expand All @@ -81,7 +84,10 @@ const getFilter = (value: Values, source: string, format: string): Filter[] => {
case 'past_year':
return [
resetTodayFilter,
todayFilter,
{
key: lteKeyName,
value: DateTime.now().endOf('day').toISO() ?? ''
},
{
key: gteKeyName,
value: minusFromNow('year')
Expand Down
5 changes: 4 additions & 1 deletion src/components/Layout/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import preval from 'preval.macro'

const Footer = (): React.ReactElement => {
const buildDate = preval`module.exports = new Date().toISOString().slice(0, 19).replace('T', ' ')`
const trimmedAppBuildDate = buildDate.substring(0, buildDate.length - 3)
const trimmedAppBuildDate = `Build Date: ${buildDate.substring(
0,
buildDate.length - 3
)}`

return (
<div
Expand Down
21 changes: 21 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,24 @@ export const ITEM_CLONE = 'item_clone'
export const ITEM_SAVE = 'item_save'

export const CHANGE_PASSWORD_EVENT = 'change_password'



export const cosmeticLabels = {
[R_USERS]: 'User',
[R_ITEMS]: 'Item',
[R_BATCHES]: 'Batch',
[R_DESTRUCTION]: 'Destruction',
[R_VAULT_LOCATION]: 'Vault Location',
[R_DISPATCH]: 'Dispatch',
[R_PROJECTS]: 'Project',
[R_MEDIA_TYPE]: 'Media Type',
[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',

}
11 changes: 5 additions & 6 deletions src/hooks/useCustomId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export default function useCustomid(): UseCustomId {
const { getValues } = useFormContext()
const [create] = useCreate() as any
const resource = useResourceContext()
const { total = 0 } = useGetList(resource, {
sort: { field: 'id', order: 'DESC' },
pagination: { page: 1, perPage: 1 }
const {data : existingRcordes} = useGetList(resource, {
sort: {field: 'id', order: "DESC"},
pagination: {page: 1, perPage: 1}
})
const createPath = useCreatePath()
const redirect = useRedirect()
Expand All @@ -26,10 +26,9 @@ export default function useCustomid(): UseCustomId {
const values = getValues()

const preFix = ID_FIX?.[resource]
const totalItems: number = total
const recordNumber = totalItems + 1
const highestId = existingRcordes?.[0]?.id || 0;
const id =
typeof preFix !== 'undefined' ? `${preFix}-${recordNumber}` : recordNumber
typeof preFix !== 'undefined' ? `${preFix}-${(highestId as number) + 1}` : (highestId as number) + 1

const data = { id, ...values }

Expand Down
2 changes: 1 addition & 1 deletion src/resources/addresses/AddressList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function AddressList(): React.ReactElement {
<TextField<Address> source='fullAddress' />
<BooleanField<Address> source='active' looseValue />
<DateField<Address> source='createdAt' />
<TextField<Address> source='Remarks' />
<TextField<Address> source='remarks' />
</Datagrid>
</List>
)
Expand Down
11 changes: 9 additions & 2 deletions src/resources/addresses/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { Create, Edit, Show } from 'react-admin'
import { Create, Edit, Show, useRedirect } from 'react-admin'
import * as constants from '../../constants'
const AddressList = React.lazy(async () => await import('./AddressList'))
const AddressForm = React.lazy(async () => await import('./AddressForm'))
Expand All @@ -13,8 +13,15 @@ const AddressCreate = (): React.ReactElement => {
}

export const AddressEdit = (): React.ReactElement => {
const redirect = useRedirect()
return (
<Edit mutationMode={constants.MUTATION_MODE}>
<Edit
mutationMode={constants.MUTATION_MODE}
mutationOptions={{
onSuccess: (data: { addressNumber: string; id: number }): void => {
redirect(`/${constants.R_ADDRESSES}/${data?.id}/show`)
}
}}>
<AddressForm />
</Edit>
)
Expand Down
127 changes: 90 additions & 37 deletions src/resources/audit/AuditList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import {
DateTimeInput,
useListContext,
AutocompleteArrayInput,
TextInput,
FunctionField,
DatagridConfigurable,
type DatagridConfigurableProps,
FilterButton,
ExportButton,
useGetList,
Link,
BooleanField
BooleanField,
NumberInput,
SelectInput
} from 'react-admin'
import * as constants from '../../constants'
import ActivityTypes from '../../utils/activity-types'
Expand All @@ -24,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 @@ -42,39 +61,7 @@ const SecurityRelatedFilter = ({

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

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'
/>,
<TextInput source='resource' key='resource' label='Resource' />,
<TextInput source='item' key='Item' />,
<SecurityRelatedFilter
source='securityRelated'
key='securityRelated'
label='Security Related'
/>,
<DateFilter key='createdAt' source='dateTime' label='Created At' />,
<SourceInput key='subject' source='subjectId' reference={constants.R_USERS} />
]

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

const ConfigData = useConfigData()
const labelledResources = 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={labelledResources}
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)'
/>
]
const renderResource = (record: Audit): string => {
const resourceName = labelledResources.find(
(r) => r.id === record.resource
)?.name
return String(resourceName ?? record.resource)
}
return (
<List
perPage={25}
Expand Down Expand Up @@ -242,10 +290,15 @@ export default function AuditList({
label='Security Related'
looseValue
/>
<TextField<Audit> source='resource' label='Resource' />

<FunctionField<Audit>
source='resource'
label='Resource'
render={renderResource}
/>
{!omit.includes('dataId') && (
<FunctionField<Audit>
label='Name'
label='Subject '
render={(record) => {
return (
record.dataId &&
Expand All @@ -258,7 +311,7 @@ export default function AuditList({
source value for different kinds of resource */}
{!omit.includes('subjectId') && (
<FunctionField<Audit>
label='Subject Item'
label='Object'
render={(record) => {
return (
record.subjectId &&
Expand Down
10 changes: 9 additions & 1 deletion src/resources/batches/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,16 @@ const Actions = (): React.ReactElement => {
}

const BatchEdit = (): React.ReactElement => {
const redirect = useRedirect()
return (
<Edit mutationMode={constants.MUTATION_MODE} actions={<Actions />}>
<Edit
mutationMode={constants.MUTATION_MODE}
actions={<Actions />}
mutationOptions={{
onSuccess: (data: { batchNumber: string; id: number }): void => {
redirect(`/${constants.R_BATCHES}/${data?.id}/show`)
}
}}>
<BatchForm isEdit />
</Edit>
)
Expand Down
13 changes: 1 addition & 12 deletions src/resources/destruction/DestructionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
useUpdate
} from 'react-admin'
import * as constants from '../../constants'
import DatePicker from '../../components/DatePicker'
import { yupResolver } from '@hookform/resolvers/yup'
import * as yup from 'yup'
import { ConditionalReferenceInput } from '../batches/BatchForm'
Expand All @@ -38,7 +37,7 @@ const DestructionFormToolbar = (

return (
<Toolbar>
<SaveButton label={isEdit ? 'Save' : 'Create'} alwaysEnable />
<SaveButton label={isEdit ? 'Save' : 'Create'} />
</Toolbar>
)
}
Expand Down Expand Up @@ -155,16 +154,6 @@ export default function DestructionForm(props: Props): React.ReactElement {
toolbar={<DestructionFormToolbar isEdit={isEdit} />}
resolver={yupResolver(schema)}
onSubmit={handleSubmit as any}>
<DatePicker
label='Year'
source='year'
variant='outlined'
format='YYYY'
dataPickerProps={{
views: ['year'],
disabled: true
}}
/>
{isEdit && (
<TextInput
fullWidth
Expand Down
Loading

0 comments on commit f8f1519

Please sign in to comment.