Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Commit

Permalink
Add tracking for live editting
Browse files Browse the repository at this point in the history
Reviewed By: lblasa

Differential Revision: D51707053

fbshipit-source-id: 5946020546271319d679cf9ecce32981d61b2799
  • Loading branch information
Luke De Feo authored and facebook-github-bot committed Nov 30, 2023
1 parent 2d5ead4 commit b6c482f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions desktop/plugins/public/ui-debugger/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export function plugin(client: PluginClient<Events, Methods>) {
snapshot,
mutableLiveClientData,
client,
metadata,
);

const perfEvents = createDataSource<PerformanceStatsEvent, 'txId'>([], {
Expand Down
25 changes: 24 additions & 1 deletion desktop/plugins/public/ui-debugger/plugin/uiActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
*/

import {Atom, PluginClient} from 'flipper-plugin';
import {debounce} from 'lodash';
import {debounce, last} from 'lodash';
import {
ClientNode,
CompoundTypeHint,
Events,
FrameworkEventType,
Id,
Metadata,
MetadataId,
Methods,
SnapshotInfo,
Expand All @@ -37,6 +38,7 @@ export function uiActions(
snapshot: Atom<SnapshotInfo | null>,
liveClientData: LiveClientState,
client: PluginClient<Events, Methods>,
metadata: Atom<Map<MetadataId, Metadata>>,
): UIActions {
const onExpandNode = (node: Id) => {
uiState.expandedNodes.update((draft) => {
Expand Down Expand Up @@ -226,13 +228,34 @@ export function uiActions(
metadataIdPath,
compoundTypeHint,
});
trackLiveEditDebounced(nodeId, metadataIdPath, value);
return true;
} catch (error) {
console.warn('[ui-debugger] Failed to edit attribute', error);
return false;
}
};

const trackLiveEditDebounced = debounce(
(nodeId: Id, metadataIdPath: MetadataId[], value: any) => {
const node = nodes.get().get(nodeId);
const attributePath = metadataIdPath.map(
(id) => metadata.get().get(id)?.name ?? id.toString(),
);

tracker.track('attribute-editted', {
nodeId: nodeId,
nodeName: node?.name ?? 'Unknown',
attributeName: last(attributePath) ?? 'Unknown',
attributePath,
value: value,
attributeType: (typeof value).toString(),
tags: node?.tags ?? [],
});
},
100,
);

return {
onExpandNode,
onCollapseNode,
Expand Down
11 changes: 10 additions & 1 deletion desktop/plugins/public/ui-debugger/utils/tracker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import {getFlipperLib} from 'flipper-plugin';

import {FrameworkEventType, Tag} from '../ClientTypes';
import {FrameworkEventType, Id, Tag} from '../ClientTypes';
import {TraversalMode, SelectionSource} from '../DesktopTypes';

const UI_DEBUGGER_IDENTIFIER = 'ui-debugger';
Expand Down Expand Up @@ -55,6 +55,15 @@ type TrackerEvents = {
searchTerm: string;
tags: Tag[];
};
'attribute-editted': {
nodeId: Id;
attributeType: string;
nodeName: string;
attributeName: string;
attributePath: string[];
value: any;
tags: Tag[];
};
'ide-opened': {
ide: string;
name: string;
Expand Down

0 comments on commit b6c482f

Please sign in to comment.