Skip to content

Commit 3fdef0e

Browse files
authored
Devtools Fast follow group 1 (#23)
* Address memoization issue in ActivitiesGrid * socket client fix * Prettier --------- Co-authored-by: Corina Gum <>
1 parent 23985b5 commit 3fdef0e

File tree

4 files changed

+47
-29
lines changed

4 files changed

+47
-29
lines changed

packages/devtools/src/components/ActivitiesGrid/ActivitiesGrid.tsx

+20-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FC } from 'react';
1+
import { FC, useMemo } from 'react';
22
import {
33
Menu,
44
MenuButton,
@@ -71,6 +71,24 @@ const ActivitiesGrid: FC<ActivitiesGridProps> = ({
7171
}
7272
};
7373

74+
const memoizedRowsList = useMemo(
75+
() =>
76+
list
77+
.slice()
78+
.reverse()
79+
.filter((event) => filterActivities(event, params))
80+
.map((event, index) => (
81+
<ActivityRow
82+
key={event.id}
83+
event={event}
84+
index={index}
85+
isSelected={selected?.id === event.id}
86+
onSelect={handleRowSelect}
87+
/>
88+
)),
89+
[list, params, selected, handleRowSelect]
90+
);
91+
7492
const handleTypeFilter = (path: string) => {
7593
if (params.get('path') === path) {
7694
params.delete('path');
@@ -121,19 +139,7 @@ const ActivitiesGrid: FC<ActivitiesGridProps> = ({
121139
</thead>
122140
<tbody>
123141
{list.length ? (
124-
list
125-
.slice()
126-
.reverse()
127-
.filter((event) => filterActivities(event, params))
128-
.map((event, index) => (
129-
<ActivityRow
130-
key={event.id}
131-
event={event}
132-
index={index}
133-
isSelected={selected?.id === event.id}
134-
onSelect={handleRowSelect}
135-
/>
136-
))
142+
memoizedRowsList
137143
) : (
138144
<tr>
139145
<td colSpan={4} className={mergeClasses(classes.cell, classes.emptyTable)}>

packages/devtools/src/components/ComposeBox/ComposeBox.styles.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { makeStyles } from '@fluentui/react-components';
22

3-
export const useClasses = makeStyles({
3+
const useComposeBoxClasses = makeStyles({
44
composeBoxContainer: {
55
position: 'relative',
66
margin: '1rem 3.125rem',
@@ -19,3 +19,5 @@ export const useClasses = makeStyles({
1919
position: 'relative',
2020
},
2121
});
22+
23+
export default useComposeBoxClasses;

packages/devtools/src/components/ComposeBox/ComposeBox.tsx

+21-11
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
1-
import React, { useState, useRef, useEffect, useCallback } from 'react';
1+
import {
2+
FC,
3+
useState,
4+
ChangeEvent,
5+
KeyboardEvent,
6+
useRef,
7+
useEffect,
8+
useCallback,
9+
useMemo,
10+
} from 'react';
211
import { Textarea } from '@fluentui/react-components';
3-
import { useClasses } from './ComposeBox.styles';
4-
import NewMessageToolbar from './ComposeBoxToolbar/ComposeBoxToolbar';
5-
import { useCardStore } from '../../stores/CardStore';
6-
import AttachmentsContainer from '../AttachmentsContainer/AttachmentsContainer';
712
import { Attachment } from '@microsoft/spark.api';
13+
14+
import { useCardStore } from '../../stores/CardStore';
815
import { AttachmentType } from '../../types/Attachment';
16+
import AttachmentsContainer from '../AttachmentsContainer/AttachmentsContainer';
17+
import NewMessageToolbar from './ComposeBoxToolbar/ComposeBoxToolbar';
18+
import useComposeBoxClasses from './ComposeBox.styles';
919

1020
export interface ComposeBoxProps {
1121
onSend: (message: string, attachments?: Attachment[]) => void;
1222
messageHistory: string[];
1323
onMessageSent: (message: string) => void;
1424
}
1525

16-
const ComposeBox: React.FC<ComposeBoxProps> = ({ onSend, messageHistory, onMessageSent }) => {
17-
const classes = useClasses();
26+
const ComposeBox: FC<ComposeBoxProps> = ({ onSend, messageHistory, onMessageSent }) => {
27+
const classes = useComposeBoxClasses();
1828
const [message, setMessage] = useState('');
1929
const [attachments, setAttachments] = useState<Attachment[]>([]);
2030
const [uiAttachments, setUiAttachments] = useState<AttachmentType[]>([]);
@@ -31,7 +41,7 @@ const ComposeBox: React.FC<ComposeBoxProps> = ({ onSend, messageHistory, onMessa
3141

3242
// Convert API Attachment to UI AttachmentType
3343
const convertToAttachmentType = (attachment: Attachment): AttachmentType => {
34-
// Check if it's a card attachment
44+
// Check for card attachment
3545
if (attachment.contentType?.startsWith('application/vnd.microsoft.card.')) {
3646
return {
3747
type: 'card',
@@ -95,7 +105,7 @@ const ComposeBox: React.FC<ComposeBoxProps> = ({ onSend, messageHistory, onMessa
95105
}, [message, attachments, onSend, onMessageSent]);
96106

97107
const handleKeyDown = useCallback(
98-
(e: React.KeyboardEvent) => {
108+
(e: KeyboardEvent) => {
99109
if (e.key === 'Enter' && !e.shiftKey) {
100110
e.preventDefault();
101111
handleSendMessage();
@@ -166,14 +176,14 @@ const ComposeBox: React.FC<ComposeBoxProps> = ({ onSend, messageHistory, onMessa
166176
);
167177

168178
// Memoized message input handler to prevent re-renders
169-
const handleMessageChange = useCallback((e: React.ChangeEvent<HTMLTextAreaElement>) => {
179+
const handleMessageChange = useCallback((e: ChangeEvent<HTMLTextAreaElement>) => {
170180
setMessage(e.target.value);
171181
}, []);
172182

173183
// Check if there's content to send
174184
const hasContent = message.trim().length > 0 || attachments.length > 0;
175185

176-
const memoizedToolbar = React.useMemo(
186+
const memoizedToolbar = useMemo(
177187
() => <NewMessageToolbar onSend={handleToolbarAction} hasContent={hasContent} />,
178188
[handleToolbarAction, hasContent]
179189
);

packages/devtools/src/utils/dev.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ if (import.meta.env.DEV) {
3131
* Only works in development mode
3232
*/
3333
autoFillAndSendMessage = () => {
34-
// Get the dev message from environment variable or use a default
35-
const devMessage = import.meta.env.VITE_DEV_MESSAGE || 'This is a development test message';
34+
// Get the dev message from environment variable
35+
const devMessage = import.meta.env.VITE_DEV_MESSAGE || null;
3636

3737
// Wait for DOM to be fully loaded
3838
setTimeout(() => {
@@ -55,7 +55,7 @@ if (import.meta.env.DEV) {
5555
'value'
5656
)?.set;
5757

58-
if (nativeInputValueSetter) {
58+
if (nativeInputValueSetter && devMessage) {
5959
// Set the value directly using the native setter
6060
nativeInputValueSetter.call(composeTextarea, devMessage);
6161

0 commit comments

Comments
 (0)