Skip to content

Commit

Permalink
add default extension settings in the send media event view
Browse files Browse the repository at this point in the history
  • Loading branch information
Nina Ciocanu committed May 14, 2024
1 parent 2baf070 commit de715b4
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 19 deletions.
66 changes: 54 additions & 12 deletions src/view/actions/sendStreamingMediaEvent.jsx
Expand Up @@ -44,18 +44,28 @@ const wrapGetInitialValues =
eventType,
playerId,
handleMediaSessionAutomatically = false,
instanceName,
instanceName = initInfo.extensionSettings.instances[0].name,
xdm = {}
} = initInfo.settings || {};

const { mediaCollection = {} } = xdm;

const instanceSettings = initInfo.extensionSettings.instances.find(
instance => instance.name === instanceName
);
const {
playhead,
qoeDataDetails,
advertisingDetails,
advertisingDetails = {
playerName: instanceSettings?.streamingMedia?.playerName || ""
},
chapterDetails,
advertisingPodDetails,
sessionDetails,
sessionDetails = {
channel: instanceSettings?.streamingMedia?.channel || "",
playerName: instanceSettings?.streamingMedia?.playerName || "",
appVersion: instanceSettings?.streamingMedia?.appVersion || ""
},
errorDetails,
customMetadata,
statesEnd,
Expand Down Expand Up @@ -331,8 +341,9 @@ const advertisingDetailsSection = dataElementSection(
textField({
name: "playerName",
label: "Ad player name",
isRequired: true,
description: "The name of the player responsible for rendering the ad."
description: "The name of the player responsible for rendering the ad.",
dataElementSupported: false,
isDisabled: true
})
]
);
Expand Down Expand Up @@ -432,9 +443,10 @@ const sessionDetailsSection = dataElementSection(
textField({
name: "channel",
label: "Channel",
isRequired: true,
isDisabled: true,
description:
"Distribution station or channels where the content is played. Any string value is accepted here."
"Distribution station or channels where the content is played. Any string value is accepted here.",
dataElementSupported: false
}),
numberField({
name: "length", // integer
Expand All @@ -456,8 +468,9 @@ const sessionDetailsSection = dataElementSection(
textField({
name: "playerName",
label: "Content player name",
isRequired: true,
description: "Name of the media player."
dataElementSupported: false,
isDisabled: true,
description: "The name of the player responsible for playing the media."
}),
textField({
name: "adLoad",
Expand All @@ -474,9 +487,10 @@ const sessionDetailsSection = dataElementSection(
textField({
name: "appVersion",
label: "Application version",
isRequired: false,
description:
"The SDK version used by the player. This could have any custom value that makes sense for your player."
"The SDK version used by the player. This could have any custom value that makes sense for your player.",
dataElementSupported: false,
isDisabled: true
}),
textField({
name: "artist",
Expand Down Expand Up @@ -715,13 +729,41 @@ const eventBasedDetailFormConditionals = [
)
];

const onInstanceChange = ({ context, instanceName, initInfo }) => {
const extensionSettings = initInfo.extensionSettings;
const instanceSettings = extensionSettings.instances.find(
instance => instance.name === instanceName
);

context.setFieldValue(
`sessionDetails.channel`,
instanceSettings.streamingMedia.channel || "",
true
);
context.setFieldValue(
`sessionDetails.playerName`,
instanceSettings.streamingMedia.playerName || "",
true
);
context.setFieldValue(
`sessionDetails.appVersion`,
instanceSettings.streamingMedia.appVersion || "",
true
);
context.setFieldValue(
`advertisingDetails.playerName`,
instanceSettings.streamingMedia.playerName || "",
true
);
};

const sendEventForm = form(
{
wrapGetInitialValues,
wrapGetSettings
},
[
instancePicker({ name: "instanceName" }),
instancePicker({ name: "instanceName", onInstanceChange }),
comboBox({
name: "eventType",
label: "Media event type",
Expand Down
10 changes: 7 additions & 3 deletions src/view/components/formikReactSpectrum3/formikPicker.jsx
Expand Up @@ -15,7 +15,7 @@ import { useField } from "formik";
import PropTypes from "prop-types";
import React from "react";

const FormikPicker = ({ name, width, validate, ...otherProps }) => {
const FormikPicker = ({ name, width, validate, onChange, ...otherProps }) => {
const [{ value }, { touched, error }, { setValue, setTouched }] = useField({
name,
validate
Expand All @@ -24,7 +24,10 @@ const FormikPicker = ({ name, width, validate, ...otherProps }) => {
return (
<Picker
selectedKey={value}
onSelectionChange={setValue}
onSelectionChange={key => {
setValue(key);
onChange(key);
}}
onBlur={() => {
setTouched(true);
}}
Expand All @@ -39,7 +42,8 @@ const FormikPicker = ({ name, width, validate, ...otherProps }) => {
FormikPicker.propTypes = {
name: PropTypes.string.isRequired,
width: PropTypes.string,
validate: PropTypes.func
validate: PropTypes.func,
onChange: PropTypes.func
};

export default FormikPicker;
7 changes: 5 additions & 2 deletions src/view/components/instanceNamePicker.jsx
Expand Up @@ -21,7 +21,8 @@ const InstanceNamePicker = ({
name,
initInfo,
description,
disabledDescription
disabledDescription,
onChange
}) => {
const items = getInstanceOptions(initInfo);
const isDisabled = items.length <= 1;
Expand All @@ -36,6 +37,7 @@ const InstanceNamePicker = ({
description={
isDisabled && disabledDescription ? disabledDescription : description
}
onChange={onChange}
>
{item => <Item key={item.value}>{item.label}</Item>}
</FormikPicker>
Expand All @@ -47,7 +49,8 @@ InstanceNamePicker.propTypes = {
name: PropTypes.string.isRequired,
initInfo: PropTypes.object.isRequired,
description: PropTypes.string,
disabledDescription: PropTypes.string
disabledDescription: PropTypes.string,
onChange: PropTypes.func
};

export default InstanceNamePicker;
10 changes: 9 additions & 1 deletion src/view/forms/instancePicker.jsx
Expand Up @@ -11,6 +11,7 @@ governing permissions and limitations under the License.
*/
import React from "react";
import PropTypes from "prop-types";
import { useFormikContext } from "formik";
import InstanceNamePicker from "../components/instanceNamePicker";

/** @typedef {import("./form").Form} Form */
Expand All @@ -20,7 +21,7 @@ import InstanceNamePicker from "../components/instanceNamePicker";
* @param {string} options.name - The formik key to use for this field.
* @returns {Form} A form field for an instance name picker.
*/
export default function instancePicker({ name }) {
export default function instancePicker({ name, onInstanceChange }) {
const form = {
getInitialValues({ initInfo }) {
const { [name]: value = initInfo.extensionSettings.instances[0].name } =
Expand All @@ -35,11 +36,18 @@ export default function instancePicker({ name }) {
return settings;
},
Component({ namePrefix = "", initInfo }) {
const formikContext = useFormikContext();
const onChange = context => key => {
if (onInstanceChange) {
onInstanceChange({ context, instanceName: key, initInfo });
}
};
return (
<InstanceNamePicker
data-test-id={`${namePrefix}${name}Picker`}
name={`${namePrefix}${name}`}
initInfo={initInfo}
onChange={onChange(formikContext)}
/>
);
}
Expand Down
5 changes: 4 additions & 1 deletion src/view/forms/textField.jsx
Expand Up @@ -36,7 +36,8 @@ export default function textField({
label,
description,
width = "size-5000",
validationSchemaBase = string()
validationSchemaBase = string(),
isDisabled = false
}) {
let validationSchema = validationSchemaBase;
if (isRequired) {
Expand All @@ -61,6 +62,7 @@ export default function textField({
isRequired={isRequired}
description={description}
width={width}
isDisabled={isDisabled}
/>
</DataElementSelector>
);
Expand All @@ -84,6 +86,7 @@ export default function textField({
isRequired={isRequired}
description={description}
width={width}
isDisabled={isDisabled}
/>
);
};
Expand Down

0 comments on commit de715b4

Please sign in to comment.