mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-09 01:37:24 +03:00
Merge pull request #228 from acelaya-forks/feature/memoize-server-version
Feature/memoize server version
This commit is contained in:
commit
f57f6b7745
6 changed files with 463 additions and 455 deletions
|
@ -4,3 +4,4 @@
|
||||||
./dist
|
./dist
|
||||||
./node_modules
|
./node_modules
|
||||||
./test
|
./test
|
||||||
|
./shlink-web-client.gif
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
A ReactJS-based progressive web application for [Shlink](https://shlink.io).
|
A ReactJS-based progressive web application for [Shlink](https://shlink.io).
|
||||||
|
|
||||||
|
![shlink-web-client](shlink-web-client.gif)
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
There are three ways in which you can use this application.
|
There are three ways in which you can use this application.
|
||||||
|
|
890
package-lock.json
generated
890
package-lock.json
generated
File diff suppressed because it is too large
Load diff
BIN
shlink-web-client.gif
Normal file
BIN
shlink-web-client.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.3 MiB |
|
@ -1,5 +1,5 @@
|
||||||
import { createAction, handleActions } from 'redux-actions';
|
import { createAction, handleActions } from 'redux-actions';
|
||||||
import { pipe } from 'ramda';
|
import { identity, memoizeWith, pipe } from 'ramda';
|
||||||
import { resetShortUrlParams } from '../../short-urls/reducers/shortUrlsListParams';
|
import { resetShortUrlParams } from '../../short-urls/reducers/shortUrlsListParams';
|
||||||
import { versionToPrintable, versionToSemVer as toSemVer } from '../../utils/versionHelpers';
|
import { versionToPrintable, versionToSemVer as toSemVer } from '../../utils/versionHelpers';
|
||||||
|
|
||||||
|
@ -18,6 +18,11 @@ const versionToSemVer = pipe(
|
||||||
toSemVer(MIN_FALLBACK_VERSION)
|
toSemVer(MIN_FALLBACK_VERSION)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const getServerVersion = memoizeWith(identity, (serverId, health) => health().then(({ version }) => ({
|
||||||
|
version: versionToSemVer(version),
|
||||||
|
printableVersion: versionToPrintable(version),
|
||||||
|
})));
|
||||||
|
|
||||||
export const resetSelectedServer = createAction(RESET_SELECTED_SERVER);
|
export const resetSelectedServer = createAction(RESET_SELECTED_SERVER);
|
||||||
|
|
||||||
export const selectServer = ({ findServerById }, buildShlinkApiClient) => (serverId) => async (dispatch) => {
|
export const selectServer = ({ findServerById }, buildShlinkApiClient) => (serverId) => async (dispatch) => {
|
||||||
|
@ -36,14 +41,14 @@ export const selectServer = ({ findServerById }, buildShlinkApiClient) => (serve
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { health } = buildShlinkApiClient(selectedServer);
|
const { health } = buildShlinkApiClient(selectedServer);
|
||||||
const { version } = await health();
|
const { version, printableVersion } = await getServerVersion(serverId, health);
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: SELECT_SERVER,
|
type: SELECT_SERVER,
|
||||||
selectedServer: {
|
selectedServer: {
|
||||||
...selectedServer,
|
...selectedServer,
|
||||||
version: versionToSemVer(version),
|
version,
|
||||||
printableVersion: versionToPrintable(version),
|
printableVersion,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { v4 as uuid } from 'uuid';
|
||||||
import reducer, {
|
import reducer, {
|
||||||
selectServer,
|
selectServer,
|
||||||
resetSelectedServer,
|
resetSelectedServer,
|
||||||
|
@ -27,9 +28,8 @@ describe('selectedServerReducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('selectServer', () => {
|
describe('selectServer', () => {
|
||||||
const serverId = 'abc123';
|
|
||||||
const selectedServer = {
|
const selectedServer = {
|
||||||
id: serverId,
|
id: 'abc123',
|
||||||
};
|
};
|
||||||
const version = '1.19.0';
|
const version = '1.19.0';
|
||||||
const ServersServiceMock = {
|
const ServersServiceMock = {
|
||||||
|
@ -56,7 +56,7 @@ describe('selectedServerReducer', () => {
|
||||||
|
|
||||||
apiClientMock.health.mockResolvedValue({ version: serverVersion });
|
apiClientMock.health.mockResolvedValue({ version: serverVersion });
|
||||||
|
|
||||||
await selectServer(ServersServiceMock, buildApiClient)(serverId)(dispatch);
|
await selectServer(ServersServiceMock, buildApiClient)(uuid())(dispatch);
|
||||||
|
|
||||||
expect(dispatch).toHaveBeenCalledTimes(3);
|
expect(dispatch).toHaveBeenCalledTimes(3);
|
||||||
expect(dispatch).toHaveBeenNthCalledWith(1, { type: RESET_SELECTED_SERVER });
|
expect(dispatch).toHaveBeenNthCalledWith(1, { type: RESET_SELECTED_SERVER });
|
||||||
|
@ -65,7 +65,7 @@ describe('selectedServerReducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('invokes dependencies', async () => {
|
it('invokes dependencies', async () => {
|
||||||
await selectServer(ServersServiceMock, buildApiClient)(serverId)(() => {});
|
await selectServer(ServersServiceMock, buildApiClient)(uuid())(() => {});
|
||||||
|
|
||||||
expect(ServersServiceMock.findServerById).toHaveBeenCalledTimes(1);
|
expect(ServersServiceMock.findServerById).toHaveBeenCalledTimes(1);
|
||||||
expect(buildApiClient).toHaveBeenCalledTimes(1);
|
expect(buildApiClient).toHaveBeenCalledTimes(1);
|
||||||
|
@ -76,7 +76,7 @@ describe('selectedServerReducer', () => {
|
||||||
|
|
||||||
apiClientMock.health.mockRejectedValue({});
|
apiClientMock.health.mockRejectedValue({});
|
||||||
|
|
||||||
await selectServer(ServersServiceMock, buildApiClient)(serverId)(dispatch);
|
await selectServer(ServersServiceMock, buildApiClient)(uuid())(dispatch);
|
||||||
|
|
||||||
expect(apiClientMock.health).toHaveBeenCalled();
|
expect(apiClientMock.health).toHaveBeenCalled();
|
||||||
expect(dispatch).toHaveBeenNthCalledWith(3, { type: SELECT_SERVER, selectedServer: expectedSelectedServer });
|
expect(dispatch).toHaveBeenNthCalledWith(3, { type: SELECT_SERVER, selectedServer: expectedSelectedServer });
|
||||||
|
@ -87,7 +87,7 @@ describe('selectedServerReducer', () => {
|
||||||
|
|
||||||
ServersServiceMock.findServerById.mockReturnValue(undefined);
|
ServersServiceMock.findServerById.mockReturnValue(undefined);
|
||||||
|
|
||||||
await selectServer(ServersServiceMock, buildApiClient)(serverId)(dispatch);
|
await selectServer(ServersServiceMock, buildApiClient)(uuid())(dispatch);
|
||||||
|
|
||||||
expect(ServersServiceMock.findServerById).toHaveBeenCalled();
|
expect(ServersServiceMock.findServerById).toHaveBeenCalled();
|
||||||
expect(apiClientMock.health).not.toHaveBeenCalled();
|
expect(apiClientMock.health).not.toHaveBeenCalled();
|
||||||
|
|
Loading…
Reference in a new issue