<commit_before>import _, { messages } from 'intl'
import ActionButton from 'action-button'
import decorate from 'apply-decorators'
import Icon from 'icon'
import React from 'react'
import { addSubscriptions } from 'utils'
import { alert, confirm } from 'modal'
import { createRemote, editRemote, subscribeRemotes } from 'xo'
import { error } from 'notification'
import { format } from 'xo-remote-parser'
import { generateId, linkState } from 'reaclette-utils'
import { injectState, provideState } from 'reaclette'
import { map, some, trimStart } from 'lodash'
import { Password, Number } from 'form'

const remoteTypes = {
  file: 'remoteTypeLocal',
  nfs: 'remoteTypeNfs',
  smb: 'remoteTypeSmb',
}

export default decorate([
  addSubscriptions({
    remotes: subscribeRemotes,
  }),
  provideState({
    initialState: () => ({
      domain: undefined,
      host: undefined,
      name: undefined,
      options: undefined,
      password: undefined,
      path: undefined,
      port: undefined,
      type: undefined,
      username: undefined,
    }),
    effects: {
      linkState,
      setPort: (_, port) => state => ({
        port: port === undefined && state.remote !== undefined ? '' : port,
      }),
      editRemote: ({ reset }) => state => {
        const {
          remote,
          domain = remote.domain,
          host = remote.host,
          name,
          options = remote.options || '',
          password = remote.password,
          path = remote.path,
          port = remote.port,
          type = remote.type,
          username = remote.username,
        } = state
        return editRemote(remote, {
          name,
          url: format({
            domain,
            host,
            password,
            path,
            port: port || undefined,
            type,
            username,
          }),
          options: options !== '' ? options : null,
        }).then(reset)
      },
      createRemote: ({ reset }) => async (state, { remotes }) => {
        if (some(remotes, { name: state.name })) {
          return alert(<commit_msg>fix(xo-web/remotes): SMB domain default value<commit_after>import _, { messages } from 'intl'
import ActionButton from 'action-button'
import decorate from 'apply-decorators'
import Icon from 'icon'
import React from 'react'
import { addSubscriptions } from 'utils'
import { alert, confirm } from 'modal'
import { createRemote, editRemote, subscribeRemotes } from 'xo'
import { error } from 'notification'
import { format } from 'xo-remote-parser'
import { generateId, linkState } from 'reaclette-utils'
import { injectState, provideState } from 'reaclette'
import { map, some, trimStart } from 'lodash'
import { Password, Number } from 'form'

const remoteTypes = {
  file: 'remoteTypeLocal',
  nfs: 'remoteTypeNfs',
  smb: 'remoteTypeSmb',
}

export default decorate([
  addSubscriptions({
    remotes: subscribeRemotes,
  }),
  provideState({
    initialState: () => ({
      domain: undefined,
      host: undefined,
      name: undefined,
      options: undefined,
      password: undefined,
      path: undefined,
      port: undefined,
      type: undefined,
      username: undefined,
    }),
    effects: {
      linkState,
      setPort: (_, port) => state => ({
        port: port === undefined && state.remote !== undefined ? '' : port,
      }),
      editRemote: ({ reset }) => state => {
        const {
          remote,
          domain = remote.domain || '',
          host = remote.host,
          name,
          options = remote.options || '',
          password = remote.password,
          path = remote.path,
          port = remote.port,
          type = remote.type,
          username = remote.username,
        } = state
        return editRemote(remote, {
          name,
          url: format({
            domain,
            host,
            password,
            path,
            port: port || undefined,
            type,
            username,
          }),
          options: options !== '' ? options : null,
        }).then(reset)
      },
      createRemote: ({ reset }) => async (state, { remotes }) => {
        if (some(remotes, { name: state.name })) {
          return alert(
{'fraction_non_alphanumeric': 0.12357142857142857, 'fraction_numerical': 0.0, 'mean_word_length': 2.1801665404996213, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '2009123', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1143, 'n_words': 327}