From 39d266f70181337673c282905653df92cb4f8b2c Mon Sep 17 00:00:00 2001 From: William Petit Date: Wed, 26 Aug 2020 14:51:53 +0200 Subject: [PATCH] =?UTF-8?q?Cr=C3=A9ation/mise=20=C3=A0=20jour=20basique=20?= =?UTF-8?q?d'un=20DAD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DecisionSupportFilePanel.tsx | 8 +- .../ClarificationSection.tsx | 48 +++++--- .../DecisionSupportFilePage.tsx | 77 +++++++++--- .../DecisionSupportFilePage/MetadataPanel.tsx | 60 +++++++--- client/src/components/Navbar.tsx | 19 ++- client/src/gql/client.tsx | 40 ++++++- client/src/gql/mutations/dsf.tsx | 40 +++++++ client/src/gql/queries/decisions.tsx | 32 ----- client/src/gql/queries/dsf.tsx | 35 ++++++ client/src/hooks/useDebounce.tsx | 19 +++ client/src/util/date.ts | 4 + cmd/server/migration.go | 5 +- internal/graph/dsf_handler.go | 59 ++++++++++ internal/graph/mutation.graphql | 13 ++ internal/graph/mutation.resolvers.go | 8 ++ internal/graph/query.graphql | 18 +++ internal/graph/query.resolvers.go | 18 +++ internal/model/dsf.go | 19 +++ internal/model/dsf_repository.go | 111 ++++++++++++++++++ 19 files changed, 536 insertions(+), 97 deletions(-) create mode 100644 client/src/gql/mutations/dsf.tsx delete mode 100644 client/src/gql/queries/decisions.tsx create mode 100644 client/src/gql/queries/dsf.tsx create mode 100644 client/src/hooks/useDebounce.tsx create mode 100644 client/src/util/date.ts create mode 100644 internal/graph/dsf_handler.go create mode 100644 internal/model/dsf.go create mode 100644 internal/model/dsf_repository.go diff --git a/client/src/components/DashboardPage/DecisionSupportFilePanel.tsx b/client/src/components/DashboardPage/DecisionSupportFilePanel.tsx index cf3c80b..1fa31e8 100644 --- a/client/src/components/DashboardPage/DecisionSupportFilePanel.tsx +++ b/client/src/components/DashboardPage/DecisionSupportFilePanel.tsx @@ -3,11 +3,11 @@ import { DecisionSupportFile, DecisionSupportFileStatus } from '../../types/deci import { ItemPanel, TabDefinition, Item } from './ItemPanel'; import { useUserProfile } from '../../gql/queries/profile'; import { inWorkgroup } from '../../types/workgroup'; -import { useDecisions } from '../../gql/queries/decisions'; +import { useDecisionSupportFiles } from '../../gql/queries/dsf'; export function DecisionSupportFilePanel() { const { user } = useUserProfile(); - const { decisions } = useDecisions(); + const { decisionSupportFiles } = useDecisionSupportFiles(); const tabs: TabDefinition[] = [ { @@ -31,9 +31,9 @@ export function DecisionSupportFilePanel() { return ( item.id} diff --git a/client/src/components/DecisionSupportFilePage/ClarificationSection.tsx b/client/src/components/DecisionSupportFilePage/ClarificationSection.tsx index 5683bc6..264dfbc 100644 --- a/client/src/components/DecisionSupportFilePage/ClarificationSection.tsx +++ b/client/src/components/DecisionSupportFilePage/ClarificationSection.tsx @@ -1,23 +1,35 @@ import React, { FunctionComponent, useState, ChangeEvent, useEffect } from 'react'; import { DecisionSupportFileUpdaterProps } from './DecisionSupportFileUpdaterProps'; +import { useDebounce } from '../../hooks/useDebounce'; +import { asDate } from '../../util/date'; export interface ClarificationSectionProps extends DecisionSupportFileUpdaterProps {}; const ClarificationSectionName = 'clarification'; export const ClarificationSection: FunctionComponent = ({ dsf, updateDSF }) => { - const [ section, setSection ] = useState({ - objectives: '', - motivations: '', - scope: '', - nature: '', - deadline: undefined, - hasDeadline: false, + const [ state, setState ] = useState({ + changed: false, + section: { + objectives: '', + motivations: '', + scope: '', + nature: '', + deadline: undefined, + hasDeadline: false, + } }); useEffect(() => { - updateDSF({ ...dsf, sections: { ...dsf.sections, [ClarificationSectionName]: { ...section }} }) - }, [section]); + if (!state.changed) return; + updateDSF({ ...dsf, sections: { ...dsf.sections, [ClarificationSectionName]: { ...state.section }} }) + setState(state => ({ ...state, changed: false })); + }, [state.changed]); + + useEffect(() => { + if (!dsf.sections[ClarificationSectionName]) return; + setState(state => ({ ...state, changed: false, section: {...state.section, ...dsf.sections[ClarificationSectionName] }})); + }, [dsf.sections[ClarificationSectionName]]); const onTitleChange = (evt: ChangeEvent) => { const title = (evt.currentTarget).value; @@ -27,12 +39,12 @@ export const ClarificationSection: FunctionComponent const onSectionAttrChange = (attrName: string, evt: ChangeEvent) => { const target = evt.currentTarget; const value = target.hasOwnProperty('checked') ? target.checked : target.value; - setSection(section => ({ ...section, [attrName]: value })); + setState(state => ({ ...state, changed: true, section: {...state.section, [attrName]: value }})); }; const onDeadlineChange = (evt: ChangeEvent) => { const deadline = evt.currentTarget.valueAsDate; - setSection(section => ({ ...section, deadline })); + setState(state => ({ ...state, changed: true, section: { ...state.section, deadline }})); }; return ( @@ -48,7 +60,7 @@ export const ClarificationSection: FunctionComponent