Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions api-editor/gui/src/common/util/stringOperations.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { truncate } from './stringOperations';

describe('truncate', () => {
test('should return strings with at most max length unchanged', () => {
expect(truncate('Lorem ipsum', 11)).toBe('Lorem ipsum');
});

test('should truncate strings longer than max length and append ...', () => {
expect(truncate('Lorem ipsum', 10)).toBe('Lorem ips\u2026');
});
});
3 changes: 3 additions & 0 deletions api-editor/gui/src/common/util/stringOperations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const truncate = function (text: string, maxLength: number): string {
return text.length > maxLength ? text.substring(0, maxLength - 1) + '\u2026' : text;
};
2 changes: 2 additions & 0 deletions api-editor/gui/src/features/annotations/AnnotationView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import {
showRenameAnnotationForm,
showTodoAnnotationForm,
} from '../ui/uiSlice';
import { truncate } from '../../common/util/stringOperations';

interface AnnotationViewProps {
target: string;
Expand Down Expand Up @@ -252,6 +253,7 @@ export const AnnotationView: React.FC<AnnotationViewProps> = function ({ target
{todoAnnotation && (
<AnnotationTag
type="todo"
name={truncate(todoAnnotation.newTodo, 50)}
annotation={todoAnnotation}
onEdit={() => dispatch(showTodoAnnotationForm(target))}
onDelete={() => dispatch(removeTodo(target))}
Expand Down