Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dynamic name length #2607

Merged
merged 1 commit into from
Oct 31, 2023
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
3 changes: 3 additions & 0 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,7 @@ export const getAddOrRemoveRoleIds = (roles: any, payload: any) => {
// lg breakpoint is 1200px for MUI
export const isGreaterThanLgBreakpoint = () => window.innerWidth > 1200;

export const slicedString = (string: string, length: number) =>
string?.length > length ? `${string.slice(0, length)}...` : string;

export default getObject;
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { WhatsAppToJsx } from 'common/RichEditor';
import { MessageType } from '../MessageType/MessageType';
import styles from './ChatConversation.module.css';
import Track from 'services/TrackService';
import { slicedString } from 'common/utils';

export interface ChatConversationProps {
contactId: number;
Expand Down Expand Up @@ -152,7 +153,7 @@ const ChatConversation = ({
chatBubble = [styles.ChatBubble, styles.ChatBubbleUnread];
}

const name = contactName?.length > 20 ? `${contactName.slice(0, 20)}...` : contactName;
const name = slicedString(contactName, 20);

const { type, body } = lastMessage;
const isTextType = type === 'TEXT';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Dropdown } from 'components/UI/Form/Dropdown/Dropdown';
import { Input } from 'components/UI/Form/Input/Input';
import { MessageType } from 'containers/Chat/ChatConversations/MessageType/MessageType';
import { MEDIA_MESSAGE_TYPES } from 'common/constants';
import { validateMedia } from 'common/utils';
import { slicedString, validateMedia } from 'common/utils';
import setLogs from 'config/logs';
import { UPLOAD_MEDIA } from 'graphql/mutations/Chat';
import CrossIcon from 'assets/images/icons/Cross.svg?react';
Expand Down Expand Up @@ -167,7 +167,7 @@ export const AddAttachment = ({
if (media) {
const mediaName = media.name;
const extension = mediaName.slice((Math.max(0, mediaName.lastIndexOf('.')) || Infinity) + 1);
const shortenedName = mediaName.length > 15 ? `${mediaName.slice(0, 15)}...` : mediaName;
const shortenedName = slicedString(mediaName, 15);
setFileName(shortenedName);
setUploading(true);
uploadMedia({
Expand Down
3 changes: 2 additions & 1 deletion src/containers/Chat/ChatMessages/ContactBar/ContactBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { DialogBox } from '../../../../components/UI/DialogBox/DialogBox';
import { Tooltip } from '../../../../components/UI/Tooltip/Tooltip';
import { CLEAR_MESSAGES } from '../../../../graphql/mutations/Chat';
import { showChats } from '../../../../common/responsive';
import { slicedString } from 'common/utils';
import { CollectionInformation } from '../../../Collection/CollectionInformation/CollectionInformation';
import AddContactsToCollection from '../AddContactsToCollection/AddContactsToCollection';

Expand Down Expand Up @@ -617,7 +618,7 @@ export const ContactBar = ({
noWrap
data-testid="beneficiaryName"
>
{displayName}
{slicedString(displayName, 40)}
</Typography>
</div>
{contactCollections}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import { setNotification } from 'common/notification';
import { listIcon } from '../SuperAdminContactManagement/SuperAdminContactManagement';
import styles from './AdminContactManagement.module.css';
import { exportCsvFile } from 'common/utils';
import { exportCsvFile, slicedString } from 'common/utils';

export const AdminContactManagement = () => {
const [fileName, setFileName] = useState<string>('');
Expand Down Expand Up @@ -49,7 +49,7 @@
if (extension !== 'csv') {
setErrors([{ message: 'Please make sure the file format matches the sample' }]);
} else {
const shortenedName = mediaName.length > 10 ? `${mediaName.slice(0, 10)}...` : mediaName;
const shortenedName = slicedString(mediaName, 10);

Check warning on line 52 in src/containers/ContactManagement/AdminContactManagement/AdminContactManagement.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/ContactManagement/AdminContactManagement/AdminContactManagement.tsx#L52

Added line #L52 was not covered by tests
setFileName(shortenedName);
setCsvContent(reader.result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import CrossIcon from 'assets/images/icons/Cross.svg?react';
import { UPLOAD_CONTACTS_SAMPLE } from 'config';
import { IMPORT_CONTACTS } from 'graphql/mutations/Contact';
import { slicedString } from 'common/utils';
import { setNotification } from 'common/notification';
import styles from './UploadContactsDialog.module.css';

Expand Down Expand Up @@ -76,7 +77,7 @@
if (extension !== 'csv') {
setError(true);
} else {
const shortenedName = mediaName.length > 15 ? `${mediaName.slice(0, 15)}...` : mediaName;
const shortenedName = slicedString(mediaName, 15);

Check warning on line 80 in src/containers/ContactManagement/UploadContactsDialog/UploadContactsDialog.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/ContactManagement/UploadContactsDialog/UploadContactsDialog.tsx#L80

Added line #L80 was not covered by tests
setFileName(shortenedName);
setCsvContent(reader.result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { List } from 'containers/List/List';
import Menu from 'components/UI/Menu/Menu';
import { Button } from 'components/UI/Form/Button/Button';
import { FILTER_WEBHOOK_LOGS, GET_WEBHOOK_LOGS_COUNT } from 'graphql/queries/WebhookLogs';
import { copyToClipboard } from 'common/utils';
import { copyToClipboard, slicedString } from 'common/utils';
import { DATE_TIME_FORMAT } from 'common/constants';
import styles from './WebhookLogsList.module.css';

Expand Down Expand Up @@ -121,7 +121,7 @@ export const WebhookLogsList = () => {
onKeyDown={handleClick}
aria-hidden="true"
>
{newtext.length > 21 ? `${newtext.slice(0, 21)}...` : newtext}
{slicedString(newtext, 21)}
</div>
</Menu>
);
Expand Down
Loading