From 8763c02eb652e865343445e84d3c4228211a5eba Mon Sep 17 00:00:00 2001 From: Maxym Borodenko Date: Mon, 20 Aug 2018 16:20:00 +0300 Subject: [PATCH] Display an error if descriptor has not been uploaded --- src/ui/catalog/Links.tsx | 2 +- src/ui/catalog/descriptor/DescriptorCard.tsx | 14 +++++- .../steps/import/index.tsx | 43 ++++++++++++++----- 3 files changed, 46 insertions(+), 13 deletions(-) diff --git a/src/ui/catalog/Links.tsx b/src/ui/catalog/Links.tsx index 56bb444..caf85d3 100644 --- a/src/ui/catalog/Links.tsx +++ b/src/ui/catalog/Links.tsx @@ -66,7 +66,7 @@ function DescriptorLink({ if (edit) { return ( - { children || descriptor.title } + { children || } ); } else if ((descriptor.state === PublishState.PUBLISHED) || (descriptor._permissions && descriptor._permissions.write)) { diff --git a/src/ui/catalog/descriptor/DescriptorCard.tsx b/src/ui/catalog/descriptor/DescriptorCard.tsx index 5cbbdf7..cf21434 100644 --- a/src/ui/catalog/descriptor/DescriptorCard.tsx +++ b/src/ui/catalog/descriptor/DescriptorCard.tsx @@ -79,6 +79,7 @@ interface IDescriptorCardProps extends React.ClassAttributes { descriptor: Descriptor; className?: string; classes: any; + errorMessage?: string; selectedProps: { disabled: boolean, selectable: boolean, @@ -136,11 +137,17 @@ const styles = (theme) => ({ // padding: '20px', // height: 'auto', }, + errorMessage: { + display: 'block', + marginTop: '12px', + color: 'red', + wordBreak: 'break-word', + }, btnBlue: theme.buttons.blue, btnDefault: theme.buttons.default, }); -const DescriptorCard = ({complete = true, compact, descriptor, classes, className, selectedProps, actions, ...other}: IDescriptorCardProps & ICardProps) => { +const DescriptorCard = ({complete = true, compact, descriptor, classes, className, selectedProps, actions, errorMessage, ...other}: IDescriptorCardProps & ICardProps) => { const onClick = (select) => () => { const {onSelect, onUnselect} = selectedProps; @@ -169,7 +176,7 @@ const DescriptorCard = ({complete = true, compact, descriptor, classes, classNam { descriptor.title || 'Untitled' } - : descriptor.title || 'Untitled' + : || 'Untitled' } /> @@ -206,6 +213,9 @@ const DescriptorCard = ({complete = true, compact, descriptor, classes, classNam )) } ) } + { errorMessage && +
{ errorMessage }
+ }
diff --git a/src/ui/pages/descriptorlist/descriptorlist-stepper/steps/import/index.tsx b/src/ui/pages/descriptorlist/descriptorlist-stepper/steps/import/index.tsx index 9ec6f66..393a6b3 100644 --- a/src/ui/pages/descriptorlist/descriptorlist-stepper/steps/import/index.tsx +++ b/src/ui/pages/descriptorlist/descriptorlist-stepper/steps/import/index.tsx @@ -30,7 +30,8 @@ class ImportDescriptorsStep extends React.Component { public constructor(props: any) { super(props); this.state = { - uploadedDescriptors: null, + uploadedDescriptors: [], + nonSavedDescriptors: [], }; } @@ -38,12 +39,6 @@ class ImportDescriptorsStep extends React.Component { this.props.onGotoStep(id); } - protected handleDescriptors = (parsedDescriptors: Descriptor[]) => { - this.setState({ ...this.state, uploadedDescriptors: parsedDescriptors }, () => { - this.importDescriptors(parsedDescriptors); - }); - } - private importDescriptors = async (d: Descriptor[]) => { const {descriptorList, importDescriptor, addDescriptorsToDescriptorList} = this.props; const imported: string[] = []; @@ -54,10 +49,19 @@ class ImportDescriptorsStep extends React.Component { descriptor.owner = descriptorList.owner; const r = importDescriptor(descriptor) .then((saved) => { - log('Imported', saved); + const descriptors = this.state.uploadedDescriptors; + const alreadyInList = descriptors.map((d) => d.uuid).indexOf(saved.uuid) !== -1; + if (!alreadyInList) { + descriptors.push(saved); + this.setState({ uploadedDescriptors: descriptors }); + } + imported.push(saved.uuid); }) .catch((error) => { + const descriptors = this.state.nonSavedDescriptors; + descriptors.push({ descriptor, error: error.response.data.error }); + this.setState({ nonSavedDescriptors: descriptors }); log(`Descriptor import error`, error); }); await r; @@ -70,12 +74,14 @@ class ImportDescriptorsStep extends React.Component { public render() { const { location, stillLoading, onDelete, onPublish } = this.props; + const notSaved: number = this.state.nonSavedDescriptors.length; + return ( - - { this.state.uploadedDescriptors ? ( + + { this.state.uploadedDescriptors.length > 0 ? (

{ `Uploaded ${this.state.uploadedDescriptors.length} descriptor definitions` }

@@ -90,6 +96,23 @@ class ImportDescriptorsStep extends React.Component { ) : (

No descriptors uploaded

) } + + { notSaved > 0 && ( +
+

{ `${notSaved} error${notSaved !== 1 ? 's' : '' } due uploading` }

+ + + { this.state.nonSavedDescriptors.map((d, index) => ( + + + + )) } + +
+ ) } ); -- GitLab