Skip to content

Commit c4a1a82

Browse files
author
Jonas Gossens
committed
🐛 Add locationId to personFinder, fix endless wait cursor
1 parent 6975546 commit c4a1a82

File tree

4 files changed

+34
-19
lines changed

4 files changed

+34
-19
lines changed

examples/react-chayns-personfinder/Example.jsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ export default class PersonFinderExample extends PureComponent {
3636
<PersonFinder
3737
dynamic
3838
placeholder="UAC 1"
39-
uacIds={[1]}
39+
uacId={1}
40+
onChange={PersonFinderExample.handleSelect}
41+
/>
42+
<PersonFinder
43+
dynamic
44+
placeholder="UAC 1 Location 1"
45+
uacId={1}
46+
locationId={1}
4047
onChange={PersonFinderExample.handleSelect}
4148
/>
4249
<PersonFinder

src/react-chayns-personfinder/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Then it can be used like in the following example:
4040
| defaultValues | Tags that should be added to the TagInput (multiple-prop) on initial rendering | array | |
4141
| boxClassName | ClassName of the box-overlay | string | |
4242
| uacId | ID of the UAC-Group to search in | number | |
43+
| locationId | LocationId of the UAC-Group to search in | number | |
4344

4445
## Clear the PersonFinder
4546
If you want to clear the PersonFinder, you need to have a reference to the ReactElement:

src/react-chayns-personfinder/component/PersonFinder.jsx

+2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ export default class PersonFinder extends Component {
1010
showPersons: PropTypes.bool,
1111
showSites: PropTypes.bool,
1212
uacId: PropTypes.number,
13+
locationId: PropTypes.number,
1314
};
1415

1516
static defaultProps = {
1617
multiple: false,
1718
showPersons: true,
1819
showSites: false,
1920
uacId: null,
21+
locationId: null,
2022
};
2123

2224
personFinder = React.createRef();

src/react-chayns-personfinder/component/PersonFinderData.jsx

+23-18
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export default class PersonFinderData extends Component {
3030
autoLoading: PropTypes.bool,
3131
boxClassName: PropTypes.string,
3232
uacId: PropTypes.number,
33+
locationId: PropTypes.number,
3334
};
3435

3536
static defaultProps = {
@@ -43,6 +44,7 @@ export default class PersonFinderData extends Component {
4344
autoLoading: true,
4445
boxClassName: null,
4546
uacId: null,
47+
locationId: null,
4648
};
4749

4850
resultList = null;
@@ -163,7 +165,7 @@ export default class PersonFinderData extends Component {
163165
}
164166

165167
const {
166-
persons: enablePersons, sites: enableSites, includeOwn, uacId,
168+
persons: enablePersons, sites: enableSites, includeOwn, uacId, locationId,
167169
} = this.props;
168170

169171
const promises = [];
@@ -172,7 +174,7 @@ export default class PersonFinderData extends Component {
172174
const loadSites = enableSites && this.loadMore[LOCATION_RELATION] && (type === ALL_RELATIONS || type === LOCATION_RELATION);
173175

174176
if (uacId) {
175-
promises.push(loadPersons ? this.fetchUacPersons(value, uacId) : Promise.resolve(false));
177+
promises.push(loadPersons ? this.fetchUacPersons(value, uacId, locationId) : Promise.resolve(false));
176178
} else {
177179
promises.push(loadPersons ? this.fetchPersonRelations(value, includeOwn) : Promise.resolve(false));
178180
}
@@ -229,7 +231,7 @@ export default class PersonFinderData extends Component {
229231
}
230232

231233
// eslint-disable-next-line class-methods-use-this
232-
async fetchUacPersons(value, uacId) {
234+
async fetchUacPersons(value, uacId, locationId) {
233235
const config = {
234236
method: 'GET',
235237
headers: {
@@ -238,23 +240,26 @@ export default class PersonFinderData extends Component {
238240
mode: 'cors',
239241
};
240242

241-
const response = await fetch(`https://sub50.tobit.com/backend/${uacId}/usergroup/1/users?filter=${value}`, config);
242-
const json = await response.json();
243-
244-
const result = { related: [], unrelated: [], type: PERSON_RELATION };
245-
json.forEach((item) => {
246-
result.related.push({
247-
firstName: item.firstname,
248-
lastName: item.lastname,
249-
personId: item.personId,
250-
relationCount: 0,
251-
relations: [],
252-
score: 0,
253-
userId: item.id,
243+
const response = await fetch(`https://sub50.tobit.com/backend/${locationId || chayns.env.site.locationId}/usergroup/${uacId}/users?filter=${value}`, config);
244+
if (response.status === 200) {
245+
const json = await response.json();
246+
247+
const result = { related: [], unrelated: [], type: PERSON_RELATION };
248+
json.forEach((item) => {
249+
result.related.push({
250+
firstName: item.firstname,
251+
lastName: item.lastname,
252+
personId: item.personId,
253+
relationCount: 0,
254+
relations: [],
255+
score: 0,
256+
userId: item.id,
257+
});
254258
});
255-
});
256259

257-
return Promise.resolve(result);
260+
return Promise.resolve(result);
261+
}
262+
return Promise.resolve(null);
258263
}
259264

260265
async fetchPersonRelations(value, canFindOwn = false) {

0 commit comments

Comments
 (0)