Skip to content

Commit

Permalink
Restore naming convention settings and add disable lines
Browse files Browse the repository at this point in the history
  • Loading branch information
dgcohen committed Oct 11, 2023
1 parent 78d4a8f commit 8c70722
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 75 deletions.
15 changes: 15 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,20 @@ module.exports = {
"@typescript-eslint/strict-boolean-expressions": ["off"],
"@typescript-eslint/explicit-function-return-type": ["off"],
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/naming-convention": [
"warn",
{
selector: ["typeProperty", "parameter"],
format: ["camelCase"],
},
{
selector: ["function"],
format: ["camelCase", "PascalCase"],
},
{
selector: "variable",
format: ["camelCase", "PascalCase", "UPPER_CASE"],
},
],
},
}
1 change: 1 addition & 0 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Head from "next/head"
import "@nypl/design-system-react-components/dist/styles.css"

// eslint-disable-next-line @typescript-eslint/naming-convention
function App({ Component, pageProps }) {
return (
<>
Expand Down
2 changes: 2 additions & 0 deletions src/types/drbTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export interface Agent {
roles: string[]
}

/* eslint-disable @typescript-eslint/naming-convention */

export interface EditionLink {
link_id: string
mediaType: string
Expand Down
72 changes: 37 additions & 35 deletions src/types/searchTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,43 @@ export interface SearchParams {
identifiers?: Identifiers
}

type SearchFormField = { value: string }

export interface SearchResultsResponse {
results?: SearchResults
aggregations?: SearchResults
drbResults?: DRBResults
page: number
}

export interface SearchResults {
totalResults: number
itemListElement: SearchResultsElement[]
}

export interface SearchResultsElement {
result?: SearchResult
field?: string
}

export interface SearchFormInputField {
name: string
label: string
}

export type SearchFormActionType =
| "input_change"
| "filter_change"
| "form_reset"

export interface SearchFormAction {
type: SearchFormActionType
field?: string
payload: SearchParams | SearchFilters | string | string[]
}

/* eslint-disable @typescript-eslint/naming-convention */

export interface SearchQueryParams extends Identifiers {
q?: string
contributor?: string
Expand All @@ -56,8 +93,6 @@ export interface SearchQueryParams extends Identifiers {
per_page?: number
}

type SearchFormField = { value: string }

export interface SearchFormEvent {
q?: SearchFormField
search_scope?: SearchFormField
Expand All @@ -70,23 +105,6 @@ export interface SearchFormEvent {
materialType?: SearchFormField
}

export interface SearchResultsResponse {
results?: SearchResults
aggregations?: SearchResults
drbResults?: DRBResults
page: number
}

export interface SearchResults {
totalResults: number
itemListElement: SearchResultsElement[]
}

export interface SearchResultsElement {
result?: SearchResult
field?: string
}

export interface SearchResult {
"@id"?: string
uri?: string
Expand All @@ -100,19 +118,3 @@ export interface SearchResult {
electronicResources?: ElectronicResource[]
numItemsTotal?: number
}

export interface SearchFormInputField {
name: string
label: string
}

export type SearchFormActionType =
| "input_change"
| "filter_change"
| "form_reset"

export interface SearchFormAction {
type: SearchFormActionType
field?: string
payload: SearchParams | SearchFilters | string | string[]
}
80 changes: 40 additions & 40 deletions src/utils/searchUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,46 +113,6 @@ export function getQueryString({
return completeQuery?.length ? `?q=${completeQuery}` : ""
}

/**
* mapQueryToSearchParams
* Maps the SearchQueryParams structure from the request to a SearchParams object, which is expected by fetchResults
*/
export function mapQueryToSearchParams({
q,
// eslint-disable-next-line @typescript-eslint/naming-convention
search_scope,
// eslint-disable-next-line @typescript-eslint/naming-convention
sort_direction,
page,
contributor,
title,
subject,
sort,
issn,
isbn,
oclc,
lccn,
filters,
}: SearchQueryParams): SearchParams {
return {
q,
field: search_scope,
page,
contributor,
title,
subject,
sortBy: sort,
order: sort_direction,
filters,
identifiers: {
issn,
isbn,
oclc,
lccn,
},
}
}

/**
* mapRequestBodyToSearchParams
* Maps the POST request body from an JS disabled advanced search to a SearchParams object
Expand Down Expand Up @@ -198,3 +158,43 @@ export function mapElementsToSearchResultsBibs(
return new SearchResultsBib(result.result)
})
}

/* eslint-disable @typescript-eslint/naming-convention */

/**
* mapQueryToSearchParams
* Maps the SearchQueryParams structure from the request to a SearchParams object, which is expected by fetchResults
*/
export function mapQueryToSearchParams({
q,
search_scope,
sort_direction,
page,
contributor,
title,
subject,
sort,
issn,
isbn,
oclc,
lccn,
filters,
}: SearchQueryParams): SearchParams {
return {
q,
field: search_scope,
page,
contributor,
title,
subject,
sortBy: sort,
order: sort_direction,
filters,
identifiers: {
issn,
isbn,
oclc,
lccn,
},
}
}

0 comments on commit 8c70722

Please sign in to comment.