From 06d40ac85f381a183e855d9ed33c0cc745d75f1a Mon Sep 17 00:00:00 2001 From: jasquat Date: Fri, 29 Jul 2022 16:23:55 -0400 Subject: [PATCH] updated several FIXME lines for typescript errors --- src/components/PaginationForTable.tsx | 10 ++---- src/components/ProcessBreadcrumb.tsx | 8 ++--- src/components/ReactDiagramEditor.tsx | 32 +++++++++---------- src/helpers.tsx | 18 +++++++++++ src/index.tsx | 1 - src/routes/AdminRoutes.tsx | 9 ------ src/routes/ProcessGroupEdit.tsx | 13 +++----- src/routes/ProcessGroupShow.tsx | 29 +++++------------- src/routes/ProcessGroups.tsx | 33 ++++---------------- src/routes/ProcessInstanceList.tsx | 39 ++++++------------------ src/routes/ProcessInstanceReportList.tsx | 3 +- src/routes/ProcessInstanceReportShow.tsx | 27 ++++++---------- src/routes/ProcessInstanceShow.tsx | 4 +-- src/routes/ProcessModelEdit.tsx | 24 ++++++--------- src/routes/ProcessModelEditDiagram.tsx | 9 ++---- src/routes/ProcessModelShow.tsx | 4 +-- src/routes/TaskList.tsx | 25 +++------------ src/services/UserService.ts | 10 +++--- 18 files changed, 106 insertions(+), 192 deletions(-) diff --git a/src/components/PaginationForTable.tsx b/src/components/PaginationForTable.tsx index e9681e1..4bb750f 100644 --- a/src/components/PaginationForTable.tsx +++ b/src/components/PaginationForTable.tsx @@ -12,7 +12,7 @@ type OwnProps = { pagination: { [key: string]: number; }; - tableToDisplay: string; + tableToDisplay: any; queryParamString?: string; path: string; }; @@ -66,9 +66,8 @@ export default function PaginationForTable({ }; const buildPaginationNav = () => { - let previousPageTag = ''; + let previousPageTag = null; if (page === 1) { - // @ts-expect-error TS(2322) FIXME: Type 'Element' is not assignable to type 'string'. previousPageTag = (
  • ); } else { - // @ts-expect-error TS(2322) FIXME: Type 'Element' is not assignable to type 'string'. previousPageTag = (
  • = pagination.pages) { - // @ts-expect-error TS(2322) FIXME: Type 'Element' is not assignable to type 'string'. nextPageTag = (
  • ); } else { - // @ts-expect-error TS(2322) FIXME: Type 'Element' is not assignable to type 'string'. nextPageTag = (
  • ); } else { - // @ts-expect-error TS(2322) FIXME: Type 'Element' is not assignable to type 'string'. processModelBreadcrumb = ( Process Model: {processModelId} ); } - // @ts-expect-error TS(2322) FIXME: Type 'Element' is not assignable to type 'string'. processGroupBreadcrumb = ( ); } else if (processGroupId) { - // @ts-expect-error TS(2322) FIXME: Type 'Element' is not assignable to type 'string'. processGroupBreadcrumb = ( Process Group: {processGroupId} ); diff --git a/src/components/ReactDiagramEditor.tsx b/src/components/ReactDiagramEditor.tsx index ed3976c..ed2dc33 100644 --- a/src/components/ReactDiagramEditor.tsx +++ b/src/components/ReactDiagramEditor.tsx @@ -60,7 +60,7 @@ type OwnProps = { activeTaskBpmnIds?: string[] | null; completedTasksBpmnIds?: string[] | null; saveDiagram?: (..._args: any[]) => any; - diagramXML?: string; + diagramXML?: string | null; fileName?: string; onLaunchScriptEditor?: (..._args: any[]) => any; url?: string; @@ -90,15 +90,12 @@ export default function ReactDiagramEditor({ return; } - // @ts-expect-error TS(2531) FIXME: Object is possibly 'null'. - document.getElementById('diagram-container').innerHTML = ''; - const temp = document.createElement('template'); - let canvasClass = 'diagram-editor-canvas'; if (diagramType === 'readonly') { canvasClass = 'diagram-viewer-canvas'; } + const temp = document.createElement('template'); temp.innerHTML = `
    `; - const frag = temp.content; - // @ts-expect-error TS(2531) FIXME: Object is possibly 'null'. - document.getElementById('diagram-container').appendChild(frag); + + const diagramContainerElement = + document.getElementById('diagram-container'); + if (diagramContainerElement) { + diagramContainerElement.innerHTML = ''; + diagramContainerElement.appendChild(frag); + } let diagramModeler: any = null; @@ -209,8 +210,7 @@ export default function ReactDiagramEditor({ let modeler = diagramModelerState; if (diagramType === 'dmn') { - // @ts-expect-error TS(2531) FIXME: Object is possibly 'null'. - modeler = diagramModelerState.getActiveViewer(); + modeler = (diagramModelerState as any).getActiveViewer(); } const canvas = (modeler as any).get('canvas'); @@ -218,8 +218,7 @@ export default function ReactDiagramEditor({ // only get the canvas if the dmn active viewer is actually // a Modeler and not an Editor which is what it will when we are // actively editing a decision table - // @ts-expect-error TS(2531) FIXME: Object is possibly 'null'. - if (modeler.constructor.name === 'Modeler') { + if ((modeler as any).constructor.name === 'Modeler') { canvas.zoom('fit-viewport'); } @@ -320,10 +319,11 @@ export default function ReactDiagramEditor({ function handleSave() { if (saveDiagram) { - // @ts-expect-error TS(2531) FIXME: Object is possibly 'null'. - diagramModelerState.saveXML({ format: true }).then((xmlObject: any) => { - saveDiagram(xmlObject.xml); - }); + (diagramModelerState as any) + .saveXML({ format: true }) + .then((xmlObject: any) => { + saveDiagram(xmlObject.xml); + }); } } diff --git a/src/helpers.tsx b/src/helpers.tsx index 8625282..fa62e3b 100644 --- a/src/helpers.tsx +++ b/src/helpers.tsx @@ -1,5 +1,9 @@ import { format } from 'date-fns'; import { DATE_FORMAT } from './config'; +import { + DEFAULT_PER_PAGE, + DEFAULT_PAGE, +} from './components/PaginationForTable'; // https://www.30secondsofcode.org/js/s/slugify export const slugifyString = (str: any) => { @@ -46,3 +50,17 @@ export const convertSecondsToFormattedDate = (seconds: number) => { export const objectIsEmpty = (obj: object) => { return Object.keys(obj).length === 0; }; + +export const getPageInfoFromSearchParams = ( + searchParams: any, + defaultPerPage: string | number = DEFAULT_PER_PAGE, + defaultPage: string | number = DEFAULT_PAGE +) => { + const page = parseInt(searchParams.get('page') || defaultPage.toString(), 10); + const perPage = parseInt( + searchParams.get('per_page') || defaultPerPage.toString(), + 10 + ); + + return { page, perPage }; +}; diff --git a/src/index.tsx b/src/index.tsx index bacef50..ebd4041 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -7,7 +7,6 @@ import './index.css'; import reportWebVitals from './reportWebVitals'; import UserService from './services/UserService'; -// import HttpService from './services/HttpService'; // @ts-expect-error TS(2345) FIXME: Argument of type 'HTMLElement | null' is not assig... Remove this comment to see the full error message const root = ReactDOMClient.createRoot(document.getElementById('root')); diff --git a/src/routes/AdminRoutes.tsx b/src/routes/AdminRoutes.tsx index d4d8753..eb265be 100644 --- a/src/routes/AdminRoutes.tsx +++ b/src/routes/AdminRoutes.tsx @@ -25,13 +25,11 @@ export default function AdminRoutes() { } /> } /> } /> } /> @@ -41,32 +39,26 @@ export default function AdminRoutes() { /> } /> } /> } /> } /> } /> } /> } /> { - // @ts-expect-error TS(2531) FIXME: Object is possibly 'null'. - navigate(`/admin/process-groups/${processGroup.id}`); + navigate(`/admin/process-groups/${(processGroup as any).id}`); }; const navigateToProcessGroups = (_result: any) => { @@ -34,22 +33,19 @@ export default function ProcessGroupEdit() { const updateProcessGroup = (event: any) => { event.preventDefault(); HttpService.makeCallToBackend({ - // @ts-expect-error TS(2531) FIXME: Object is possibly 'null'. - path: `/process-groups/${processGroup.id}`, + path: `/process-groups/${(processGroup as any).id}`, successCallback: navigateToProcessGroup, httpMethod: 'PUT', postBody: { display_name: displayName, - // @ts-expect-error TS(2531) FIXME: Object is possibly 'null'. - id: processGroup.id, + id: (processGroup as any).id, }, }); }; const deleteProcessGroup = () => { HttpService.makeCallToBackend({ - // @ts-expect-error TS(2531) FIXME: Object is possibly 'null'. - path: `/process-groups/${processGroup.id}`, + path: `/process-groups/${(processGroup as any).id}`, successCallback: navigateToProcessGroups, httpMethod: 'DELETE', }); @@ -90,4 +86,5 @@ export default function ProcessGroupEdit() { ); } + return null; } diff --git a/src/routes/ProcessGroupShow.tsx b/src/routes/ProcessGroupShow.tsx index 013017a..e0d2fea 100644 --- a/src/routes/ProcessGroupShow.tsx +++ b/src/routes/ProcessGroupShow.tsx @@ -2,11 +2,9 @@ import { useEffect, useState } from 'react'; import { Link, useSearchParams, useParams } from 'react-router-dom'; import { Button, Table, Stack } from 'react-bootstrap'; import ProcessBreadcrumb from '../components/ProcessBreadcrumb'; -import PaginationForTable, { - DEFAULT_PER_PAGE, - DEFAULT_PAGE, -} from '../components/PaginationForTable'; +import PaginationForTable from '../components/PaginationForTable'; import HttpService from '../services/HttpService'; +import { getPageInfoFromSearchParams } from '../helpers'; export default function ProcessGroupShow() { const params = useParams(); @@ -17,13 +15,7 @@ export default function ProcessGroupShow() { const [pagination, setPagination] = useState(null); useEffect(() => { - // @ts-expect-error TS(2345) FIXME: Argument of type 'string | 1' is not assignable to... Remove this comment to see the full error message - const page = parseInt(searchParams.get('page') || DEFAULT_PAGE, 10); - const perPage = parseInt( - // @ts-expect-error TS(2345) FIXME: Argument of type 'string | 50' is not assignable t... Remove this comment to see the full error message - searchParams.get('per_page') || DEFAULT_PER_PAGE, - 10 - ); + const { page, perPage } = getPageInfoFromSearchParams(searchParams); const setProcessModelFromResult = (result: any) => { setProcessModels(result.results); @@ -48,8 +40,9 @@ export default function ProcessGroupShow() { {(row as any).id} @@ -76,13 +69,7 @@ export default function ProcessGroupShow() { }; if (processGroup && pagination) { - const perPage = parseInt( - // @ts-expect-error TS(2345) FIXME: Argument of type 'string | 50' is not assignable t... Remove this comment to see the full error message - searchParams.get('per_page') || DEFAULT_PER_PAGE, - 10 - ); - // @ts-expect-error TS(2345) FIXME: Argument of type 'string | 1' is not assignable to... Remove this comment to see the full error message - const page = parseInt(searchParams.get('page') || DEFAULT_PAGE, 10); + const { page, perPage } = getPageInfoFromSearchParams(searchParams); return (
    @@ -107,7 +94,6 @@ export default function ProcessGroupShow() { page={page} perPage={perPage} pagination={pagination} - // @ts-expect-error TS(2322) FIXME: Type 'Element' is not assignable to type 'string'. tableToDisplay={buildTable()} path={`/admin/process-groups/${(processGroup as any).id}`} /> @@ -115,4 +101,5 @@ export default function ProcessGroupShow() {
    ); } + return null; } diff --git a/src/routes/ProcessGroups.tsx b/src/routes/ProcessGroups.tsx index 83f542c..b3c10bc 100644 --- a/src/routes/ProcessGroups.tsx +++ b/src/routes/ProcessGroups.tsx @@ -2,11 +2,9 @@ import { useEffect, useState } from 'react'; import { Link, useSearchParams } from 'react-router-dom'; import { Button, Table } from 'react-bootstrap'; import ProcessBreadcrumb from '../components/ProcessBreadcrumb'; -import PaginationForTable, { - DEFAULT_PER_PAGE, - DEFAULT_PAGE, -} from '../components/PaginationForTable'; +import PaginationForTable from '../components/PaginationForTable'; import HttpService from '../services/HttpService'; +import { getPageInfoFromSearchParams } from '../helpers'; // Example process group json // {'admin': False, 'display_name': 'Test Workflows', 'display_order': 0, 'id': 'test_process_group'} @@ -21,15 +19,7 @@ export default function ProcessGroups() { setProcessGroups(result.results); setPagination(result.pagination); }; - - const page = parseInt( - searchParams.get('page') || DEFAULT_PAGE.toString(), - 10 - ); - const perPage = parseInt( - searchParams.get('per_page') || DEFAULT_PER_PAGE.toString(), - 10 - ); + const { page, perPage } = getPageInfoFromSearchParams(searchParams); HttpService.makeCallToBackend({ path: `/process-groups?per_page=${perPage}&page=${page}`, successCallback: setProcessGroupsFromResult, @@ -63,30 +53,19 @@ export default function ProcessGroups() { }; const processGroupsDisplayArea = () => { - const perPage = parseInt( - searchParams.get('per_page') || DEFAULT_PER_PAGE.toString(), - 10 - ); - const page = parseInt( - searchParams.get('page') || DEFAULT_PAGE.toString(), - 10 - ); - let displayText = ''; + const { page, perPage } = getPageInfoFromSearchParams(searchParams); + let displayText = null; if (processGroups?.length > 0) { - // @ts-expect-error TS(2322) FIXME: Type 'Element' is not assignable to type 'string'. displayText = ( ); } else { - // @ts-expect-error TS(2322) FIXME: Type 'Element' is not assignable to type 'string'. displayText =

    No Groups To Display

    ; } return displayText; diff --git a/src/routes/ProcessInstanceList.tsx b/src/routes/ProcessInstanceList.tsx index aa64c73..76a89f7 100644 --- a/src/routes/ProcessInstanceList.tsx +++ b/src/routes/ProcessInstanceList.tsx @@ -14,12 +14,10 @@ import ProcessBreadcrumb from '../components/ProcessBreadcrumb'; import { convertDateToSeconds, convertSecondsToFormattedDate, + getPageInfoFromSearchParams, } from '../helpers'; -import PaginationForTable, { - DEFAULT_PER_PAGE, - DEFAULT_PAGE, -} from '../components/PaginationForTable'; +import PaginationForTable from '../components/PaginationForTable'; import 'react-datepicker/dist/react-datepicker.css'; import ErrorContext from '../contexts/ErrorContext'; @@ -59,15 +57,10 @@ export default function ProcessInstanceList() { setPagination(result.pagination); } function getProcessInstances() { - const page = searchParams.get('page') || DEFAULT_PAGE; - const perPage = parseInt( - // @ts-expect-error TS(2345) FIXME: Argument of type 'string | 50' is not assignable t... Remove this comment to see the full error message - searchParams.get('per_page') || DEFAULT_PER_PAGE, - 10 - ); + const { page, perPage } = getPageInfoFromSearchParams(searchParams); let queryParamString = `per_page=${perPage}&page=${page}`; - Object.keys(parametersToAlwaysFilterBy).forEach((paramName) => { + Object.keys(parametersToAlwaysFilterBy).forEach((paramName: string) => { // @ts-expect-error TS(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message const functionToCall = parametersToAlwaysFilterBy[paramName]; const searchParamValue = searchParams.get(paramName); @@ -81,8 +74,7 @@ export default function ProcessInstanceList() { queryParamString += `&process_status=${searchParams.get( 'process_status' )}`; - // @ts-expect-error TS(2345) FIXME: Argument of type 'string | null' is not assignable... Remove this comment to see the full error message - setProcessStatus(searchParams.get('process_status')); + setProcessStatus(searchParams.get('process_status') || ''); } HttpService.makeCallToBackend({ @@ -119,12 +111,7 @@ export default function ProcessInstanceList() { const handleFilter = (event: any) => { event.preventDefault(); - const page = searchParams.get('page') || DEFAULT_PAGE; - const perPage = parseInt( - // @ts-expect-error TS(2345) FIXME: Argument of type 'string | 50' is not assignable t... Remove this comment to see the full error message - searchParams.get('per_page') || DEFAULT_PER_PAGE, - 10 - ); + const { page, perPage } = getPageInfoFromSearchParams(searchParams); let queryParamString = `per_page=${perPage}&page=${page}`; if (isTrueComparison(startFrom, '>', startTill)) { @@ -312,20 +299,13 @@ export default function ProcessInstanceList() { }; if (pagination) { - const perPage = parseInt( - // @ts-expect-error TS(2345) FIXME: Argument of type 'string | 50' is not assignable t... Remove this comment to see the full error message - searchParams.get('per_page') || DEFAULT_PER_PAGE, - 10 - ); - // @ts-expect-error TS(2345) FIXME: Argument of type 'string | 1' is not assignable to... Remove this comment to see the full error message - const page = parseInt(searchParams.get('page') || DEFAULT_PAGE, 10); + const { page, perPage } = getPageInfoFromSearchParams(searchParams); return (

    Process Instances for {params.process_model_id}

    {filterOptions()} @@ -333,7 +313,6 @@ export default function ProcessInstanceList() { page={page} perPage={perPage} pagination={pagination} - // @ts-expect-error TS(2322) FIXME: Type 'Element' is not assignable to type 'string'. tableToDisplay={buildTable()} queryParamString={getSearchParamsAsQueryString()} path={`/admin/process-models/${params.process_group_id}/${params.process_model_id}/process-instances`} @@ -341,4 +320,6 @@ export default function ProcessInstanceList() {
    ); } + + return null; } diff --git a/src/routes/ProcessInstanceReportList.tsx b/src/routes/ProcessInstanceReportList.tsx index a4fd92b..2d12983 100644 --- a/src/routes/ProcessInstanceReportList.tsx +++ b/src/routes/ProcessInstanceReportList.tsx @@ -47,8 +47,7 @@ export default function ProcessInstanceReportList() {

    Reports for Process Model: {params.process_model_id}