Skip to content
Snippets Groups Projects
Unverified Commit 7ff46f6f authored by github-automation-metabase's avatar github-automation-metabase Committed by GitHub
Browse files

Remove unnecessary api call from create collection form (#46736) (#46755)

parent e05a1ea9
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,10 @@ import {
export const collectionApi = Api.injectEndpoints({
endpoints: builder => ({
/**
* @deprecated This endpoint is extremely slow on large instances, it should not be used
* you probably only need a few collections, just fetch those
*/
listCollections: builder.query<Collection[], ListCollectionsRequest>({
query: params => ({
method: "GET",
......
......@@ -22,7 +22,7 @@ import * as Errors from "metabase/lib/errors";
import type { Collection } from "metabase-types/api";
import type { State } from "metabase-types/store";
import FormAuthorityLevelFieldContainer from "../../containers/FormAuthorityLevelFieldContainer";
import { FormAuthorityLevelField } from "../../containers/FormAuthorityLevelFieldContainer";
const COLLECTION_SCHEMA = Yup.object({
name: Yup.string()
......@@ -111,7 +111,7 @@ function CreateCollectionForm({
validationSchema={COLLECTION_SCHEMA}
onSubmit={handleCreate}
>
{({ dirty, values }) => (
{({ dirty }) => (
<Form>
<FormInput
name="name"
......@@ -131,9 +131,7 @@ function CreateCollectionForm({
title={t`Collection it's saved in`}
filterPersonalCollections={filterPersonalCollections}
/>
<FormAuthorityLevelFieldContainer
collectionParentId={values.parent_id}
/>
<FormAuthorityLevelField />
<FormFooter>
<FormErrorMessage inline />
{!!onCancel && (
......
import { connect } from "react-redux";
import _ from "underscore";
import Collections from "metabase/entities/collections";
import { useSelector } from "metabase/lib/redux";
import { PLUGIN_COLLECTION_COMPONENTS } from "metabase/plugins";
import { getUserIsAdmin } from "metabase/selectors/user";
import type { Collection } from "metabase-types/api";
import type { State } from "metabase-types/store";
interface OwnProps {
collectionParentId: Collection["id"];
}
interface StateProps {
isAdmin: boolean;
}
type FormAuthorityLevelFieldContainerProps = OwnProps & StateProps;
function mapStateToProps(state: State): StateProps {
return {
isAdmin: getUserIsAdmin(state),
};
}
function FormAuthorityLevelFieldContainer({
isAdmin,
}: FormAuthorityLevelFieldContainerProps) {
export function FormAuthorityLevelField() {
const isAdmin = useSelector(getUserIsAdmin);
if (!isAdmin) {
return null;
}
......@@ -34,10 +14,3 @@ function FormAuthorityLevelFieldContainer({
<PLUGIN_COLLECTION_COMPONENTS.FormCollectionAuthorityLevelPicker name="authority_level" />
);
}
// eslint-disable-next-line import/no-default-export -- deprecated usage
export default _.compose(
// Ensures there's data for the `collectionsMap` prop
Collections.loadList({ loadingAndErrorWrapper: false }),
connect(mapStateToProps),
)(FormAuthorityLevelFieldContainer);
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