Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
setCurrentOrganizationId,
organizationsAvailableToUser: organizations,
} = useCurrentOrganization();
const [searchResults, setResults] = useState(organizations);
const selectOrganization = (id) => () => {
setCurrentOrganizationId(id);
toggle();
};
// TODO: clean this up once
// https://github.com/orbitjs/orbit/pull/525
// is merged, where we'll be able to retrieve the query result
// without local filtering. (so we can skip the cache query step)
const performSearch = useDebouncedCallback(
async () => {
const filters = [{ attribute: 'name', value: `like:${searchTerm}` }];
if (!isSuperAdmin) {
filters.push({ attribute: 'scope-to-current-user', value: 'isnull:' });
}
await dataStore.query((q) => q.findRecords(ORGANIZATION).filter(filters), defaultOptions());
const records = await dataStore.cache.query((q) => q.findRecords(ORGANIZATION));
// TODO: MAY need to do a local filter on organizations that the current user owns
const filtered = records.filter((record) => {
const { name } = attributesFor(record);
if (!name) {
return false;
}