Skip to content

Commit

Permalink
feat: remove some any and migrate some files to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelDemey committed Nov 8, 2024
1 parent b3d0fa7 commit e8c7c74
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 12 deletions.
13 changes: 11 additions & 2 deletions src/packages/components/datatable/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PropsWithChildren, useState } from 'react';
import { ComponentPropsWithoutRef, PropsWithChildren, useState } from 'react';
import { FilterMatchMode } from 'primereact/api';
import { DataTable as PrimeDataTable } from 'primereact/datatable';
import { IconField } from 'primereact/iconfield';
Expand All @@ -12,11 +12,20 @@ const { D } = createAllDictionary({
en: 'Search in the table...',
},
});

type DataTableTypes = {
withPagination?: boolean;
globalFilterFields?: boolean;
};
export const DataTable = ({
children,
withPagination = true,
...props
}: Readonly<PropsWithChildren<any>>) => {
}: Readonly<
PropsWithChildren<
DataTableTypes & ComponentPropsWithoutRef<typeof PrimeDataTable>
>
>) => {
const [globalFilterValue, setGlobalFilterValue] = useState('');
const [filters, setFilters] = useState({
global: { value: null, matchMode: FilterMatchMode.CONTAINS },
Expand Down
4 changes: 2 additions & 2 deletions src/packages/components/list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ type ListTypes<T> = {

export const List = <T extends object>({
items,
getContent = (value: any) => value.toString(),
getKey = (value: any) => value.toString(),
getContent = (value: T) => value.toString(),
getKey = (value: T) => value.toString(),
}: Readonly<ListTypes<T>>) => {
if (!items || items.length === 0) {
return null;
Expand Down
8 changes: 4 additions & 4 deletions src/packages/components/pagination/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ function checkInvalidPage(targetPage: number, listSize: number) {
}

const numberPerPageOptions = [
{ value: 10, label: 10 },
{ value: 25, label: 25 },
{ value: 100, label: 100 },
{ value: 10, label: '10' },
{ value: 25, label: '25' },
{ value: 100, label: '100' },
];
/**
* Component used to display a pagination block for a list.
* itemEls: The list of item we want to paginate
*/
export const Pagination = ({ itemEls }: { itemEls: any }) => {
export const Pagination = ({ itemEls }: { itemEls: JSX.Element[] }) => {
const navigate = useNavigate();
const { pathname, search } = useLocation();

Expand Down
1 change: 1 addition & 0 deletions src/packages/model/Dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type CatalogRecord = {
created: string;
updated: string;
contributor: string;
creator: string;
catalogRecord: CatalogRecord;
validationState: ValidationState;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import D, { D1, D2 } from '../../../deprecated-locales';
import { z } from 'zod';
import D, { D1, D2 } from '../../../deprecated-locales';
import { Dataset } from '../../../model/Dataset';
import { formatValidation } from '../../../utils/validation';

const Dataset = z.object({
const ZodDataset = z.object({
labelLg1: z
.string({ required_error: D.mandatoryProperty(D1.title) })
.trim()
Expand Down Expand Up @@ -34,8 +35,8 @@ const Dataset = z.object({
.nonempty({ message: D.mandatoryProperty(D1.generatedBy) }),
});

export const validate = ({ catalogRecord, ...otherFields }) =>
formatValidation(Dataset)({
export const validate = ({ catalogRecord, ...otherFields }: Dataset) =>
formatValidation(ZodDataset)({
creator: catalogRecord?.creator,
contributor: catalogRecord?.contributor,
...otherFields,
Expand Down

0 comments on commit e8c7c74

Please sign in to comment.