Skip to content
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 @@ -285,6 +285,7 @@ const PageTemplateListPage = ({
pageTemplate={pageTemplate}
onClose={handleClosePageDialog}
onSave={handleSavePageTemplate}
isGlobal
/>
)}
{openCloneDialog && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ const PageTemplatePopup = ({
summitId,
sponsorId,
sponsorshipIds,
title
title,
isGlobal
}) => {
const popupTitle =
title ??
Expand Down Expand Up @@ -82,7 +83,7 @@ const PageTemplatePopup = ({
kind: yup.string().equals([PAGES_MODULE_KINDS.MEDIA]),
name: yup.string().required(T.translate("validation.required")),
type: yup.string().required(T.translate("validation.required")),
upload_deadline: yup.date().required(T.translate("validation.required")),
upload_deadline: yup.date().nullable(),
description: yup.string().required(T.translate("validation.required")),
max_file_size: yup.number().when("type", {
is: PAGE_MODULES_MEDIA_TYPES.FILE,
Expand Down Expand Up @@ -301,7 +302,7 @@ const PageTemplatePopup = ({
</Grid2>
<Divider sx={{ mb: 2 }} />
<Box sx={{ py: 2 }}>
<PageModules name="modules" />
<PageModules name="modules" isGlobal={isGlobal} />
</Box>
</DialogContent>
<Divider />
Expand All @@ -323,7 +324,8 @@ PageTemplatePopup.propTypes = {
sponsorshipIds: PropTypes.array,
summitId: PropTypes.number,
sponsorId: PropTypes.number,
title: PropTypes.string
title: PropTypes.string,
isGlobal: PropTypes.bool
};

export default PageTemplatePopup;
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import MuiFormikDatepicker from "openstack-uicore-foundation/lib/components/mui/
import MuiFormikTextField from "../../../../../components/mui/formik-inputs/mui-formik-textfield";
import MuiFormikRadioGroup from "../../../../../components/mui/formik-inputs/mui-formik-radio-group";
import MuiFormikFilesizeField from "../../../../../components/mui/formik-inputs/mui-formik-file-size-field";
import { PAGE_MODULES_MEDIA_TYPES } from "../../../../../utils/constants";
import {
COLUMN_6,
COLUMN_12,
PAGE_MODULES_MEDIA_TYPES
} from "../../../../../utils/constants";
import MuiFormikSelect from "../../../../../components/mui/formik-inputs/mui-formik-select";

const MediaRequestModule = ({ baseName, index, mediaFileTypes }) => {
const MediaRequestModule = ({ baseName, index, mediaFileTypes, isGlobal }) => {
const { values } = useFormikContext();
const buildFieldName = (field) => `${baseName}[${index}].${field}`;

Expand Down Expand Up @@ -47,7 +51,7 @@ const MediaRequestModule = ({ baseName, index, mediaFileTypes }) => {
<Grid2 size={12}>
<Divider sx={{ mx: -2 }} />
</Grid2>
<Grid2 size={6}>
<Grid2 size={isGlobal ? COLUMN_12 : COLUMN_6}>
<InputLabel htmlFor={buildFieldName("name")}>
{T.translate("page_template_list.page_crud.name")}
</InputLabel>
Expand All @@ -57,15 +61,17 @@ const MediaRequestModule = ({ baseName, index, mediaFileTypes }) => {
margin="none"
/>
</Grid2>
<Grid2 size={6}>
<InputLabel htmlFor={buildFieldName("upload_deadline")}>
{T.translate("page_template_list.page_crud.upload_deadline")}
</InputLabel>
<MuiFormikDatepicker
name={buildFieldName("upload_deadline")}
margin="none"
/>
</Grid2>
{!isGlobal && (
<Grid2 size={6}>
<InputLabel htmlFor={buildFieldName("upload_deadline")}>
{T.translate("page_template_list.page_crud.upload_deadline")}
</InputLabel>
<MuiFormikDatepicker
name={buildFieldName("upload_deadline")}
margin="none"
/>
</Grid2>
)}

{mediaType === PAGE_MODULES_MEDIA_TYPES.FILE && (
<>
Expand Down Expand Up @@ -129,7 +135,9 @@ const MediaRequestModule = ({ baseName, index, mediaFileTypes }) => {

MediaRequestModule.propTypes = {
baseName: PropTypes.string.isRequired,
index: PropTypes.number.isRequired
index: PropTypes.number.isRequired,
mediaFileTypes: PropTypes.array.isRequired,
isGlobal: PropTypes.bool
};

const mapStateToProps = ({ mediaUploadState }) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import DocumentDownloadModule from "./modules/page-template-document-download-mo
import MediaRequestModule from "./modules/page-template-media-request-module";
import { getAllMediaFileTypes } from "../../../../actions/media-file-type-actions";

const PageModules = ({ name = "modules", getAllMediaFileTypes }) => {
const PageModules = ({ name = "modules", getAllMediaFileTypes, isGlobal }) => {
const { values, setFieldValue, errors, submitCount } = useFormikContext();
const modules = getIn(values, name) || [];
const moduleErrors = getIn(errors, name);
Expand Down Expand Up @@ -129,7 +129,13 @@ const PageModules = ({ name = "modules", getAllMediaFileTypes }) => {
case PAGES_MODULE_KINDS.DOCUMENT:
return <DocumentDownloadModule baseName={name} index={index} />;
case PAGES_MODULE_KINDS.MEDIA:
return <MediaRequestModule baseName={name} index={index} />;
return (
<MediaRequestModule
baseName={name}
index={index}
isGlobal={isGlobal}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at this point isGlobal means nothing, can we change it to showUploadDeadline={!isGlobal} instead ? and add a default to isGlobal

/>
);
default:
return null;
}
Expand Down Expand Up @@ -225,7 +231,8 @@ const PageModules = ({ name = "modules", getAllMediaFileTypes }) => {
};

PageModules.propTypes = {
name: PropTypes.string
name: PropTypes.string,
isGlobal: PropTypes.bool
};

const mapStateToProps = () => ({});
Expand Down
36 changes: 35 additions & 1 deletion src/utils/__tests__/page-template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,30 @@ describe("normalizePageTemplateModules", () => {
const [result] = normalizePageTemplateModules([module]);
expect(result.max_file_size).toBe(2048);
});

it("should omit upload_deadline from payload when null (global template)", () => {
const module = {
kind: PAGES_MODULE_KINDS.MEDIA,
type: PAGE_MODULES_MEDIA_TYPES.FILE,
upload_deadline: null,
file_type_id: 3,
max_file_size: 1024
};
const [result] = normalizePageTemplateModules([module]);
expect(result).not.toHaveProperty("upload_deadline");
});

it("should omit upload_deadline from payload when undefined", () => {
const module = {
kind: PAGES_MODULE_KINDS.MEDIA,
type: PAGE_MODULES_MEDIA_TYPES.FILE,
upload_deadline: undefined,
file_type_id: 3,
max_file_size: 1024
};
const [result] = normalizePageTemplateModules([module]);
expect(result).not.toHaveProperty("upload_deadline");
});
});

describe("MEDIA kind — INPUT type", () => {
Expand All @@ -116,7 +140,17 @@ describe("normalizePageTemplateModules", () => {
type: PAGE_MODULES_MEDIA_TYPES.INPUT
};
const [result] = normalizePageTemplateModules([module]);
expect(result.upload_deadline).toBeUndefined();
expect(result).not.toHaveProperty("upload_deadline");
});

it("should omit upload_deadline from payload when null (global template)", () => {
const module = {
kind: PAGES_MODULE_KINDS.MEDIA,
type: PAGE_MODULES_MEDIA_TYPES.INPUT,
upload_deadline: null
};
const [result] = normalizePageTemplateModules([module]);
expect(result).not.toHaveProperty("upload_deadline");
});
});

Expand Down
4 changes: 4 additions & 0 deletions src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,12 @@ export const ONE_HUNDRED = 100;

export const COLUMN_4 = 4;

export const COLUMN_6 = 6;

export const COLUMN_8 = 8;

export const COLUMN_12 = 12;

export const DEFAULT_Z_INDEX = 1;

export const HIGH_Z_INDEX = 9999;
Expand Down
3 changes: 2 additions & 1 deletion src/utils/page-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export const normalizePageTemplateModules = (modules = [], timeZone = null) =>
normalizedModule.upload_deadline = timeZone
? moment.tz(module.upload_deadline, timeZone).unix()
: moment.utc(module.upload_deadline).unix();
} else {
delete normalizedModule.upload_deadline;
}

if (module.file_type_id) {
Expand Down Expand Up @@ -81,4 +83,3 @@ export const normalizePageTemplateModules = (modules = [], timeZone = null) =>

return normalizedModule;
});

Loading