Skip to content
Snippets Groups Projects
Unverified Commit 71395256 authored by Alexander Polyankin's avatar Alexander Polyankin Committed by GitHub
Browse files

Remove flow from entities (#19212)

parent 98dd210f
No related branches found
No related tags found
No related merge requests found
......@@ -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,
......
......@@ -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
......
......@@ -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);
......
......@@ -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`,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment