Commit 4ef70934 authored by Matija Obreza's avatar Matija Obreza

Fix: Allow using all published + owned descriptors

parent be159f46
Pipeline #7702 passed with stages
in 4 minutes and 23 seconds
......@@ -5,7 +5,7 @@ import { bindActionCreators } from 'redux';
import { log } from 'utilities/debug';
import { parse } from 'query-string';
import { listMyDescriptors as listMatchingDescriptors } from 'descriptors/actions/dashboard';
import { listAccessibleDescriptors as listMatchingDescriptors } from 'descriptors/actions/dashboard';
import { addDescriptorsToDataset, removeDescriptorsFromDataset } from 'datasets/actions/editor';
import Descriptor from 'model/catalog/Descriptor';
......
......@@ -10,7 +10,7 @@ import DescriptorFilter from 'model/catalog/DescriptorFilter';
import { listCrops } from 'actions/crop';
import DescriptorPicker from 'descriptors/ui/c/DescriptorPicker';
import { importDescriptor } from 'descriptors/actions/editor';
import { listMyDescriptors as listMatchingDescriptors } from 'descriptors/actions/dashboard';
import { listAccessibleDescriptors as listMatchingDescriptors } from 'descriptors/actions/dashboard';
import { Page, Pagination } from 'model/common.model';
import {
loadDescriptorList, saveDescriptorList, addDescriptorsToDescriptorList, removeDescriptorsFromDescriptorList,
......
......@@ -49,6 +49,27 @@ export const createDescriptor = () => (dispatch) => {
return dispatch(push(`/dashboard/descriptors/edit`));
};
export function listAccessibleDescriptors(page?, results?, sortBy?: string[], filter?: string | DescriptorFilter, order?) {
return (dispatch, getState) => {
dispatch(loadingDescriptors(page, results, sortBy, filter, order));
return DescriptorService.listAccessibleDescriptors(filter, { page, size: results, properties: sortBy, direction: order })
.then((paged) => {
dereferenceReferences(paged.content, 'owner', (o) => o as Partner);
if (paged.number === 0) {
dispatch(receiveDescriptorPage(paged, page, results, sortBy, filter, order));
} else {
dispatch(appendDescriptorPage(paged, page, results, sortBy, filter, order));
}
return dispatch(addFilterCode(paged.filterCode, paged.filter));
})
.catch((error) => {
log('Error', error);
});
};
}
export function listMyDescriptors(page?, results?, sortBy?: string[], filter?: string | DescriptorFilter, order?) {
return (dispatch, getState) => {
......
......@@ -16,6 +16,7 @@ const URL_EXPORT_DESCRIPTORS = `/api/v1/descriptor/export`;
const URL_GET_OTHER_DESCRIPTOR_INFO = UrlTemplate.parse(`/api/v1/descriptor/extra/{UUID}`);
const URL_REVIEW_DESCRIPTOR = `/api/v1/descriptor/for-review`;
const URL_LIST_DESCRIPTORS = `/api/v1/descriptor/list`;
const URL_LIST_ACCESSIBLE_DESCRIPTORS = `/api/v1/descriptor/list-accessible`;
const URL_MY_DESCRIPTORS = `/api/v1/descriptor/list-mine`;
const URL_LIST_DESCRIPTORS_BY_SHORT = UrlTemplate.parse(`/api/v1/descriptor/list/{filterCode}`);
const URL_REJECT_DESCRIPTOR = `/api/v1/descriptor/reject`;
......@@ -198,6 +199,32 @@ class DescriptorService {
}).then(({ data }) => data as FilteredPage<Descriptor>);
}
/**
* listAccessibleDescriptors at /api/v1/descriptor/list-accessible
*
* @param filter filter
* @param page undefined
*/
public static listAccessibleDescriptors(filter: string | DescriptorFilter, page?: IPageRequest): Promise<FilteredPage<Descriptor>> {
const qs = page && QueryString.stringify({
f: typeof filter === 'string' ? filter : undefined,
p: page.page || undefined,
l: page.size || undefined,
d: page.direction && page.direction.length && page.direction || undefined,
s: page.properties || undefined,
}, {});
const apiUrl = URL_LIST_ACCESSIBLE_DESCRIPTORS + (qs ? `?${qs}` : '');
// console.log(`Fetching from ${apiUrl}`);
const content = { data: typeof filter === 'string' ? null : { ...filter } };
return axiosBackend.request({
url: apiUrl,
method: 'POST',
...content,
}).then(({ data }) => data as FilteredPage<Descriptor>);
}
/**
* myDescriptors at /api/v1/descriptor/list-mine
*
......@@ -206,7 +233,7 @@ class DescriptorService {
*/
public static myDescriptors(filter: string | DescriptorFilter, page?: IPageRequest): Promise<FilteredPage<Descriptor>> {
const qs = QueryString.stringify({
const qs = page && QueryString.stringify({
f: typeof filter === 'string' ? filter : undefined,
p: page.page || undefined,
l: page.size || undefined,
......
Markdown is supported
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