Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow tracks in event asset upload #698

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import EventDetailsTabHierarchyNavigation from "./EventDetailsTabHierarchyNaviga
import Notifications from "../../../shared/Notifications";
import { style_button_spacing } from "../../../../utils/eventDetailsUtils";
import { Formik, FormikProps } from "formik";
import { getAssetUploadOptions } from "../../../../selectors/eventSelectors";
import { translateOverrideFallback } from "../../../../utils/utils";
import { useAppDispatch, useAppSelector } from "../../../../store";
import { setModalAssetsTabHierarchy, updateAssets } from "../../../../slices/eventDetailsSlice";
import { AssetTabHierarchy } from "../modals/EventDetails";
import { useTranslation } from "react-i18next";
import { getUploadAssetOptions } from "../../../../selectors/eventDetailsSelectors";

/**
* This component manages the add asset sub-tab for assets tab of event details modal
Expand All @@ -21,15 +21,10 @@ const EventDetailsAssetsAddAsset = ({
const { t } = useTranslation();
const dispatch = useAppDispatch();

const uploadAssetOptions = useAppSelector(state => getAssetUploadOptions(state));
const uploadAssetOptions = useAppSelector(state => getUploadAssetOptions(state));

const initialValues: { [key: string]: File } = {};

// Get upload assets that are not of type track
const uploadAssets = uploadAssetOptions.filter(
(asset) => asset.type !== "track"
);

const openSubTab = (subTabName: AssetTabHierarchy) => {
dispatch(setModalAssetsTabHierarchy(subTabName));
};
Expand Down Expand Up @@ -80,14 +75,14 @@ const EventDetailsAssetsAddAsset = ({
{/* file select for upload for different types of assets */}
<table className="main-tbl">
<tbody>
{uploadAssets.length === 0 ? (
{uploadAssetOptions && uploadAssetOptions.length === 0 ? (
<tr>
<td>
{t("EVENTS.EVENTS.NEW.UPLOAD_ASSET.NO_OPTIONS")}
</td>
</tr>
) : (
uploadAssets.map((asset, key) => (
uploadAssetOptions && uploadAssetOptions.map((asset, key) => (
<tr key={key}>
<td>
{" "}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ const EventDetailsAssetsTab = ({
<th className="medium">
{!isFetchingAssetUploadOptions &&
!!uploadAssetOptions &&
uploadAssetOptions.filter(
(asset) => asset.type !== "track"
).length > 0 &&
uploadAssetOptions.length > 0 &&
!transactionsReadOnly &&
hasAccess(
"ROLE_UI_EVENTS_DETAILS_ASSETS_EDIT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ const NewAssetUploadPage = <T extends RequiredFormProps>({

const uploadAssetOptions = useAppSelector(state => getAssetUploadOptions(state));

// Get upload assets that are not of type track
const uploadAssets = uploadAssetOptions.filter(
(asset) => asset.type !== "track"
);

// if user not chose upload in step before, the skip this step
if (formik.values.sourceMode !== "UPLOAD") {
nextPage(formik.values);
Expand Down Expand Up @@ -61,14 +56,14 @@ const NewAssetUploadPage = <T extends RequiredFormProps>({
<div className="obj-container">
<table className="main-tbl">
<tbody>
{uploadAssets.length === 0 ? (
{uploadAssetOptions.length === 0 ? (
<tr>
<td>
{t("EVENTS.EVENTS.NEW.UPLOAD_ASSET.NO_OPTIONS")}
</td>
</tr>
) : (
uploadAssets.map((asset, key) => (
uploadAssetOptions.map((asset, key) => (
<tr key={key}>
<td>
{" "}
Expand Down
15 changes: 5 additions & 10 deletions src/components/events/partials/wizards/NewEventSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,21 @@ const NewEventSummary = <T extends RequiredFormProps>({
const extendedMetadata = useAppSelector(state => getExtendedEventMetadata(state));
const workflowDef = useAppSelector(state => getWorkflowDef(state));

// Get upload assets that are not of type track
const uploadAssetsOptionsNonTrack = uploadAssetOptions.filter(
(asset) => asset.type !== "track"
);

// upload asset that user has provided
let uploadAssetsNonTrack: {
name: string,
translate?: string,
value: any,
}[] = [];
for (let i = 0; uploadAssetsOptionsNonTrack.length > i; i++) {
let fieldValue = formik.values[uploadAssetsOptionsNonTrack[i].id];
for (let i = 0; uploadAssetOptions.length > i; i++) {
let fieldValue = formik.values[uploadAssetOptions[i].id];
if (!!fieldValue) {
const displayOverride = uploadAssetsOptionsNonTrack[i].displayOverride
const displayOverride = uploadAssetOptions[i].displayOverride
uploadAssetsNonTrack = uploadAssetsNonTrack.concat({
name: uploadAssetsOptionsNonTrack[i].id,
name: uploadAssetOptions[i].id,
translate: !!displayOverride
? t(displayOverride)
: translateOverrideFallback(uploadAssetsOptionsNonTrack[i], t),
: translateOverrideFallback(uploadAssetOptions[i], t),
value: fieldValue,
});
}
Expand Down
32 changes: 14 additions & 18 deletions src/components/events/partials/wizards/NewEventWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import {
getAssetUploadOptions,
getEventMetadata,
getExtendedEventMetadata,
getSourceUploadOptions,
} from "../../../../selectors/eventSelectors";
import { useAppDispatch, useAppSelector } from "../../../../store";
import { getOrgProperties, getUserInformation } from "../../../../selectors/userInfoSelectors";
import { MetadataCatalog, UploadAssetOption, postNewEvent } from "../../../../slices/eventSlice";
import { MetadataCatalog, UploadOption, postNewEvent } from "../../../../slices/eventSlice";
import { UserInfoState } from "../../../../slices/userInfoSlice";

/**
Expand All @@ -32,7 +33,8 @@ const NewEventWizard: React.FC<{
}) => {
const dispatch = useAppDispatch();

const uploadAssetOptions = useAppSelector(state => getAssetUploadOptions(state));
const uploadSourceOptions = useAppSelector(state => getSourceUploadOptions(state));
const assetUploadOptions = useAppSelector(state => getAssetUploadOptions(state));
const metadataFields = useAppSelector(state => getEventMetadata(state));
const extendedMetadata = useAppSelector(state => getExtendedEventMetadata(state));
const user = useAppSelector(state => getUserInformation(state));
Expand All @@ -48,7 +50,7 @@ const NewEventWizard: React.FC<{
const initialValues = getInitialValues(
metadataFields,
extendedMetadata,
uploadAssetOptions,
uploadSourceOptions,
user,
);

Expand Down Expand Up @@ -76,9 +78,7 @@ const NewEventWizard: React.FC<{
{
translation: "EVENTS.EVENTS.NEW.UPLOAD_ASSET.CAPTION",
name: "upload-asset",
hidden:
uploadAssetOptions.filter((asset) => asset.type !== "track").length ===
0,
hidden: assetUploadOptions.length === 0,
},
{
translation: "EVENTS.EVENTS.NEW.PROCESSING.CAPTION",
Expand Down Expand Up @@ -233,7 +233,7 @@ const NewEventWizard: React.FC<{
const getInitialValues = (
metadataFields: MetadataCatalog,
extendedMetadata: MetadataCatalog[],
uploadAssetOptions: UploadAssetOption[],
uploadSourceOptions: UploadOption[],
user: UserInfoState
) => {
let initialValues = initialFormValuesNewEvents;
Expand Down Expand Up @@ -267,20 +267,16 @@ const getInitialValues = (
}

// Add possible files that can be uploaded in source step
if (!!uploadAssetOptions) {
if (!!uploadSourceOptions) {
initialValues.uploadAssetsTrack = [];
// Sort by displayOrder
uploadAssetOptions = uploadAssetOptions.slice().sort((a: any, b: any) => a.displayOrder - b.displayOrder)
uploadSourceOptions = uploadSourceOptions.slice().sort((a: any, b: any) => a.displayOrder - b.displayOrder)
// initial value of upload asset needs to be null, because object (file) is saved there
for (const option of uploadAssetOptions) {
if (option.type === "track") {
initialValues.uploadAssetsTrack.push({
...option,
file: undefined,
});
} else {
initialValues[option.id] = null;
}
for (const option of uploadSourceOptions) {
initialValues.uploadAssetsTrack.push({
...option,
file: undefined,
});
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,8 @@
"CAPTIONS_WEBVTT": "Captions WebVTT",
"PREVIEW_IMAGE": "Preview image",
"SMIL": "Smil catalog",
"TRACK_PARTS": "Track parts"
"TRACK_PARTS": "Track parts",
"SUBTITLES": "Subtitles"
}
},
"ACCESS": {
Expand Down
2 changes: 2 additions & 0 deletions src/selectors/eventDetailsSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export const isTransactionReadOnly = (state: RootState) =>
state.eventDetails.transactionsReadOnly;
export const getUploadAssetOptions = (state: RootState) =>
state.eventDetails.uploadAssetOptions;
export const getUploadSourceOptions = (state: RootState) =>
state.eventDetails.uploadSourceOptions;
export const getAssetAttachments = (state: RootState) =>
state.eventDetails.assetAttachments;
export const getAssetAttachmentDetails = (state: RootState) =>
Expand Down
1 change: 1 addition & 0 deletions src/selectors/eventSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const getSchedulingSeriesOptions = (state: RootState) =>
state.events.schedulingInfo.seriesOptions;
export const getTotalEvents = (state: RootState) => state.events.total;
export const getAssetUploadOptions = (state: RootState) => state.events.uploadAssetOptions;
export const getSourceUploadOptions = (state: RootState) => state.events.uploadSourceOptions;
export const isFetchingAssetUploadOptions = (state: RootState) =>
state.events.isFetchingAssetUploadOptions;
export const getAssetUploadWorkflow = (state: RootState) =>
Expand Down
65 changes: 33 additions & 32 deletions src/slices/eventDetailsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { getRecordings } from "../selectors/recordingSelectors";
import { createAppAsyncThunk } from '../createAsyncThunkWithTypes';
import { Statistics, fetchStatistics, fetchStatisticsValueUpdate } from './statisticsSlice';
import { TransformedAcl } from './aclDetailsSlice';
import { MetadataCatalog } from './eventSlice';
import { MetadataCatalog, UploadOption } from './eventSlice';
import { Event } from "./eventSlice";
import {
AssetTabHierarchy,
Expand Down Expand Up @@ -115,16 +115,6 @@ type Device = {
// url: string,
}

export type UploadAssetOption = {
id: string,
title: string, // translation key
type: string, // "track", "attachment" etc.
flavorType: string,
flavorSubType: string,
accept: string,
displayOrder: number,
}

export type Publication = {
enabled: boolean,
hide?: string,
Expand Down Expand Up @@ -226,7 +216,8 @@ type EventDetailsState = {
publications: number,
},
transactionsReadOnly: boolean,
uploadAssetOptions: UploadAssetOption[] | undefined,
uploadSourceOptions: UploadOption[] | undefined,
uploadAssetOptions: UploadOption[] | undefined,
assetAttachments: Array< Assets & {
type: string,
}>,
Expand Down Expand Up @@ -458,6 +449,7 @@ const initialState: EventDetailsState = {
publications: 0,
},
transactionsReadOnly: false,
uploadSourceOptions: [],
uploadAssetOptions: [],
assetAttachments: [],
assetAttachmentDetails: {
Expand Down Expand Up @@ -662,19 +654,8 @@ export const fetchAssets = createAppAsyncThunk('eventDetails/fetchAssets', async
);
const resourceOptionsListResponse = await resourceOptionsListRequest.data;

let uploadAssetOptions: UploadAssetOption[] | undefined = [];
const optionsData = formatUploadAssetOptions(resourceOptionsListResponse);

for (const option of optionsData.options) {
if (option.type !== "track") {
uploadAssetOptions.push({ ...option });
}
}

// if no asset options, undefine the option variable
uploadAssetOptions =
uploadAssetOptions.length > 0 ? uploadAssetOptions : undefined;

if (transactionsReadOnly) {
dispatch(
addNotification({
Expand All @@ -687,7 +668,12 @@ export const fetchAssets = createAppAsyncThunk('eventDetails/fetchAssets', async
);
}

return { assets, transactionsReadOnly, uploadAssetOptions }
return {
assets,
transactionsReadOnly,
uploadAssetOptions: optionsData.assetOptions,
uploadSourceOptions: optionsData.sourceOptions
}
});

const formatUploadAssetOptions = (optionsData: { [key: string]: string }) => {
Expand All @@ -696,12 +682,17 @@ const formatUploadAssetOptions = (optionsData: { [key: string]: string }) => {
const workflowPrefix = "EVENTS.EVENTS.NEW.UPLOAD_ASSET.WORKFLOWDEFID";

let optionsResult: {
assetOptions: UploadOption[],
sourceOptions: UploadOption[],
workflow?: string,
options: UploadAssetOption[],
} = {
options: []
assetOptions: [],
sourceOptions: [],
workflow: "",
};
let uploadOptions = [];

let uploadAssets: UploadOption[] = [];
let uploadSource: UploadOption[] = [];

for (const [key, value] of Object.entries(optionsData)) {
if (key.charAt(0) !== "$") {
Expand All @@ -710,18 +701,26 @@ const formatUploadAssetOptions = (optionsData: { [key: string]: string }) => {
key.indexOf(optionPrefixSource) >= 0
) {
// parse upload asset options
let options: UploadAssetOption = JSON.parse(value);
let options: UploadOption = JSON.parse(value);
if (!options["title"]) {
options["title"] = key;
}
uploadOptions.push({ ...options });
if ((options["showForExistingEvents"] !== undefined && (key.indexOf(optionPrefixAsset) >= 0 && options["showForExistingEvents"]))
|| (options["showForExistingEvents"] === undefined && (key.indexOf(optionPrefixAsset) >= 0))) {
uploadAssets.push({ ...options });
}
if ((options["showForExistingEvents"] !== undefined && (key.indexOf(optionPrefixSource) >= 0 && options["showForExistingEvents"]))
|| (options["showForExistingEvents"] === undefined && (key.indexOf(optionPrefixSource) >= 0))) {
uploadSource.push({ ...options });
}
} else if (key.indexOf(workflowPrefix) >= 0) {
// parse upload workflow definition id
optionsResult["workflow"] = value;
optionsResult.workflow = value;
}
}
}
optionsResult["options"] = uploadOptions;
optionsResult.assetOptions = uploadAssets;
optionsResult.sourceOptions = uploadSource;

return optionsResult;
};
Expand Down Expand Up @@ -1643,7 +1642,7 @@ export const updateAssets = createAppAsyncThunk('eventDetails/updateAssets', asy
let formData = new FormData();

let assets: {
options: UploadAssetOption[],
options: UploadOption[],
} = {
options: [],
};
Expand Down Expand Up @@ -1953,12 +1952,14 @@ const eventDetailsSlice = createSlice({
assets: EventDetailsState["assets"],
transactionsReadOnly: EventDetailsState["transactionsReadOnly"],
uploadAssetOptions: EventDetailsState["uploadAssetOptions"],
uploadSourceOptions: EventDetailsState["uploadSourceOptions"],
}>) => {
state.statusAssets = 'succeeded';
const eventDetails = action.payload;
state.assets = eventDetails.assets;
state.transactionsReadOnly = eventDetails.transactionsReadOnly;
state.uploadAssetOptions = eventDetails.uploadAssetOptions;
state.uploadSourceOptions = eventDetails.uploadSourceOptions;
})
.addCase(fetchAssets.rejected, (state, action) => {
state.statusAssets = 'failed';
Expand Down
Loading
Loading