-
Notifications
You must be signed in to change notification settings - Fork 7
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
fix: add enhancements #17, #12 (custom settings) #24
Conversation
@@ -22,14 +22,17 @@ | |||
"not op_mini all" | |||
], | |||
"dependencies": { | |||
"@essex-js-toolkit/hooks": "workspace:packages/hooks", | |||
"@thematic/core": "^0.8.0", | |||
"@thematic/fluent": "^0.8.0", | |||
"@thematic/react": "^0.8.0", | |||
"@types/d3-array": "^2.2.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@types/<x>
dependencies should go into devDeps and peerDeps
packages/hierarchy-browser/src/hooks/useUpdatedCommunityProvider.ts
Outdated
Show resolved
Hide resolved
const isLoaded = hierachyDataProvider.updateNeighbors(neighbors) | ||
setIsNeighborsLoaded(isLoaded) // trigger neighbor refresh | ||
} | ||
}, [neighbors]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hierarchyDataProvider dep?
] { | ||
const [isNeighborsLoaded, setIsNeighborsLoaded] = useState<boolean>(false) | ||
useEffect(() => { | ||
hierachyDataProvider && hierachyDataProvider.updateCommunities(communities) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ?. operator can be used here instead of steeltoeing:
hierarchyDataProvider?.updateCommunities(...)
hierachyDataProvider && hierachyDataProvider.updateCommunities(communities) | ||
}, [communities]) | ||
useMemo(() => { | ||
hierachyDataProvider && hierachyDataProvider.updateEntities(entities) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here as well
@@ -98,15 +110,19 @@ export const CommunityCard: React.FC<ICommunityCardProps> = memo( | |||
filterProps={filterProps} | |||
getEntityCallback={loadMore} | |||
level={level} | |||
fontStyles={fontStyles} | |||
controls={controls} | |||
/> | |||
<Flex> | |||
<Content style={contentStyle}> | |||
{entities && entities.length > 0 ? ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
entities?.length
}: ICommunityCardProps) { | ||
const [dataProvider] = useState<CommunityDataProvider | undefined>( | ||
const [dataProvider] = useState<CommunityDataProvider>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useMemo<CommunityDataProvider>(() => new CommunityDataProvider(...), [/* no deps intentionally */])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so if you use no deps on a useMemo, it will only run once? What is the advantage of using useMemo over useState?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a readability thing. useState implies that you have something that's going to be mutated by your logic. Because there's no mutation involved a useMemo communicates your intent better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taking another pass at looking through the code
@@ -39,14 +37,19 @@ | |||
"@babel/plugin-transform-runtime": "^7.11.5", | |||
"@essex/scripts": "^11.0.1", | |||
"@fluentui/react": "^7.146.1", | |||
"@types/d3-array": "^2.2.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these @types/ libraries should be in peerDeps as well
? controls.showMembership | ||
: membership | ||
filterData = | ||
controls.showFilter !== undefined ? controls.showFilter : filterData |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The safest check here is x != null
, which accounts for both null and undefined
useLayoutEffect(() => { | ||
if (isOpen && !entitiesLoaded) { | ||
useEffect(() => { | ||
if (isOpen && !entitiesLoaded && size && size > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need the && size
check. Undefined and null both return false for > 0
settings && settings.isOpen !== undefined ? settings.isOpen : index === 0, | ||
[settings], | ||
) | ||
const visibleColumns = useMemo(() => settings && settings.visibleColumns, [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
settings?.visibleColumns
() => new HierarchyDataProvider(communities, entities, neighbors), | ||
[], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a comment inside the deps array that we're ignoring communities, entities and neighbors
intentionally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay do you want me to add a tslint ignore line as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it's popping a linter error, then yes. But even if not, I think a comment inside the dep array that it was left intentionally empty will help future readers understand the decision
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is only a warning in the linter so it doesn't effect the build but I can add it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The linter warnings are worth working through and resolving. Some of them may not be worth enabling by default. The issues it's reporting on about hooks dependencies are definitely worth taking a close look at
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just disabled the rule for the block of code here for both dataproviders. I think that there maybe other packages that have a similar issue for your awareness in case we decide to do clean up on those later linting errors later.
const nextNeghbors = this.loadNeighborsAsync(params) | ||
return nextNeghbors || [] | ||
} catch (err) { | ||
throw Error( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this swallows the source error, which may be useful for debugging - maybe we should log it out before throwing a new Error?
* fix: remove react peerDep and add enhancements * fix: yarn versions * fix: linting * fix: add react and fluent as peerdeps * fix: deps and typings * fix: remove conditionals for dataproviders * fix: clean up controls boolean hook * fix: yarn install * fix: update version * fix: add changes to types in hooks and peerDeps * fix: linting * chore: add comments and disable linting for no hook-deps on singletons * fix: add console log on error handling Co-authored-by: Amber Hoak <amhoak@microsoft.com>
Add settings property for allowing custom display of tables and complete following tickets: