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

feat(diagnostics): auto select the first element in the client or plugin dropdowns when opening the diagnostics panel. #244

Merged
merged 3 commits into from
Oct 23, 2024
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
7 changes: 2 additions & 5 deletions webview-ui/src/diagnostics_panel/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ function constructSubscribedSignalFilter() {

function App() {
// State
const [selectedPlugin, setSelectedPlugin] = useState<string>('no_plugin_selected');
const [selectedClient, setSelectedClient] = useState<string>('no_client_selected');
const [selectedPlugin, setSelectedPlugin] = useState<string>('');
const [selectedClient, setSelectedClient] = useState<string>('');
const [currentTab, setCurrentTab] = useState<string>();

// Load initial state from vscode
Expand Down Expand Up @@ -117,7 +117,6 @@ function App() {
<VSCodePanelView id="view-4" style={{ flexDirection: 'column' }}>
<StatGroupSelectionBox
labelName="Client"
defaultDropdownId="no_client_selected"
statParentId="client_frame_timings"
onChange={handleClientSelection}
/>
Expand Down Expand Up @@ -185,7 +184,6 @@ function App() {
<VSCodePanelView id="view-7">
<StatGroupSelectionBox
labelName="Script Plugin"
defaultDropdownId="no_plugin_selected"
statParentId="handle_counts"
onChange={handlePluginSelection}
/>
Expand Down Expand Up @@ -223,7 +221,6 @@ function App() {
<VSCodePanelView id="view-8">
<StatGroupSelectionBox
labelName="Script Plugin"
defaultDropdownId="no_plugin_selected"
statParentId="fine_grained_subscribers"
onChange={handlePluginSelection}
/>
Expand Down
37 changes: 22 additions & 15 deletions webview-ui/src/diagnostics_panel/controls/StatGroupSelectionBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { VSCodeDropdown, VSCodeOption } from '@vscode/webview-ui-toolkit/react';

type SelectionBoxProps = {
labelName: string;
defaultDropdownId: string;
statParentId: string;
onChange: (selectedGroupId: string) => void;
};
Expand All @@ -15,9 +14,10 @@ interface StatGroupEntry {
name: string;
}

export function StatGroupSelectionBox({ labelName, defaultDropdownId, statParentId, onChange }: SelectionBoxProps) {
export function StatGroupSelectionBox({ labelName, statParentId, onChange }: SelectionBoxProps) {
// the groups directly under the 'statParentId'
const [groups, setGroup] = useState<StatGroupEntry[]>([{ id: defaultDropdownId, name: 'n/a' }]);
const [groups, setGroup] = useState<StatGroupEntry[]>([]);
const [selectedGroupId, setSelectedGroupId] = useState<string | undefined>(undefined);

const _onChange = useCallback(
(e: Event | React.FormEvent<HTMLElement>): void => {
Expand All @@ -27,6 +27,10 @@ export function StatGroupSelectionBox({ labelName, defaultDropdownId, statParent
[groups]
);

useEffect(() => {
onChange(selectedGroupId || "");
}, [selectedGroupId]);

//draws chart
useEffect(() => {
const eventHandler = (e: MessageEvent): void => {
Expand All @@ -40,14 +44,15 @@ export function StatGroupSelectionBox({ labelName, defaultDropdownId, statParent
}
// Add it to the list
setGroup(prevState => {
// See if the group is not in the list
if (
prevState === undefined ||
prevState?.findIndex(x => {
return x.id === msg.data.id;
}) === -1
) {
return [...(prevState ?? []), { id: msg.data.id, name: msg.data.name }];
const isNewGroup = !prevState || prevState.findIndex(x => x.id === msg.data.id) === -1;
if (isNewGroup) {
// auto select the first group we get if nothing selected
if (!selectedGroupId) {
setSelectedGroupId(msg.data.id);
}
// add new group to end of list
const newState = [...(prevState ?? []), { id: msg.data.id, name: msg.data.name }];
return newState;
}
return prevState;
});
Expand All @@ -66,10 +71,12 @@ export function StatGroupSelectionBox({ labelName, defaultDropdownId, statParent
return (
<div className="dropdown-container">
<label htmlFor="my-dropdown">{labelName}</label>
<VSCodeDropdown id="my-dropdown" onChange={_onChange}>
{(groups ?? []).map(option => {
return <VSCodeOption key={option.id}>{option.name}</VSCodeOption>;
})}
<VSCodeDropdown id="my-dropdown" onChange={_onChange} disabled={groups.length === 0}>
{(groups ?? []).map(option => (
<VSCodeOption key={option.id}>
{option.name}
</VSCodeOption>
))}
</VSCodeDropdown>
</div>
);
Expand Down
Loading