-
-
Notifications
You must be signed in to change notification settings - Fork 317
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
Codify lodash usage in eslint #1270
Merged
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
290d14c
Restrict lodash usage to whitelisted methods
Janpot 192be51
fewf
Janpot a1f4913
Merge branch 'master' into WIP-lodash-restriction
Janpot a3f4f5f
Merge branch 'master' into WIP-lodash-restriction
Janpot 7a451a9
Merge branch 'master' into WIP-lodash-restriction
Janpot 584837d
Restrict lodash
Janpot 3caff6d
Update immutability.ts
Janpot 49229a6
fix types
Janpot 4ce54b5
Merge branch 'master' into WIP-lodash-restriction
Janpot f442aa1
like zo
Janpot a0bdb99
Update .eslintrc.js
Janpot f169c98
remove filterKeys
Janpot 00b237e
Merge branch 'master' into WIP-lodash-restriction
Janpot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,8 @@ import { | |
JsExpressionAttrValue, | ||
} from '@mui/toolpad-core'; | ||
import { createProvidedContext, useAssertedContext } from '@mui/toolpad-utils/react'; | ||
import { filterKeys, mapProperties, mapValues } from '@mui/toolpad-utils/collections'; | ||
import { set as setObjectPath } from 'lodash-es'; | ||
import { QueryClient, QueryClientProvider, useMutation } from '@tanstack/react-query'; | ||
import { | ||
BrowserRouter, | ||
|
@@ -52,12 +54,10 @@ import { | |
NodeRuntimeWrapper, | ||
ResetNodeErrorsKeyProvider, | ||
} from '@mui/toolpad-core/runtime'; | ||
import * as _ from 'lodash-es'; | ||
import ErrorIcon from '@mui/icons-material/Error'; | ||
import { getBrowserRuntime } from '@mui/toolpad-core/jsBrowserRuntime'; | ||
import * as builtIns from '@mui/toolpad-components'; | ||
import { errorFrom } from '@mui/toolpad-utils/errors'; | ||
import { mapProperties, mapValues } from '@mui/toolpad-utils/collections'; | ||
import useBoolean from '@mui/toolpad-utils/hooks/useBoolean'; | ||
import usePageTitle from '@mui/toolpad-utils/hooks/usePageTitle'; | ||
import invariant from 'invariant'; | ||
|
@@ -134,10 +134,10 @@ const INITIAL_FETCH: UseFetch = { | |
rows: [], | ||
}; | ||
|
||
const USE_DATA_QUERY_CONFIG_KEYS: readonly (keyof UseDataQueryConfig)[] = [ | ||
const USE_DATA_QUERY_CONFIG_KEYS = new Set<string>([ | ||
'enabled', | ||
'refetchInterval', | ||
]; | ||
] satisfies (keyof UseDataQueryConfig)[]); | ||
|
||
function usePageNavigator(): NavigateToPage { | ||
const navigate = useNavigate(); | ||
|
@@ -354,7 +354,7 @@ function resolveBindables( | |
return { loading: true }; | ||
} | ||
|
||
_.set(result, `${resultKey}${path}`, resolvedBinding?.value); | ||
setObjectPath(result, `${resultKey}${path}`, resolvedBinding?.value); | ||
} | ||
|
||
return { value: result[resultKey] || {} }; | ||
|
@@ -562,7 +562,9 @@ function parseBindings( | |
}); | ||
} | ||
|
||
const configBindings = _.pick(elm.attributes, USE_DATA_QUERY_CONFIG_KEYS); | ||
const configBindings = filterKeys(elm.attributes, (key) => | ||
USE_DATA_QUERY_CONFIG_KEYS.has(key), | ||
); | ||
const nestedBindablePaths = flattenNestedBindables(configBindings); | ||
|
||
for (const [nestedPath, paramValue] of nestedBindablePaths) { | ||
|
@@ -1226,7 +1228,7 @@ function QueryNode({ page, node }: QueryNodeProps) { | |
Object.fromEntries(node.params ?? []), | ||
); | ||
|
||
const configBindings = _.pick(node.attributes, USE_DATA_QUERY_CONFIG_KEYS); | ||
const configBindings = filterKeys(node.attributes, (key) => USE_DATA_QUERY_CONFIG_KEYS.has(key)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could abstract this to our own There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing it altogether |
||
const options = resolveBindables(bindings, `${node.id}.config`, configBindings); | ||
|
||
const inputError = params.error || options.error; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,18 @@ | ||
import * as _ from 'lodash-es'; | ||
import postgres from './postgres/client'; | ||
import mysql from './mysql/client'; | ||
import rest from './rest/client'; | ||
import { ClientDataSource } from '../types'; | ||
import googleSheets from './googleSheets/client'; | ||
import local from './local/client'; | ||
import { PRODUCTION_DATASOURCES } from '../constants'; | ||
|
||
type ClientDataSources = { [key: string]: ClientDataSource<any, any> | undefined }; | ||
|
||
export const allClientDataSources: ClientDataSources = { | ||
const dataSources: ClientDataSources = { | ||
rest, | ||
postgres, | ||
googleSheets, | ||
mysql, | ||
local, | ||
}; | ||
|
||
const clientDataSources = _.pick(allClientDataSources, [...PRODUCTION_DATASOURCES]); | ||
|
||
export default clientDataSources; | ||
export default dataSources; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,18 @@ | ||
import * as _ from 'lodash-es'; | ||
import { ServerDataSource } from '../types'; | ||
import postgres from './postgres/server'; | ||
import mysql from './mysql/server'; | ||
import rest from './rest/server'; | ||
import googleSheets from './googleSheets/server'; | ||
import local from './local/server'; | ||
|
||
import { PRODUCTION_DATASOURCES } from '../constants'; | ||
|
||
type ServerDataSources = { [key: string]: ServerDataSource<any, any, any> | undefined }; | ||
|
||
const serverDataSources: ServerDataSources = _.pick( | ||
{ | ||
rest, | ||
postgres, | ||
googleSheets, | ||
mysql, | ||
local, | ||
}, | ||
[...PRODUCTION_DATASOURCES], | ||
); | ||
const dataSources: ServerDataSources = { | ||
rest, | ||
postgres, | ||
googleSheets, | ||
mysql, | ||
local, | ||
}; | ||
|
||
export default serverDataSources; | ||
export default dataSources; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 we plan to eventually completely get rid of
lodash
we could maybe create utility methods for these operations, which for now would still uselodash
but then we would know where to replace it.Just a possibility, maybe it helps to have the
lodash
imports less spread out.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.
To be honest, I'm not sure we should even have utility functions for this. ideally we improve the algorithm altogether to be not so lodashy.
setObjectPath
also makes us write type-unsafe code, I don't want to enable that sort of code in our codebaseThere 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.
Got it, yeah for this specific type of operation maybe just normal Javascript would be possible and be more type-safe.