Skip to content

Commit

Permalink
chore: update dev packages and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
plwai committed Feb 4, 2023
1 parent d43cb3d commit da61524
Show file tree
Hide file tree
Showing 3 changed files with 2,984 additions and 4,271 deletions.
56 changes: 37 additions & 19 deletions index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ type ActionState = {
};

type Events = { actionDispatched: ActionState; actionInit: ActionState };
type Methods = {
dispatchAction(params: { type: string; payload: any }): Promise<void>;
};

const columns = [
{
Expand Down Expand Up @@ -65,7 +68,7 @@ function createRows(actions: ActionState[]): Record<string, any>[] {
});
}

export function plugin(client: PluginClient<Events, {}>) {
export function plugin(client: PluginClient<Events, Methods>) {
const selectedID = createState<number | null>(null, { persist: "selection" });
const actions = createState<ActionState[]>([], { persist: "actions" });
const actionType = createState<string>();
Expand Down Expand Up @@ -105,11 +108,14 @@ export function plugin(client: PluginClient<Events, {}>) {
async function sendDispatchMessage() {
if (client.isConnected) {
try {
const payloadStringValue = actionPayloadString.get();
const actionTypeValue = actionType.get();
const payloadStringValue = actionPayloadString.get() ?? "";
const actionTypeValue = actionType.get() ?? "";
let actionPayload;
try {
actionPayload = payloadStringValue.trim() == "" ? [] : JSON.parse(payloadStringValue);
actionPayload =
payloadStringValue.trim() == ""
? []
: JSON.parse(payloadStringValue);
} catch (e) {
// can happen when we try to parse a string input
message.error("Invalid JSON format in the payload");
Expand Down Expand Up @@ -143,8 +149,8 @@ export function plugin(client: PluginClient<Events, {}>) {
const Container = styled.div({
// Styling DataInspector's 'added' objects
'& div[class*="-Added"]': {
backgroundColor: '#deffdd',
'@media (prefers-color-scheme: dark)': {
backgroundColor: "#deffdd",
"@media (prefers-color-scheme: dark)": {
backgroundColor: theme.semanticColors.diffAddedBackground,
},
},
Expand All @@ -163,8 +169,16 @@ export function Component() {
return (
<>
<Panel title="Dispatch Action to the app" gap pad>
<Input allowClear value={actionType} onChange={instance.setActionType} />
<TextArea rows={4} value={actionPayloadString} onChange={instance.setActionPayloadString} />
<Input
allowClear
value={actionType}
onChange={instance.setActionType}
/>
<TextArea
rows={4}
value={actionPayloadString}
onChange={instance.setActionPayloadString}
/>
<Button onClick={instance.sendDispatchMessage}>Dispatch Action</Button>
</Panel>
<DataTable<Record<string, any>>
Expand All @@ -184,9 +198,10 @@ export function Component() {
);
}

function renderSidebar(selectedData: ActionState) {
const [keyFilter, setKeyFilter] = useState('');
const [filteredSelectedData, setFilteredSelectedData] = useState<typeof selectedData>(selectedData);
function renderSidebar(selectedData?: ActionState) {
const [keyFilter, setKeyFilter] = useState("");
const [filteredSelectedData, setFilteredSelectedData] =
useState<typeof selectedData>(selectedData);

useEffect(() => {
if (!keyFilter || !selectedData) {
Expand All @@ -199,14 +214,14 @@ function renderSidebar(selectedData: ActionState) {
after: {},
};

Object.keys(selectedData.after).forEach(key => {
Object.keys(selectedData.after).forEach((key) => {
if (key.toLowerCase().includes(keyFilter.toLowerCase())) {
const typedKey = key as keyof typeof selectedData.after;
filteredData.after[typedKey] = selectedData.after[typedKey] || {};
}
});

Object.keys(selectedData.before).forEach(key => {
Object.keys(selectedData.before).forEach((key) => {
if (key.toLowerCase().includes(keyFilter.toLowerCase())) {
const typedKey = key as keyof typeof selectedData.before;
filteredData.before[typedKey] = selectedData.before[typedKey];
Expand All @@ -230,15 +245,15 @@ function renderSidebar(selectedData: ActionState) {
<Container>
<Layout.Container gap pad>
<Panel title="Action" gap pad>
<DataInspector data={actionData} collapsed={true} expandRoot={true}></DataInspector>
<DataInspector data={actionData} collapsed={true} expandRoot={true} />
</Panel>
<Panel title="State" gap pad>
<Input
allowClear
value={keyFilter}
placeholder="Filter state keys..."
style={{marginTop: 8}}
onChange={e => setKeyFilter(e.target.value)}
style={{ marginTop: 8 }}
onChange={(e) => setKeyFilter(e.target.value)}
/>
<Tabs defaultActiveKey="Diff" centered={true}>
<Tab tab="Diff" tabKey="Diff">
Expand All @@ -249,11 +264,14 @@ function renderSidebar(selectedData: ActionState) {
filter={keyFilter}
highlightColor={theme.searchHighlightBackground.green}
expandRoot={!!keyFilter}
>
</DataInspector>
/>
</Tab>
<Tab tab="State Tree" tabKey="StateTree">
<DataInspector data={selectedData.after} collapsed={true} expandRoot={false}></DataInspector>
<DataInspector
data={selectedData.after}
collapsed={true}
expandRoot={false}
/>
</Tab>
</Tabs>
</Panel>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://fbflipper.com/schemas/plugin-package/v2.json",
"name": "flipper-plugin-redux-debugger",
"id": "flipper-plugin-redux-debugger",
"version": "2.0.1",
"version": "2.0.2",
"description": "Redux Debugger for Flipper",
"main": "dist/bundle.js",
"flipperBundlerEntry": "index.tsx",
Expand Down
Loading

0 comments on commit da61524

Please sign in to comment.