Skip to content

Commit 8bdc2cd

Browse files
committed
feat: refactor userEditing structure
1 parent 52a0d54 commit 8bdc2cd

File tree

3 files changed

+90
-30
lines changed

3 files changed

+90
-30
lines changed

packages/blueprints-integration/src/userEditing.ts

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import { JSONBlob } from '@sofie-automation/shared-lib/dist/lib/JSONBlob'
22
import type { ITranslatableMessage } from './translations'
33
import { JSONSchema } from '@sofie-automation/shared-lib/dist/lib/JSONSchemaTypes'
4+
import { SourceLayerType } from './content'
45

56
/**
67
* Description of a user performed editing operation allowed on an document
78
*/
8-
export type UserEditingDefinition = UserEditingDefinitionAction | UserEditingDefinitionForm
9+
export type UserEditingDefinition =
10+
| UserEditingDefinitionAction
11+
| UserEditingDefinitionForm
12+
| UserEditingDefinitionSourceLayerForm
913

1014
/**
1115
* A simple 'action' that can be performed
@@ -19,7 +23,7 @@ export interface UserEditingDefinitionAction {
1923
/** Icon to show when this action is 'active' */
2024
svgIcon?: string
2125
/** Icon to show when this action is 'disabled' */
22-
svgIconDisabled?: string
26+
svgIconInactive?: string
2327
/** Whether this action should be indicated as being active */
2428
isActive?: boolean
2529
/** Button Type */
@@ -35,29 +39,44 @@ export interface UserEditingDefinitionForm {
3539
id: string
3640
/** Label to show to the user for this operation */
3741
label: ITranslatableMessage
38-
/** Used to group the schemas and filter them */
39-
grouping?: UserEditingGroupingType[]
40-
/** The json schemas describing the form to display */
41-
schemas: Record<string, JSONBlob<JSONSchema>>
42+
/** The json schema describing the form to display */
43+
schema: JSONBlob<JSONSchema>
4244
/** Current values to populate the form with */
4345
currentValues: Record<string, any>
4446
}
4547

48+
/**
49+
* A form based operation where the user first selects the type
50+
* of form they want to use (i.e. Camera form vs VT form)
51+
*/
52+
export interface UserEditingDefinitionSourceLayerForm {
53+
type: UserEditingType.SOURCE_LAYER_FORM
54+
/** Id of this operation */
55+
id: string
56+
/** Label to show to the user for this operation */
57+
label: ITranslatableMessage
58+
/** The json schemas describing the form to display */
59+
schemas: Record<string, UserEditingSourceLayer>
60+
/** Current values to populate the form with */
61+
currentValues: {
62+
type: SourceLayerType
63+
value: Record<string, any>
64+
}
65+
}
66+
4667
export enum UserEditingType {
4768
/** Action */
4869
ACTION = 'action',
49-
/** Form of selections */
70+
/** Form */
5071
FORM = 'form',
72+
/** Forms that the user has to select a sourceLayerType first */
73+
SOURCE_LAYER_FORM = 'sourceLayerForm',
5174
}
5275

53-
/**
54-
* Grouping of schemas
55-
*/
56-
export interface UserEditingGroupingType {
57-
filter?: string
58-
label?: string
59-
color?: string
60-
svgIcon?: string
76+
export interface UserEditingSourceLayer {
77+
sourceLayerLabel: string
78+
sourceLayerType: SourceLayerType
79+
schema: JSONBlob<JSONSchema>
6180
}
6281

6382
export enum UserEditingButtonType {
Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import type {
22
UserEditingType,
3-
UserEditingGroupingType,
43
JSONBlob,
54
JSONSchema,
5+
UserEditingSourceLayer,
66
UserEditingButtonType,
7+
SourceLayerType,
78
} from '@sofie-automation/blueprints-integration'
89
import type { ITranslatableMessage } from '../TranslatableMessage'
910

10-
export type CoreUserEditingDefinition = CoreUserEditingDefinitionAction | CoreUserEditingDefinitionForm
11+
export type CoreUserEditingDefinition =
12+
| CoreUserEditingDefinitionAction
13+
| CoreUserEditingDefinitionForm
14+
| CoreUserEditingDefinitionSourceLayerForm
1115

1216
export interface CoreUserEditingDefinitionAction {
1317
type: UserEditingType.ACTION
@@ -18,26 +22,47 @@ export interface CoreUserEditingDefinitionAction {
1822
/** Icon to show when this action is 'active' */
1923
svgIcon?: string
2024
/** Icon to show when this action is 'disabled' */
21-
svgIconDisabled?: string
25+
svgIconInactive?: string
2226
/** Whether this action should be indicated as being active */
2327
isActive?: boolean
2428
//** Button Type */
2529
buttonType?: UserEditingButtonType
2630
}
2731

32+
/**
33+
* A simple form based operation
34+
*/
2835
export interface CoreUserEditingDefinitionForm {
2936
type: UserEditingType.FORM
3037
/** Id of this operation */
3138
id: string
3239
/** Label to show to the user for this operation */
3340
label: ITranslatableMessage
34-
/** Used to group the schemas and filter them */
35-
grouping?: UserEditingGroupingType[]
36-
/** The json schemas describing the form to display */
37-
schemas: Record<string, JSONBlob<JSONSchema>>
38-
41+
/** The json schema describing the form to display */
42+
schema: JSONBlob<JSONSchema>
3943
/** Current values to populate the form with */
4044
currentValues: Record<string, any>
4145
/** Translation namespaces to use when rendering this form */
4246
translationNamespaces: string[]
4347
}
48+
49+
/**
50+
* A form based operation where the user first selects the type
51+
* of form they want to use (i.e. Camera form vs VT form)
52+
*/
53+
export interface CoreUserEditingDefinitionSourceLayerForm {
54+
type: UserEditingType.SOURCE_LAYER_FORM
55+
/** Id of this operation */
56+
id: string
57+
/** Label to show to the user for this operation */
58+
label: ITranslatableMessage
59+
/** Sourcelayer Type */
60+
schemas: Record<string, UserEditingSourceLayer>
61+
/** Translation namespaces to use when rendering this form */
62+
translationNamespaces: string[]
63+
/** Current values to populate the form with */
64+
currentValues: {
65+
type: SourceLayerType
66+
value: Record<string, any>
67+
}
68+
}

packages/job-worker/src/blueprints/context/lib.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
CoreUserEditingDefinition,
1414
CoreUserEditingDefinitionAction,
1515
CoreUserEditingDefinitionForm,
16+
CoreUserEditingDefinitionSourceLayerForm,
1617
} from '@sofie-automation/corelib/dist/dataModel/UserEditingDefinitions'
1718
import { DBSegment } from '@sofie-automation/corelib/dist/dataModel/Segment'
1819
import { assertNever, clone, Complete, literal, omit } from '@sofie-automation/corelib/dist/lib'
@@ -56,7 +57,7 @@ import {
5657
UserEditingDefinition,
5758
UserEditingDefinitionAction,
5859
UserEditingDefinitionForm,
59-
UserEditingGroupingType,
60+
UserEditingDefinitionSourceLayerForm,
6061
UserEditingType,
6162
} from '@sofie-automation/blueprints-integration/dist/userEditing'
6263
import type { PlayoutMutatablePart } from '../../playout/model/PlayoutPartInstanceModel'
@@ -511,7 +512,7 @@ function translateUserEditsToBlueprint(
511512
id: userEdit.id,
512513
label: omit(userEdit.label, 'namespaces'),
513514
svgIcon: userEdit.svgIcon,
514-
svgIconDisabled: userEdit.svgIconDisabled,
515+
svgIconInactive: userEdit.svgIconInactive,
515516
isActive: userEdit.isActive,
516517
buttonType: userEdit.buttonType,
517518
} satisfies Complete<UserEditingDefinitionAction>
@@ -520,10 +521,17 @@ function translateUserEditsToBlueprint(
520521
type: UserEditingType.FORM,
521522
id: userEdit.id,
522523
label: omit(userEdit.label, 'namespaces'),
523-
grouping: clone(userEdit.grouping) as UserEditingGroupingType[] | undefined,
524-
schemas: clone(userEdit.schemas),
524+
schema: clone(userEdit.schema),
525525
currentValues: clone(userEdit.currentValues),
526526
} satisfies Complete<UserEditingDefinitionForm>
527+
case UserEditingType.SOURCE_LAYER_FORM:
528+
return {
529+
type: UserEditingType.SOURCE_LAYER_FORM,
530+
id: userEdit.id,
531+
label: omit(userEdit.label, 'namespaces'),
532+
schemas: clone(userEdit.schemas),
533+
currentValues: clone(userEdit.currentValues),
534+
} satisfies Complete<UserEditingDefinitionSourceLayerForm>
527535
default:
528536
assertNever(userEdit)
529537
return undefined
@@ -547,7 +555,7 @@ export function translateUserEditsFromBlueprint(
547555
id: userEdit.id,
548556
label: wrapTranslatableMessageFromBlueprints(userEdit.label, blueprintIds),
549557
svgIcon: userEdit.svgIcon,
550-
svgIconDisabled: userEdit.svgIconDisabled,
558+
svgIconInactive: userEdit.svgIconInactive,
551559
isActive: userEdit.isActive,
552560
buttonType: userEdit.buttonType,
553561
} satisfies Complete<CoreUserEditingDefinitionAction>
@@ -556,11 +564,19 @@ export function translateUserEditsFromBlueprint(
556564
type: UserEditingType.FORM,
557565
id: userEdit.id,
558566
label: wrapTranslatableMessageFromBlueprints(userEdit.label, blueprintIds),
559-
grouping: clone(userEdit.grouping),
560-
schemas: clone(userEdit.schemas),
567+
schema: clone(userEdit.schema),
561568
currentValues: clone(userEdit.currentValues),
562569
translationNamespaces: unprotectStringArray(blueprintIds),
563570
} satisfies Complete<CoreUserEditingDefinitionForm>
571+
case UserEditingType.SOURCE_LAYER_FORM:
572+
return {
573+
type: UserEditingType.SOURCE_LAYER_FORM,
574+
id: userEdit.id,
575+
label: wrapTranslatableMessageFromBlueprints(userEdit.label, blueprintIds),
576+
schemas: clone(userEdit.schemas),
577+
currentValues: clone(userEdit.currentValues),
578+
translationNamespaces: unprotectStringArray(blueprintIds),
579+
} satisfies Complete<CoreUserEditingDefinitionSourceLayerForm>
564580
default:
565581
assertNever(userEdit)
566582
return undefined

0 commit comments

Comments
 (0)