Completed
Pull Request — master (#81)
by Alejandro
03:26
created

index.js ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 4
b 0
f 0
nc 1
nop 2
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
rs 10
1
import Bottle from 'bottlejs';
2
import { withRouter } from 'react-router-dom';
3
import { connect } from 'react-redux';
4
import { assoc, pick } from 'ramda';
5
import csvjson from 'csvjson';
6
import axios from 'axios';
7
import App from '../App';
8
import ScrollToTop from '../common/ScrollToTop';
9
import MainHeader from '../common/MainHeader';
10
import { resetSelectedServer, selectServer } from '../servers/reducers/selectedServer';
11
import Home from '../common/Home';
12
import MenuLayout from '../common/MenuLayout';
13
import { createServer, createServers, deleteServer, listServers } from '../servers/reducers/server';
14
import CreateServer from '../servers/CreateServer';
15
import ServersDropdown from '../servers/ServersDropdown';
16
import TagsList from '../tags/TagsList';
17
import { filterTags, forceListTags, listTags } from '../tags/reducers/tagsList';
18
import ShortUrls from '../short-urls/ShortUrls';
19
import SearchBar from '../short-urls/SearchBar';
20
import { listShortUrls } from '../short-urls/reducers/shortUrlsList';
21
import ShortUrlsList from '../short-urls/ShortUrlsList';
22
import { resetShortUrlParams } from '../short-urls/reducers/shortUrlsListParams';
23
import Tag from '../tags/helpers/Tag';
24
import { ColorGenerator } from '../utils/ColorGenerator';
25
import { Storage } from '../utils/Storage';
26
import ShortUrlsRow from '../short-urls/helpers/ShortUrlsRow';
27
import ShortUrlsRowMenu from '../short-urls/helpers/ShortUrlsRowMenu';
28
import { ShlinkApiClient } from '../api/ShlinkApiClient';
29
import DeleteServerModal from '../servers/DeleteServerModal';
30
import DeleteServerButton from '../servers/DeleteServerButton';
31
import AsideMenu from '../common/AsideMenu';
32
import ImportServersBtn from '../servers/helpers/ImportServersBtn';
33
import { ServersImporter } from '../servers/services/ServersImporter';
34
import { ServersExporter } from '../servers/services/ServersExporter';
35
import { ServersService } from '../servers/services/ServersService';
36
import CreateShortUrl from '../short-urls/CreateShortUrl';
37
import { createShortUrl, resetCreateShortUrl } from '../short-urls/reducers/shortUrlCreation';
38
import TagsSelector from '../tags/helpers/TagsSelector';
39
import DeleteShortUrlModal from '../short-urls/helpers/DeleteShortUrlModal';
40
import { deleteShortUrl, resetDeleteShortUrl, shortUrlDeleted } from '../short-urls/reducers/shortUrlDeletion';
41
import EditTagsModal from '../short-urls/helpers/EditTagsModal';
42 4
import { editShortUrlTags, resetShortUrlsTags, shortUrlTagsEdited } from '../short-urls/reducers/shortUrlTags';
43
44
const bottle = new Bottle();
45
const { container } = bottle;
46
47
const mapActionService = (map, actionName) => {
48
  map[actionName] = container[actionName];
49
50
  return map;
51
};
52
const connectDecorator = (propsFromState, actionServiceNames) =>
53
  connect(
54
    pick(propsFromState),
55
    Array.isArray(actionServiceNames) ? actionServiceNames.reduce(mapActionService, {}) : actionServiceNames
56
  );
57
58
bottle.constant('ScrollToTop', ScrollToTop);
59
bottle.decorator('ScrollToTop', withRouter);
60
61
bottle.serviceFactory('MainHeader', MainHeader, 'ServersDropdown');
62
bottle.decorator('MainHeader', withRouter);
63
64
bottle.serviceFactory('Home', () => Home);
65
bottle.decorator('Home', connectDecorator([ 'servers' ], { resetSelectedServer }));
66
67
bottle.serviceFactory('MenuLayout', MenuLayout, 'TagsList', 'ShortUrls', 'AsideMenu', 'CreateShortUrl');
68
bottle.decorator('MenuLayout', connectDecorator([ 'selectedServer', 'shortUrlsListParams' ], { selectServer }));
69
bottle.decorator('MenuLayout', withRouter);
70
71
bottle.serviceFactory('CreateServer', CreateServer, 'ImportServersBtn');
72
bottle.decorator('CreateServer', connectDecorator([ 'selectedServer' ], { createServer, resetSelectedServer }));
73
74
bottle.serviceFactory('App', App, 'MainHeader', 'Home', 'MenuLayout', 'CreateServer');
75
76
bottle.serviceFactory('ServersDropdown', ServersDropdown, 'ServersExporter');
77
bottle.decorator('ServersDropdown', connectDecorator([ 'servers', 'selectedServer' ], { listServers, selectServer }));
78
79
bottle.serviceFactory('TagsList', () => TagsList);
80
bottle.decorator('TagsList', connectDecorator([ 'tagsList' ], { forceListTags, filterTags }));
81
82
bottle.serviceFactory('ShortUrls', ShortUrls, 'SearchBar', 'ShortUrlsList');
83
bottle.decorator('ShortUrls', connect(
84
  (state) => assoc('shortUrlsList', state.shortUrlsList.shortUrls, state.shortUrlsList)
85
));
86
87
bottle.serviceFactory('SearchBar', SearchBar, 'Tag');
88
bottle.decorator('SearchBar', connectDecorator([ 'shortUrlsListParams' ], { listShortUrls }));
89
90
bottle.serviceFactory('ShortUrlsList', ShortUrlsList, 'ShortUrlsRow');
91
bottle.decorator('ShortUrlsList', connectDecorator(
92
  [ 'selectedServer', 'shortUrlsListParams' ],
93
  { listShortUrls, resetShortUrlParams }
94
));
95
96
bottle.serviceFactory('Tag', Tag, 'ColorGenerator');
97
98
bottle.constant('localStorage', global.localStorage);
99
bottle.service('Storage', Storage, 'localStorage');
100
bottle.service('ColorGenerator', ColorGenerator, 'Storage');
101
102
bottle.serviceFactory('ShortUrlsRow', ShortUrlsRow, 'Tag', 'ShortUrlsRowMenu');
103
104
bottle.serviceFactory('ShortUrlsRowMenu', ShortUrlsRowMenu, 'DeleteShortUrlModal', 'EditTagsModal');
105
106
bottle.constant('axios', axios);
107
bottle.service('ShlinkApiClient', ShlinkApiClient, 'axios');
108
109
bottle.serviceFactory('DeleteServerModal', () => DeleteServerModal);
110
bottle.decorator('DeleteServerModal', withRouter);
111
bottle.decorator('DeleteServerModal', connect(null, { deleteServer }));
112
113
bottle.serviceFactory('DeleteServerButton', DeleteServerButton, 'DeleteServerModal');
114
bottle.serviceFactory('AsideMenu', AsideMenu, 'DeleteServerButton');
115
116
bottle.serviceFactory('ImportServersBtn', ImportServersBtn, 'ServersImporter');
117
bottle.decorator('ImportServersBtn', connect(null, { createServers }));
118
119
bottle.constant('csvjson', csvjson);
120
bottle.constant('window', global.window);
121
bottle.service('ServersImporter', ServersImporter, 'csvjson');
122
bottle.service('ServersService', ServersService, 'Storage');
123
bottle.service('ServersExporter', ServersExporter, 'ServersService', 'window', 'csvjson');
124
125
bottle.serviceFactory('CreateShortUrl', CreateShortUrl, 'TagsSelector');
126
bottle.decorator('CreateShortUrl', connectDecorator([ 'shortUrlCreationResult' ], {
127
  createShortUrl,
128
  resetCreateShortUrl,
129
}));
130
131
bottle.serviceFactory('TagsSelector', TagsSelector, 'ColorGenerator');
132
bottle.decorator('TagsSelector', connectDecorator([ 'tagsList' ], { listTags }));
133
134
bottle.serviceFactory('DeleteShortUrlModal', () => DeleteShortUrlModal);
135
bottle.decorator('DeleteShortUrlModal', connectDecorator(
136
  [ 'shortUrlDeletion' ],
137
  { deleteShortUrl, resetDeleteShortUrl, shortUrlDeleted }
138
));
139
140
bottle.serviceFactory('editShortUrlTags', editShortUrlTags, 'ShlinkApiClient');
141
bottle.serviceFactory('resetShortUrlsTags', () => resetShortUrlsTags);
142
bottle.serviceFactory('shortUrlTagsEdited', () => shortUrlTagsEdited);
143
144
bottle.serviceFactory('EditTagsModal', EditTagsModal, 'TagsSelector');
145
bottle.decorator('EditTagsModal', connectDecorator(
146
  [ 'shortUrlTags' ],
147
  [ 'editShortUrlTags', 'resetShortUrlsTags', 'shortUrlTagsEdited' ]
148
));
149
150
export default container;
151