diff --git a/frontend/src/metabase/entities/collections.js b/frontend/src/metabase/entities/collections.js index 4b442bc066665c72454328c2c5017bca5f745298..e076573cddd7e0c7bfe4ecad6c64f50b5770e271 100644 --- a/frontend/src/metabase/entities/collections.js +++ b/frontend/src/metabase/entities/collections.js @@ -160,9 +160,7 @@ export function getCollectionIcon(collection, { tooltip = "default" } = {}) { // API requires items in "root" collection be persisted with a "null" collection ID // Also ensure it's parsed as a number -export const canonicalCollectionId = ( - collectionId: PseudoCollectionId, -): CollectionId | null => +export const canonicalCollectionId = collectionId => collectionId == null || collectionId === "root" ? null : parseInt(collectionId, 10); @@ -174,7 +172,7 @@ export function normalizedCollection(collection) { return collection; } -export const getCollectionType = (collectionId: string, state: {}) => +export const getCollectionType = (collectionId, state) => collectionId === null || collectionId === "root" ? "root" : collectionId === getUserPersonalCollectionId(state) @@ -183,36 +181,18 @@ export const getCollectionType = (collectionId: string, state: {}) => ? "other" : null; -type UserId = number; - // a "real" collection -type CollectionId = number; - -type Collection = { - id: CollectionId, - location?: string, - personal_owner_id?: UserId, -}; // includes "root" and "personal" pseudo collection IDs -type PseudoCollectionId = CollectionId | "root" | "personal"; - -type ExpandedCollection = { - id: PseudoCollectionId, - path: ?(string[]), - parent: ?ExpandedCollection, - children: ExpandedCollection[], - is_personal?: boolean, -}; // given list of collections with { id, name, location } returns a map of ids to // expanded collection objects like { id, name, location, path, children } // including a root collection export function getExpandedCollectionsById( - collections: Collection[], - userPersonalCollectionId: ?CollectionId, -): { [key: PseudoCollectionId]: ExpandedCollection } { - const collectionsById: { [key: PseudoCollectionId]: ExpandedCollection } = {}; + collections, + userPersonalCollectionId, +) { + const collectionsById = {}; for (const c of collections) { collectionsById[c.id] = { ...c, diff --git a/frontend/src/metabase/entities/containers/EntityObjectLoader.jsx b/frontend/src/metabase/entities/containers/EntityObjectLoader.jsx index 9ed7924743af6e22862a2380526790d5dd12694a..f9f47edb376080d6b941adcc12bbffaacbc6ed53 100644 --- a/frontend/src/metabase/entities/containers/EntityObjectLoader.jsx +++ b/frontend/src/metabase/entities/containers/EntityObjectLoader.jsx @@ -7,43 +7,8 @@ import _ from "underscore"; import entityType from "./EntityType"; import LoadingAndErrorWrapper from "metabase/components/LoadingAndErrorWrapper"; -export type Props = { - // Entity ID, such as a database ID - entityId: any, - // Entity type name (e.x. "databases", "questions", etc) - entityType: string, - // Reload the object when the component is mounted (or entityId changes) - reload?: boolean, - // Wrap the object in the a class that contains helper functions - wrapped?: boolean, - // List of required properties, if the object is loaded and they are all - // present don't bother loading as the object has been loaded by some other means - properties?: string[], - // Wrap the children in LoadingAndErrorWrapper to display loading and error states - // When true (default) the children render prop won't be called until loaded - loadingAndErrorWrapper: boolean, - // selectorName overrides the default getObject selector - selectorName?: string, - // Children render prop - children?: (props: RenderProps) => ?React.Element, -}; - -export type RenderProps = { - // the loaded objecvt itself - object: ?any, - // data was loaded at least once - fetched: boolean, - // data is loaded and no pending requests - loaded: boolean, - // request is pending - loading: boolean, - // error occured - error: ?any, - remove: () => Promise<void>, -}; - // props that shouldn't be passed to children in order to properly stack -const CONSUMED_PROPS: string[] = [ +const CONSUMED_PROPS = [ "entityType", "entityId", // "reload", // Masked by `reload` function. Should we rename that? @@ -70,7 +35,7 @@ const CONSUMED_PROPS: string[] = [ }, ) export default class EntityObjectLoader extends React.Component { - props: Props; + props; static defaultProps = { loadingAndErrorWrapper: true, @@ -78,9 +43,9 @@ export default class EntityObjectLoader extends React.Component { wrapped: false, }; - _getWrappedObject: ?(props: Props) => any; + _getWrappedObject; - constructor(props: Props) { + constructor(props) { super(props); this._getWrappedObject = createSelector( @@ -103,7 +68,7 @@ export default class EntityObjectLoader extends React.Component { ); } } - UNSAFE_componentWillReceiveProps(nextProps: Props) { + UNSAFE_componentWillReceiveProps(nextProps) { if ( nextProps.entityId !== this.props.entityId && nextProps.entityId != null @@ -157,11 +122,11 @@ export default class EntityObjectLoader extends React.Component { }; } -export const entityObjectLoader = (eolProps: Props) => +export const entityObjectLoader = eolProps => // eslint-disable-line react/display-name - (ComposedComponent: any) => + ComposedComponent => // eslint-disable-next-line react/display-name - (props: Props) => ( + props => ( <EntityObjectLoader {...props} {...eolProps}> {childProps => ( <ComposedComponent diff --git a/frontend/src/metabase/entities/containers/EntityType.jsx b/frontend/src/metabase/entities/containers/EntityType.jsx index 43b13a7cddfd34f4bbbb67f64d2d76e43de9a8d9..b226eacd3918fe641b036a6d047671989d4cbcc8 100644 --- a/frontend/src/metabase/entities/containers/EntityType.jsx +++ b/frontend/src/metabase/entities/containers/EntityType.jsx @@ -3,9 +3,7 @@ import React from "react"; import { connect } from "react-redux"; import { bindActionCreators } from "redux"; -export default (entityType?: string) => ( - ComposedComponent: React.ComponentClass, -) => { +export default entityType => ComposedComponent => { const mapStateToProps = (state, props) => ({ entityDef: // dynamic require due to dependency load order issues @@ -20,7 +18,7 @@ export default (entityType?: string) => ( class extends React.Component { static displayName = "EntityType"; - _boundActionCreators: { [key: string]: Function } = {}; + _boundActionCreators = {}; constructor(props) { super(props); diff --git a/frontend/src/metabase/entities/users/forms.js b/frontend/src/metabase/entities/users/forms.js index 3ef24865f980043232961e08945a8aaaa26e57ab..1283647246b40efcff107a63b28b7213430a91da 100644 --- a/frontend/src/metabase/entities/users/forms.js +++ b/frontend/src/metabase/entities/users/forms.js @@ -6,9 +6,7 @@ import { PLUGIN_ADMIN_USER_FORM_FIELDS } from "metabase/plugins"; import validate from "metabase/lib/validate"; import FormGroupsWidget from "metabase/components/form/widgets/FormGroupsWidget"; -import type { FormFieldDefinition } from "metabase/containers/Form"; - -const DETAILS_FORM_FIELDS: () => FormFieldDefinition[] = () => [ +const DETAILS_FORM_FIELDS = () => [ { name: "first_name", title: t`First name`, @@ -30,7 +28,7 @@ const DETAILS_FORM_FIELDS: () => FormFieldDefinition[] = () => [ }, ]; -const LOCALE_FIELD: FormFieldDefinition = { +const LOCALE_FIELD = { name: "locale", title: t`Language`, type: "select", @@ -43,7 +41,7 @@ const LOCALE_FIELD: FormFieldDefinition = { ].map(([code, name]) => ({ name, value: code })), }; -const PASSWORD_FORM_FIELDS: () => FormFieldDefinition[] = () => [ +const PASSWORD_FORM_FIELDS = () => [ { name: "password", title: t`Create a password`,