Skip to content

Commit 7fdc92f

Browse files
authored
Merge pull request #340 from smiclea/CORWEB-189
Move UI configuration file to server side
2 parents da25c8a + 89fcdad commit 7fdc92f

57 files changed

Lines changed: 341 additions & 271 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

config.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// @flow
2+
3+
import type { Config } from './src/types/Config'
4+
5+
const conf: Config = {
6+
7+
// The list of pages which will not appear in the navigation menu
8+
// Remove or comment to enable them
9+
disabledPages: [
10+
'planning',
11+
'users',
12+
'projects',
13+
],
14+
15+
// Whether to show the user domain name input when logging in
16+
showUserDomainInput: false,
17+
18+
// The default user domain name used for logging in
19+
defaultUserDomain: 'default',
20+
21+
// Shows the 'Use Current User/Project/Domain for Authentification' switch
22+
// when creating a new openstack endpoint
23+
showOpenstackCurrentUserSwitch: false,
24+
25+
// Whether to use Barbican secrets when creating a new endpoint
26+
useBarbicanSecrets: true,
27+
28+
// The timeout between polling requests
29+
requestPollTimeout: 5000,
30+
31+
// The list of providers which offer storage listing
32+
storageProviders: ['openstack', 'azure'],
33+
34+
// The list of providers which offer source options
35+
sourceOptionsProviders: ['aws'],
36+
37+
// - Specifies the `limit` for each provider when listing all its VMs for pagination.
38+
// - If the provider is not in this list, the 'default' value will be used.
39+
// - If the `default` value is lower than the number of instances that fit into a page, the latter number will be used.
40+
// - `Infinity` value means no `limit` will be used, i.e. all VMs will be listed.
41+
instancesListBackgroundLoading: { default: 10, ovm: Infinity },
42+
43+
// A list of providers for which `destination-options` API call(s) will be made
44+
// If the item is just a string with the provider name, only one API call will be made
45+
// If the item has `envRequiredFields`, an additional API call will be made once the specified fields are filled
46+
providersWithExtraOptions: [
47+
'openstack',
48+
'oracle_vm',
49+
{
50+
name: 'azure',
51+
envRequiredFields: ['location', 'resource_group'],
52+
},
53+
{
54+
name: 'oci',
55+
envRequiredFields: ['compartment', 'availability_domain'],
56+
},
57+
],
58+
}
59+
60+
export const config = conf

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
"react-notification-system": "^0.2.15",
9999
"react-router-dom": "^4.2.2",
100100
"react-tooltip": "^3.4.0",
101+
"require-without-cache": "^0.0.6",
101102
"rimraf": "^2.6.2",
102103
"styled-components": "2.2.0",
103104
"styled-tools": "^0.2.2",

private/cypress/integration/6 - users and projects/1 - Create a project.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ You should have received a copy of the GNU Affero General Public License
1212
along with this program. If not, see <http://www.gnu.org/licenses/>.
1313
*/
1414

15-
// @flow
16-
17-
import { navigationMenu } from '../../../../src/config'
15+
import { navigationMenu } from '../../../../src/constants'
1816

1917
const isEnabled: () => boolean = () => {
2018
let usersEnabled = navigationMenu.find(i => i.value === 'users' && i.disabled === false)

private/cypress/integration/6 - users and projects/2 - Add a new user as a member.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ You should have received a copy of the GNU Affero General Public License
1212
along with this program. If not, see <http://www.gnu.org/licenses/>.
1313
*/
1414

15-
// @flow
16-
1715
import { navigationMenu } from '../../../../src/config'
1816

1917
const isEnabled: () => boolean = () => {

private/cypress/integration/6 - users and projects/3 - Add existing user as a member.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ You should have received a copy of the GNU Affero General Public License
1212
along with this program. If not, see <http://www.gnu.org/licenses/>.
1313
*/
1414

15-
// @flow
16-
1715
import { navigationMenu } from '../../../../src/config'
1816

1917
const isEnabled: () => boolean = () => {

private/cypress/integration/6 - users and projects/4 - Create a user.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ You should have received a copy of the GNU Affero General Public License
1212
along with this program. If not, see <http://www.gnu.org/licenses/>.
1313
*/
1414

15-
// @flow
16-
1715
import { navigationMenu } from '../../../../src/config'
1816

1917
const isEnabled: () => boolean = () => {

private/cypress/integration/6 - users and projects/5 - Edit and delete user.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ You should have received a copy of the GNU Affero General Public License
1212
along with this program. If not, see <http://www.gnu.org/licenses/>.
1313
*/
1414

15-
// @flow
16-
1715
import { navigationMenu } from '../../../../src/config'
1816

1917
const isEnabled: () => boolean = () => {

private/cypress/integration/6 - users and projects/6 - Edit and delete project.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ You should have received a copy of the GNU Affero General Public License
1212
along with this program. If not, see <http://www.gnu.org/licenses/>.
1313
*/
1414

15-
// @flow
16-
1715
import { navigationMenu } from '../../../../src/config'
1816

1917
const isEnabled: () => boolean = () => {

server/main.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ You should have received a copy of the GNU Affero General Public License
1212
along with this program. If not, see <http://www.gnu.org/licenses/>.
1313
*/
1414

15+
// @flow
16+
1517
import express from 'express'
1618
import fs from 'fs'
1719
import path from 'path'
20+
import requireWithoutCache from 'require-without-cache'
1821

1922
import packageJson from '../package.json'
2023

@@ -41,22 +44,30 @@ app.use(express.static('dist'))
4144

4245
require('./proxy')(app)
4346

47+
// $FlowIgnore
4448
app.get('/version', (req, res) => { res.send({ version: packageJson.version }) })
4549

50+
// $FlowIgnore
51+
app.get('/config', (req, res) => {
52+
res.send(requireWithoutCache('../config.js', require).config)
53+
})
54+
4655
if (isDev) {
56+
// $FlowIgnore
4757
app.use((req, res) => {
4858
res.redirect(`${req.baseUrl}/#${req.url}`)
4959
})
5060
} else {
61+
// $FlowIgnore
5162
app.get('*/env.js', (req, res) => {
5263
res.sendFile(path.resolve(__dirname, '../dist', 'env.js'))
5364
})
65+
// $FlowIgnore
5466
app.get('*', (req, res) => {
5567
res.sendFile(path.resolve(__dirname, '../dist', 'index.html'))
5668
})
5769
}
5870

59-
6071
app.listen(PORT, () => {
6172
console.log(`Express server is up on port ${PORT}`)
6273
})

src/components/App.jsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ import UserDetailsPage from './pages/UserDetailsPage'
3737
import ProjectsPage from './pages/ProjectsPage'
3838
import ProjectDetailsPage from './pages/ProjectDetailsPage'
3939

40-
import { navigationMenu } from '../config'
40+
import { navigationMenu } from '../constants'
4141
import Palette from './styleUtils/Palette'
4242
import StyleProps from './styleUtils/StyleProps'
43+
import configLoader from '../utils/Config'
4344

4445
injectGlobal`
4546
${Fonts}
@@ -63,16 +64,31 @@ const Wrapper = styled.div`
6364
}
6465
`
6566

66-
class App extends React.Component<{}> {
67+
type State = {
68+
isConfigReady: boolean,
69+
}
70+
71+
class App extends React.Component<{}, State> {
72+
state = {
73+
isConfigReady: false,
74+
}
75+
6776
componentWillMount() {
6877
userStore.tokenLogin()
78+
configLoader.load().then(() => {
79+
this.setState({ isConfigReady: true })
80+
})
6981
}
7082

7183
render() {
84+
if (!this.state.isConfigReady) {
85+
return null
86+
}
87+
7288
let renderOptionalPage = (name: string, component: any, path?: string, exact?: boolean) => {
7389
const isAdmin = userStore.loggedUser ? userStore.loggedUser.isAdmin : true
74-
// $FlowIgnore
75-
if (navigationMenu.find(m => m.value === name && !m.disabled && (!m.requiresAdmin || isAdmin))) {
90+
let isDisabled = configLoader.config.disabledPages.find(p => p === name)
91+
if (navigationMenu.find(m => m.value === name && !isDisabled && (!m.requiresAdmin || isAdmin))) {
7692
return <Route path={`${path || `/${name}`}`} component={component} exact={exact} />
7793
}
7894
return null
@@ -101,7 +117,7 @@ class App extends React.Component<{}> {
101117
<Route component={NotFoundPage} />
102118
</Switch>
103119
<Notifications />
104-
</Wrapper>
120+
</Wrapper >
105121
)
106122
}
107123
}

0 commit comments

Comments
 (0)