Skip to content

Commit

Permalink
Adds section titles for Atoms and Selectors. Adds a title proper to t… (
Browse files Browse the repository at this point in the history
#1573)

Summary:
…he selector icon so that it gives a hint. Fixed getStyles to actually accumulate styles which fixes the jarring hover-over on node labels. Improved flow typing on getStyles.

Pull Request resolved: #1573

Reviewed By: drarmstr

Differential Revision: D33892487

Pulled By: butlersrepos

fbshipit-source-id: ac26db9f3d649e055b9c39e26f6c584fc88ae69b
  • Loading branch information
butlersrepos authored and facebook-github-bot committed Feb 1, 2022
1 parent 1dad138 commit bcb17c1
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import type {Node} from '../../../types/DevtoolsTypes';

const {getStyle} = require('../../../utils/getStyle');
const NodeName = require('./NodeName');
const NodeName = require('./NodeName').default;
const React = require('react');
const styles = {
label: {
Expand Down
15 changes: 10 additions & 5 deletions packages-ext/recoil-devtools/src/pages/Popup/Items/NodeName.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import type {Node} from '../../../types/DevtoolsTypes';

const React = require('react');
import React from 'react';

const styles = {
label: {
Expand All @@ -35,13 +35,18 @@ type KeyProps = {
node: ?Node,
};

function NodeName({name, node}: KeyProps): React$Element<'span'> {
export default function NodeName({
name,
node,
}: KeyProps): React$Element<'span'> {
return (
<span style={styles.label}>
{node?.type === 'selector' && <span style={styles.selector}>S</span>}
{node?.type === 'selector' && (
<span style={styles.selector} title="This is a Recoil selector">
S
</span>
)}
{name}
</span>
);
}

module.exports = NodeName;
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {TransactionType} from '../../types/DevtoolsTypes';
import type Connection from '../../utils/Connection';

const ConnectionContext = require('./ConnectionContext');
const NodeName = require('./Items/NodeName');
const NodeName = require('./Items/NodeName').default;
const React = require('react');
const {useCallback, useContext, useEffect, useRef} = require('react');

Expand Down
11 changes: 8 additions & 3 deletions packages-ext/recoil-devtools/src/pages/Popup/PopupSnapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const React = require('react');
const {useContext, useMemo} = require('react');

const styles = {
container: {
paddingLeft: 8,
},
item: {
marginBottom: 16,
},
Expand Down Expand Up @@ -56,9 +59,11 @@ function SnapshotRenderer(): React.Node {
});

return (
<div>
{atoms}
{selectors}
<div style={styles.container}>
<h2>Atoms</h2>
{atoms.length > 0 ? atoms : 'No atoms to show.'}
<h2>Selectors</h2>
{selectors.length > 0 ? selectors : 'No selectors to show.'}
</div>
);
}
Expand Down
20 changes: 15 additions & 5 deletions packages-ext/recoil-devtools/src/utils/getStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,24 @@
*/
'use strict';

type CssMap = {
[string]: string | number,
};

function getEntries<T>(obj: {[string]: T}): Array<[string, T]> {
const keys: string[] = Object.keys(obj);
return keys.map(key => [key, obj[key]]);
}

export const getStyle = (
source: {[key: string]: {[key: string]: string | number}},
entries: {[key: string]: boolean},
source: {[key: string]: CssMap},
entries: {[string]: boolean},
): {...} | {[string]: number | string} => {
return Object.entries(entries).reduce((acc, [key, value]) => {
const classNameMap = getEntries<boolean>(entries);
return classNameMap.reduce<CssMap>((acc, [key, val]) => {
let nextAcc = {...acc};
if (Boolean(value)) {
nextAcc = {...source[key]};
if (Boolean(val)) {
nextAcc = {...nextAcc, ...source[key]};
}

return nextAcc;
Expand Down

0 comments on commit bcb17c1

Please sign in to comment.