diff --git a/.eslintrc.js b/.eslintrc.js index b5a8a66..511d279 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -27,12 +27,13 @@ module.exports = { ], rules: { '@typescript-eslint/no-unused-vars': [ - 'warn', + 'error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_', }, ], + '@typescript-eslint/no-explicit-any': 'error', }, }; diff --git a/src/app.tsx b/src/app.tsx index 8c206e8..4a005b8 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -437,6 +437,7 @@ export function App() { setSelection(newSelection); setDetailIndi(newSelection.id); setState(AppState.SHOWING_CHART); + // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (error: any) { setState(AppState.SHOWING_CHART); displayErrorPopup( diff --git a/src/datasource/wikitree_transformer.ts b/src/datasource/wikitree_transformer.ts index 21550a5..be945f8 100644 --- a/src/datasource/wikitree_transformer.ts +++ b/src/datasource/wikitree_transformer.ts @@ -119,9 +119,9 @@ export function convertFams(people: Person[]): JsonFam[] { if (husband) { fam.husb = husband; } - fam.children = Array.from(getSet(children, key)).map( - (child) => idToName.get(child)!, - ); + fam.children = Array.from(getSet(children, key)) + .map((child) => idToName.get(child)) + .filter((x) => !!x) as string[]; if ( value.spouse && ((value.spouse.marriage_date && diff --git a/src/donatso-chart.tsx b/src/donatso-chart.tsx index ac015bb..7885f05 100644 --- a/src/donatso-chart.tsx +++ b/src/donatso-chart.tsx @@ -1,4 +1,12 @@ -import f3 from 'family-chart'; +import { + Datum, + Store, + TreeDatum, + createStore, + createSvg, + elements, + view, +} from 'family-chart'; import {useEffect, useRef} from 'react'; import {IntlShape, useIntl} from 'react-intl'; import {IndiInfo, JsonFam, JsonGedcomData} from 'topola'; @@ -15,7 +23,7 @@ function getOtherSpouse(fam: JsonFam, indi: string) { return fam.husb === indi ? fam.wife : fam.husb; } -function convertData(data: JsonGedcomData, intl: IntlShape) { +function convertData(data: JsonGedcomData, intl: IntlShape): Datum[] { const famMap = new Map(); data.fams.forEach((fam) => famMap.set(fam.id, fam)); return data.indis.map((indi) => { @@ -25,6 +33,7 @@ function convertData(data: JsonGedcomData, intl: IntlShape) { .filter((fam): fam is JsonFam => fam !== undefined); const father = famc?.husb; const mother = famc?.wife; + const parents = [father, mother].filter((x) => !!x); const spouses = fams .map((fam) => getOtherSpouse(fam, indi.id)) .filter((indi): indi is string => indi !== undefined); @@ -40,40 +49,51 @@ function convertData(data: JsonGedcomData, intl: IntlShape) { gender: indi.sex, }, rels: { - father, - mother, + parents, spouses, children, }, - }; + } as Datum; }); } class ChartWrapper { - private store?: any; + private store!: Store; initializeChart(props: DonatsoChartProps, intl: IntlShape) { const data = convertData(props.data, intl); - this.store = f3.createStore({ + this.store = createStore({ data, main_id: props.selection.id, }); - const svg = f3.createSvg(document.querySelector('#dotatsoSvgContainer')); - const card = f3.elements.Card({ + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const svg = createSvg(document.querySelector('#dotatsoSvgContainer')!); + const card = elements.CardSvg({ store: this.store, svg, card_display: [ - (i: any) => + (i: Datum) => `${i.data['first name'] || ''} ${i.data['last name'] || ''}`, - (i: any) => `${i.data.birthday || ''}`, - ], + (i: Datum) => `${i.data.birthday || ''}`, + ] as any, // eslint-disable-line @typescript-eslint/no-explicit-any mini_tree: true, link_break: false, - onCardClick: (e: any, d: any) => + onCardClick: (e: MouseEvent, d: TreeDatum) => props.onSelection({id: d.data.id, generation: 0}), + card_dim: { + w: 220, + h: 70, + text_x: 75, + text_y: 15, + img_w: 60, + img_h: 60, + img_x: 5, + img_y: 5, + }, }); - this.store.setOnUpdate((props: any) => { - f3.view(this.store.getTree(), svg, card, props || {}); + this.store.setOnUpdate((props: unknown) => { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + view(this.store.getTree()!, svg, card, props || {}); }); this.store.updateTree({initial: true}); } diff --git a/src/family-chart.d.ts b/src/family-chart.d.ts deleted file mode 100644 index 89f1ee9..0000000 --- a/src/family-chart.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -// Data type definitions for the family-chart library. -declare module 'family-chart' { - export function createStore(args: any): any; - export function createSvg(args: any): any; - export function view(arg1: any, arg2: any, arg3: any, arg4: any): any; - export const elements: any; -} diff --git a/src/menu/search_index.ts b/src/menu/search_index.ts index 51031c3..cde5db6 100644 --- a/src/menu/search_index.ts +++ b/src/menu/search_index.ts @@ -104,7 +104,7 @@ class LunrSearchIndex implements SearchIndex { } private initMultiLingualLunrWithoutTrimmer( - lunrInstance: any, + lunrInstance: lunr.Builder, languages: string[], ): void { const pipelineFunctions: PipelineFunction[] = []; @@ -142,13 +142,16 @@ class LunrSearchIndex implements SearchIndex { .filter((s) => !!s) .map((s) => `${s} ${s}*`) .join(' '); - const results = this.index!.search(query); + const results = this.index.search(query); return results .sort(compare) .slice(0, MAX_RESULTS) .map((result) => ({ id: result.ref, - indi: this.indiMap.get(result.ref)!, + indi: this.indiMap.get(result.ref) || { + id: result.ref, + firstName: 'INDI NOT FOUND', + }, })); } }