forked from appsmithorg/appsmith
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
…o fix/release-blocker-gsheet
- Loading branch information
Showing
12 changed files
with
222 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React, { | ||
type ReactNode, | ||
createContext, | ||
useContext, | ||
useMemo, | ||
} from "react"; | ||
import type { Action } from "entities/Action"; | ||
import type { Plugin } from "api/PluginApi"; | ||
import type { Datasource } from "entities/Datasource"; | ||
|
||
interface PluginActionContextType { | ||
action: Action; | ||
editorConfig: unknown[]; | ||
settingsConfig: unknown[]; | ||
plugin: Plugin; | ||
datasource?: Datasource; | ||
} | ||
|
||
// No need to export this context to use it. Use the hook defined below instead | ||
const PluginActionContext = createContext<PluginActionContextType | null>(null); | ||
|
||
interface ChildrenProps { | ||
children: ReactNode[]; | ||
} | ||
|
||
export const PluginActionContextProvider = ( | ||
props: ChildrenProps & PluginActionContextType, | ||
) => { | ||
const { action, children, datasource, editorConfig, plugin, settingsConfig } = | ||
props; | ||
|
||
// using useMemo to avoid unnecessary renders | ||
const contextValue = useMemo( | ||
() => ({ | ||
action, | ||
datasource, | ||
editorConfig, | ||
plugin, | ||
settingsConfig, | ||
}), | ||
[action, datasource, editorConfig, plugin, settingsConfig], | ||
); | ||
|
||
return ( | ||
<PluginActionContext.Provider value={contextValue}> | ||
{children} | ||
</PluginActionContext.Provider> | ||
); | ||
}; | ||
|
||
// By using this hook, you are guaranteed that the states are correctly | ||
// typed and set. | ||
// Without this, consumers of the context would need to keep doing a null check | ||
export const usePluginActionContext = () => { | ||
const context = useContext(PluginActionContext); | ||
if (!context) { | ||
throw new Error( | ||
"usePluginActionContext must be used within usePluginActionContextProvider", | ||
); | ||
} | ||
return context; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import React from "react"; | ||
import { useLocation } from "react-router"; | ||
import { identifyEntityFromPath } from "../navigation/FocusEntity"; | ||
import { useSelector } from "react-redux"; | ||
import { | ||
getActionByBaseId, | ||
getDatasource, | ||
getEditorConfig, | ||
getPlugin, | ||
getPluginSettingConfigs, | ||
} from "ee/selectors/entitiesSelector"; | ||
import { PluginActionContextProvider } from "./PluginActionContext"; | ||
import { get } from "lodash"; | ||
import EntityNotFoundPane from "pages/Editor/EntityNotFoundPane"; | ||
import { getIsEditorInitialized } from "selectors/editorSelectors"; | ||
import Spinner from "components/editorComponents/Spinner"; | ||
import CenteredWrapper from "components/designSystems/appsmith/CenteredWrapper"; | ||
import { Text } from "@appsmith/ads"; | ||
|
||
interface ChildrenProps { | ||
children: React.ReactNode[]; | ||
} | ||
|
||
const PluginActionEditor = (props: ChildrenProps) => { | ||
const { pathname } = useLocation(); | ||
|
||
const isEditorInitialized = useSelector(getIsEditorInitialized); | ||
|
||
const entity = identifyEntityFromPath(pathname); | ||
const action = useSelector((state) => getActionByBaseId(state, entity.id)); | ||
|
||
const pluginId = get(action, "pluginId", ""); | ||
const plugin = useSelector((state) => getPlugin(state, pluginId)); | ||
|
||
const datasourceId = get(action, "datasource.id", ""); | ||
const datasource = useSelector((state) => getDatasource(state, datasourceId)); | ||
|
||
const settingsConfig = useSelector((state) => | ||
getPluginSettingConfigs(state, pluginId), | ||
); | ||
|
||
const editorConfig = useSelector((state) => getEditorConfig(state, pluginId)); | ||
|
||
if (!isEditorInitialized) { | ||
return ( | ||
<CenteredWrapper> | ||
<Spinner size={30} /> | ||
</CenteredWrapper> | ||
); | ||
} | ||
|
||
if (!action) { | ||
return <EntityNotFoundPane />; | ||
} | ||
|
||
if (!plugin) { | ||
return ( | ||
<CenteredWrapper> | ||
<Text color="var(--ads-v2-color-fg-error)" kind="heading-m"> | ||
Plugin not installed! | ||
</Text> | ||
</CenteredWrapper> | ||
); | ||
} | ||
|
||
if (!settingsConfig || !editorConfig) { | ||
return ( | ||
<CenteredWrapper> | ||
<Text color="var(--ads-v2-color-fg-error)" kind="heading-m"> | ||
Editor config not found! | ||
</Text> | ||
</CenteredWrapper> | ||
); | ||
} | ||
|
||
return ( | ||
<PluginActionContextProvider | ||
action={action} | ||
datasource={datasource} | ||
editorConfig={editorConfig} | ||
plugin={plugin} | ||
settingsConfig={settingsConfig} | ||
> | ||
{props.children} | ||
</PluginActionContextProvider> | ||
); | ||
}; | ||
|
||
export default PluginActionEditor; |
7 changes: 7 additions & 0 deletions
7
app/client/src/PluginActionEditor/components/PluginActionForm/PluginActionForm.tsx
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from "react"; | ||
|
||
const PluginActionForm = () => { | ||
return <div />; | ||
}; | ||
|
||
export default PluginActionForm; |
1 change: 1 addition & 0 deletions
1
app/client/src/PluginActionEditor/components/PluginActionForm/index.ts
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "./PluginActionForm"; |
7 changes: 7 additions & 0 deletions
7
app/client/src/PluginActionEditor/components/PluginActionResponsePane.tsx
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from "react"; | ||
|
||
const PluginActionResponsePane = () => { | ||
return <div />; | ||
}; | ||
|
||
export default PluginActionResponsePane; |
7 changes: 7 additions & 0 deletions
7
app/client/src/PluginActionEditor/components/PluginActionToolbar.tsx
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from "react"; | ||
|
||
const PluginActionToolbar = () => { | ||
return <div />; | ||
}; | ||
|
||
export default PluginActionToolbar; |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export { default as PluginActionEditor } from "./PluginActionEditor"; | ||
export { | ||
PluginActionContextProvider, | ||
usePluginActionContext, | ||
} from "./PluginActionContext"; | ||
export { default as PluginActionToolbar } from "./components/PluginActionToolbar"; | ||
export { default as PluginActionForm } from "./components/PluginActionForm"; | ||
export { default as PluginActionResponsePane } from "./components/PluginActionResponsePane"; |
19 changes: 19 additions & 0 deletions
19
app/client/src/ce/pages/Editor/AppPluginActionEditor/AppPluginActionEditor.tsx
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from "react"; | ||
import { | ||
PluginActionEditor, | ||
PluginActionToolbar, | ||
PluginActionForm, | ||
PluginActionResponsePane, | ||
} from "PluginActionEditor"; | ||
|
||
const AppPluginActionEditor = () => { | ||
return ( | ||
<PluginActionEditor> | ||
<PluginActionToolbar /> | ||
<PluginActionForm /> | ||
<PluginActionResponsePane /> | ||
</PluginActionEditor> | ||
); | ||
}; | ||
|
||
export default AppPluginActionEditor; |
3 changes: 3 additions & 0 deletions
3
app/client/src/ee/pages/Editor/AppPluginActionEditor/AppPluginActionEditor.tsx
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { default as CE_AppPluginActionEditor } from "ce/pages/Editor/AppPluginActionEditor/AppPluginActionEditor"; | ||
|
||
export default CE_AppPluginActionEditor; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as AppPluginActionEditor } from "ee/pages/Editor/AppPluginActionEditor/AppPluginActionEditor"; |
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