Commit 966903dc authored by Maxym Borodenko's avatar Maxym Borodenko
Browse files

Merge branch 'api-390-multiple-matching-descriptors' into 'master'

Search for matching descriptors returns a Descriptor[]

See merge request genesys-pgr/genesys-ui!153
parents 2d755b5e c9a70de5
......@@ -16,7 +16,7 @@ import StepperTemplate from 'ui/common/stepper/StepperTemplate';
interface IPastingDescriptorsStepProps extends React.ClassAttributes<any> {
addDescriptorsToDataset: (dataset: Dataset, descriptorUuids: string[]) => void;
searchMatchingDescriptor: (descriptor: Descriptor) => Promise<Descriptor>;
searchMatchingDescriptor: (descriptor: Descriptor) => Promise<Descriptor[]>;
}
class PastingDescriptorsStep extends StepperTemplate<IPastingDescriptorsStepProps> {
......@@ -70,14 +70,16 @@ class PastingDescriptorsStep extends StepperTemplate<IPastingDescriptorsStepProp
if (d && d.length > 0) {
for (const importedDescriptor of d) {
searchMatchingDescriptor(importedDescriptor)
.then((matching) => {
.then((matches) => {
const descriptors = this.state.matchingDescriptors;
const alreadyInList = descriptors.map((d) => d.uuid).indexOf(matching.uuid) !== -1;
matches.filter((m) => m != null).forEach((matching) => {
const alreadyInList = descriptors.map((d) => d.uuid).indexOf(matching.uuid) !== -1;
if (!alreadyInList) {
descriptors.push(matching);
this.setState({ ...this.state, matchingDescriptors: descriptors });
}
if (!alreadyInList) {
descriptors.push(matching);
}
});
this.setState({ ...this.state, matchingDescriptors: descriptors });
})
.catch((error) => {
log(`Error`, error);
......
......@@ -304,7 +304,7 @@ class DescriptorService {
*
* @param source source
*/
public static searchMatchingDescriptor(source: Descriptor): Promise<Descriptor> {
public static searchMatchingDescriptor(source: Descriptor): Promise<Descriptor[]> {
const apiUrl = URL_SEARCH_MATCHING_DESCRIPTOR;
// console.log(`Fetching from ${apiUrl}`);
......@@ -314,7 +314,7 @@ class DescriptorService {
url: apiUrl,
method: 'POST',
...content,
}).then(({ data }) => data as Descriptor);
}).then(({ data }) => data as Descriptor[]);
}
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment