<commit_before>/**
 * Dynamic data attachment related actions
 */

import Reflux from 'reflux';
import {dataInterface} from 'js/dataInterface';
import {notify} from 'utils';

const dataShareActions = Reflux.createActions({
  attachToParent: {children: ['completed', 'failed']},
  detachParent: {children: ['completed', 'failed']},
  getAttachedParents: {children: ['completed', 'failed']},
  getSharingEnabledAssets: {children: ['completed', 'failed']},
  toggleDataSharing: {children: ['completed', 'failed']},
});

dataShareActions.attachToParent.listen((assetUid, data) => {
  dataInterface.attachToParent(assetUid, data)
    .done(() => {
      dataShareActions.attachToParent.completed(assetUid);
    })
    .fail((response) => {
      dataShareActions.attachToParent.failed(response)
    })
});

dataShareActions.detachParent.listen((attachmentUrl) => {
  dataInterface.detachParent(attachmentUrl)
    .done(() => {
      dataShareActions.detachParent.completed();
    })
    .fail((response) => {
      dataShareActions.detachParent.failed(response)
    })
});

dataShareActions.getAttachedParents.listen((assetUid) => {
  dataInterface.getAttachedParents(assetUid)
    .done((response) => {
      if (response.results.length > 0) {
        let allParents = [];
        response.results.forEach((parent) => {
          // Remove file extension
          let filename = parent.filename.replace(/\.[^/.]+$/, '');
          // Get Uid from url
          let parentUid = parent.parent.match(/.*\/([^/]+)\//)[1];
          allParents.push({
            parentName: parent.parent_name,
            parentUrl: parent.parent,
            parentUid: parentUid,
            filename: filename,
            attachmentUrl: parent.url,
          });
          dataShareActions.getAttachedParents.completed(allParents);
        });
      } else {
        dataShareActions.getAttachedParents.completed([]);
      }
    })
    .fail(dataShareActions.getAttachedParents.failed);
});

dataShareActions.getSharingEnabledAssets.listen(() => {
  dataInterface.getSharingEnabledAssets()
    .done((response) => {
      dataShareActions.getSharingEnabledAssets.completed(response);
    })
    .fail(dataShareActions.getSharingEnabledAssets.failed);
});
dataShareActions.getSharingEnabledAssets.failed.listen(() => {
  alertify.error(t('Failed to retrieve sharing enabled assets'));
});

dataShareActions.toggleDataSharing.listen((uid, data) => {
  dataInterface.toggleDataSharing(uid, data)
    .done(dataShareActions.toggleDataSharing.completed)
    .fail((response) => {
      dataShareActions.toggleDataSharing.failed(response);
    });
});
dataShareActions.toggleDataSharing.failed.listen((response) => {
  alertify.error(response.responseJSON.detail);
});

export default dataShareActions;
<commit_msg>PR Changes: simplified action responses<commit_after>/**
 * Dynamic data attachment related actions
 */

import Reflux from 'reflux';
import alertify from 'alertifyjs';
import {dataInterface} from 'js/dataInterface';

const dataShareActions = Reflux.createActions({
  attachToParent: {children: ['completed', 'failed']},
  detachParent: {children: ['completed', 'failed']},
  getAttachedParents: {children: ['completed', 'failed']},
  getSharingEnabledAssets: {children: ['completed', 'failed']},
  toggleDataSharing: {children: ['completed', 'failed']},
});

dataShareActions.attachToParent.listen((assetUid, data) => {
  dataInterface.attachToParent(assetUid, data)
    .done(dataShareActions.attachToParent.completed)
    .fail(dataShareActions.attachToParent.failed);
});

dataShareActions.detachParent.listen((attachmentUrl) => {
  dataInterface.detachParent(attachmentUrl)
    .done(dataShareActions.detachParent.completed)
    .fail(dataShareActions.detachParent.failed);
});

dataShareActions.getAttachedParents.listen((assetUid) => {
  dataInterface.getAttachedParents(assetUid)
    .done((response) => {
      if (response.results.length > 0) {
        let allParents = [];
        response.results.forEach((parent) => {
          // Remove file extension
          let filename = parent.filename.replace(/\.[^/.]+$/, '');
          // Get Uid from url
          let parentUid = parent.parent.match(/.*\/([^/]+)\//)[1];
          allParents.push({
            parentName: parent.parent_name,
            parentUrl: parent.parent,
            parentUid: parentUid,
            filename: filename,
            attachmentUrl: parent.url,
          });
          dataShareActions.getAttachedParents.completed(allParents);
        });
      } else {
        dataShareActions.getAttachedParents.completed([]);
      }
    })
    .fail(dataShareActions.getAttachedParents.failed);
});

dataShareActions.getSharingEnabledAssets.listen(() => {
  dataInterface.getSharingEnabledAssets()
    .done(dataShareActions.getSharingEnabledAssets.completed)
    .fail(dataShareActions.getSharingEnabledAssets.failed);
});
dataShareActions.getSharingEnabledAssets.failed.listen(() => {
  alertify.error(t('Failed to retrieve sharing enabled assets'));
});

dataShareActions.toggleDataSharing.listen((uid, data) => {
  dataInterface.toggleDataSharing(uid, data)
    .done(dataShareActions.toggleDataSharing.completed)
    .fail(dataShareActions.toggleDataSharing.failed);
});
dataShareActions.toggleDataSharing.failed.listen((response) => {
  alertify.error(response?.responseJSON?.detail || t('Failed to toggle sharing'))
});

export default dataShareActions;

{'fraction_non_alphanumeric': 0.144091159713288, 'fraction_numerical': 0.0007351589781290203, 'mean_word_length': 3.9472727272727273, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6413630', 'n_tokens_mistral': 1607, 'n_tokens_neox': 1571, 'n_words': 234}