Example #1
0
  setSandboxesSelected = (ids, { additive = false, range = false } = {}) => {
    const { store, sandboxes, signals } = this.props;
    const selectedSandboxes = store.dashboard.selectedSandboxes;
    if (range === true) {
      track('Dashboard - Sandbox Shift Selection');
      const indexedSandboxes = sandboxes.map((sandbox, i) => ({ sandbox, i }));

      // We need to select a range
      const firstIndexInfo = indexedSandboxes.find(
        ({ sandbox }) => selectedSandboxes.indexOf(sandbox.id) > -1
      );

      const [id] = ids;

      const lastIndexInfo = indexedSandboxes.find(
        ({ sandbox }) => sandbox.id === id
      );

      if (firstIndexInfo && lastIndexInfo) {
        const indexes = [firstIndexInfo.i, lastIndexInfo.i].sort();
        const sandboxIds = indexedSandboxes
          .map(({ sandbox }) => sandbox.id)
          .slice(indexes[0], indexes[1] + 1);

        signals.dashboard.sandboxesSelected({
          sandboxIds,
        });
        return;
      }
    }

    let sandboxIds = ids;

    if (additive) {
      track('Dashboard - Sandbox Additive Selection');
      sandboxIds = store.dashboard.selectedSandboxes.filter(
        id => ids.indexOf(id) === -1
      );
      const additiveIds = ids.filter(
        id => store.dashboard.selectedSandboxes.indexOf(id) === -1
      );

      sandboxIds = uniq([...sandboxIds, ...additiveIds]);
    }

    signals.dashboard.sandboxesSelected({
      sandboxIds,
    });
  };
Example #2
0
                                  {(mutate, { loading: revokeLoading }) => {
                                    track('Team - Revoke Invitation');

                                    const handleClick = () =>
                                      mutate({
                                        variables: { userId: user.id, teamId },
                                      });

                                    return (
                                      <User
                                        user={user}
                                        style={{
                                          opacity: revokeLoading ? 0.5 : 1,
                                        }}
                                        rightElement={
                                          <div
                                            style={{
                                              float: 'right',
                                              fontSize: '.75rem',
                                            }}
                                          >
                                            <Button
                                              onClick={handleClick}
                                              disabled={revokeLoading}
                                              small
                                            >
                                              {revokeLoading
                                                ? 'Revoking...'
                                                : 'Revoke'}
                                            </Button>
                                          </div>
                                        }
                                      />
                                    );
                                  }}
Example #3
0
      const submit = e => {
        e.preventDefault();
        e.stopPropagation();

        let isEmail = input.value.indexOf('@') > -1;

        track('Team - Add Member', { email: isEmail });

        isEmail = false;

        // We don't enable email for now for privacy reasons

        const variables = { teamId };

        const value = input.value;
        if (isEmail) {
          variables.email = value;
        } else {
          variables.username = value;
        }

        mutate({
          variables,
        }).then(() => {
          signals.notificationAdded({
            message: `${value} has been invited!`,
            type: 'success',
          });
        });

        input.value = '';
      };
  return () => {
    if (!trackOnce || !trackedEvents[e]) {
      trackAnalytics(e, args);

      if (trackOnce) {
        trackedEvents[e] = true;
      }
    }

    return {};
  };
Example #5
0
  onMouseUp = () => {
    if (
      this.state.selection &&
      (diff(this.state.selection.startX, this.state.selection.endX) > 50 ||
        diff(this.state.selection.startY, this.state.selection.endY) > 50)
    ) {
      track('Dashboard - Sandbox Selection Done');
    }

    document.removeEventListener('mousemove', this.onMouseMove);
    document.removeEventListener('mouseup', this.onMouseUp);
    this.setState({
      selection: undefined,
    });
  };
export function recoverFiles({ recover, controller, state }) {
  const sandbox = state.get('editor.currentSandbox');

  const recoverList = recover.getRecoverList(sandbox.id, sandbox.modules);
  recover.clearSandbox(sandbox.id);

  const recoveredList = recoverList
    .map(({ recoverData, module }) => {
      if (module.code === recoverData.savedCode) {
        const titleA = `saved '${module.title}'`;
        const titleB = `recovered '${module.title}'`;
        state.push('editor.tabs', {
          type: 'DIFF',
          codeA: module.code || '',
          codeB: recoverData.code || '',
          titleA,
          titleB,
          fileTitle: module.title,
          id: `${titleA} - ${titleB}`,
        });

        const signal = controller.getSignal('editor.codeChanged');
        signal({
          code: recoverData.code,
          moduleShortid: module.shortid,
        });

        return true;
      }

      return false;
    })
    .filter(Boolean);

  if (recoveredList.length > 0 && window.showNotification) {
    track('Files Recovered', { fileCount: recoveredList.length });
    window.showNotification(
      `We recovered ${
        recoveredList.length
      } unsaved files from a previous session`,
      'notice'
    );
  }

  return {};
}
Example #7
0
            const submit = e => {
              e.preventDefault();
              e.stopPropagation();
              const name = this.state.inputValue;

              track('Team - Create Team');

              mutate({
                variables: {
                  name,
                },
                optimisticResponse: {
                  __typename: 'Mutation',
                  createTeam: {
                    __typename: 'Team',
                    id: 'new-team',
                    name,
                  },
                },
                update: (proxy, { data: { createTeam } }) => {
                  // Read the data from our cache for this query.
                  const d = proxy.readQuery({
                    query: TEAMS_QUERY,
                  });

                  // Add our team from the mutation to the end.
                  d.me.teams.push(createTeam);
                  // Write our data back to the cache.
                  proxy.writeQuery({
                    query: TEAMS_QUERY,
                    data: d,
                  });
                },
              }).then(({ data }) => {
                if (window.showNotification) {
                  window.showNotification(
                    `Succesfully created team '${data.createTeam.name}'`,
                    'success'
                  );
                }

                history.push(teamOverviewUrl(data.createTeam.id));
              });
            };
          onSubmit={e => {
            e.preventDefault();
            const path = basePath + '/' + input.value;

            track('Dashboard - Create Directory', {
              path,
            });

            mutate({
              variables: { path, teamId },
              optimisticResponse: {
                __typename: 'Mutation',
                createCollection: {
                  id: 'optimistic-id',
                  path,
                  __typename: 'Collection',
                },
              },
              update: (proxy, { data: { createCollection } }) => {
                const variables = {};
                if (teamId) {
                  variables.teamId = teamId;
                }
                // Read the data from our cache for this query.
                const d = proxy.readQuery({
                  query: PATHED_SANDBOXES_FOLDER_QUERY,
                  variables,
                });

                // Add our collection from the mutation to the end.
                d.me.collections.push(createCollection);
                // Write our data back to the cache.
                proxy.writeQuery({
                  query: PATHED_SANDBOXES_FOLDER_QUERY,
                  variables,
                  data: d,
                });
              },
            });

            input.value = '';

            close();
          }}
Example #9
0
export function saveAllModules(store, signals) {
  const sandbox = store.editor.currentSandbox;

  // In case you don't own the sandbox we cannot do >1 calls for saving module as you would then
  // also fork >1 times. The reason that we want to save seperately is because we want to have
  // fine-grained control of which saves succeed and which saves fail
  if (sandbox.owned) {
    track('Save All Modified Modules');
    sandbox.modules
      .filter(m => !store.editor.isModuleSynced(m.shortid))
      .forEach(module => {
        signals.editor.codeSaved({
          code: module.code,
          moduleShortid: module.shortid,
        });
      });
  } else {
    signals.editor.saveClicked();
  }
}