Activity as standard object (#6219)

In this PR I layout the first steps to migrate Activity to a traditional
Standard objects

Since this is a big transition, I'd rather split it into several
deployments / PRs

<img width="1512" alt="image"
src="https://github.com/user-attachments/assets/012e2bbf-9d1b-4723-aaf6-269ef588b050">

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
Co-authored-by: bosiraphael <71827178+bosiraphael@users.noreply.github.com>
Co-authored-by: Weiko <corentin@twenty.com>
Co-authored-by: Faisal-imtiyaz123 <142205282+Faisal-imtiyaz123@users.noreply.github.com>
Co-authored-by: Prateek Jain <prateekj1171998@gmail.com>
This commit is contained in:
Félix Malfait
2024-07-31 15:36:11 +02:00
committed by GitHub
parent defcee2a02
commit 80c0fc7ff1
239 changed files with 18418 additions and 8671 deletions

View File

@ -0,0 +1,77 @@
import { PartialBlock } from '@blocknote/core';
import { getFirstNonEmptyLineOfRichText } from '../getFirstNonEmptyLineOfRichText';
describe('getFirstNonEmptyLineOfRichText', () => {
it('should return an empty string if the input is null', () => {
const result = getFirstNonEmptyLineOfRichText(null);
expect(result).toBe('');
});
it('should return an empty string if the input is an empty array', () => {
const result = getFirstNonEmptyLineOfRichText([]);
expect(result).toBe('');
});
it('should return the first non-empty line of text', () => {
const input: PartialBlock[] = [
{ content: [{ text: '', type: 'text', styles: {} }] },
{ content: [{ text: ' ', type: 'text', styles: {} }] },
{ content: [{ text: 'First non-empty line', type: 'text', styles: {} }] },
{ content: [{ text: 'Second line', type: 'text', styles: {} }] },
];
const result = getFirstNonEmptyLineOfRichText(input);
expect(result).toBe('First non-empty line');
});
it('should return an empty string if all lines are empty', () => {
const input: PartialBlock[] = [
{ content: [{ text: '', type: 'text', styles: {} }] },
{ content: [{ text: ' ', type: 'text', styles: {} }] },
{ content: [{ text: '\n', type: 'text', styles: {} }] },
];
const result = getFirstNonEmptyLineOfRichText(input);
expect(result).toBe('');
});
it('should handle mixed content correctly', () => {
const input: PartialBlock[] = [
{ content: [{ text: '', type: 'text', styles: {} }] },
{ content: [{ text: ' ', type: 'text', styles: {} }] },
{ content: [{ text: 'First non-empty line', type: 'text', styles: {} }] },
{ content: [{ text: '', type: 'text', styles: {} }] },
{
content: [{ text: 'Second non-empty line', type: 'text', styles: {} }],
},
];
const result = getFirstNonEmptyLineOfRichText(input);
expect(result).toBe('First non-empty line');
});
it('should handle content with multiple text objects correctly', () => {
const input: PartialBlock[] = [
{
content: [
{ text: '', type: 'text', styles: {} },
{ text: ' ', type: 'text', styles: {} },
],
},
{
content: [
{ text: 'First non-empty line', type: 'text', styles: {} },
{ text: 'Second line', type: 'text', styles: {} },
],
},
];
const result = getFirstNonEmptyLineOfRichText(input);
expect(result).toBe('First non-empty line');
});
it('should handle content with undefined or null content', () => {
const input: PartialBlock[] = [
{ content: undefined },
{ content: [{ text: 'First non-empty line', type: 'text', styles: {} }] },
];
const result = getFirstNonEmptyLineOfRichText(input);
expect(result).toBe('First non-empty line');
});
});

View File

@ -0,0 +1,23 @@
import { PartialBlock } from '@blocknote/core';
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
export const getFirstNonEmptyLineOfRichText = (
fieldValue: PartialBlock[] | null,
): string => {
if (fieldValue === null) {
return '';
}
for (const node of fieldValue) {
if (!isUndefinedOrNull(node.content)) {
const contentArray = node.content as Array<{ text: string }>;
if (contentArray.length > 0) {
for (const content of contentArray) {
if (content.text.trim() !== '') {
return content.text;
}
}
}
}
}
return '';
};