UID Refactor 1/n move to utils
Summary: Lets start adding some organisation to the folder structure Reviewed By: lblasa Differential Revision: D47547530 fbshipit-source-id: 30d20340ccc4b1c3ab4d4712c807831d74028322
This commit is contained in:
committed by
Facebook GitHub Bot
parent
4df0ad4d35
commit
2cc0ca0167
70
desktop/plugins/public/ui-debugger/utils/dataTransform.tsx
Normal file
70
desktop/plugins/public/ui-debugger/utils/dataTransform.tsx
Normal file
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {Inspectable, InspectableObject, Metadata, MetadataId} from '../types';
|
||||
|
||||
function transformAny(
|
||||
metadata: Map<MetadataId, Metadata>,
|
||||
inspectable: Inspectable,
|
||||
): any {
|
||||
switch (inspectable.type) {
|
||||
case 'boolean':
|
||||
case 'text':
|
||||
case 'number':
|
||||
case 'color':
|
||||
case 'size':
|
||||
case 'bounds':
|
||||
case 'coordinate':
|
||||
case 'coordinate3d':
|
||||
case 'enum':
|
||||
case 'space':
|
||||
return inspectable.value;
|
||||
case 'object':
|
||||
return transformObject(metadata, inspectable);
|
||||
default:
|
||||
return JSON.parse(JSON.stringify(inspectable));
|
||||
}
|
||||
}
|
||||
|
||||
function transformObject(
|
||||
metadata: Map<MetadataId, Metadata>,
|
||||
inspectableObject: InspectableObject,
|
||||
): any {
|
||||
const object: any = {};
|
||||
Object.keys(inspectableObject.fields).forEach((key, _index) => {
|
||||
const metadataId: number = Number(key);
|
||||
const meta = metadata.get(metadataId);
|
||||
if (!meta) {
|
||||
return;
|
||||
}
|
||||
|
||||
const inspectable = inspectableObject.fields[metadataId];
|
||||
object[meta.name] = transformAny(metadata, inspectable);
|
||||
});
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
export function transform(
|
||||
attributes: Record<MetadataId, Inspectable>,
|
||||
metadata: Map<MetadataId, Metadata>,
|
||||
): any {
|
||||
const object: any = {};
|
||||
Object.keys(attributes).forEach((key) => {
|
||||
const metadataId: number = Number(key);
|
||||
const meta = metadata.get(metadataId);
|
||||
if (!meta) {
|
||||
return;
|
||||
}
|
||||
|
||||
const inspectable = attributes[metadataId] as InspectableObject;
|
||||
object[meta.name] = transformObject(metadata, inspectable);
|
||||
});
|
||||
return object;
|
||||
}
|
||||
25
desktop/plugins/public/ui-debugger/utils/reactQuery.tsx
Normal file
25
desktop/plugins/public/ui-debugger/utils/reactQuery.tsx
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {QueryClient, setLogger} from 'react-query';
|
||||
|
||||
export const queryClient = new QueryClient({});
|
||||
|
||||
setLogger({
|
||||
log: (...args) => {
|
||||
console.log('[ui-debugger] ReactQuery ', ...args);
|
||||
},
|
||||
warn: (...args) => {
|
||||
console.warn('[ui-debugger] ReactQuery ', ...args);
|
||||
},
|
||||
error: (...args) => {
|
||||
//downgrade react query network errors to warning so they dont get sent to scribe
|
||||
console.warn('[ui-debugger] ReactQuery ', ...args);
|
||||
},
|
||||
});
|
||||
77
desktop/plugins/public/ui-debugger/utils/tracker.tsx
Normal file
77
desktop/plugins/public/ui-debugger/utils/tracker.tsx
Normal file
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {getFlipperLib} from 'flipper-plugin';
|
||||
import {SelectionSource} from '..';
|
||||
import {FrameworkEventType, Tag} from '../types';
|
||||
|
||||
const UI_DEBUGGER_IDENTIFIER = 'ui-debugger';
|
||||
|
||||
type NodeEventPayload = {
|
||||
name: string;
|
||||
tags: Tag[];
|
||||
source?: SelectionSource;
|
||||
};
|
||||
|
||||
type TrackerEvents = {
|
||||
'more-options-opened': {};
|
||||
'context-menu-opened': {};
|
||||
'play-pause-toggled': {
|
||||
paused: boolean;
|
||||
};
|
||||
'framework-event-monitored': {
|
||||
eventType: FrameworkEventType;
|
||||
monitored: boolean;
|
||||
};
|
||||
'search-term-updated': {
|
||||
searchTerm: string;
|
||||
};
|
||||
'node-selected': NodeEventPayload;
|
||||
'node-focused': NodeEventPayload;
|
||||
'context-menu-name-copied': {
|
||||
name: string;
|
||||
};
|
||||
'context-menu-copied': {
|
||||
name: string;
|
||||
key: string;
|
||||
value: string;
|
||||
};
|
||||
'big-grep-searched': {
|
||||
searchTerm: string;
|
||||
tags: Tag[];
|
||||
};
|
||||
'ide-opened': {
|
||||
ide: string;
|
||||
name: string;
|
||||
tags: Tag[];
|
||||
};
|
||||
};
|
||||
|
||||
export interface Tracker {
|
||||
track<Event extends keyof TrackerEvents>(
|
||||
event: Event,
|
||||
payload: TrackerEvents[Event],
|
||||
): void;
|
||||
}
|
||||
|
||||
class UIDebuggerTracker implements Tracker {
|
||||
track<Event extends keyof TrackerEvents>(
|
||||
event: Event,
|
||||
payload: TrackerEvents[Event],
|
||||
): void {
|
||||
getFlipperLib().logger.track(
|
||||
'usage',
|
||||
event,
|
||||
payload,
|
||||
UI_DEBUGGER_IDENTIFIER,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export const tracker: Tracker = new UIDebuggerTracker();
|
||||
Reference in New Issue
Block a user