in source/console/src/views/Client.tsx [524:561]
async getSites() {
try {
let sites: IGeneralQueryData[] = [];
/**
* Permission is for users in Associate Group only.
* If there's no permission for the associate user, the user gets nothing.
*/
if (this.userGroups.length > 0 ||
(this.userGroups.length === 0 && this.state.permission.id !== '')) {
sites = await this.graphQlCommon.listSites();
if (this.userGroups.length === 0) {
const permittedSites = this.state.permission.sites;
sites = sites.filter(site =>
permittedSites.map(permittedSite => {
return permittedSite.id;
}).includes(site.id)
);
}
}
const initialSite = this.getInitialSelectItem('Site', sites);
if (initialSite) this.setLocalStorage('selectedSite', initialSite);
const selectedSite = this.getLocalStorage('selectedSite');
if (selectedSite && selectedSite.id && selectedSite.id !== '') {
this.setState({ selectedSite });
this.getAreas(selectedSite);
}
sites.sort((a, b) => a.name.localeCompare(b.name));
this.setState({ sites });
} catch (error) {
LOGGER.error('Error while getting sites', error);
this.setState({ error: I18n.get('error.get.sites') });
}
}