Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: picking settingsConfig from ApiEditorContext instead of props #37758

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/client/cypress/limited-tests.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# To run only limited tests - give the spec names in below format:
cypress/e2e/Regression/ClientSide/Templates/Fork_Template_spec.js
cypress/e2e/Regression/ClientSide/BugTests/AbortAction_Spec.ts
cypress/e2e/Regression/ServerSide/ApiTests/API_MultiPart_Spec.ts
# For running all specs - uncomment below:
#cypress/e2e/**/**/*

Expand Down
8 changes: 8 additions & 0 deletions app/client/src/pages/Editor/APIEditor/ApiEditorContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ export function ApiEditorContextProvider({
],
);

/* @ts-expect-error: Types are not available */
if (typeof window.Cypress?.log === "function") {
/* @ts-expect-error: Types are not available */
window.Cypress.log({
message: `ApiEditorContextProvider, ${JSON.stringify(settingsConfig || {})} ${JSON.stringify(value.settingsConfig || {})}`,
});
}

return (
<ApiEditorContext.Provider value={value}>
{children}
Expand Down
14 changes: 13 additions & 1 deletion app/client/src/pages/Editor/APIEditor/CommonEditorForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ function CommonEditorForm(props: CommonFormPropsWithExtraParams) {
moreActionsMenu,
notification,
saveActionName,
settingsConfig,
} = useContext(ApiEditorContext);

const {
Expand All @@ -194,9 +195,20 @@ function CommonEditorForm(props: CommonFormPropsWithExtraParams) {
isRunning,
onRunClick,
pluginId,
settingsConfig,
} = props;

/* @ts-expect-error: Types are not available */
if (typeof window.Cypress?.log === "function") {
/* @ts-expect-error: Types are not available */
window.Cypress.log({
message: `CommonEditorForm: context, ${JSON.stringify(settingsConfig || {})}`,
});
/* @ts-expect-error: Types are not available */
window.Cypress.log({
message: `CommonEditorForm: props, ${JSON.stringify(props.settingsConfig || {})}`,
});
}

const params = useParams<{ baseApiId?: string; baseQueryId?: string }>();

// passing lodash's equality function to ensure that this selector does not cause a rerender multiple times.
Expand Down
11 changes: 11 additions & 0 deletions app/client/src/pages/Editor/APIEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ function ApiEditorWrapper(props: ApiEditorWrapperProps) {
const settingsConfig = useSelector((state) =>
getPluginSettingConfigs(state, pluginId),
);
const settingsConfigAll = useSelector(
(state) => state.entities.plugins.settingConfigs,
);
const pagePermissions = useSelector(getPagePermissions);
const isFeatureEnabled = useFeatureFlag(FEATURE_FLAG.license_gac_enabled);
const isConverting = useSelector((state) =>
Expand Down Expand Up @@ -163,6 +166,14 @@ function ApiEditorWrapper(props: ApiEditorWrapperProps) {
return <ConvertEntityNotification icon={icon} name={action?.name || ""} />;
}, [action?.name, isConverting, icon]);

/* @ts-expect-error: Types are not available */
if (typeof window.Cypress?.log === "function") {
/* @ts-expect-error: Types are not available */
window.Cypress.log({
message: `ApiEditorWrapper, ${JSON.stringify(settingsConfigAll || {})} ${JSON.stringify(plugins)} ${pluginId}`,
});
}

return (
<ApiEditorContextProvider
actionRightPaneBackLink={actionRightPaneBackLink}
Expand Down
8 changes: 8 additions & 0 deletions app/client/src/pages/Editor/ActionSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ const ActionSettingsWrapper = styled.div`
`;

function ActionSettings(props: ActionSettingsProps): JSX.Element {
/* @ts-expect-error: Types are not available */
if (typeof window.Cypress?.log === "function") {
/* @ts-expect-error: Types are not available */
window.Cypress.log({
message: `props.actionSettingsConfig, ${JSON.stringify(props.actionSettingsConfig || {})}`,
});
}

return (
<ActionSettingsWrapper>
{!props.actionSettingsConfig ? (
Expand Down
21 changes: 21 additions & 0 deletions app/client/src/sagas/PluginSagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ function* fetchPluginFormConfigsSaga(action?: {
const graphqlPlugin = getGraphQLPlugin(plugins);
const appsmithAIPlugin = getAppsmithAIPlugin(plugins);

if (
/* @ts-expect-error: Types are not available */
typeof window.Cypress?.log === "function"
) {
/* @ts-expect-error: Types are not available */
window.Cypress.log({
message: `fetchPluginFormConfigsSaga, ${apiPlugin ? JSON.stringify(apiPlugin) : " No apiPlugin "} ${apiPlugin && defaultActionSettings[apiPlugin.type] ? JSON.stringify(defaultActionSettings[apiPlugin.type] || {}) : " No apiPlugin settings"}`,
});
}

if (apiPlugin) {
pluginIdFormsToFetch.add(apiPlugin.id);
}
Expand Down Expand Up @@ -183,6 +193,17 @@ function* fetchPluginFormConfigsSaga(action?: {
editorConfigs[pluginId] = pluginFormData[index].editor;
}

if (
/* @ts-expect-error: Types are not available */
typeof window.Cypress?.log === "function" &&
plugin?.type === PluginType.API
) {
/* @ts-expect-error: Types are not available */
window.Cypress.log({
message: `fetchPluginFormConfigsSaga, ${JSON.stringify(pluginFormData[index].setting || {})} ${JSON.stringify(defaultActionSettings[plugin.type] || {})}`,
});
}

Comment on lines +196 to +206
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider improving type safety and logging implementation.

The current implementation has several areas for improvement:

  1. Using @ts-expect-error is not ideal for handling Cypress types
  2. The logging implementation could be more structured

Consider these improvements:

+ // Add to a types file
+ interface CypressWindow extends Window {
+   Cypress?: {
+     log: (args: { message: string }) => void;
+   };
+ }

- /* @ts-expect-error: Types are not available */
- typeof window.Cypress?.log === "function"
+ typeof (window as CypressWindow).Cypress?.log === "function"

- /* @ts-expect-error: Types are not available */
- window.Cypress.log({
+ (window as CypressWindow).Cypress?.log({
-   message: `fetchPluginFormConfigsSaga, ${JSON.stringify(pluginFormData[index].setting || {})} ${JSON.stringify(defaultActionSettings[plugin.type] || {})}`,
+   message: `Plugin Settings:
+     Current: ${JSON.stringify(pluginFormData[index].setting || {})}
+     Default: ${JSON.stringify(defaultActionSettings[plugin.type] || {})}`
  });

Committable suggestion skipped: line range outside the PR's diff.

// Action settings form if not available use default
if (plugin && !pluginFormData[index].setting) {
settingConfigs[pluginId] = defaultActionSettings[plugin.type];
Expand Down
Loading