-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): convert security groups views to React (#7676)
- Loading branch information
1 parent
b6aabe1
commit 2b6a941
Showing
20 changed files
with
466 additions
and
383 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
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
10 changes: 0 additions & 10 deletions
10
app/scripts/modules/core/src/managed/managedResourceStatusIndicator.component.ts
This file was deleted.
Oops, something went wrong.
127 changes: 0 additions & 127 deletions
127
app/scripts/modules/core/src/securityGroup/AllSecurityGroupsCtrl.js
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
app/scripts/modules/core/src/securityGroup/AllSecurityGroupsCtrl.spec.js
This file was deleted.
Oops, something went wrong.
81 changes: 81 additions & 0 deletions
81
app/scripts/modules/core/src/securityGroup/CreateSecurityGroupButton.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,81 @@ | ||
import * as React from 'react'; | ||
|
||
import { Application } from 'core/application'; | ||
import { CloudProviderRegistry, ICloudProviderConfig, ProviderSelectionService } from 'core/cloudProvider'; | ||
import { ModalInjector, ReactInjector } from 'core/reactShims'; | ||
import { Tooltip } from 'core/presentation'; | ||
import { IAccountDetails } from 'core/account'; | ||
import { SETTINGS } from 'core/config/settings'; | ||
|
||
import { FirewallLabels } from './label/FirewallLabels'; | ||
|
||
const providerFilterFn = (_application: Application, _account: IAccountDetails, provider: ICloudProviderConfig) => { | ||
const sgConfig = provider.securityGroup; | ||
return ( | ||
sgConfig && | ||
(sgConfig.CreateSecurityGroupModal || | ||
(sgConfig.createSecurityGroupTemplateUrl && sgConfig.createSecurityGroupController)) | ||
); | ||
}; | ||
|
||
const getDefaultCredentials = (app: Application, provider: string) => | ||
app.defaultCredentials[provider] || SETTINGS.providers[provider].defaults.account; | ||
const getDefaultRegion = (app: Application, provider: string) => | ||
app.defaultRegions[provider] || SETTINGS.providers[provider].defaults.region; | ||
|
||
const getAngularModalOptions = (provider: any, selectedProvider: string, app: Application) => ({ | ||
templateUrl: provider.createSecurityGroupTemplateUrl, | ||
controller: `${provider.createSecurityGroupController} as ctrl`, | ||
size: 'lg', | ||
resolve: { | ||
securityGroup: () => { | ||
return { | ||
credentials: getDefaultCredentials(app, selectedProvider), | ||
subnet: 'none', | ||
regions: [getDefaultRegion(app, selectedProvider)], | ||
}; | ||
}, | ||
application: () => { | ||
return app; | ||
}, | ||
}, | ||
}); | ||
|
||
const getReactModalOptions = (selectedProvider: string, app: Application) => ({ | ||
credentials: getDefaultCredentials(app, selectedProvider), | ||
application: app, | ||
isNew: true, | ||
}); | ||
|
||
export const CreateSecurityGroupButton = ({ app }: { app: Application }) => { | ||
const createSecurityGroup = (): void => { | ||
const { skinSelectionService } = ReactInjector; | ||
|
||
ProviderSelectionService.selectProvider(app, 'securityGroup', providerFilterFn).then(selectedProvider => { | ||
skinSelectionService.selectSkin(selectedProvider).then(selectedSkin => { | ||
const provider = CloudProviderRegistry.getValue(selectedProvider, 'securityGroup', selectedSkin); | ||
|
||
if (provider.CreateSecurityGroupModal) { | ||
provider.CreateSecurityGroupModal.show(getReactModalOptions(selectedProvider, app)); | ||
} else { | ||
// angular | ||
ModalInjector.modalService | ||
.open(getAngularModalOptions(provider, selectedProvider, app)) | ||
.result.catch(() => {}); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<button className="btn btn-sm btn-default" onClick={createSecurityGroup}> | ||
<span className="glyphicon glyphicon-plus-sign visible-lg-inline" /> | ||
<Tooltip value="Create Load Balancer"> | ||
<span className="glyphicon glyphicon-plus-sign visible-md-inline visible-sm-inline" /> | ||
</Tooltip> | ||
<span className="visible-lg-inline"> Create {FirewallLabels.get('Firewall')}</span> | ||
</button> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.