How to use react-orbitjs - 10 common examples

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 / ui / components / project-table / table / row / index.tsx View on Github external
<div>
            {isPrivate &amp;&amp; }
            {showProjectActions &amp;&amp; }
          </div>
        

        
      
    );
  }
}

export default compose(
  withRouter,
  withMomentTimezone,
  withOrbit(({ project }) =&gt; ({
    // refetching the project (from local cache)
    // subscribes this component to changes to the project.
    project: (q) =&gt; q.findRecord(project),
    organization: (q) =&gt; q.findRelatedRecord(project, 'organization'),
    owner: (q) =&gt; q.findRelatedRecord(project, 'owner'),
    group: (q) =&gt; q.findRelatedRecord(project, 'group'),
    products: (q) =&gt; q.findRelatedRecords(project, 'products'),
  }))
)(Row);
github sillsdev / appbuilder-portal / source / SIL.AppBuilder.Portal.Frontend / src / ui / routes / projects / show / overview / products / item / tasks.tsx View on Github external
export default function ProductTasksForCurrentUser({ product }: IProps) {
  const { t } = useTranslations();
  const { currentUser } = useCurrentUser();
  const { dataStore } = useOrbit();

  let tasks = [];

  try {
    tasks = dataStore.cache.query((q) =>
      q
        .findRecords('userTask')
        .filter({ relation: 'product', record: product })
        .filter({ relation: 'user', record: currentUser })
    );

    // for some reason the backend is sending task creations to the frontend qucik
    // enough where the key-checking mechanisms hasn't yet added the first task,
    // so a subsequent task will become a duplicate because both received tasks
    // have yet to be added to the local cache.
    tasks = uniqBy(tasks, (task) => (task.keys || {}).remoteId);
github sillsdev / appbuilder-portal / source / SIL.AppBuilder.Portal.Frontend / src / ui / routes / admin / settings / stores / -components / form.tsx View on Github external
export default function StoreForm({ save, cancel, store }) {
  const { t } = useTranslations();
  const { dataStore } = useOrbit();

  const {
    result: { storeTypes },
  } = useQuery({ storeTypes: [(q) =&gt; q.findRecords('storeType'), buildOptions()] });

  const attributes = attributesFor(store || {});
  const isEditing = !!store;

  const existingStoreType = useMemo(() =&gt; getStoreType(dataStore, store), [dataStore, store]);

  // Form States
  const [name, setName] = useState(attributes.name || '');
  const [storeType, setStoreType] = useState(existingStoreType);
  const [description, setDescription] = useState(attributes.description || '');
  const [errors, setError] = useState&gt;({});
  // End Form States

  const onSubmit = async (e) =&gt; {
    e.preventDefault();
    e.stopPropagation();
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]);
github sillsdev / appbuilder-portal / source / SIL.AppBuilder.Portal.Frontend / src / ui / routes / projects / show / overview / products / index.tsx View on Github external
export default function Products({ project }: IProps) {
  const { t } = useTranslations();
  const {
    dataStore,
    subscriptions: { products, organization },
  } = useOrbit({
    products: (q) =&gt; q.findRelatedRecords(project, 'products'),
    organization: (q) =&gt; q.findRelatedRecord(project, 'organization'),
    // cache busters
    userTasks: (q) =&gt; q.findRecords('userTask'),
    project: (q) =&gt; q.findRecord(project),
  });

  useLiveData(`projects/${idFromRecordIdentity(dataStore, project)}`);
  useLiveData(`products`);
  useLiveData(`user-tasks`);

  let productList;

  if (isEmpty(products)) {
    productList = (
      <div>
        <span data-test-project-product-empty-text="">{t('project.products.empty')}</span>
      </div>
    );
  } else {
    productList = products.map((product) =&gt; );
github sillsdev / appbuilder-portal / source / SIL.AppBuilder.Portal.Frontend / src / ui / routes / projects / show / with-data.tsx View on Github external
return function ProjectDataFetcher(props) {
    const { match } = useRouter();
    const {
      params: { id },
    } = match;

    const {
      isLoading,
      error,
      result: { project },
    } = useQuery({
      project: [
        (q) => buildFindRecord(q, 'project', id),
        buildOptions({
          include: [
            'products.product-builds.product-artifacts',
            'products.product-builds.product-publications',
            'products.user-tasks.user',
            // 'products.user-tasks.product.product-definition.workflow',
            'products.product-definition',
            // 'products.product-workflow',
            'organization.organization-product-definitions.product-definition.workflow.store-type',
            'group',
            'owner.group-memberships.group',
            'owner.organization-memberships.organization',
            'reviewers',
            'type',
github sillsdev / appbuilder-portal / source / SIL.AppBuilder.Portal.Frontend / src / data / orbitjs-operations-support / serialize-from-api.ts View on Github external
(data as JSONAPIOperationsPayload).operations.forEach((operation) => {
      let removedRecords = [];
      let transforms = [];

      let operationData;

      switch (operation.op) {
        case 'get':
        case 'update':
        case 'add':
          pushPayload(store, { ...operation });
          break;
        case 'remove':
          operationData = operation.data || operation.ref;
          removedRecords = Array.isArray(operationData) ? operationData : [operationData];

          removedRecords.forEach((record) => {
            let recordIdentity = recordIdentityFrom(
              store,
              record.id,
              toOrbitType(store, record.type)
            );
            // was this record already removed from the cache?
            // maybe we are receiving an operations payload that is telling us
            // to remove something that we've already removed.
            let exists = false;
github sillsdev / appbuilder-portal / source / SIL.AppBuilder.Portal.Frontend / src / ui / routes / organizations / settings / stores / index.tsx View on Github external
export function StoresRoute({ selected, onChange }) {
  const { t } = useTranslations();

  return (
    <div data-test-org-settings-stores="">
      <h2>{t('org.storesTitle')}</h2>
      <h3>{t('org.storeSelectTitle')}</h3>

      
    </div>
  );
}

export default compose(
  withOrbit((passedProps) =&gt; {
    const { organization } = passedProps;

    return {
      organizationStores: (q) =&gt; q.findRelatedRecords(organization, 'organizationStores'),
    };
  }),
  mapProps(({ organizationStores, updateOrganizationStore }) =&gt; {
    const { isSuperAdmin } = getPermissions();

    return {
      selected: organizationStores,
      onChange(store) {
        // if not superadmin, this onChange handler is a noop
        if (isSuperAdmin) {
          updateOrganizationStore(store);
        }
github sillsdev / appbuilder-portal / source / SIL.AppBuilder.Portal.Frontend / src / data / orbitjs-operations-support / serialize-from-api.ts View on Github external
removedRecords.forEach((record) => {
            let recordIdentity = recordIdentityFrom(
              store,
              record.id,
              toOrbitType(store, record.type)
            );
            // was this record already removed from the cache?
            // maybe we are receiving an operations payload that is telling us
            // to remove something that we've already removed.
            let exists = false;

            try {
              exists = store.cache.query((q) => q.findRecord(recordIdentity));
            } catch (e) {
              // don't care if this throws an exception;
            }

            if (exists) {
github sillsdev / appbuilder-portal / source / SIL.AppBuilder.Portal.Frontend / src / ui / components / product-transitions / details.tsx View on Github external
export default function TransitionDetails({ product }) {
  const { t } = useTranslations();
  const { dataStore } = useOrbit();
  const [transitions, setTransitions] = useState([]);
  const { currentUser } = useCurrentUser();
  const { timezone } = attributesFor(currentUser);

  const productRemoteId = remoteIdentityFrom(dataStore, product).keys.remoteId;

  useEffect(() => {
    async function fetcher() {
      let response = await get(`/api/products/${productRemoteId}/transitions`);
      try {
        let json = await response.json();

        let transitions = json.data;
        setTransitions(transitions || []);
      } catch (e) {
        console.debug('transitions not ready, or do not exist');