Skip to content

Commit 253c827

Browse files
authored
Merge pull request #41 from cloudblue/feat/LITE-29547
LITE-29547: Control if next & previous actions are allowed in fast API adapter & fix export config for tools
2 parents 3c2dab6 + 945110b commit 253c827

File tree

11 files changed

+151
-93
lines changed

11 files changed

+151
-93
lines changed

components/src/index.js

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,26 @@
1-
import $injector from './core/injector';
2-
import registerWidget from './core/registerWidget';
1+
import $injector from '~core/injector';
2+
import registerWidget from '~core/registerWidget';
33

4-
import tabs from './widgets/tabs/widget.vue';
5-
import tab from './widgets/tab/widget.vue';
6-
import pad from './widgets/pad/widget.vue';
7-
import card from './widgets/card/widget.vue';
8-
import icon from './widgets/icon/widget.vue';
9-
import view from './widgets/view/widget.vue';
10-
import navigation from './widgets/navigation/widget.vue';
11-
import status from './widgets/status/widget.vue';
12-
import textfield from './widgets/textfield/widget.vue';
13-
import table from './widgets/table/widget.vue';
14-
import button from './widgets/button/widget.vue';
15-
import complexTable from './widgets/complexTable/widget.vue';
164

17-
import _store from './core/store';
18-
import _bus from './core/eventBus';
19-
import {
20-
connectPortalRoutesDict,
21-
} from './constants/portal-routes';
5+
export { default as Tabs } from '~widgets/tabs/widget.vue';
6+
export { default as Tab } from '~widgets/tab/widget.vue';
7+
export { default as Pad } from '~widgets/pad/widget.vue';
8+
export { default as Card } from '~widgets/card/widget.vue';
9+
export { default as Icon } from '~widgets/icon/widget.vue';
10+
export { default as View } from '~widgets/view/widget.vue';
11+
export { default as Navigation } from '~widgets/navigation/widget.vue';
12+
export { default as Status } from '~widgets/status/widget.vue';
13+
export { default as Textfield } from '~widgets/textfield/widget.vue';
14+
export { default as Table } from '~widgets/table/widget.vue';
15+
export { default as ComplexTable } from './widgets/complexTable/widget.vue';
16+
export { default as Button } from '~widgets/button/widget.vue';
2217

23-
export const Tabs = tabs;
24-
export const Tab = tab;
25-
export const Pad = pad;
26-
export const Card = card;
27-
export const Icon = icon;
28-
export const View = view;
29-
export const Navigation = navigation;
30-
export const Status = status;
31-
export const Textfield = textfield;
32-
export const Table = table;
33-
export const Button = button;
34-
export const ComplexTable = complexTable;
18+
export { default as store } from '~core/store';
19+
export { default as bus } from '~core/eventBus';
3520

36-
export const bus = _bus;
37-
export const store = _store;
38-
39-
export const connectPortalRoutes = connectPortalRoutesDict;
21+
export {
22+
connectPortalRoutesDict as connectPortalRoutes,
23+
} from '~constants/portal-routes';
4024

4125
export default (widgets = {}, options = {}) => {
4226
for (const widget in widgets) registerWidget(widget, widgets[widget]);

components/webpack.config.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = {
1010
outputModule: true,
1111
},
1212

13-
entry: path.resolve(__dirname, './src/index.js'),
13+
entry: path.resolve(__dirname, 'src/index.js'),
1414

1515
output: {
1616
path: path.resolve(__dirname, '..', 'dist'),
@@ -37,7 +37,7 @@ module.exports = {
3737
{
3838
test: /\.js$/,
3939
loader: 'babel-loader',
40-
include: [path.resolve('app'), path.resolve('test')],
40+
include: [path.resolve(__dirname, 'src'), path.resolve('test')],
4141
exclude: /node_modules/,
4242
},
4343
{
@@ -61,9 +61,9 @@ module.exports = {
6161

6262
resolve: {
6363
alias: {
64-
'~core': path.resolve(__dirname, './src/core'),
65-
'~widgets': path.resolve(__dirname, './src/widgets'),
66-
'~constants': path.resolve(__dirname, './src/constants'),
64+
'~core': path.resolve(__dirname, 'src/core'),
65+
'~widgets': path.resolve(__dirname, 'src/widgets'),
66+
'~constants': path.resolve(__dirname, 'src/constants'),
6767
},
6868
},
6969

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
"version": "30.1.0",
44
"exports": {
55
".": "./dist/index.js",
6-
"./tools": "./dist/tools"
6+
"./tools/*": "./dist/tools/*"
77
},
88
"scripts": {
99
"build": "NODE_ENV=production webpack --config ./webpack.config.js",
1010
"build:core": "NODE_ENV=production webpack --config ./components/webpack.config.js",
1111
"build:tools": "NODE_ENV=production webpack --config ./tools/webpack.config.js",
12-
"start": "NODE_ENV=development webpack serve",
12+
"start": "NODE_ENV=development webpack serve --config ./webpack-dev.config.js",
1313
"start:https": "npm run start -- --server-type https",
1414
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs --fix --ignore-path .gitignore",
1515
"test": "jest --config ./jest.config.js",

tools/api/fastApi/adapter.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,22 @@ export const fastApiTableAdapter = (endpoint, rowsPerPage = 10) => {
5454
};
5555

5656
/**
57-
* @returns {Promise<{total: number, page: number, items: *[]}>}
57+
* @returns {{total: number, page: number, items: *[]}|Promise<{total: number, page: number, items: *[]}>}
5858
*/
5959
const next = () => {
60+
if (state.page >= Math.ceil(state.total / limit)) return state;
61+
6062
state.page++;
6163

6264
return load();
6365
};
6466

6567
/**
66-
* @returns {Promise<{total: number, page: number, items: *[]}>}
68+
* @returns {{total: number, page: number, items: *[]}|Promise<{total: number, page: number, items: *[]}>}
6769
*/
6870
const previous = () => {
71+
if (state.page <= 1) return state;
72+
6973
state.page--;
7074

7175
return load();

tools/api/fastApi/adapter.spec.js

Lines changed: 80 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -111,47 +111,100 @@ describe('#fastApiTableAdapter', () => {
111111
});
112112

113113
describe('#next', () => {
114-
beforeEach(async () => {
115-
fetchResponse.contentRangeTotal = 1;
116-
fetchResponse.items = ['foo'];
114+
describe('if there is a next page', () => {
115+
beforeEach(async () => {
116+
fetchResponse.contentRangeTotal = 11;
117+
fetchResponse.items = ['foo'];
117118

118-
result = await adapter.next();
119-
});
119+
await adapter.load();
120+
result = await adapter.next();
121+
});
120122

121-
it('increases the current page and performs a request', () => {
122-
expect(fetch).toHaveBeenCalledWith('/foo?limit=10&offset=10');
123+
it('increases the current page and performs a request', () => {
124+
expect(fetch).toHaveBeenCalledTimes(2);
125+
expect(fetch).toHaveBeenCalledWith('/foo?limit=10&offset=10');
126+
});
127+
128+
it('returns the result of calling load', () => {
129+
expect(result).toEqual({
130+
page: 2,
131+
total: 11,
132+
items: ['foo'],
133+
});
134+
});
123135
});
124136

125-
it('returns the result of calling load', () => {
126-
expect(result).toEqual({
127-
page: 2,
128-
total: 1,
129-
items: ['foo'],
137+
describe('if there is NOT a next page', () => {
138+
beforeEach(async () => {
139+
fetchResponse.contentRangeTotal = 10;
140+
fetchResponse.items = ['foo'];
141+
142+
await adapter.load();
143+
result = await adapter.next();
144+
});
145+
146+
it('does not perform a request', () => {
147+
expect(fetch).toHaveBeenCalledTimes(1);
148+
});
149+
150+
it('returns the current state', () => {
151+
expect(result).toEqual({
152+
page: 1,
153+
total: 10,
154+
items: ['foo'],
155+
});
130156
});
131157
});
132158
});
133159

134160
describe('#previous', () => {
135-
beforeEach(async () => {
136-
fetchResponse.contentRangeTotal = 1;
137-
fetchResponse.items = ['bar'];
161+
describe('if there is a previous page', () => {
162+
beforeEach(async () => {
163+
fetchResponse.contentRangeTotal = 33;
164+
fetchResponse.items = ['bar'];
138165

139-
// Increase page to 3
140-
await adapter.next();
141-
await adapter.next();
166+
// Increase page to 3
167+
await adapter.load();
168+
await adapter.next();
169+
await adapter.next();
142170

143-
result = await adapter.previous();
144-
});
171+
result = await adapter.previous();
172+
});
145173

146-
it('decreases the current page and performs a request', () => {
147-
expect(fetch).toHaveBeenCalledWith('/foo?limit=10&offset=20');
174+
it('decreases the current page and performs a request', () => {
175+
expect(fetch).toHaveBeenCalledWith('/foo?limit=10&offset=20');
176+
});
177+
178+
it('returns the result of calling load', () => {
179+
expect(result).toEqual({
180+
page: 2,
181+
total: 33,
182+
items: ['bar'],
183+
});
184+
});
148185
});
149186

150-
it('returns the result of calling load', () => {
151-
expect(result).toEqual({
152-
page: 2,
153-
total: 1,
154-
items: ['bar'],
187+
describe('if there is NOT a previous page', () => {
188+
beforeEach(async () => {
189+
fetchResponse.contentRangeTotal = 33;
190+
fetchResponse.items = ['bar'];
191+
192+
// Do not increase page
193+
await adapter.load();
194+
195+
result = await adapter.previous();
196+
});
197+
198+
it('does not performs a request', () => {
199+
expect(fetch).toHaveBeenCalledTimes(1);
200+
});
201+
202+
it('returns the current state', () => {
203+
expect(result).toEqual({
204+
page: 1,
205+
total: 33,
206+
items: ['bar'],
207+
});
155208
});
156209
});
157210
});

tools/api/fastApi/index.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

tools/api/fastApi/vue-composable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { fastApiTableAdapter } from './adapter';
1111
*
1212
* @returns {{next: ((function(): Promise<void>)|*), filter: ((function(*): Promise<void>)|*), total: Ref<UnwrapRef<number>>, load: ((function(): Promise<void>)|*), previous: ((function(): Promise<void>)|*), setRowsPerPage: ((function(*): Promise<void>)|*), page: Ref<UnwrapRef<number>>, loading: Ref<UnwrapRef<boolean>>, items: Ref<UnwrapRef<[]>>}}
1313
*/
14-
export const fastApiTableAdapterComposable = (endpoint, rowsPerPage = 10) => {
14+
export const useFastApiTableAdapter = (endpoint, rowsPerPage = 10) => {
1515
const adapter = fastApiTableAdapter(endpoint, rowsPerPage);
1616

1717
const items = ref(adapter.items);

tools/api/fastApi/vue-composable.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fastApiTableAdapterComposable } from './vue-composable';
1+
import { useFastApiTableAdapter } from './vue-composable';
22
import { fastApiTableAdapter } from './adapter';
33

44

@@ -23,13 +23,13 @@ jest.mock('./adapter', () => ({
2323
}),
2424
}));
2525

26-
describe('#fastApiTableAdapterComposable', () => {
26+
describe('#useFastApiTableAdapter', () => {
2727
let composable;
2828
let adapter;
2929

3030
describe('#constructor', () => {
3131
beforeEach(() => {
32-
composable = fastApiTableAdapterComposable('/foo');
32+
composable = useFastApiTableAdapter('/foo');
3333
});
3434

3535
it('creates a new fastApiTableAdapter', () => {
@@ -52,7 +52,7 @@ describe('#fastApiTableAdapterComposable', () => {
5252

5353
describe('methods', () => {
5454
beforeEach(() => {
55-
composable = fastApiTableAdapterComposable('/foo', 10);
55+
composable = useFastApiTableAdapter('/foo', 10);
5656
adapter = composable._adapter;
5757
});
5858

tools/webpack.config.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ module.exports = {
99
},
1010

1111
entry: {
12-
fastApi: {
13-
import: path.resolve(__dirname, 'api/fastApi/index.js'),
14-
filename: 'tools/[name].js',
12+
fastApiAdapter: {
13+
import: path.resolve(__dirname, 'api/fastApi/adapter.js'),
14+
filename: 'tools/fastApi/index.js',
15+
},
16+
fastApiAdapterVue: {
17+
import: path.resolve(__dirname, 'api/fastApi/vue-composable.js'),
18+
filename: 'tools/fastApi/vue.js',
1519
},
1620
},
1721

@@ -31,4 +35,8 @@ module.exports = {
3135
},
3236
],
3337
},
38+
39+
externals: {
40+
vue: 'vue',
41+
},
3442
};

webpack-dev.config.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const configs = require('./webpack.config');
2+
const { parallelism } = require('./webpack.config');
3+
4+
5+
const devServerConfig = {
6+
devServer: {
7+
compress: true,
8+
port: process.env.PORT || 3003,
9+
allowedHosts: 'all',
10+
headers: {
11+
"Access-Control-Allow-Origin": "*",
12+
},
13+
static: false,
14+
},
15+
};
16+
17+
module.exports = [
18+
devServerConfig,
19+
...configs,
20+
];
21+
22+
23+
module.exports.parallelism = parallelism;

0 commit comments

Comments
 (0)