How to use the react-orbitjs/dist.localIdFromRecordIdentity function in react-orbitjs

To help you get started, we’ve selected a few react-orbitjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sillsdev / appbuilder-portal / source / SIL.AppBuilder.Portal.Frontend / src / data / containers / with-current-organization / hook.ts View on Github external
const [store, dispatch] = useRedux();
  const { currentOrganizationId } = store.data;

  const currentUserOrganizations = retrieveRelation(dataStore, [
    currentUser,
    'organizationMemberships',
    'organization',
  ]);

  let organizationsAvailableToUser = currentUserOrganizations;

  if (isSuperAdmin && all) {
    organizationsAvailableToUser = _.uniqBy([...currentUserOrganizations, ...all], (org) => org.id);
  }

  const localId = localIdFromRecordIdentity(dataStore, {
    type: 'organization',
    id: currentOrganizationId,
  });

  let currentOrganization = useMemo(() => {
    try {
      if (currentOrganizationId) {
        return dataStore.cache.query((q) => q.findRecord({ type: 'organization', id: localId }));
      }
    } catch (e) {
      // if the current user is a super admin, this  org has not yet
      // been added to the cache
      console.warn(`org not found for ${currentOrganizationId}`, e);
    }
  }, [currentOrganizationId, dataStore.cache, localId]);