Skip to content

Commit

Permalink
refactor: remove useModelGist
Browse files Browse the repository at this point in the history
  • Loading branch information
Birkbjo committed Nov 27, 2023
1 parent 883a9bc commit af5b5d6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 227 deletions.
21 changes: 9 additions & 12 deletions src/components/sectionList/SectionListPagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import {
NumericObjectParam,
withDefault,
} from 'use-query-params'
import { GistPaginator } from '../../lib/'
import { Pager } from '../../types/generated'

type SectionListPaginationProps = {
pager: Pager | undefined
}

type PaginationQueryParams = {
export type PaginationQueryParams = {
page: number
pageSize: number
}
Expand Down Expand Up @@ -67,16 +66,15 @@ const validatePagerParams = (
}
}

function useUpdatePaginationParams(pager?: Pager): GistPaginator {
const [, setParams] = usePaginationQueryParams()
type Paginator = {
changePageSize: (pageSize: number) => boolean
getPrevPage: () => boolean
goToPage: (page: number) => boolean
pager?: Pager
}

const getNextPage = useCallback(() => {
if (!pager?.nextPage) {
return false
}
setParams((prevPager) => ({ ...prevPager, page: pager.page + 1 }))
return true
}, [pager, setParams])
function useUpdatePaginationParams(pager?: Pager): Paginator {
const [, setParams] = usePaginationQueryParams()

const getPrevPage = useCallback(() => {
if (!pager?.prevPage) {
Expand Down Expand Up @@ -106,7 +104,6 @@ function useUpdatePaginationParams(pager?: Pager): GistPaginator {
)

return {
getNextPage,
getPrevPage,
goToPage,
changePageSize,
Expand Down
22 changes: 1 addition & 21 deletions src/components/sectionList/filters/useSectionListFilter.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { useCallback, useMemo } from 'react'
import { useQueryParam, ObjectParam, UrlUpdateType } from 'use-query-params'
import {
Schema,
useSchemaFromHandle,
CustomObjectParam,
GistParams,
} from '../../../lib'
import { Schema, useSchemaFromHandle, CustomObjectParam } from '../../../lib'
import { usePaginationQueryParams } from '../SectionListPagination'

type ObjectParamType = typeof ObjectParam.default
Expand All @@ -17,21 +12,6 @@ type Filters = Record<string, string | undefined>
// this would translate to "token" in the old API, but does not exist in GIST-API
export const IDENTIFIABLE_KEY = 'identifiable'

const IDENTIFIABLE_FIELDS = {
name: {
operator: 'ilike',
},
code: {
operator: 'ilike',
},
shortName: {
operator: 'ilike',
},
id: {
operator: 'eq',
},
}

const getVerifiedFiltersForSchema = (
filters: ObjectParamType,
schema: Schema
Expand Down
7 changes: 0 additions & 7 deletions src/lib/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
export { useModelGist } from './useModelGist'
export type {
GistPaginator,
GistParams,
UseModelGistResultPaginated,
UseModelGistResult,
} from './useModelGist'
export { isValidUid } from './uid'
export { parsePublicAccessString } from './parsePublicAccess'
export { getIn, stringToPathArray, getFieldFilterFromPath } from './path'
187 changes: 0 additions & 187 deletions src/lib/models/useModelGist.ts

This file was deleted.

0 comments on commit af5b5d6

Please sign in to comment.