Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
LaVizu
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
behaviors-ai-public
LaVizu
Commits
71c0e569
Commit
71c0e569
authored
May 07, 2019
by
Dorian Goepp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove legacy code from modeHandler
parent
f1897672
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
110 deletions
+0
-110
src/utils/modeHandler.js
src/utils/modeHandler.js
+0
-110
No files found.
src/utils/modeHandler.js
View file @
71c0e569
...
...
@@ -2,116 +2,6 @@ import React, {Component} from 'react';
import
Form
from
'
react-jsonschema-form
'
;
import
{
merge
}
from
'
lodash/object
'
;
export
class
modeHandler
{
constructor
(
object
,
configGetter
,
configSetter
)
{
this
.
target
=
object
this
.
configGetter
=
configGetter
;
this
.
configSetter
=
configSetter
;
// get the current config; if it does not exist yet, create it
let
config
=
this
.
configGetter
()
||
{};
merge
(
config
,
this
.
announceCapabilities
(
config
));
if
(
config
.
configurable
)
{
merge
(
config
,
this
.
defaultConfigFromSchema
(
config
));
}
this
.
configSetter
(
config
);
}
/**
* Search for the 'settingsSchema' and 'readme' properties of the managed component. A corresponding field in the
* configuration is set accordingly. This is used to display or not the UI buttons to show the Readme or the
* configuration for of a component.
* @param {Object} config current configuration of the object
* @return the new configuration object (possibly unmodified)
*/
announceCapabilities
(
config
)
{
if
(
this
.
target
.
settingsSchema
)
{
config
.
configurable
=
true
;
}
else
{
config
.
configurable
=
false
;
}
if
(
this
.
target
.
readme
)
{
config
.
hasReadme
=
true
;
}
else
{
config
.
hasReadme
=
false
;
}
return
config
;
}
/**
* Search for properties in a JSON Schema. If they are here, use the default value of each JsonSchema property for
* the configuration. This means that if a property is already defined in the configuration, it will not be
* altered.
* @param {Object} config current configuration of the object
* @return the new configuration object (possibly unmodified)
*/
defaultConfigFromSchema
(
config
)
{
const
schema
=
this
.
target
.
settingsSchema
;
if
(
!
schema
)
{
return
config
;
}
else
if
(
!
(
'
properties
'
in
schema
))
{
console
.
warn
(
"
no properties in the schema
"
);
return
config
;
}
else
{
for
(
let
[
key
,
value
]
of
Object
.
entries
(
schema
.
properties
))
{
if
(
!
(
key
in
config
))
{
let
message
=
"
The key '
"
+
key
+
"
' is missing in the configuration.
"
;
if
(
'
default
'
in
value
)
{
config
[
key
]
=
value
.
default
;
message
+=
"
Using default value '
"
+
value
.
default
+
"
'.
"
;
}
console
.
debug
(
message
);
}
}
return
config
;
}
}
/**
* Return either the value of the normal parameter, in normal mode, or the content for the `readme` and `settings`
* modes.
*
* The display mode is defined by the 'displayMode' attribute of the component's configuration.
* @param {Jsx} normal The content to return in the normal mode (neither settings nor readme)
*/
modalDisplay
(
normal
)
{
const
config
=
this
.
configGetter
();
if
(
config
&&
'
displayMode
'
in
config
)
{
if
(
config
.
configurable
&&
config
.
displayMode
===
"
settings
"
)
{
return
(
<
Form
schema
=
{
this
.
target
.
settingsSchema
}
onSubmit
=
{
this
.
handleSettingsChange
.
bind
(
this
)}
formData
=
{
config
}
/>
)
;
}
if
(
config
.
hasReadme
&&
config
.
displayMode
===
"
readme
"
)
{
return
this
.
target
.
readme
;
}
}
return
normal
;
}
/**
* Given a new configuration object (from the form), update the configuration of the component (in FlexLayout).
*
* The update is done through Lodash's merge function.
* @param {Object} value update for the configuration of the component (we take the field formData)
* @return Also return the updated configuration.
*/
handleSettingsChange
({
formData
})
{
let
config
=
this
.
configGetter
();
merge
(
config
,
formData
);
this
.
configSetter
(
config
);
return
config
;
}
}
export
class
Modal
extends
Component
{
constructor
(
props
)
{
super
(
props
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment