Skip to content

Commit 525cd59

Browse files
committed
feat: simplify structure for userEditing source
1 parent 4ef35fd commit 525cd59

File tree

3 files changed

+17
-33
lines changed

3 files changed

+17
-33
lines changed

packages/blueprints-integration/src/userEditing.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ export interface UserEditingDefinitionSourceLayerForm {
5858
/** The json schemas describing the form to display */
5959
schemas: Record<string, UserEditingSourceLayer>
6060
/** Current values to populate the form with */
61-
currentValues: {
62-
type: SourceLayerType
63-
value: Record<string, any>
64-
}
61+
currentValues: Record<string, any>
6562
}
6663

6764
export enum UserEditingType {

packages/corelib/src/dataModel/UserEditingDefinitions.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type {
44
JSONSchema,
55
UserEditingSourceLayer,
66
UserEditingButtonType,
7-
SourceLayerType,
87
} from '@sofie-automation/blueprints-integration'
98
import type { ITranslatableMessage } from '../TranslatableMessage'
109

@@ -61,8 +60,5 @@ export interface CoreUserEditingDefinitionSourceLayerForm {
6160
/** Translation namespaces to use when rendering this form */
6261
translationNamespaces: string[]
6362
/** Current values to populate the form with */
64-
currentValues: {
65-
type: SourceLayerType
66-
value: Record<string, any>
67-
}
63+
currentValues: Record<string, any>
6864
}

packages/webui/src/client/ui/UserEditOperations/PropertiesPanel.tsx

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -404,26 +404,18 @@ function EditingTypeChangeSourceLayerSource(props: {
404404
props.pendingChanges.find((change) => change.operationId === props.userEditOperation.id)?.sourceLayerType ||
405405
props.userEditOperation.currentValues.type
406406
)
407-
const [schemaValues, setSchemaValues] = React.useState({
408-
type: selectedSourceGroup,
409-
values:
410-
props.pendingChanges.find((change) => change.operationId === props.userEditOperation.id)?.value ||
411-
props.userEditOperation.currentValues.value,
412-
})
413-
414-
const selectedSourceObject = Object.values<UserEditingSourceLayer>(props.userEditOperation.schemas).find(
415-
(layer) => layer.sourceLayerType === selectedSourceGroup
407+
const [selectedValues, setSelectedValues] = React.useState<Record<string, string>>(
408+
props.pendingChanges.find((change) => change.operationId === props.userEditOperation.id)?.value ||
409+
props.userEditOperation.currentValues.value
416410
)
417-
const jsonSchema = selectedSourceObject?.schema
418-
const schema = jsonSchema ? JSONBlobParse(jsonSchema) : undefined
419411

420-
const groups = clone(props.userEditOperation.schemas) || {}
412+
const jsonSchema = Object.values<UserEditingSourceLayer>(props.userEditOperation.schemas).find(
413+
(layer) => layer.sourceLayerType === selectedSourceGroup
414+
)?.schema
415+
const selectedGroupSchema = jsonSchema ? JSONBlobParse(jsonSchema) : undefined
421416

422417
const handleSourceChange = () => {
423-
setSchemaValues({
424-
type: selectedSourceGroup,
425-
values: schemaValues.values,
426-
})
418+
setSelectedValues(selectedValues)
427419
// Add to pending changes instead of executing immediately
428420
props.setPendingChanges((prev) => {
429421
const filtered = prev.filter(
@@ -434,12 +426,11 @@ function EditingTypeChangeSourceLayerSource(props: {
434426
)
435427
)
436428
// Only use the key,value pair from the selected source group:
437-
const newKey = Object.keys(schemaValues.values).find((key) => {
429+
const newKey = Object.keys(props.userEditOperation.schemas).find((key) => {
438430
return props.userEditOperation.schemas[key].sourceLayerType === selectedSourceGroup
439431
})
440432
if (!newKey) return filtered
441-
const newValue = props.userEditOperation.currentValues.value[newKey]
442-
433+
const newValue = selectedValues[newKey]
443434
return [
444435
...filtered,
445436
{
@@ -455,7 +446,7 @@ function EditingTypeChangeSourceLayerSource(props: {
455446
return (
456447
<>
457448
<div className="propertiespanel-pop-up__groupselector">
458-
{Object.values<UserEditingSourceLayer>(groups).map((group, index) => {
449+
{Object.values<UserEditingSourceLayer>(props.userEditOperation.schemas).map((group, index) => {
459450
return (
460451
<button
461452
className={classNames(
@@ -474,12 +465,12 @@ function EditingTypeChangeSourceLayerSource(props: {
474465
)
475466
})}
476467
</div>
477-
{schema && (
478-
<div onClick={handleSourceChange}>
468+
{selectedGroupSchema && (
469+
<div onChange={handleSourceChange}>
479470
<a className="propertiespanel-pop-up__label">{t('Source')}:</a>
480471
<SchemaFormInPlace
481-
schema={schema}
482-
object={schemaValues.values}
472+
schema={selectedGroupSchema}
473+
object={selectedValues}
483474
translationNamespaces={props.userEditOperation.translationNamespaces}
484475
/>
485476
<br />

0 commit comments

Comments
 (0)