Skip to content

Commit

Permalink
correct uses of useListExportCallback and usePrefilledTemplateCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
nafiz1001 committed Dec 20, 2024
1 parent ac4ad4b commit 890310c
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions frontend/src/components/containers/ContainersListContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ export default function ContainersListContent() {
const templateActions = useAppSelector(selectContainerTemplateActions)
const prefills = useAppSelector(selectContainerPrefillTemplates)

const prefillTemplate = usePrefilledTemplateCallback(api.containers.prefill.request, filters, sortByList[0])
const prefillTemplate = usePrefilledTemplateCallback(api.containers.prefill.request, filters, sortByList)

const listExport = useListExportCallback(api.containers.listExport, filters, sortByList[0])
const listExport = useListExportCallback(api.containers.listExport, filters, sortByList)

const containersTableCallbacks = usePagedItemsActionsCallbacks(ContainersTableActions)

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/indices/IndicesListContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ function IndicesListContent() {
const navigate = useNavigate()
const pagedItems = useAppSelector(selectIndicesTable)
const templateActions = useAppSelector(selectIndicesTemplateActions)
const { filters, sortBy, totalCount } = pagedItems
const { filters, sortByList, totalCount } = pagedItems

const listExport = useListExportCallback(api.indices.listExport, filters, sortBy)
const listExport = useListExportCallback(api.indices.listExport, filters, sortByList)

const pagedItemCallbacks = usePagedItemsActionsCallbacks(IndicesTableActions)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ function wrapIndividual(individual: Individual) {

function IndividualsListContent() {
const individualsTableState = useAppSelector(selectIndividualsTable)
const { filters, sortBy, totalCount } = individualsTableState
const { filters, sortByList, totalCount } = individualsTableState

const listExport = useListExportCallback(api.individuals.listExport, filters, sortBy)
const listExport = useListExportCallback(api.individuals.listExport, filters, sortByList)

const mapIndividualIDs = useItemsByIDToDataObjects(selectIndividualsByID, wrapIndividual)

Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/libraries/LibrariesListContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ function wrapLibrary(library: Library) {
export default function LibariesListContent() {

const librariesTableState = useAppSelector(selectLibrariesTable)
const { filters, fixedFilters, sortBy, totalCount, isFetching } = librariesTableState
const { filters, fixedFilters, sortByList, totalCount, isFetching } = librariesTableState
const templateActions = useAppSelector(selectLibraryTemplateActions)
const prefills = useAppSelector(selectLibraryPrefillTemplates)
const [sampleCategory, setSampleCategory] = useState<SampleCategory>()

const prefillTemplate = usePrefilledTemplateCallback(api.libraries.prefill.request, {...filters, ...fixedFilters}, sortBy)
const prefillTemplate = usePrefilledTemplateCallback(api.libraries.prefill.request, {...filters, ...fixedFilters}, sortByList)

const listExport = useListExportCallback(api.libraries.listExport, {...filters, ...fixedFilters}, sortBy)
const listExport = useListExportCallback(api.libraries.listExport, {...filters, ...fixedFilters}, sortByList)

const librariesTableCallbacks = usePagedItemsActionsCallbacks(LibrariesTableActions)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,6 @@ export function serializeSortByParams(...sortByList: SortBy[]) {
* @param sortBy
* @returns
*/
export function filtersQueryParams(filters: FilterSet, sortBy: SortBy){
return {...serializeFilterParamsWithDescriptions(filters), ordering: serializeSortByParams(sortBy)}
export function filtersQueryParams(filters: FilterSet, sortByList: SortBy[]){
return {...serializeFilterParamsWithDescriptions(filters), ordering: serializeSortByParams(...sortByList)}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ type ListExportFunc = typeof api.samples.listExport // Just letting typescript
* @param sortBy
* @returns
*/
export default function useListExportCallback(listExport: ListExportFunc, filters: FilterSet, sortBy: SortBy) {
export default function useListExportCallback(listExport: ListExportFunc, filters: FilterSet, sortByList: SortBy[]) {
const token = useAppSelector(selectAuthTokenAccess)

return useCallback(() => {
return withToken(token, listExport)(filtersQueryParams(filters, sortBy))
return withToken(token, listExport)(filtersQueryParams(filters, sortByList))
.then(response => response.data)

}, [filters, listExport, sortBy, token])
}, [filters, listExport, sortByList, token])
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ type PrefillFunc = typeof api.samples.prefill.request
* @param sortBy The current sort order in a table
* @returns
*/
export function usePrefilledTemplateCallback(prefillFunc: PrefillFunc, filters: FilterSet, sortBy: SortBy) {
export function usePrefilledTemplateCallback(prefillFunc: PrefillFunc, filters: FilterSet, sortByList: SortBy[]) {
const token = useAppSelector(selectAuthTokenAccess)

return useCallback(({template}) =>
withToken(token, prefillFunc)(filtersQueryParams(filters, sortBy), template)
withToken(token, prefillFunc)(filtersQueryParams(filters, sortByList), template)
.then(response => response)
, [filters, prefillFunc, sortBy, token])
, [filters, prefillFunc, sortByList, token])
}
4 changes: 2 additions & 2 deletions frontend/src/components/projects/ProjectsListContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ function wrapProject(project: Project) {

const ProjectsListContent = () => {
const projectsTableState = useAppSelector(selectProjectsTable)
const { filters, sortBy, totalCount } = projectsTableState
const { filters, sortByList, totalCount } = projectsTableState
const templateActions = useAppSelector(selectProjectTemplateActions)

const listExport = useListExportCallback(api.projects.listExport, filters, sortBy)
const listExport = useListExportCallback(api.projects.listExport, filters, sortByList)

const projectsTableCallbacks = usePagedItemsActionsCallbacks(ProjectsTableActions)

Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/samples/SamplesListContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ function wrapSample(sample: Sample) {

function SamplesListContent() {
const samplesTableState = useAppSelector(selectSamplesTable)
const { filters, fixedFilters, sortBy, totalCount, isFetching } = samplesTableState
const { filters, fixedFilters, sortByList, totalCount, isFetching } = samplesTableState
const templateActions = useAppSelector(selectSampleTemplateActions)
const prefills = useAppSelector(selectSamplePrefillTemplates)
const [sampleCategory, setSampleCategory] = useState<SampleCategory>()

const prefillTemplate = usePrefilledTemplateCallback(api.samples.prefill.request, {...filters, ...fixedFilters}, sortBy)
const prefillTemplate = usePrefilledTemplateCallback(api.samples.prefill.request, {...filters, ...fixedFilters}, sortByList)

const listExport = useListExportCallback(api.samples.listExport, {...filters, ...fixedFilters}, sortBy)
const listExport = useListExportCallback(api.samples.listExport, {...filters, ...fixedFilters}, sortByList)

const listExportMetadata = useListExportCallback(api.samples.listExportMetadata, {...filters, ...fixedFilters}, sortBy)
const listExportMetadata = useListExportCallback(api.samples.listExportMetadata, {...filters, ...fixedFilters}, sortByList)

const samplesTableCallbacks = usePagedItemsActionsCallbacks(SamplesTableActions)

Expand Down

0 comments on commit 890310c

Please sign in to comment.