mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-09 09:47:28 +03:00
Created function which dynamically resolve action services from the container for connected components
This commit is contained in:
parent
bab1e57ab1
commit
d6e53918a2
1 changed files with 30 additions and 23 deletions
|
@ -1,7 +1,6 @@
|
||||||
import Bottle from 'bottlejs';
|
import Bottle from 'bottlejs';
|
||||||
import { withRouter } from 'react-router-dom';
|
import { withRouter } from 'react-router-dom';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { compose } from 'redux';
|
|
||||||
import { assoc, pick } from 'ramda';
|
import { assoc, pick } from 'ramda';
|
||||||
import csvjson from 'csvjson';
|
import csvjson from 'csvjson';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
@ -43,6 +42,18 @@ import EditTagsModal from '../short-urls/helpers/EditTagsModal';
|
||||||
import { editShortUrlTags, resetShortUrlsTags, shortUrlTagsEdited } from '../short-urls/reducers/shortUrlTags';
|
import { editShortUrlTags, resetShortUrlsTags, shortUrlTagsEdited } from '../short-urls/reducers/shortUrlTags';
|
||||||
|
|
||||||
const bottle = new Bottle();
|
const bottle = new Bottle();
|
||||||
|
const { container } = bottle;
|
||||||
|
|
||||||
|
const mapActionService = (map, actionName) => {
|
||||||
|
map[actionName] = container[actionName];
|
||||||
|
|
||||||
|
return map;
|
||||||
|
};
|
||||||
|
const connectDecorator = (propsFromState, actionServiceNames) =>
|
||||||
|
connect(
|
||||||
|
pick(propsFromState),
|
||||||
|
Array.isArray(actionServiceNames) ? actionServiceNames.reduce(mapActionService, {}) : actionServiceNames
|
||||||
|
);
|
||||||
|
|
||||||
bottle.constant('ScrollToTop', ScrollToTop);
|
bottle.constant('ScrollToTop', ScrollToTop);
|
||||||
bottle.decorator('ScrollToTop', withRouter);
|
bottle.decorator('ScrollToTop', withRouter);
|
||||||
|
@ -51,27 +62,22 @@ bottle.serviceFactory('MainHeader', MainHeader, 'ServersDropdown');
|
||||||
bottle.decorator('MainHeader', withRouter);
|
bottle.decorator('MainHeader', withRouter);
|
||||||
|
|
||||||
bottle.serviceFactory('Home', () => Home);
|
bottle.serviceFactory('Home', () => Home);
|
||||||
bottle.decorator('Home', connect(pick([ 'servers' ]), { resetSelectedServer }));
|
bottle.decorator('Home', connectDecorator([ 'servers' ], { resetSelectedServer }));
|
||||||
|
|
||||||
bottle.serviceFactory('MenuLayout', MenuLayout, 'TagsList', 'ShortUrls', 'AsideMenu', 'CreateShortUrl');
|
bottle.serviceFactory('MenuLayout', MenuLayout, 'TagsList', 'ShortUrls', 'AsideMenu', 'CreateShortUrl');
|
||||||
bottle.decorator(
|
bottle.decorator('MenuLayout', connectDecorator([ 'selectedServer', 'shortUrlsListParams' ], { selectServer }));
|
||||||
'MenuLayout',
|
bottle.decorator('MenuLayout', withRouter);
|
||||||
compose(
|
|
||||||
connect(pick([ 'selectedServer', 'shortUrlsListParams' ]), { selectServer }),
|
|
||||||
withRouter
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
bottle.serviceFactory('CreateServer', CreateServer, 'ImportServersBtn');
|
bottle.serviceFactory('CreateServer', CreateServer, 'ImportServersBtn');
|
||||||
bottle.decorator('CreateServer', connect(pick([ 'selectedServer' ]), { createServer, resetSelectedServer }));
|
bottle.decorator('CreateServer', connectDecorator([ 'selectedServer' ], { createServer, resetSelectedServer }));
|
||||||
|
|
||||||
bottle.serviceFactory('App', App, 'MainHeader', 'Home', 'MenuLayout', 'CreateServer');
|
bottle.serviceFactory('App', App, 'MainHeader', 'Home', 'MenuLayout', 'CreateServer');
|
||||||
|
|
||||||
bottle.serviceFactory('ServersDropdown', ServersDropdown, 'ServersExporter');
|
bottle.serviceFactory('ServersDropdown', ServersDropdown, 'ServersExporter');
|
||||||
bottle.decorator('ServersDropdown', connect(pick([ 'servers', 'selectedServer' ]), { listServers, selectServer }));
|
bottle.decorator('ServersDropdown', connectDecorator([ 'servers', 'selectedServer' ], { listServers, selectServer }));
|
||||||
|
|
||||||
bottle.serviceFactory('TagsList', () => TagsList);
|
bottle.serviceFactory('TagsList', () => TagsList);
|
||||||
bottle.decorator('TagsList', connect(pick([ 'tagsList' ]), { forceListTags, filterTags }));
|
bottle.decorator('TagsList', connectDecorator([ 'tagsList' ], { forceListTags, filterTags }));
|
||||||
|
|
||||||
bottle.serviceFactory('ShortUrls', ShortUrls, 'SearchBar', 'ShortUrlsList');
|
bottle.serviceFactory('ShortUrls', ShortUrls, 'SearchBar', 'ShortUrlsList');
|
||||||
bottle.decorator('ShortUrls', connect(
|
bottle.decorator('ShortUrls', connect(
|
||||||
|
@ -79,11 +85,11 @@ bottle.decorator('ShortUrls', connect(
|
||||||
));
|
));
|
||||||
|
|
||||||
bottle.serviceFactory('SearchBar', SearchBar, 'Tag');
|
bottle.serviceFactory('SearchBar', SearchBar, 'Tag');
|
||||||
bottle.decorator('SearchBar', connect(pick([ 'shortUrlsListParams' ]), { listShortUrls }));
|
bottle.decorator('SearchBar', connectDecorator([ 'shortUrlsListParams' ], { listShortUrls }));
|
||||||
|
|
||||||
bottle.serviceFactory('ShortUrlsList', ShortUrlsList, 'ShortUrlsRow');
|
bottle.serviceFactory('ShortUrlsList', ShortUrlsList, 'ShortUrlsRow');
|
||||||
bottle.decorator('ShortUrlsList', connect(
|
bottle.decorator('ShortUrlsList', connectDecorator(
|
||||||
pick([ 'selectedServer', 'shortUrlsListParams' ]),
|
[ 'selectedServer', 'shortUrlsListParams' ],
|
||||||
{ listShortUrls, resetShortUrlParams }
|
{ listShortUrls, resetShortUrlParams }
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -101,7 +107,8 @@ bottle.constant('axios', axios);
|
||||||
bottle.service('ShlinkApiClient', ShlinkApiClient, 'axios');
|
bottle.service('ShlinkApiClient', ShlinkApiClient, 'axios');
|
||||||
|
|
||||||
bottle.serviceFactory('DeleteServerModal', () => DeleteServerModal);
|
bottle.serviceFactory('DeleteServerModal', () => DeleteServerModal);
|
||||||
bottle.decorator('DeleteServerModal', compose(withRouter, connect(null, { deleteServer })));
|
bottle.decorator('DeleteServerModal', withRouter);
|
||||||
|
bottle.decorator('DeleteServerModal', connect(null, { deleteServer }));
|
||||||
|
|
||||||
bottle.serviceFactory('DeleteServerButton', DeleteServerButton, 'DeleteServerModal');
|
bottle.serviceFactory('DeleteServerButton', DeleteServerButton, 'DeleteServerModal');
|
||||||
bottle.serviceFactory('AsideMenu', AsideMenu, 'DeleteServerButton');
|
bottle.serviceFactory('AsideMenu', AsideMenu, 'DeleteServerButton');
|
||||||
|
@ -116,23 +123,23 @@ bottle.service('ServersService', ServersService, 'Storage');
|
||||||
bottle.service('ServersExporter', ServersExporter, 'ServersService', 'window', 'csvjson');
|
bottle.service('ServersExporter', ServersExporter, 'ServersService', 'window', 'csvjson');
|
||||||
|
|
||||||
bottle.serviceFactory('CreateShortUrl', CreateShortUrl, 'TagsSelector');
|
bottle.serviceFactory('CreateShortUrl', CreateShortUrl, 'TagsSelector');
|
||||||
bottle.decorator('CreateShortUrl', connect(pick([ 'shortUrlCreationResult' ]), {
|
bottle.decorator('CreateShortUrl', connectDecorator([ 'shortUrlCreationResult' ], {
|
||||||
createShortUrl,
|
createShortUrl,
|
||||||
resetCreateShortUrl,
|
resetCreateShortUrl,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
bottle.serviceFactory('TagsSelector', TagsSelector, 'ColorGenerator');
|
bottle.serviceFactory('TagsSelector', TagsSelector, 'ColorGenerator');
|
||||||
bottle.decorator('TagsSelector', connect(pick([ 'tagsList' ]), { listTags }));
|
bottle.decorator('TagsSelector', connectDecorator([ 'tagsList' ], { listTags }));
|
||||||
|
|
||||||
bottle.serviceFactory('DeleteShortUrlModal', () => DeleteShortUrlModal);
|
bottle.serviceFactory('DeleteShortUrlModal', () => DeleteShortUrlModal);
|
||||||
bottle.decorator('DeleteShortUrlModal', connect(
|
bottle.decorator('DeleteShortUrlModal', connectDecorator(
|
||||||
pick([ 'shortUrlDeletion' ]),
|
[ 'shortUrlDeletion' ],
|
||||||
{ deleteShortUrl, resetDeleteShortUrl, shortUrlDeleted }
|
{ deleteShortUrl, resetDeleteShortUrl, shortUrlDeleted }
|
||||||
));
|
));
|
||||||
bottle.serviceFactory('EditTagsModal', EditTagsModal, 'TagsSelector');
|
bottle.serviceFactory('EditTagsModal', EditTagsModal, 'TagsSelector');
|
||||||
bottle.decorator('EditTagsModal', connect(
|
bottle.decorator('EditTagsModal', connectDecorator(
|
||||||
pick([ 'shortUrlTags' ]),
|
[ 'shortUrlTags' ],
|
||||||
{ editShortUrlTags, resetShortUrlsTags, shortUrlTagsEdited }
|
{ editShortUrlTags, resetShortUrlsTags, shortUrlTagsEdited }
|
||||||
));
|
));
|
||||||
|
|
||||||
export default bottle.container;
|
export default container;
|
||||||
|
|
Loading…
Reference in a new issue