diff --git a/CommonServer/Services/DatabaseService.ts b/CommonServer/Services/DatabaseService.ts index c12ac83b74..96abd7b53b 100644 --- a/CommonServer/Services/DatabaseService.ts +++ b/CommonServer/Services/DatabaseService.ts @@ -365,8 +365,8 @@ class DatabaseService { return createBy; } - private serializeCreate( - data: TBaseModel | QueryDeepPartialEntity + private SanitizeCreateOrUpdate( + data: TBaseModel | QueryDeepPartialEntity, props: DatabaseCommonInteractionProps, isUpdate: boolean = false ): TBaseModel | QueryDeepPartialEntity { const columns: Columns = this.model.getTableColumns(); @@ -419,6 +419,12 @@ class DatabaseService { } } + // check createByUserId. + + if (!isUpdate && props.userId) { + (data as any)['createdByUserId'] = props.userId; + } + return data; } @@ -461,7 +467,7 @@ class DatabaseService { createBy = await this.checkUniqueColumnBy(createBy); // serialize. - createBy.data = this.serializeCreate(createBy.data) as TBaseModel; + createBy.data = this.SanitizeCreateOrUpdate(createBy.data, createBy.props) as TBaseModel; try { createBy.data = await this.getRepository().save(createBy.data); @@ -1386,8 +1392,8 @@ class DatabaseService { beforeUpdateBy.query ); const data: QueryDeepPartialEntity = - this.serializeCreate( - beforeUpdateBy.data + this.SanitizeCreateOrUpdate( + beforeUpdateBy.data, updateBy.props, true ) as QueryDeepPartialEntity; const items: Array = await this._findBy({ diff --git a/CommonUI/package-lock.json b/CommonUI/package-lock.json index 16c58b8c34..2ebc02fec9 100644 --- a/CommonUI/package-lock.json +++ b/CommonUI/package-lock.json @@ -30,6 +30,7 @@ "react-color": "^2.19.3", "react-dom": "^18.1.0", "react-icons": "^4.4.0", + "react-markdown": "^8.0.3", "react-modern-drawer": "^1.1.1", "react-router": "^6.3.0", "react-router-dom": "^6.3.0", @@ -39,6 +40,7 @@ "reactstrap": "^9.1.1", "redux": "^4.2.0", "rehype-sanitize": "^5.0.1", + "remark-gfm": "^3.0.1", "universal-cookie": "^4.0.4", "use-async-effect": "^2.2.6", "web-vitals": "^2.1.4", diff --git a/CommonUI/package.json b/CommonUI/package.json index d5162d15a1..f6a9851536 100644 --- a/CommonUI/package.json +++ b/CommonUI/package.json @@ -32,6 +32,7 @@ "react-color": "^2.19.3", "react-dom": "^18.1.0", "react-icons": "^4.4.0", + "react-markdown": "^8.0.3", "react-modern-drawer": "^1.1.1", "react-router": "^6.3.0", "react-router-dom": "^6.3.0", @@ -41,6 +42,7 @@ "reactstrap": "^9.1.1", "redux": "^4.2.0", "rehype-sanitize": "^5.0.1", + "remark-gfm": "^3.0.1", "universal-cookie": "^4.0.4", "use-async-effect": "^2.2.6", "web-vitals": "^2.1.4", diff --git a/CommonUI/src/Components/Detail/Detail.tsx b/CommonUI/src/Components/Detail/Detail.tsx index ffa0f2b95e..8631ee7fae 100644 --- a/CommonUI/src/Components/Detail/Detail.tsx +++ b/CommonUI/src/Components/Detail/Detail.tsx @@ -7,6 +7,7 @@ import FieldType from '../Types/FieldType'; import HiddenText from '../HiddenText/HiddenText'; import { JSONObject } from 'Common/Types/JSON'; import _ from 'lodash'; +import MarkdownViewer from '../Markdown.tsx/MarkdownViewer'; export interface ComponentProps { item: JSONObject; @@ -16,6 +17,12 @@ export interface ComponentProps { } const Detail: Function = (props: ComponentProps): ReactElement => { + + + const getMarkdownViewer = (text: string): ReactElement => { + return + } + const getField: Function = (field: Field, index: number): ReactElement => { const fieldKey: string = field.key; @@ -43,6 +50,10 @@ const Detail: Function = (props: ComponentProps): ReactElement => { ); } + if (field.fieldType === FieldType.Markdown) { + data = getMarkdownViewer(data as string); + } + if (field.fieldType === FieldType.HiddenText) { data = ( diff --git a/CommonUI/src/Components/Markdown.tsx/Markdown.tsx b/CommonUI/src/Components/Markdown.tsx/MarkdownEditor.tsx similarity index 95% rename from CommonUI/src/Components/Markdown.tsx/Markdown.tsx rename to CommonUI/src/Components/Markdown.tsx/MarkdownEditor.tsx index 5b2eac0991..93bfa4fb70 100644 --- a/CommonUI/src/Components/Markdown.tsx/Markdown.tsx +++ b/CommonUI/src/Components/Markdown.tsx/MarkdownEditor.tsx @@ -18,7 +18,7 @@ export interface ComponentProps { onBlur?: (() => void) | undefined; } -const Markdown: FunctionComponent = ( +const MarkdownEditor: FunctionComponent = ( props: ComponentProps ): ReactElement => { const [value, setValue] = useState(''); @@ -80,4 +80,4 @@ const Markdown: FunctionComponent = ( ); }; -export default Markdown; +export default MarkdownEditor; diff --git a/CommonUI/src/Components/Markdown.tsx/MarkdownViewer.tsx b/CommonUI/src/Components/Markdown.tsx/MarkdownViewer.tsx new file mode 100644 index 0000000000..89649ecd19 --- /dev/null +++ b/CommonUI/src/Components/Markdown.tsx/MarkdownViewer.tsx @@ -0,0 +1,27 @@ +import React, { + FunctionComponent, + ReactElement, +} from 'react'; + +// https://github.com/remarkjs/react-markdown +import ReactMarkdown from 'react-markdown'; + +// https://github.com/remarkjs/remark-gfm +import remarkGfm from 'remark-gfm' + +export interface ComponentProps { + text: string +} + +const MarkdownViewer: FunctionComponent = ( + props: ComponentProps +): ReactElement => { + + return ( +
+ +
+ ); +}; + +export default MarkdownViewer; diff --git a/Dashboard/src/Pages/Incidents/View/InternalNote.tsx b/Dashboard/src/Pages/Incidents/View/InternalNote.tsx index b662482127..662cf71eb3 100644 --- a/Dashboard/src/Pages/Incidents/View/InternalNote.tsx +++ b/Dashboard/src/Pages/Incidents/View/InternalNote.tsx @@ -66,6 +66,7 @@ const IncidentDelete: FunctionComponent = ( id="table-incident-internal-note" isDeleteable={true} isCreateable={true} + isEditable={true} isViewable={false} query={{ incidentId: modelId, @@ -110,7 +111,7 @@ const IncidentDelete: FunctionComponent = ( field: { note: true, }, - title: 'Internal Note', + title: 'Note', type: FieldType.Markdown, }, { @@ -123,7 +124,7 @@ const IncidentDelete: FunctionComponent = ( title: 'Created By', type: FieldType.Entity, getElement: (item: JSONObject): ReactElement => { - if (item['user']) { + if (item['createdByUser']) { return (