From d4aa5357707c184f7e450465befeb693379ec5a9 Mon Sep 17 00:00:00 2001 From: Janicki Artur Date: Wed, 26 Sep 2018 13:27:25 +0200 Subject: [PATCH] init rich test editor for project Feature #14120 Arvados-DCO-1.1-Signed-off-by: Janicki Artur --- package.json | 5 ++-- src/components/text-field/text-field.tsx | 30 +++++++++++++++++++ src/store/projects/project-update-actions.ts | 6 ++-- .../form-fields/project-form-fields.tsx | 4 +-- typings/global.d.ts | 3 +- 5 files changed, 41 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 620ff5a6..175ef176 100644 --- a/package.json +++ b/package.json @@ -12,14 +12,15 @@ "axios": "0.18.0", "classnames": "2.2.6", "lodash": "4.17.10", - "react": "16.4.2", + "react": "16.5.2", "react-copy-to-clipboard": "5.0.1", - "react-dom": "16.4.2", + "react-dom": "16.5.2", "react-dropzone": "5.0.1", "react-redux": "5.0.7", "react-router": "4.3.1", "react-router-dom": "4.3.1", "react-router-redux": "5.0.0-alpha.9", + "react-rte": "0.16.1", "react-scripts-ts": "2.17.0", "react-splitter-layout": "3.0.1", "react-transition-group": "2.4.0", diff --git a/src/components/text-field/text-field.tsx b/src/components/text-field/text-field.tsx index b5671dbb..beea2ba3 100644 --- a/src/components/text-field/text-field.tsx +++ b/src/components/text-field/text-field.tsx @@ -6,6 +6,7 @@ import * as React from 'react'; import { WrappedFieldProps } from 'redux-form'; import { ArvadosTheme } from '~/common/custom-theme'; import { TextField as MaterialTextField, StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core'; +import RichTextEditor from 'react-rte'; type CssRules = 'textField'; @@ -27,3 +28,32 @@ export const TextField = withStyles(styles)((props: WrappedFieldProps & WithStyl fullWidth={true} {...props.input} />); + + +interface RichEditorTextFieldData { + label?: string; +} + +type RichEditorTextFieldProps = RichEditorTextFieldData & WrappedFieldProps & WithStyles; + +export const RichEditorTextField = withStyles(styles)( + class RichEditorTextField extends React.Component { + state = { + value: RichTextEditor.createValueFromString(this.props.input.value, 'html') + }; + + onChange = (value: any) => { + this.setState({ value }); + this.props.input.onChange(value.toString('html')); + } + + render() { + return ( + + ); + } + } +); \ No newline at end of file diff --git a/src/store/projects/project-update-actions.ts b/src/store/projects/project-update-actions.ts index afa2e35e..34ea42f5 100644 --- a/src/store/projects/project-update-actions.ts +++ b/src/store/projects/project-update-actions.ts @@ -10,6 +10,7 @@ import { getCommonResourceServiceError, CommonResourceServiceError } from "~/ser import { ServiceRepository } from "~/services/services"; import { ProjectResource } from '~/models/project'; import { ContextMenuResource } from "~/store/context-menu/context-menu-actions"; +import { getResource } from '~/store/resources/resources'; export interface ProjectUpdateFormDialogData { uuid: string; @@ -20,8 +21,9 @@ export interface ProjectUpdateFormDialogData { export const PROJECT_UPDATE_FORM_NAME = 'projectUpdateFormName'; export const openProjectUpdateDialog = (resource: ContextMenuResource) => - (dispatch: Dispatch) => { - dispatch(initialize(PROJECT_UPDATE_FORM_NAME, resource)); + (dispatch: Dispatch, getState: () => RootState) => { + const project = getResource(resource.uuid)(getState().resources); + dispatch(initialize(PROJECT_UPDATE_FORM_NAME, project)); dispatch(dialogActions.OPEN_DIALOG({ id: PROJECT_UPDATE_FORM_NAME, data: {} })); }; diff --git a/src/views-components/form-fields/project-form-fields.tsx b/src/views-components/form-fields/project-form-fields.tsx index 6446c763..5bf59c7e 100644 --- a/src/views-components/form-fields/project-form-fields.tsx +++ b/src/views-components/form-fields/project-form-fields.tsx @@ -4,7 +4,7 @@ import * as React from "react"; import { Field } from "redux-form"; -import { TextField } from "~/components/text-field/text-field"; +import { TextField, RichEditorTextField } from "~/components/text-field/text-field"; import { PROJECT_NAME_VALIDATION, PROJECT_DESCRIPTION_VALIDATION } from "~/validators/validators"; export const ProjectNameField = () => @@ -18,6 +18,6 @@ export const ProjectNameField = () => export const ProjectDescriptionField = () => ; diff --git a/typings/global.d.ts b/typings/global.d.ts index da8e4415..b9f1cc62 100644 --- a/typings/global.d.ts +++ b/typings/global.d.ts @@ -12,4 +12,5 @@ declare interface System { } declare var System: System; -declare module 'react-splitter-layout'; \ No newline at end of file +declare module 'react-splitter-layout'; +declare module 'react-rte'; \ No newline at end of file -- 2.30.2