-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
589 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React from 'react'; | ||
import { FormBase } from 'components/Form'; | ||
import { historyFilter } from 'formSchema/analyst'; | ||
import historyFilterUiSchema from 'formSchema/uiSchema/history/historyFilterUiSchema'; | ||
import transformToTitleCase from 'utils/formatString'; | ||
|
||
interface HistoryFilterProps { | ||
filterOptions: { typeOptions: string[]; userOptions: string[] }; | ||
filters: any; | ||
onFilterChange: (newFilters: any) => void; | ||
} | ||
|
||
export const filterByType = (historyItem: any, filters: any) => | ||
!filters?.types?.length || filters?.types?.includes(historyItem.tableName); | ||
|
||
export const filterByUser = (historyItem: any, filters: any) => | ||
!filters?.users?.length || filters?.users?.includes(historyItem.user); | ||
|
||
export const getTypeOptions = (historyItems: any[], filters: any) => { | ||
return [ | ||
...new Set( | ||
historyItems | ||
.filter( | ||
(item) => | ||
!filters?.users?.length || filters?.users?.includes(item.user) | ||
) | ||
.map((item) => item.tableName) | ||
), | ||
]; | ||
}; | ||
|
||
export const getUserOptions = (historyItems: any[], filters: any) => { | ||
return [ | ||
...new Set( | ||
historyItems | ||
.filter( | ||
(item) => | ||
!filters?.types?.length || filters?.types?.includes(item.tableName) | ||
) | ||
.map((item) => item.user) | ||
), | ||
]; | ||
}; | ||
|
||
const HistoryFilter: React.FC<HistoryFilterProps> = ({ | ||
filterOptions, | ||
filters, | ||
onFilterChange, | ||
}) => { | ||
const { typeOptions, userOptions } = filterOptions; | ||
|
||
const formattedTypeOptions = typeOptions | ||
.filter((type) => type !== 'attachment') | ||
.map((type) => ({ | ||
value: type, | ||
label: transformToTitleCase(type), | ||
})); | ||
|
||
const filterSchema = historyFilter(formattedTypeOptions, userOptions); | ||
|
||
return ( | ||
<FormBase | ||
schema={filterSchema as any} | ||
uiSchema={historyFilterUiSchema as any} | ||
formData={filters} | ||
onChange={(e) => onFilterChange(e.formData)} | ||
formContext={{ skipUnsavedWarning: true }} | ||
// eslint-disable-next-line react/no-children-prop | ||
children | ||
/> | ||
); | ||
}; | ||
|
||
export default HistoryFilter; |
Oops, something went wrong.