Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/release/v3.10.2' into release/…
Browse files Browse the repository at this point in the history
…v3.10.3
  • Loading branch information
ChayanitBm committed Oct 18, 2024
2 parents 986d2ae + 337dba9 commit 570f517
Show file tree
Hide file tree
Showing 230 changed files with 6,172 additions and 1,043 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/check_do_not_merge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ on:

jobs:
ok-to-merge:
if: contains(github.event.pull_request.labels.*.name, 'DO NOT MERGE') == false
runs-on: ubuntu-latest
steps:
- name: This PR is labeled with do not merge
if: contains(github.event.pull_request.labels.*.name, 'DO NOT MERGE') == true
run: |
echo "This PR cannot be merged"
exit 1
- name: This PR is not labeled with do not merge
if: contains(github.event.pull_request.labels.*.name, 'DO NOT MERGE') == false
run: |
echo "This PR can be merged"
exit 0
74 changes: 73 additions & 1 deletion .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import path from 'path';
import { readdirSync } from 'fs';
import type { InlineConfig, Plugin } from 'vite';
import type { StorybookConfig } from '@storybook/react-vite';

const config: StorybookConfig = {
Expand All @@ -9,11 +12,80 @@ const config: StorybookConfig = {
'@storybook/addon-controls',
'@storybook/addon-viewport',
'@storybook/addon-toolbars',

'@storybook/addon-a11y',
],
framework: '@storybook/react-vite',
staticDirs: ['../static'],
viteFinal: async (config) => {
config.plugins?.push(
assetPlugin(config, {
markup: `[ICONS]`,
exclude: [/.*stories.*/],
assetDir: 'src/v4/icons',
storyFileName: 'icons.stories.tsx',
}),
);
return config;
},
};

export default config;

const assetPlugin: (
config: InlineConfig,
options: {
assetDir: string;
storyFileName: string;
exclude?: Array<RegExp>;
markup: string | RegExp;
},
) => Plugin = (config, { storyFileName, assetDir, exclude, markup }) => {
return {
enforce: 'pre',
name: 'vite-plugin-v4-icons',
transform(code, id) {
const rootDir = config.root!;

if (id.includes(storyFileName)) {
let icons = '',
imports = '';
readdirSync(path.join(rootDir, assetDir)).forEach((file) => {
if (file.match(/.*\.(tsx)/) && exclude?.every((ex) => !file.match(ex))) {
const fileName = file.replace(/.tsx/, '');
const source = {
relativePath: path.join(assetDir.replace(/.*src\//, ''), fileName),
path: path.join(rootDir, assetDir, file),
};

// eslint-disable-next-line @typescript-eslint/no-var-requires
const exportedAssets = require(source.path!);
const entries = Object.entries(exportedAssets);

entries.map(([key, _]) => {
const componentName = key === 'default' ? fileName : key;
imports +=
key == 'default'
? `import ${fileName} from "src/${source?.relativePath}";\n`
: `import {${key}} from "src/${source?.relativePath}";\n`;
icons += `
<button
key="${key}"
data-name="${componentName}"
>
<${componentName} width='25' height='25' />
<div>
<p>${componentName}</p>
<p>${source.relativePath.replace('/src', '')}</p>
</div>
</button>
`;
});
}
});

code = imports + code.replace(markup, icons);
}
return code;
},
};
};
2 changes: 1 addition & 1 deletion src/core/components/Modal/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { ReactNode } from 'react';
import styled, { css } from 'styled-components';
import { Close } from '~/icons';

export const CloseIcon = styled(Close).attrs<{ icon?: ReactNode }>({ width: 18, height: 18 })`
export const CloseIcon = styled(Close).attrs<{ icon?: ReactNode }>({ width: 20, height: 20 })`
padding: 0 6px;
cursor: pointer;
margin-left: auto;
Expand Down
34 changes: 32 additions & 2 deletions src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ import {
} from '@amityco/ts-sdk';
import isEmpty from 'lodash/isEmpty';

export type Mentioned = { userId: string; length: number; index: number; type: string };
export type Mentionees = Parameters<typeof CommentRepository.updateComment>[1]['mentionees'];
export type Mentioned = {
userId: string;
length: number;
index: number;
type: string;
displayName: string;
};
export type Mentionees = Amity.UserMention[];
export type Metadata = {
mentioned?: Mentioned[];
};
Expand Down Expand Up @@ -116,6 +122,7 @@ export function extractMetadata(
length: displayName.length - AT_SIGN_LENGTH,
type: 'user',
userId: id,
displayName,
})),
];

Expand Down Expand Up @@ -160,3 +167,26 @@ export function parseMentionsMarkup(
export function isNonNullable<TValue>(value: TValue | undefined | null): value is TValue {
return value != null;
}

export function reconstructMentions(
metadata?: Metadata,
mentionees?: Mentionees,
): { plainTextIndex: number; id: string; display: string }[] {
if (!metadata?.mentioned || mentionees?.length === 0) {
return [];
}

const userIds = mentionees?.find((mentionee) => mentionee.type === 'user')?.userIds || [];

return metadata?.mentioned?.map((mention, index) => {
const id = userIds[index];
const displayName = mention.displayName;
const display = '@' + (displayName ?? id);

return {
plainTextIndex: mention.index,
id,
display,
};
});
}
8 changes: 8 additions & 0 deletions src/social/components/CommunityForm/EditCommunityForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ const EditCommunityForm = ({
await onSubmit?.({ ...data, avatarFileId: data.avatarFileId || undefined });

notification.success({ content: <FormattedMessage id="community.updateSuccess" /> });
} catch (error) {
console.log('error', error);
if (error instanceof Error) {
if (error.message.indexOf(':') > -1) {
const [, errorMessage] = error.message.split(':');
notification.error({ content: errorMessage });
}
}
} finally {
setSubmitting(false);
}
Expand Down
1 change: 0 additions & 1 deletion src/social/components/SideSectionMyCommunity/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const SideSectionMyCommunity = ({ className, activeCommunity }: SideSectionMyCom
const open = () => setIsOpen(true);

const close = (communityId?: string) => {
console.log('communityId', communityId);
setIsOpen(false);
communityId && onCommunityCreated(communityId);
};
Expand Down
5 changes: 4 additions & 1 deletion src/social/components/UserHeader/UIUserHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import {
UserHeaderTitle,
} from './styles';
import { useCustomComponent } from '~/core/providers/CustomComponentsProvider';
import { BrandBadge } from '~/v4/social/internal-components/BrandBadge/BrandBadge';

interface UIUserHeaderProps {
userId?: string | null;
displayName?: string | null;
avatarFileUrl?: string | null;
children?: ReactNode;
isBanned?: boolean;
isBrand?: boolean;
onClick?: (userId: string) => void;
}

Expand All @@ -26,6 +28,7 @@ const UIUserHeader = ({
children,
onClick,
isBanned,
isBrand,
}: UIUserHeaderProps) => {
const onClickUser = () => userId && onClick?.(userId);
return (
Expand All @@ -36,7 +39,7 @@ const UIUserHeader = ({
onClick={onClickUser}
/>
<UserHeaderTitle title={userId || undefined} onClick={onClickUser}>
<div>{displayName}</div> {isBanned && <BanIcon />}
<div>{displayName}</div> {isBanned && <BanIcon />} {isBrand && <BrandBadge />}
</UserHeaderTitle>
{children && <UserHeaderSubtitle>{children}</UserHeaderSubtitle>}
</UserHeaderContainer>
Expand Down
1 change: 1 addition & 0 deletions src/social/components/UserHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const UserHeader = ({ userId, children, onClick, isBanned = false }: UserHeaderP
displayName={user?.displayName}
avatarFileUrl={avatarFileUrl}
isBanned={isBanned}
isBrand={user?.isBrand}
onClick={onClick}
>
{children}
Expand Down
1 change: 1 addition & 0 deletions src/social/components/UserHeader/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const UserHeaderTitle = styled.div`
display: flex;
min-width: 0;
align-items: center;
gap: 8px;
> div {
text-overflow: ellipsis;
Expand Down
7 changes: 3 additions & 4 deletions src/social/components/post/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@ import { PostEditorContainer, Footer, ContentContainer, PostButton } from './sty
import { usePostEditor } from './usePostEditor';

interface PostEditorProps {
postId?: string;
post: Amity.Post;
onSave: () => void;
className?: string;
placeholder?: string;
}

const PostEditor = ({
postId,
post,
placeholder = "What's going on...",
className,
onSave,
}: PostEditorProps) => {
const {
post,
markup,
onChange,
queryMentionees,
Expand All @@ -30,7 +29,7 @@ const PostEditor = ({
isEmpty,
handleSave,
} = usePostEditor({
postId,
post,
onSave,
});

Expand Down
6 changes: 3 additions & 3 deletions src/social/components/post/Editor/usePostEditor.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { PostRepository } from '@amityco/ts-sdk';
import { useMemo, useState } from 'react';
import { parseMentionsMarkup } from '~/helpers/utils';
import { parseMentionsMarkup, reconstructMentions } from '~/helpers/utils';
import usePost from '~/social/hooks/usePost';
import usePostByIds from '~/social/hooks/usePostByIds';
import useSocialMention from '~/social/hooks/useSocialMention';

export const usePostEditor = ({ postId, onSave }: { postId?: string; onSave: () => void }) => {
const post = usePost(postId);
export const usePostEditor = ({ post, onSave }: { post: Amity.Post; onSave: () => void }) => {
const initialChildrenPosts = usePostByIds(post?.children);
const { text, markup, mentions, mentionees, metadata, clearAll, onChange, queryMentionees } =
useSocialMention({
Expand All @@ -18,6 +17,7 @@ export const usePostEditor = ({ postId, onSave }: { postId?: string; onSave: ()
typeof post?.data === 'string' ? post?.data : (post?.data as Amity.ContentDataText)?.text,
post?.metadata,
),
remoteMentions: reconstructMentions(post?.metadata, post?.mentionees),
});

// List of the children posts removed - these will be deleted on save.
Expand Down
4 changes: 2 additions & 2 deletions src/social/components/post/Post/DefaultPostRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,13 @@ const DefaultPostRenderer = (props: DefaultPostRendererProps) => {
</ReviewButtonsContainer>
)}

{isEditing && (
{isEditing && post && (
<Modal
data-qa-anchor="post-editor-modal"
title={formatMessage({ id: 'post.editPost' })}
onCancel={closeEditingPostModal}
>
<PostEditor postId={post?.postId} onSave={closeEditingPostModal} />
<PostEditor post={post} onSave={closeEditingPostModal} />
</Modal>
)}
</>
Expand Down
7 changes: 4 additions & 3 deletions src/social/hooks/useSocialMention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface UseSocialMentionProps {
targetType?: 'user' | 'community' | string;
remoteText?: string;
remoteMarkup?: string;
remoteMentions?: { plainTextIndex: number; id: string; display: string }[];
}

export type QueryMentioneesFnType = (query?: string) => Promise<
Expand All @@ -24,15 +25,15 @@ const useSocialMention = ({
targetType,
remoteText,
remoteMarkup,
remoteMentions = [],
}: UseSocialMentionProps) => {
const isCommunityFeed = targetType === 'community';
const community = useCommunity(targetId);

const [text, setText] = useState(remoteText ?? '');
const [markup, setMarkup] = useState(remoteMarkup ?? remoteText);
const [mentions, setMentions] = useState<
{ plainTextIndex: number; id: string; display: string }[]
>([]);
const [mentions, setMentions] =
useState<{ plainTextIndex: number; id: string; display: string }[]>(remoteMentions);

useEffect(() => {
setText(remoteText || '');
Expand Down
4 changes: 2 additions & 2 deletions src/social/pages/CommunityEdit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ const CommunityEditPage = ({

useEffect(() => setActiveTab(tab), [tab]);

const { onClickCommunity } = useNavigation();
const { onBack } = useNavigation();
const community = useCommunity(communityId);
const avatarFileUrl = useImage({ fileId: community?.avatarFileId, imageSize: 'medium' });

const handleReturnToCommunity = () => communityId && onClickCommunity(communityId);
const handleReturnToCommunity = () => communityId && onBack();

const handleEditCommunity = async (
data: Parameters<typeof CommunityRepository.updateCommunity>[1],
Expand Down
4 changes: 2 additions & 2 deletions src/v4/chat/components/MessageComposer/MessageComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { MentionPlugin } from '~/v4/social/internal-components/Lexical/plugins/M

import { useMutation } from '@tanstack/react-query';
import {
editorStateToText,
editorToText,
getEditorConfig,
MentionData,
} from '~/v4/social/internal-components/Lexical/utils';
Expand Down Expand Up @@ -148,7 +148,7 @@ export const MessageComposer = ({
if (!channel) return;
if (!editorRef.current) return;

const { mentioned, mentionees, text } = editorStateToText(editorRef.current);
const { mentioned, mentionees, text } = editorToText(editorRef.current);

if (text?.trim().length === 0) return;

Expand Down
Loading

0 comments on commit 570f517

Please sign in to comment.