Skip to content

Commit

Permalink
Small fixes and import cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fgatti675 committed Feb 2, 2024
1 parent e569d32 commit 7c518ed
Show file tree
Hide file tree
Showing 51 changed files with 466 additions and 372 deletions.
7 changes: 3 additions & 4 deletions examples/example_pro/src/SampleApp/SampleApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import "@fontsource/roboto"
import { getAnalytics, logEvent } from "firebase/analytics";
import { User as FirebaseUser } from "firebase/auth";

import { CMSView, GitHubIcon, IconButton, Tooltip } from "@firecms/firebase_pro";
import { Authenticator, FireCMSProApp, FirestoreIndexesBuilder, } from "@firecms/firebase_pro";
import { CMSView, GitHubIcon, IconButton, Tooltip , Authenticator, FireCMSProApp, FirestoreIndexesBuilder } from "@firecms/firebase_pro";
import { useDataEnhancementPlugin } from "@firecms/data_enhancement";
import { useImportExportPlugin } from "@firecms/data_import_export";

Expand All @@ -22,7 +21,7 @@ import { localeCollectionGroup, productsCollection } from "./collections/product
import { blogCollection } from "./collections/blog_collection";
import { showcaseCollection } from "./collections/showcase_collection";

import { algoliaSearchControllerBuilder, pineconeSearchControllerBuilder } from "./text_search";
import { algoliaSearchControllerBuilder } from "./text_search";

import { CustomLoginView } from "./CustomLoginView";
import { cryptoCollection } from "./collections/crypto_collection";
Expand Down Expand Up @@ -162,7 +161,7 @@ function SampleApp() {
// 'microsoft.com',
// 'apple.com'
]}
textSearchControllerBuilder={pineconeSearchControllerBuilder}
textSearchControllerBuilder={algoliaSearchControllerBuilder}
firestoreIndexesBuilder={firestoreIndexesBuilder}
logo={logo}
collections={(params) => collections}
Expand Down
2 changes: 1 addition & 1 deletion examples/example_v3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"build": "vite build",
"preview": "vite preview",
"serve": "vite preview",
"deploy": "firecms deploy"
"deploy": "vite build && firecms deploy --project=firecms-demo-27150"
},
"dependencies": {
"firecms": "^3.0.0-beta.1",
Expand Down
1 change: 0 additions & 1 deletion examples/example_v3/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { SampleEntityView } from "./custom_entity_view/SampleEntityView";
import { colorPropertyConfig } from "./property_configs/color_property_config";
import { pricePropertyConfig } from "./property_configs/property_config_builder";
import { usersCollection } from "./collections/users_collection";
import { pagesCollection } from "./collections/pages";
import { ExampleCMSView } from "./views/ExampleCMSView";
import { SampleCustomEntityCollection } from "./views/SampleCustomEntityCollection";

Expand Down
1 change: 1 addition & 0 deletions examples/example_v3/src/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export const pineconeSearchControllerBuilder = buildPineconeSearchController({
throw new Error("Path not supported");
}
});

Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import React, { useEffect } from "react";

import { FastField, Formik, getIn, useFormikContext } from "formik";
import {
EnumValueConfig,
EnumValues,
FormikArrayContainer,
} from "@firecms/core";
import { EnumValueConfig, EnumValues, FormikArrayContainer, } from "@firecms/core";
import {
AutoAwesomeIcon,
Button,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
import {
EntityCollection,
useSnackbarController
} from "@firecms/core";
import {
Button,
ContentCopyIcon,
Dialog,
DialogActions,
DialogContent,
Typography,
} from "@firecms/ui";
import { EntityCollection, useSnackbarController } from "@firecms/core";
import { Button, ContentCopyIcon, Dialog, DialogActions, DialogContent, Typography, } from "@firecms/ui";
import React from "react";
import JSON5 from "json5";
import { Highlight, themes } from "prism-react-renderer"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,8 @@ import {
} from "@firecms/data_import_export";
import { getIn, useFormikContext } from "formik";

import {
FieldConfigBadge,
getFieldConfig,
getFieldId,
Properties,
Property,
PropertyConfig,
} from "@firecms/core";
import {
Container,
Select,
Tooltip,
Typography
} from "@firecms/ui";
import { FieldConfigBadge, getFieldConfig, getFieldId, Properties, Property, PropertyConfig, } from "@firecms/core";
import { Container, Select, Tooltip, Typography } from "@firecms/ui";
import React, { useState } from "react";
import { OnPropertyChangedParams, PropertyFormDialog, PropertyWithId } from "../PropertyEditView";
import { getFullId, idToPropertiesPath, namespaceToPropertiesOrderPath } from "../util";
Expand Down
10 changes: 8 additions & 2 deletions packages/firebase_firecms/src/hooks/useInitialiseFirebase.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useEffect, useState } from "react";

import { FirebaseApp, initializeApp } from "firebase/app";
import { deleteApp, FirebaseApp, getApps, initializeApp } from "firebase/app";

/**
* @group Firebase
Expand Down Expand Up @@ -56,7 +56,13 @@ export function useInitialiseFirebase({

const initFirebase = useCallback((config: Record<string, unknown>) => {
try {
const initialisedFirebaseApp = initializeApp(config, name ?? "[DEFAULT]");
const targetName = name ?? "[DEFAULT]";
const currentApps = getApps();
const existingApp = currentApps.find(app => app.name === targetName);
if (existingApp) {
deleteApp(existingApp);
}
const initialisedFirebaseApp = initializeApp(config, targetName);
setConfigError(undefined);
setFirebaseConfigLoading(false);
setFirebaseApp(initialisedFirebaseApp);
Expand Down
2 changes: 1 addition & 1 deletion packages/firebase_firecms/src/types/text_search.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { User as FirebaseUser } from "firebase/auth";
import { FirebaseApp } from "firebase/app";
import { EntityCollection, ResolvedEntityCollection } from "@firecms/core";
Expand Down Expand Up @@ -32,4 +31,5 @@ export type FirestoreTextSearchController = {
* @param props
*/
search: (props: { searchString: string, path: string, currentUser: FirebaseUser }) => (Promise<readonly string[]> | undefined),

};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
Entity,
FetchCollectionProps,
FetchEntityProps,
ResolvedProperty,
SaveEntityProps
} from "@firecms/core";

Expand Down
2 changes: 1 addition & 1 deletion packages/firebase_firecms_pro/src/FireCMSProAppProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
FirebaseSignInOption,
FirebaseSignInProvider,
FirestoreIndexesBuilder,
FirestoreTextSearchController, FirestoreTextSearchControllerBuilder
FirestoreTextSearchControllerBuilder
} from "@firecms/firebase";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import React, { ReactNode, useCallback, useEffect, useRef, useState } from "react";

import { FirebaseApp, FirebaseError } from "firebase/app";
import {
ErrorView,
FireCMSLogo,
useModeController,
} from "@firecms/core";
import { ErrorView, FireCMSLogo, useModeController, } from "@firecms/core";
import {
ArrowBackIcon,
Button,
Expand Down
3 changes: 2 additions & 1 deletion packages/firecms/src/FireCMSApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,8 @@ function FireCMSAppAuthenticated({
const saasPlugin = useSaasPlugin({
projectConfig,
firestoreDelegate,
collectionConfigController
collectionConfigController,
appConfig
});

const plugins: FireCMSPlugin<any, any, any>[] = [importExportPlugin, collectionEditorPlugin, dataEnhancementPlugin, saasPlugin];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ export function TextSearchInfoDialog({
closeDialog,
collection,
collectionConfigController,
parentCollectionIds
parentCollectionIds,
hasOwnTextSearchImplementation
}: {
open: boolean,
closeDialog: () => void,
path: string,
collection: EntityCollection,
collectionConfigController: CollectionsConfigController,
parentCollectionIds?: string[]
parentCollectionIds?: string[],
hasOwnTextSearchImplementation: boolean
}) {

const snackbarController = useSnackbarController();
Expand All @@ -54,40 +56,51 @@ export function TextSearchInfoDialog({

<Typography variant={"h5"} className={"flex flex-row gap-4 items-center"}>
<SearchIcon/>
Enable local text search
Enable text search
</Typography>

<SubscriptionPlanWidget
includeCTA={false}
showForPlans={["free"]}
message={<>Upgrade to PLUS to use local search</>}/>

<Typography>
Local text search is the simplest way to enable text search in your
collection. It loads all documents in the collection in the browser
and performs the search locally. This is the recommended option for
small collections.
</Typography>

<div className={"flex flex-col gap-2 my-2"}>
<Alert color={"warning"}>
Local text search is not recommended for large collections.
</Alert>

<Typography variant={"caption"}>
Note that enabling local text search will need to fetch all documents
from your collection and store them in the browser. This can be inefficient
for large collections. It can also incur in additional costs.
message={<>Upgrade to PLUS to use text search</>}/>

{!hasOwnTextSearchImplementation && <>

<div className={"flex flex-col gap-2 my-2"}>
<Alert color={"warning"}>
Local text search is not recommended for large collections.
</Alert>

<Typography variant={"caption"}>
Note that enabling local text search will need to fetch all documents
from your collection and store them in the browser. This can be inefficient
for large collections. It can also incur in additional costs.
</Typography>

<Typography variant={"caption"}>
If you are using a paid plan, you are encouraged to use an external
search engine such as Algolia or Elastic Search.
</Typography>
</div>

<Typography>
Local text search is the simplest way to enable text search in your
collection. It loads all documents in the collection in the browser
and performs the search locally. This is the recommended option for
small collections.
</Typography>

<Typography variant={"caption"}>
If you are using a paid plan, you are encouraged to use an external
search engine such as Algolia or Elastic Search.
</>}

{hasOwnTextSearchImplementation && <>
<Typography>
You have implemented your own text search controller. You enable text search
for your collection.
</Typography>
</div>
</>}

<div className={"flex items-end justify-end gap-4"}>
{projectConfig.localTextSearchEnabled && !collection.textSearchEnabled &&
{(hasOwnTextSearchImplementation || projectConfig.localTextSearchEnabled) && !collection.textSearchEnabled &&
<LoadingButton variant={"outlined"}
loading={enablingForCollection}
size={"large"}
Expand All @@ -107,7 +120,7 @@ export function TextSearchInfoDialog({
Enable for this collection
</LoadingButton>}

{!projectConfig.localTextSearchEnabled &&
{!hasOwnTextSearchImplementation && !projectConfig.localTextSearchEnabled &&
<LoadingButton variant={"outlined"}
loading={enablingLocalSearch}
size={"large"}
Expand Down
7 changes: 6 additions & 1 deletion packages/firecms/src/hooks/useSaasPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import { ProjectConfig } from "./useBuildProjectConfig";
import { TextSearchInfoDialog } from "../components/subscriptions/TextSearchInfoDialog";
import { FirestoreDelegate } from "@firecms/firebase";
import { CollectionsConfigController } from "@firecms/collection_editor";
import { FireCMSAppConfig } from "../types";

export function useSaasPlugin({ projectConfig, firestoreDelegate, collectionConfigController }: {
export function useSaasPlugin({ projectConfig, firestoreDelegate, collectionConfigController, appConfig }: {
projectConfig: ProjectConfig;
appConfig?: FireCMSAppConfig;
firestoreDelegate: FirestoreDelegate
collectionConfigController: CollectionsConfigController;
}): FireCMSPlugin {

const hasOwnTextSearchImplementation = Boolean(appConfig?.textSearchControllerBuilder);
return {
name: "Saas plugin",
collectionView: {
Expand All @@ -25,6 +29,7 @@ export function useSaasPlugin({ projectConfig, firestoreDelegate, collectionConf
context.dialogsController.open({
key: "text_search_info",
Component: (props) => <TextSearchInfoDialog {...props}
hasOwnTextSearchImplementation={hasOwnTextSearchImplementation}
collectionConfigController={collectionConfigController}
parentCollectionIds={parentCollectionIds}
path={path}
Expand Down
2 changes: 1 addition & 1 deletion packages/firecms/src/utils/admin_views.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React from "react";

import { CMSView } from "@firecms/core";
import { ProjectSettings } from "../components/settings/ProjectSettings";
Expand Down
2 changes: 1 addition & 1 deletion packages/firecms/test/mocks/useBuildMockProjectConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FireCMSUserProject, ProjectConfig, Role } from "../../src";
import { ProjectConfig } from "../../src";
import { MOCK_PROJECT_ID } from "./constants";

export function useBuildMockProjectConfig(): ProjectConfig {
Expand Down
4 changes: 1 addition & 3 deletions packages/firecms_cli/src/test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// import { cli } from "./cli";
// import { main } from "./commands/auth";
import { createFireCMSApp } from "./commands/init";
import { login, logout, parseJwt } from "./commands/auth";
import { entry } from "./cli";
import { login } from "./commands/auth";

async function main(){
// await logout("dev", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { useDataOrder } from "../../hooks/data/useDataOrder";
import {
Entity,
EntityCollection,
EntityTableController,
FilterValues,
FireCMSContext,
SelectedCellProps,
EntityTableController,
User
} from "../../types";
import { useDebouncedData } from "./useDebouncedData";
Expand Down
1 change: 0 additions & 1 deletion packages/firecms_core/src/components/EntityPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useMemo } from "react";
import { PropertyPreview } from "../preview";
import { Entity, EntityCollection, ResolvedEntityCollection, ResolvedProperties } from "../types";
import { resolveCollection } from "../util";
import { useFireCMSContext } from "../hooks";
import { cn, defaultBorderMixin, IconButton, OpenInNewIcon } from "@firecms/ui";
import { CustomizationController } from "../types/customization_controller";
import { useCustomizationController } from "../hooks/useCustomizationController";
Expand Down
2 changes: 1 addition & 1 deletion packages/firecms_core/src/core/Scaffold.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Link } from "react-router-dom";

import { Drawer as DefaultDrawer, DrawerProps } from "./Drawer";
import { useLargeLayout, useNavigationController } from "../hooks";
import { CircularProgressCenter, ErrorBoundary, FireCMSAppBar, FireCMSAppBarProps, FireCMSLogo } from "../components";
import { ErrorBoundary, FireCMSAppBar, FireCMSAppBarProps, FireCMSLogo } from "../components";
import { ChevronLeftIcon, cn, defaultBorderMixin, IconButton, MenuIcon, Sheet, Tooltip } from "@firecms/ui";

export const DRAWER_WIDTH = 280;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import React, { useCallback, useMemo } from "react";
import { Entity, EntityCollection, EntityReference, FieldProps, ResolvedProperty } from "../../types";
import { ReferencePreview } from "../../preview";
import { FieldHelperText, FormikArrayContainer } from "../components";
import { LabelWithIcon } from "../../components";
import { ErrorView, LabelWithIcon } from "../../components";
import { getIconForProperty, getReferenceFrom } from "../../util";

import { useClearRestoreValue, useNavigationController, useReferenceDialog } from "../../hooks";
import { Button, ExpandablePanel } from "@firecms/ui";
import { ErrorView } from "../../components";

type ArrayOfReferencesFieldProps = FieldProps<EntityReference[]>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import {
fieldBackgroundDisabledMixin,
fieldBackgroundHoverMixin,
fieldBackgroundMixin,
Typography
Typography,
useInjectStyles
} from "@firecms/ui";
import { useInjectStyles } from "@firecms/ui";

const mdParser = new MarkdownIt();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import { Entity, FieldProps } from "../../types";

import { PropertyPreview } from "../../preview";
import { FieldHelperText } from "../components";
import { LabelWithIcon } from "../../components";
import { ErrorBoundary, LabelWithIcon } from "../../components";
import { getIconForProperty } from "../../util";
import { cn, paperMixin } from "@firecms/ui";
import { ErrorBoundary } from "../../components";

/**
*
Expand Down
Loading

0 comments on commit 7c518ed

Please sign in to comment.