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

Thomas Brooks #2

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

d3vkit
Copy link

@d3vkit d3vkit commented Dec 7, 2021

No description provided.

Copy link
Author

@d3vkit d3vkit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments on the PR of areas I would change or that are problematic. This also does not have enough specs - I would normally write specs for every file, but only have specs for the search function.

Comment on lines +17 to +19
const formattedData = dataFormatter(props.data);
const filteredData = search(formattedData, props.searchTerm, props.onlyPublic);
const treeData = treeFormatter(filteredData, props.showIcons, props.withSystemName);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I were to redo this exercise, I think I would make a Formatter class which would take the data when initialized, and then have functions like "formatAsTree". Then this code would live together where it belongs.


import { Schema } from "./data";

export const dataFormatter = (data: Schema[]) : any[] => {
Copy link
Author

@d3vkit d3vkit Dec 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started out trying to write this with TS, but it became too complicated and eventually to move forward I just used any. I would not normally use any, because that defeats the purpose. I liked the small amount of type-checking I did have, so I left it instead of making it straight js.

Comment on lines +57 to +71
if (parentKey === 'schema') {
Icon = TableOutlined;
}

if (item.systemName === 'forms') {
Icon = FormOutlined;
}

if (item.systemName === 'views') {
Icon = FilterOutlined;
}

if (item.systemName === 'columns') {
Icon = NumberOutlined;
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better: Make this a switch
Best: Make an IconFactory

hasChildren = (currentNode.hasOwnProperty("children") && currentNode.children.length);

let matched = (
searchTerm === '' ||
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the things I wanted to try to do but ran out of time for was to pass filters down to the search. I would create filters that have a call function: SearchFilter, PublicFilter, something like that. I was hoping to do something like filters.forEach(filter => filter.call()) There is some connectedness to the searchTerm and onlyPublic so this may not have worked as I wanted. But I wanted to make it more extensible, so new filters could be added.

};

const search = (data, searchTerm = '', onlyPublic = false) => {
var cloned = JSON.parse(JSON.stringify(data));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid changing our data, clone it. I think if this is not JSON I would have to do something more involved.

let hasChildren;

currentNode.hasOwnProperty("children") && currentNode.children.forEach(child => {
let keepChild = filter(child, searchTerm, onlyPublic);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is doing depth-first search recursively; in a refactor I would change it to iterative to avoid stack overflow.

@d3vkit d3vkit marked this pull request as ready for review December 7, 2021 11:23
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.

1 participant