You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "eric-briscoe (via GitHub)" <gi...@apache.org> on 2023/02/03 00:03:09 UTC
[GitHub] [superset] eric-briscoe commented on a diff in pull request #22967: feat(ssh_tunnel): SSH Tunnel Switch extension
eric-briscoe commented on code in PR #22967:
URL: https://github.com/apache/superset/pull/22967#discussion_r1095201459
##########
superset-frontend/packages/superset-ui-core/src/ui-overrides/ExtensionsRegistry.ts:
##########
@@ -49,6 +49,15 @@ interface MenuObjectChildProps {
disable?: boolean;
}
+export interface SwitchProps {
+ isEditMode: boolean;
+ dbFetched: any;
+ disableSSHTunnelingForEngine?: boolean;
+ useSSHTunneling: boolean;
+ setUseSSHTunneling: React.Dispatch<React.SetStateAction<boolean>>;
+ setDB: React.Dispatch<any>;
Review Comment:
NOTE for other reviewers: @Antonio-RiveroMartnez and I discussed this and this any is a current necessity due to ExtensionsRegistry being in ui-core, and the DatabaseObject Type being in Superset-frontend/src and we do not want to duplicate Types, or create a circular dependency. Moving the DatabaseObject Type or resolving this by moving ExtensionRegistry to superset seemed out of scope for this PR but is being looked at in effort to improve the extensions capability.
##########
superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx:
##########
@@ -1346,14 +1357,33 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
payload: { login_method: method },
})
}
- removeSSHTunnelConfig={() =>
- setDB({
- type: ActionType.removeSSHTunnelConfig,
- })
- }
/>
);
+ const renderDefaultSSHTunnelSwitch = () => (
Review Comment:
@Antonio-RiveroMartnez one improvement we could consider is to converting renderDefaultSSHTunnelSwitch function into an actual component in separate file. Then import it at top of file. Also add a prop which is `isSSHTunneling` where the switch component just returns undefined so the show / hide logic is internal to the switch. Then we can collapse the conditional rendering blocks into a simple normal component block.
add the isSSHTunneling to interface:
````
export interface SwitchProps {
isEditMode: boolean;
isSSHTunneling: boolean;
dbFetched: any;
disableSSHTunnelingForEngine?: boolean;
useSSHTunneling: boolean;
setUseSSHTunneling: React.Dispatch<React.SetStateAction<boolean>>;
setDB: React.Dispatch<any>;
}
```
Then where we set the SSHTunnelSwitchExtension we could change to something like:
```
import SSHTunnelSwitch from './SSHTTunnelSwitch';
const SSHTunnelSwitchComponent= extensionsRegistry.get(
'ssh_tunnel.form.switch',
) ?? SSHTunnelSwitch;
```
this way lower in the code on lines 1591-1601 and 1877-1897
can look like:
```
<SSHTunnelSwitchComponent
isEditMode={isEditMode}
isSSHTunneling={isSSHTunneling}
dbFetched={dbFetched}
disableSSHTunnelingForEngine={disableSSHTunnelingForEngine}
useSSHTunneling={useSSHTunneling}
setUseSSHTunneling={setUseSSHTunneling}
setDB={setDB}
/>
```
and not need to do all the condition checks if using extension vs base component, etc. what do you think?
##########
superset-frontend/packages/superset-ui-core/src/ui-overrides/ExtensionsRegistry.ts:
##########
@@ -69,6 +78,7 @@ export type Extensions = Partial<{
'welcome.message': React.ComponentType;
'welcome.banner': React.ComponentType;
'welcome.main.replacement': React.ComponentType;
+ 'ssh_tunnel.form.switch': React.ComponentType<SwitchProps>;
Review Comment:
@Antonio-RiveroMartnez this is a great improvement to add props typing for extension points to create a protected contract, well done! I would like to make this a standard pattern to cover all the extension points in the future.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org