diff --git a/package.json b/package.json index ecdb0dd69..28f4a83ce 100644 --- a/package.json +++ b/package.json @@ -93,7 +93,7 @@ "moment-duration-format": "^2.3.2", "moment-timezone": "^0.5.33", "mui-color-input": "^9.0.0", - "openstack-uicore-foundation": "5.0.38", + "openstack-uicore-foundation": "5.0.39", "p-limit": "^6.1.0", "path-browserify": "^1.0.1", "postcss-loader": "^6.2.1", diff --git a/src/actions/media-upload-actions.js b/src/actions/media-upload-actions.js index 648398b3b..074867e16 100644 --- a/src/actions/media-upload-actions.js +++ b/src/actions/media-upload-actions.js @@ -20,15 +20,13 @@ import { createAction, stopLoading, startLoading, - showMessage, - showSuccessMessage, - authErrorHandler, + snackbarErrorHandler, + snackbarSuccessHandler, escapeFilterValue, fetchResponseHandler, fetchErrorHandler } from "openstack-uicore-foundation/lib/utils/actions"; -import debounce from "lodash/debounce" -import history from "../history"; +import debounce from "lodash/debounce"; import { getAccessTokenSafely } from "../utils/methods"; import { DEBOUNCE_WAIT, DEFAULT_PER_PAGE } from "../utils/constants"; @@ -89,9 +87,9 @@ export const getMediaUploads = createAction(REQUEST_MEDIA_UPLOADS), createAction(RECEIVE_MEDIA_UPLOADS), `${window.API_BASE_URL}/api/v1/summits/${currentSummit.id}/media-upload-types`, - authErrorHandler, - { order, orderDir, term } - )(params)(dispatch).then(() => { + snackbarErrorHandler, + { order, orderDir, term, perPage } + )(params)(dispatch).finally(() => { dispatch(stopLoading()); }); }; @@ -111,94 +109,89 @@ export const getMediaUpload = (mediaUploadId) => async (dispatch, getState) => { null, createAction(RECEIVE_MEDIA_UPLOAD), `${window.API_BASE_URL}/api/v1/summits/${currentSummit.id}/media-upload-types/${mediaUploadId}`, - authErrorHandler - )(params)(dispatch).then(() => { + snackbarErrorHandler + )(params)(dispatch).finally(() => { dispatch(stopLoading()); }); }; -export const queryMediaUploads = debounce( - async (summitId, input, callback) => { - const accessToken = await getAccessTokenSafely(); - const apiUrl = URI( - `${window.API_BASE_URL}/api/v1/summits/${summitId}/media-upload-types` - ); - - apiUrl.addQuery("access_token", accessToken); - apiUrl.addQuery("order", "name"); - apiUrl.addQuery("expand", "type"); - apiUrl.addQuery("per_page", DEFAULT_PER_PAGE); - - if (input) { - input = escapeFilterValue(input); - apiUrl.addQuery("filter[]", `name=@${input}`); - } +export const queryMediaUploads = debounce(async (summitId, input, callback) => { + const accessToken = await getAccessTokenSafely(); + const apiUrl = URI( + `${window.API_BASE_URL}/api/v1/summits/${summitId}/media-upload-types` + ); + + apiUrl.addQuery("access_token", accessToken); + apiUrl.addQuery("order", "name"); + apiUrl.addQuery("expand", "type"); + apiUrl.addQuery("per_page", DEFAULT_PER_PAGE); + + if (input) { + input = escapeFilterValue(input); + apiUrl.addQuery("filter[]", `name=@${input}`); + } - fetch(apiUrl.toString()) - .then(fetchResponseHandler) - .then((json) => { - const options = [...json.data]; - callback(options); - }) - .catch(fetchErrorHandler); - }, - DEBOUNCE_WAIT -); + fetch(apiUrl.toString()) + .then(fetchResponseHandler) + .then((json) => { + const options = [...json.data]; + callback(options); + }) + .catch(fetchErrorHandler); +}, DEBOUNCE_WAIT); export const resetMediaUploadForm = () => (dispatch) => { dispatch(createAction(RESET_MEDIA_UPLOAD_FORM)({})); }; -export const saveMediaUpload = - (entity, noAlert = false) => - async (dispatch, getState) => { - const { currentSummitState } = getState(); - const accessToken = await getAccessTokenSafely(); - const { currentSummit } = currentSummitState; +export const saveMediaUpload = (entity) => async (dispatch, getState) => { + const { currentSummitState } = getState(); + const accessToken = await getAccessTokenSafely(); + const { currentSummit } = currentSummitState; - dispatch(startLoading()); + dispatch(startLoading()); - const normalizedEntity = normalizeEntity(entity); - const params = { access_token: accessToken }; + const normalizedEntity = normalizeEntity(entity); + const params = { access_token: accessToken }; - if (entity.id) { - putRequest( - createAction(UPDATE_MEDIA_UPLOAD), - createAction(MEDIA_UPLOAD_UPDATED), - `${window.API_BASE_URL}/api/v1/summits/${currentSummit.id}/media-upload-types/${entity.id}`, - normalizedEntity, - authErrorHandler, - entity - )(params)(dispatch).then(() => { - if (!noAlert) - dispatch(showSuccessMessage(T.translate("media_upload.saved"))); - else dispatch(stopLoading()); - }); - } else { - const successMessage = { - title: T.translate("general.done"), - html: T.translate("media_upload.created"), - type: "success" - }; - - postRequest( - createAction(UPDATE_MEDIA_UPLOAD), - createAction(MEDIA_UPLOAD_ADDED), - `${window.API_BASE_URL}/api/v1/summits/${currentSummit.id}/media-upload-types`, - normalizedEntity, - authErrorHandler, - entity - )(params)(dispatch).then((payload) => { + if (entity.id) { + return putRequest( + createAction(UPDATE_MEDIA_UPLOAD), + createAction(MEDIA_UPLOAD_UPDATED), + `${window.API_BASE_URL}/api/v1/summits/${currentSummit.id}/media-upload-types/${entity.id}`, + normalizedEntity, + snackbarErrorHandler, + entity + )(params)(dispatch) + .then(() => { dispatch( - showMessage(successMessage, () => { - history.push( - `/app/summits/${currentSummit.id}/media-uploads/${payload.response.id}` - ); + snackbarSuccessHandler({ + title: T.translate("general.success"), + html: T.translate("media_upload.saved") }) ); - }); - } - }; + }) + .finally(() => dispatch(stopLoading())); + } + + return postRequest( + createAction(UPDATE_MEDIA_UPLOAD), + createAction(MEDIA_UPLOAD_ADDED), + `${window.API_BASE_URL}/api/v1/summits/${currentSummit.id}/media-upload-types`, + normalizedEntity, + snackbarErrorHandler, + entity + )(params)(dispatch) + .then(() => { + dispatch( + snackbarSuccessHandler({ + title: T.translate("general.success"), + html: T.translate("media_upload.created") + }) + ); + }) + .finally(() => dispatch(stopLoading())); +}; export const linkToPresentationType = (mediaUpload, presentationTypeId) => async (dispatch, getState) => { @@ -215,8 +208,8 @@ export const linkToPresentationType = createAction(MEDIA_UPLOAD_LINKED)({ mediaUpload }), `${window.API_BASE_URL}/api/v1/summits/${currentSummit.id}/media-upload-types/${mediaUpload.id}/presentation-types/${presentationTypeId}`, null, - authErrorHandler - )(params)(dispatch).then(() => { + snackbarErrorHandler + )(params)(dispatch).finally(() => { dispatch(stopLoading()); }); }; @@ -236,8 +229,8 @@ export const unlinkFromPresentationType = createAction(MEDIA_UPLOAD_UNLINKED)({ mediaUploadId }), `${window.API_BASE_URL}/api/v1/summits/${currentSummit.id}/media-upload-types/${mediaUploadId}/presentation-types/${presentationTypeId}`, null, - authErrorHandler - )(params)(dispatch).then(() => { + snackbarErrorHandler + )(params)(dispatch).finally(() => { dispatch(stopLoading()); }); }; @@ -257,10 +250,8 @@ export const deleteMediaUpload = createAction(MEDIA_UPLOAD_DELETED)({ mediaUploadId }), `${window.API_BASE_URL}/api/v1/summits/${currentSummit.id}/media-upload-types/${mediaUploadId}`, null, - authErrorHandler - )(params)(dispatch).then(() => { - dispatch(stopLoading()); - }); + snackbarErrorHandler + )(params)(dispatch); }; export const copyMediaUploads = (summitId) => async (dispatch, getState) => { @@ -272,16 +263,23 @@ export const copyMediaUploads = (summitId) => async (dispatch, getState) => { const params = { access_token: accessToken }; - postRequest( + return postRequest( null, createAction(MEDIA_UPLOADS_COPIED), `${window.API_BASE_URL}/api/v1/summits/${summitId}/media-upload-types/all/clone/${currentSummit.id}`, null, - authErrorHandler - )(params)(dispatch).then(() => { - dispatch(stopLoading()); - dispatch(getMediaUploads()); - }); + snackbarErrorHandler + )(params)(dispatch) + .then(() => { + dispatch( + snackbarSuccessHandler({ + title: T.translate("general.success"), + html: T.translate("media_upload.media_uploads_copied") + }) + ); + dispatch(getMediaUploads()); + }) + .finally(() => dispatch(stopLoading())); }; const normalizeEntity = (entity) => { diff --git a/src/components/forms/media-upload-form.js b/src/components/forms/media-upload-form.js deleted file mode 100644 index f73670a6c..000000000 --- a/src/components/forms/media-upload-form.js +++ /dev/null @@ -1,312 +0,0 @@ -/** - * Copyright 2019 OpenStack Foundation - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * */ - -import React from "react"; -import T from "i18n-react/dist/i18n-react"; -import "awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css"; -import Dropdown from "openstack-uicore-foundation/lib/components/inputs/dropdown" -import Input from "openstack-uicore-foundation/lib/components/inputs/text-input"; -import TextEditorV3 from "openstack-uicore-foundation/lib/components/inputs/editor-input-v3"; -import { isEmpty, scrollToError, shallowEqual } from "../../utils/methods"; - -class MediaUploadForm extends React.Component { - constructor(props) { - super(props); - - this.state = { - entity: { ...props.entity }, - errors: props.errors - }; - - this.handleChange = this.handleChange.bind(this); - this.handleSubmit = this.handleSubmit.bind(this); - } - - componentDidUpdate(prevProps) { - const state = {}; - scrollToError(this.props.errors); - - if (!shallowEqual(prevProps.entity, this.props.entity)) { - state.entity = { ...this.props.entity }; - state.errors = {}; - } - - if (!shallowEqual(prevProps.errors, this.props.errors)) { - state.errors = { ...this.props.errors }; - } - - if (!isEmpty(state)) { - this.setState({ ...this.state, ...state }); - } - } - - handleChange(ev) { - const entity = { ...this.state.entity }; - const errors = { ...this.state.errors }; - let { value, id } = ev.target; - - if (ev.target.type === "checkbox") { - value = ev.target.checked; - } - - errors[id] = ""; - entity[id] = value; - this.setState({ entity, errors }); - } - - handleSubmit(ev) { - ev.preventDefault(); - - this.props.onSubmit(this.state.entity); - } - - hasErrors(field) { - const { errors } = this.state; - if (field in errors) { - return errors[field]; - } - - return ""; - } - - render() { - const { entity } = this.state; - const { currentSummit, mediaFileTypes } = this.props; - - const private_storage_ddl = [ - { value: "None", label: "None" }, - { value: "DropBox", label: "DropBox" }, - { value: "Local", label: "Local" } - ]; - - const public_storage_ddl = [ - { value: "None", label: "None" }, - { value: "Local", label: "Local" } - ]; - - if (window.PUBLIC_STORAGES.includes("S3")) - public_storage_ddl.push({ value: "S3", label: "S3" }); - - if (window.PUBLIC_STORAGES.includes("SWIFT")) - public_storage_ddl.push({ value: "Swift", label: "Swift" }); - - const presentation_types_ddl = currentSummit.event_types - .filter((t) => t.class_name === "PresentationType") - .map((t) => ({ value: t.id, label: t.name })); - - const mediaFileTypesDDL = mediaFileTypes.map((mft) => ({ - value: mft.id, - label: mft.name - })); - - return ( -
- -
-
- - -
-
-
-
- - -
-
- - -
-
-