mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-26 13:00:39 +03:00
M: Improve cst table UI
This commit is contained in:
parent
5d6c911583
commit
53998cfa92
28
rsconcept/frontend/src/components/ui/TextContent.tsx
Normal file
28
rsconcept/frontend/src/components/ui/TextContent.tsx
Normal file
|
@ -0,0 +1,28 @@
|
|||
import clsx from 'clsx';
|
||||
|
||||
import { globals } from '@/utils/constants';
|
||||
import { truncateText } from '@/utils/utils';
|
||||
|
||||
import { CProps } from '../props';
|
||||
|
||||
export interface TextContentProps extends CProps.Styling {
|
||||
text: string;
|
||||
maxLength?: number;
|
||||
}
|
||||
|
||||
function TextContent({ className, text, maxLength, ...restProps }: TextContentProps) {
|
||||
const truncated = maxLength ? truncateText(text, maxLength) : text;
|
||||
const isTruncated = maxLength && text.length > maxLength;
|
||||
return (
|
||||
<div
|
||||
className={clsx('text-xs text-pretty', className)}
|
||||
data-tooltip-id={isTruncated ? globals.tooltip : undefined}
|
||||
data-tooltip-content={isTruncated ? text : undefined}
|
||||
{...restProps}
|
||||
>
|
||||
{truncated}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default TextContent;
|
|
@ -152,7 +152,7 @@ export const OptionsState = ({ children }: OptionsStateProps) => {
|
|||
id={`${globals.tooltip}`}
|
||||
layer='z-topmost'
|
||||
place='right-start'
|
||||
className={clsx('mt-3 translate-y-1/2', 'max-w-[20rem]')}
|
||||
className={clsx('mt-1 translate-y-1/2', 'max-w-[20rem]')}
|
||||
/>
|
||||
{children}
|
||||
</>
|
||||
|
|
|
@ -7,6 +7,7 @@ import BadgeConstituenta from '@/components/info/BadgeConstituenta';
|
|||
import { CProps } from '@/components/props';
|
||||
import DataTable, { createColumnHelper, RowSelectionState, VisibilityState } from '@/components/ui/DataTable';
|
||||
import NoData from '@/components/ui/NoData';
|
||||
import TextContent from '@/components/ui/TextContent';
|
||||
import TextURL from '@/components/ui/TextURL';
|
||||
import { useConceptOptions } from '@/context/ConceptOptionsContext';
|
||||
import useWindowSize from '@/hooks/useWindowSize';
|
||||
|
@ -30,6 +31,9 @@ const COLUMN_DEFINITION_HIDE_THRESHOLD = 1000;
|
|||
const COLUMN_TYPE_HIDE_THRESHOLD = 1200;
|
||||
const COLUMN_CONVENTION_HIDE_THRESHOLD = 1800;
|
||||
|
||||
const COMMENT_MAX_SYMBOLS = 100;
|
||||
const DEFINITION_MAX_SYMBOLS = 120;
|
||||
|
||||
const columnHelper = createColumnHelper<IConstituenta>();
|
||||
|
||||
function TableRSList({
|
||||
|
@ -111,7 +115,7 @@ function TableRSList({
|
|||
size: 1000,
|
||||
minSize: 200,
|
||||
maxSize: 1000,
|
||||
cell: props => <div className='text-xs text-pretty'>{props.getValue()}</div>
|
||||
cell: props => <TextContent text={props.getValue()} maxLength={DEFINITION_MAX_SYMBOLS} />
|
||||
}),
|
||||
columnHelper.accessor('convention', {
|
||||
id: 'convention',
|
||||
|
@ -120,7 +124,7 @@ function TableRSList({
|
|||
minSize: 100,
|
||||
maxSize: 500,
|
||||
enableHiding: true,
|
||||
cell: props => <div className='text-xs text-pretty'>{props.getValue()}</div>
|
||||
cell: props => <TextContent text={props.getValue()} maxLength={COMMENT_MAX_SYMBOLS} />
|
||||
})
|
||||
],
|
||||
[colors]
|
||||
|
|
|
@ -66,6 +66,21 @@ export function applyPattern(text: string, mapping: Record<string, string>, patt
|
|||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate text to max symbols. Add ellipsis if truncated.
|
||||
*/
|
||||
export function truncateText(text: string, maxSymbols: number): string {
|
||||
if (text.length <= maxSymbols) {
|
||||
return text;
|
||||
}
|
||||
const trimmedText = text.slice(0, maxSymbols);
|
||||
const lastSpaceIndex = trimmedText.lastIndexOf(' ');
|
||||
if (lastSpaceIndex === -1) {
|
||||
return trimmedText + '...';
|
||||
}
|
||||
return trimmedText.slice(0, lastSpaceIndex) + '...';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Axios response is html.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue
Block a user