Skip to content
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

Merged
merged 13 commits into from
Nov 30, 2020
Merged

Conversation

ahoak
Copy link
Contributor

@ahoak ahoak commented Nov 24, 2020

Add settings property for allowing custom display of tables and complete following tickets:

@@ -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",
Copy link
Member

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/package.json Show resolved Hide resolved
const isLoaded = hierachyDataProvider.updateNeighbors(neighbors)
setIsNeighborsLoaded(isLoaded) // trigger neighbor refresh
}
}, [neighbors])
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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 ? (
Copy link
Member

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>(
Copy link
Member

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 */])

Copy link
Contributor Author

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?

Copy link
Member

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.

@ahoak ahoak changed the title fix: remove react peerDep and add enhancements fix: add enhancements #17, #12 Nov 25, 2020
@ahoak ahoak changed the title fix: add enhancements #17, #12 fix: add enhancements #17, #12 (custom settings) Nov 25, 2020
Copy link
Member

@darthtrevino darthtrevino left a 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",
Copy link
Member

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
Copy link
Member

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) {
Copy link
Member

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, [
Copy link
Member

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),
[],
Copy link
Member

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?

Copy link
Contributor Author

@ahoak ahoak Nov 25, 2020

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?

Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

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(
Copy link
Member

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?

@ahoak ahoak merged commit 4aba0fd into main Nov 30, 2020
@ahoak ahoak deleted the fix/hierarchy_browser branch November 30, 2020 17:22
darthtrevino pushed a commit that referenced this pull request Feb 7, 2022
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants