Commit 19149319 authored by Matija Obreza's avatar Matija Obreza

Fix: Allow using all published + owned descriptors

Signed-off-by: Matija Obreza's avatarMatija Obreza <matija.obreza@croptrust.org>
parent 5783d3fb
......@@ -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 } from 'descriptors/actions/dashboard';
import { addDescriptorsToDataset, removeDescriptorsFromDataset } from 'datasets/actions/editor';
import Descriptor from 'model/catalog/Descriptor';
......@@ -18,7 +18,7 @@ import StepperTemplate from 'ui/common/stepper/StepperTemplate';
class Traits extends StepperTemplate<any> {
protected static needs = [
() => listMatchingDescriptors(),
() => listAccessibleDescriptors(),
];
protected addDescriptor = (descriptor: Descriptor) => {
const { item: dataset, addDescriptorsToDataset } = this.props;
......@@ -65,7 +65,7 @@ class Traits extends StepperTemplate<any> {
}
protected renderContent = () => this.props.item ? (
<DescriptorPicker
loadDescriptors={ listMatchingDescriptors }
loadDescriptors={ this.props.listAccessibleDescriptors }
matchingDescriptors={ this.props.matchingDescriptors }
currentDescriptors={ this.props.item.descriptors }
onAddDescriptor={ this.addDescriptor }
......@@ -81,9 +81,9 @@ class Traits extends StepperTemplate<any> {
) : null
public componentWillMount() {
const {listMatchingDescriptors, matchingDescriptors } = this.props;
const {listAccessibleDescriptors, matchingDescriptors } = this.props;
if (!matchingDescriptors) {
listMatchingDescriptors();
listAccessibleDescriptors();
}
}
}
......@@ -100,7 +100,7 @@ const mapStateToProps = (state, ownProps) => ({
});
const mapDispatchToProps = (dispatch) => bindActionCreators({
listMatchingDescriptors,
listAccessibleDescriptors,
addDescriptorsToDataset,
removeDescriptorsFromDataset,
loadCrops,
......
......@@ -10,7 +10,7 @@ import DescriptorFilter from 'model/catalog/DescriptorFilter';
import { loadCrops } from 'crop/actions/public';
import DescriptorPicker from 'descriptors/ui/c/DescriptorPicker';
import { importDescriptor } from 'descriptors/actions/editor';
import { listMyDescriptors as listMatchingDescriptors } from 'descriptors/actions/dashboard';
import { listAccessibleDescriptors } from 'descriptors/actions/dashboard';
import Page, { IPageRequest } from 'model/Page';
import Pagination from 'model/Pagination';
import {
......@@ -24,7 +24,7 @@ interface IDescriptorListProps extends React.ClassAttributes<any> {
history: any;
pagination?: Pagination<DescriptorFilter>;
matchingDescriptors: Page<Descriptor>;
listMatchingDescriptors: (page?: IPageRequest, filter?: DescriptorFilter) => void;
listAccessibleDescriptors: (page?: IPageRequest, filter?: DescriptorFilter) => void;
addDescriptorToDescriptorList: any;
addDescriptorsToDescriptorList: (descriptorList: DescriptorList, descriptorUuids: string[]) => void;
removeDescriptorsFromDescriptorList: (descriptorList: DescriptorList, descriptorUuids: string[]) => void;
......@@ -35,11 +35,11 @@ interface IDescriptorListProps extends React.ClassAttributes<any> {
class SelectDescriptorsStep extends StepperTemplate<IDescriptorListProps> {
protected static needs = [
({ search }) => listMatchingDescriptors({page: parse(search).p, size: parse(search).l, properties: parse(search).s, direction: parse(search).d }),
({ search }) => listAccessibleDescriptors({ page: parse(search).p, size: parse(search).l, properties: parse(search).s, direction: parse(search).d }),
];
protected renderContent = () => (
<DescriptorPicker
loadDescriptors={ this.props.listMatchingDescriptors }
loadDescriptors={ this.props.listAccessibleDescriptors }
matchingDescriptors={ this.props.matchingDescriptors }
currentDescriptors={ this.props.item && this.props.item.descriptors }
onAddDescriptor={ this.addDescriptor }
......@@ -120,7 +120,7 @@ const mapDispatchToProps = (dispatch) => bindActionCreators({
importDescriptor,
removeDescriptorFromDescriptorList,
addDescriptorToDescriptorList,
listMatchingDescriptors,
listAccessibleDescriptors,
loadCrops,
addDescriptorsToDescriptorList,
removeDescriptorsFromDescriptorList,
......
......@@ -56,7 +56,7 @@ export function listMyDescriptors(page?: IPageRequest, filter?: string | Descrip
return (dispatch, getState) => {
// dispatch(loadingDescriptors(page.page, page.size, page.properties, filter, page.direction));
console.log('Figure it out', page, filter);
return DescriptorService.myDescriptors(filter, page)
.then((paged) => {
dereferenceReferences(paged.content, 'owner', (o) => o as Partner);
......@@ -72,6 +72,24 @@ export function listMyDescriptors(page?: IPageRequest, filter?: string | Descrip
});
};
}
export const listAccessibleDescriptors = (page?: IPageRequest, filter?: string | DescriptorFilter) => (dispatch) => {
console.log('Figure it out', page, filter);
return DescriptorService.listAccessibleDescriptors(filter, page)
.then((paged) => {
dereferenceReferences(paged.content, 'owner', (o) => o as Partner);
if (paged.number === 0) {
dispatch(receiveDescriptorPage(paged));
} else {
dispatch(appendDescriptorPage(paged));
}
return dispatch(addFilterCode(paged.filterCode, paged.filter));
})
.catch((error) => {
log('Error', error);
});
};
export function loadMoreDescriptors(page?: FilteredPage<Descriptor>) {
return (dispatch, getState) => {
......
......@@ -88,7 +88,7 @@ class DescriptorPicker extends React.Component<IDescriptorPickerProps, any> {
const { loadDescriptors, pagination } = this.props;
log('Applying new filter', newFilters);
loadDescriptors({ page: pagination.page, size: pagination.size, properties: pagination.sort as string[], direction: pagination.dir as SortDirection }, pagination.filter);
loadDescriptors({ page: pagination.page, size: pagination.size, properties: pagination.sort as string[], direction: pagination.dir as SortDirection }, newFilters);
}
private onDescriptorSelected = (select) => (descriptor: Descriptor) => {
const { onAddDescriptor, onRemoveDescriptor } = this.props;
......
......@@ -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
*
......
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