@things-factory/more-base 10.1.206 → 10.1.219

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,18 @@
1
+ import { navigate } from '@operato/shell'
2
+
1
3
  import { ADD_MORENDA, ADD_MORENDA_HEAD, ADD_MORENDA_TAIL } from '../actions/more'
2
4
 
5
+ /**
6
+ * A morenda that names the page it opens (`page`) and no action of its own opens that page.
7
+ *
8
+ * The page is said once, where the morenda is registered: the menu reads it to mark the row of the open page
9
+ * (`currentMorenda` in @operato/menu), and the action that goes there is made from it here, so the two cannot
10
+ * name different pages. A morenda that does something other than open a page keeps its own `action`.
11
+ */
12
+ function withPageAction(morenda) {
13
+ return morenda?.page && !morenda.action ? { ...morenda, action: () => navigate(morenda.page) } : morenda
14
+ }
15
+
3
16
  const INITIAL_STATE = {
4
17
  morendas: [],
5
18
  heads: [],
@@ -9,7 +22,7 @@ const INITIAL_STATE = {
9
22
  const more = (state = INITIAL_STATE, action) => {
10
23
  switch (action.type) {
11
24
  case ADD_MORENDA:
12
- let morenda = action.morenda
25
+ let morenda = withPageAction(action.morenda)
13
26
  return {
14
27
  ...state,
15
28
  morendas: [...state.morendas, morenda]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/more-base",
3
- "version": "10.1.206",
3
+ "version": "10.1.219",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.ts",
6
6
  "things-factory": true,
@@ -24,7 +24,8 @@
24
24
  "migration:create": "node ../../node_modules/typeorm/cli.js migration:create ./server/migrations/migration"
25
25
  },
26
26
  "dependencies": {
27
- "@things-factory/shell": "^10.1.206"
27
+ "@operato/shell": "^10.29.39",
28
+ "@things-factory/shell": "^10.1.208"
28
29
  },
29
- "gitHead": "18588a058a4a6cb21c379b2da5517e077c6442ba"
30
+ "gitHead": "1e96a252aafc460942bf5093b5aeed24828783d4"
30
31
  }
@@ -0,0 +1,37 @@
1
+ jest.mock('@operato/shell', () => ({ navigate: jest.fn() }))
2
+
3
+ import { navigate } from '@operato/shell'
4
+
5
+ import { ADD_MORENDA } from '../client/actions/more'
6
+ import more from '../client/reducers/more'
7
+
8
+ /** The morendas the rail's 「관리」 rows and the more panel read (`more.morendas`). */
9
+ describe('the morenda registry', () => {
10
+ beforeEach(() => (navigate as jest.Mock).mockClear())
11
+
12
+ it('★ a morenda that names its page opens that page', () => {
13
+ const state = more(undefined, { type: ADD_MORENDA, morenda: { name: 'roles', page: 'roles' } })
14
+
15
+ state.morendas[0].action()
16
+
17
+ expect(navigate).toHaveBeenCalledWith('roles')
18
+ expect(state.morendas[0].page).toBe('roles')
19
+ })
20
+
21
+ it('★ a morenda with its own action keeps it, page or not', () => {
22
+ const own = jest.fn()
23
+ const state = more(undefined, { type: ADD_MORENDA, morenda: { name: 'logs', page: 'logs', action: own } })
24
+
25
+ state.morendas[0].action()
26
+
27
+ expect(own).toHaveBeenCalled()
28
+ expect(navigate).not.toHaveBeenCalled()
29
+ })
30
+
31
+ it('a morenda with neither is kept as it came', () => {
32
+ const morenda = { name: 'about' }
33
+ const state = more(undefined, { type: ADD_MORENDA, morenda })
34
+
35
+ expect(state.morendas[0]).toBe(morenda)
36
+ })
37
+ })