From 56cb7236cad6414513545fbff59dd101db1724d9 Mon Sep 17 00:00:00 2001 From: IRBorisov <8611739+IRBorisov@users.noreply.github.com> Date: Mon, 18 Mar 2024 16:21:39 +0300 Subject: [PATCH] Refactoring: improve id's and labels Do not use html labels without inputs --- .../src/components/ConstituentaPicker.tsx | 14 ++++- .../src/components/ConstituentaTooltip.tsx | 2 +- .../src/components/DataTable/DataTable.tsx | 21 ++++++- .../components/DataTable/PaginationTools.tsx | 10 +++- .../src/components/DataTable/TableBody.tsx | 4 +- .../src/components/RSInput/RSInput.tsx | 2 +- .../src/components/RefsInput/RefsInput.tsx | 2 +- .../frontend/src/components/ui/Checkbox.tsx | 6 +- .../src/components/ui/CheckboxTristate.tsx | 6 +- .../frontend/src/components/ui/FileInput.tsx | 5 +- .../frontend/src/components/ui/Label.tsx | 18 ++++-- .../src/components/ui/LabeledValue.tsx | 2 +- .../frontend/src/components/ui/SearchBar.tsx | 4 +- .../src/dialogs/DlgCloneLibraryItem.tsx | 17 +++++- .../DlgConstituentaTemplate/ArgumentsTab.tsx | 1 + .../ConstituentaTab.tsx | 6 ++ .../DlgConstituentaTemplate/TemplateTab.tsx | 5 +- .../frontend/src/dialogs/DlgCreateCst.tsx | 6 ++ .../frontend/src/dialogs/DlgCreateVersion.tsx | 2 + .../dialogs/DlgEditReference/EntityTab.tsx | 14 ++++- .../dialogs/DlgEditReference/SyntacticTab.tsx | 3 + .../DlgEditVersions/DlgEditVersions.tsx | 2 + .../frontend/src/dialogs/DlgRenameCst.tsx | 2 + .../frontend/src/models/miscellaneousAPI.ts | 59 +++++++++++-------- .../frontend/src/pages/CreateRSFormPage.tsx | 11 +++- .../src/pages/LibraryPage/LibraryPage.tsx | 16 +---- .../src/pages/LibraryPage/SearchPanel.tsx | 8 ++- .../src/pages/LibraryPage/ViewLibrary.tsx | 5 +- rsconcept/frontend/src/pages/LoginPage.tsx | 6 +- .../frontend/src/pages/PasswordChangePage.tsx | 6 +- .../EditorConstituenta/FormConstituenta.tsx | 5 ++ .../RSFormPage/EditorRSForm/FormRSForm.tsx | 5 ++ .../ViewConstituents/ConstituentsSearch.tsx | 8 ++- rsconcept/frontend/src/pages/RegisterPage.tsx | 10 +++- .../pages/UserProfilePage/EditorPassword.tsx | 9 ++- .../pages/UserProfilePage/EditorProfile.tsx | 12 +++- rsconcept/frontend/src/utils/constants.ts | 46 +++++++-------- 37 files changed, 250 insertions(+), 110 deletions(-) diff --git a/rsconcept/frontend/src/components/ConstituentaPicker.tsx b/rsconcept/frontend/src/components/ConstituentaPicker.tsx index 521fda43..72f8921c 100644 --- a/rsconcept/frontend/src/components/ConstituentaPicker.tsx +++ b/rsconcept/frontend/src/components/ConstituentaPicker.tsx @@ -13,6 +13,7 @@ import ConstituentaBadge from './ConstituentaBadge'; import FlexColumn from './ui/FlexColumn'; interface ConstituentaPickerProps { + id?: string; prefixID?: string; data?: IConstituenta[]; rows?: number; @@ -29,6 +30,7 @@ interface ConstituentaPickerProps { const columnHelper = createColumnHelper(); function ConstituentaPicker({ + id, data, value, initialFilter = '', @@ -85,13 +87,19 @@ function ConstituentaPicker({ ); return ( -
- setFilterText(newValue)} /> +
+ setFilterText(newValue)} + /> + event.stopPropagation()} /> ); diff --git a/rsconcept/frontend/src/components/DataTable/DataTable.tsx b/rsconcept/frontend/src/components/DataTable/DataTable.tsx index 0d3fd336..5bc0746d 100644 --- a/rsconcept/frontend/src/components/DataTable/DataTable.tsx +++ b/rsconcept/frontend/src/components/DataTable/DataTable.tsx @@ -14,7 +14,7 @@ import { useReactTable, type VisibilityState } from '@tanstack/react-table'; -import { useState } from 'react'; +import { useMemo, useState } from 'react'; import { CProps } from '../props'; import DefaultNoData from './DefaultNoData'; @@ -33,7 +33,9 @@ export interface IConditionalStyle { export interface DataTableProps extends CProps.Styling, Pick, 'data' | 'columns' | 'onRowSelectionChange' | 'onColumnVisibilityChange'> { + id?: string; dense?: boolean; + rows?: number; headPosition?: string; noHeader?: boolean; noFooter?: boolean; @@ -66,9 +68,11 @@ export interface DataTableProps * No sticky header if omitted */ function DataTable({ + id, style, className, dense, + rows, headPosition, conditionalRowStyles, noFooter, @@ -120,8 +124,20 @@ function DataTable({ const isEmpty = tableImpl.getRowModel().rows.length === 0; + // TODO: refactor formula for different font sizes and pagination tools + const fixedSize = useMemo(() => { + if (!rows) { + return undefined; + } + if (dense) { + return `calc(2px + (2px + 1.6875rem)*${rows} + ${noHeader ? '0px' : '(2px + 2.1875rem)'})`; + } else { + return `calc(2px + (2px + 2.1875rem)*${rows + (noHeader ? 0 : 1)})`; + } + }, [rows, dense, noHeader]); + return ( -
+
{!noHeader ? ( ({ {enablePagination && !isEmpty ? ( { + id?: string; table: Table; paginationOptions: number[]; onChangePaginationOption?: (newValue: number) => void; } -function PaginationTools({ table, paginationOptions, onChangePaginationOption }: PaginationToolsProps) { +function PaginationTools({ + id, + table, + paginationOptions, + onChangePaginationOption +}: PaginationToolsProps) { const handlePaginationOptionsChange = useCallback( (event: React.ChangeEvent) => { const perPage = Number(event.target.value); @@ -55,6 +61,7 @@ function PaginationTools({ table, paginationOptions, onChangePaginationOp ({ table, paginationOptions, onChangePaginationOp ) : null} {row.getVisibleCells().map((cell: Cell) => (
+ ( return (
-
- + {label ? {label} : null} ); } diff --git a/rsconcept/frontend/src/components/ui/FileInput.tsx b/rsconcept/frontend/src/components/ui/FileInput.tsx index e789d594..17b71ba1 100644 --- a/rsconcept/frontend/src/components/ui/FileInput.tsx +++ b/rsconcept/frontend/src/components/ui/FileInput.tsx @@ -15,7 +15,7 @@ interface FileInputProps extends Omit { onChange?: (event: React.ChangeEvent) => void; } -function FileInput({ label, acceptType, title, className, style, onChange, ...restProps }: FileInputProps) { +function FileInput({ id, label, acceptType, title, className, style, onChange, ...restProps }: FileInputProps) { const inputRef = useRef(null); const [fileName, setFileName] = useState(''); @@ -37,6 +37,7 @@ function FileInput({ label, acceptType, title, className, style, onChange, ...re return (
); } diff --git a/rsconcept/frontend/src/components/ui/Label.tsx b/rsconcept/frontend/src/components/ui/Label.tsx index f46e169e..6db68ddf 100644 --- a/rsconcept/frontend/src/components/ui/Label.tsx +++ b/rsconcept/frontend/src/components/ui/Label.tsx @@ -10,11 +10,19 @@ function Label({ text, className, ...restProps }: LabelProps) { if (!text) { return null; } - return ( - - ); + if (restProps.htmlFor) { + return ( + + ); + } else { + return ( + + {text} + + ); + } } export default Label; diff --git a/rsconcept/frontend/src/components/ui/LabeledValue.tsx b/rsconcept/frontend/src/components/ui/LabeledValue.tsx index d7821606..e0322fe6 100644 --- a/rsconcept/frontend/src/components/ui/LabeledValue.tsx +++ b/rsconcept/frontend/src/components/ui/LabeledValue.tsx @@ -8,7 +8,7 @@ interface LabeledValueProps { function LabeledValue({ id, label, text, title }: LabeledValueProps) { return (
- + {label} {text}
); diff --git a/rsconcept/frontend/src/components/ui/SearchBar.tsx b/rsconcept/frontend/src/components/ui/SearchBar.tsx index 1dfcc2b2..1decbc2a 100644 --- a/rsconcept/frontend/src/components/ui/SearchBar.tsx +++ b/rsconcept/frontend/src/components/ui/SearchBar.tsx @@ -6,17 +6,19 @@ import TextInput from './TextInput'; interface SearchBarProps extends CProps.Styling { value: string; + id?: string; onChange?: (newValue: string) => void; noBorder?: boolean; } -function SearchBar({ value, onChange, noBorder, ...restProps }: SearchBarProps) { +function SearchBar({ id, value, onChange, noBorder, ...restProps }: SearchBarProps) { return (
- setTitle(event.target.value)} /> setTitle(event.target.value)} + /> + setAlias(event.target.value)} /> -