-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathCompactBehaviorSharedDataPropertiesEditor.js
More file actions
63 lines (59 loc) · 2.23 KB
/
CompactBehaviorSharedDataPropertiesEditor.js
File metadata and controls
63 lines (59 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// @flow
import * as React from 'react';
import { ColumnStackLayout } from '../../UI/Layout';
import { Trans } from '@lingui/macro';
import { CompactPropertiesEditorByVisibility } from '../../CompactPropertiesEditor/CompactPropertiesEditorByVisibility';
import propertiesMapToSchema from '../../PropertiesEditor/PropertiesMapToSchema';
import { useForceRecompute } from '../../Utils/UseForceUpdate';
import { type ResourceManagementProps } from '../../ResourcesList/ResourceSource';
type CompactBehaviorPropertiesEditorProps = {|
project: gdProject,
behaviorMetadata: gdBehaviorMetadata,
behaviorSharedData: gdBehaviorsSharedData,
resourceManagementProps: ResourceManagementProps,
isAdvancedSectionInitiallyUncollapsed?: boolean,
|};
export const CompactBehaviorSharedDataPropertiesEditor = ({
project,
behaviorMetadata,
behaviorSharedData,
resourceManagementProps,
}: CompactBehaviorPropertiesEditorProps): React.Node => {
const [schemaRecomputeTrigger, forceRecomputeSchema] = useForceRecompute();
const propertiesSchema = React.useMemo(
() => {
if (schemaRecomputeTrigger) {
// schemaRecomputeTrigger allows to invalidate the schema when required.
}
const behaviorMetadataSharedProperties = behaviorMetadata.getSharedProperties();
return propertiesMapToSchema({
properties: behaviorMetadataSharedProperties,
defaultValueProperties: behaviorMetadataSharedProperties,
getPropertyValue: (instance, name) =>
instance
.getProperties()
.get(name)
.getValue(),
onUpdateProperty: (instance, name, value) => {
instance.updateProperty(name, value);
},
object: null,
visibility: 'All',
});
},
[schemaRecomputeTrigger, behaviorMetadata]
);
return (
<ColumnStackLayout expand noMargin noOverflowParent>
<CompactPropertiesEditorByVisibility
project={project}
object={null}
schema={propertiesSchema}
instances={[behaviorSharedData]}
resourceManagementProps={resourceManagementProps}
placeholder={<Trans>Nothing to configure for this behavior.</Trans>}
onRefreshAllFields={forceRecomputeSchema}
/>
</ColumnStackLayout>
);
};