@kaspernj/api-maker 1.0.433 → 1.0.434

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaspernj/api-maker",
3
- "version": "1.0.433",
3
+ "version": "1.0.434",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "index.js",
@@ -1,5 +1,6 @@
1
1
  import BaseComponent from "../base-component"
2
2
  import * as inflection from "inflection"
3
+ import FontAwesomeIcon from "react-native-vector-icons/FontAwesome"
3
4
  import PropTypes from "prop-types"
4
5
  import qs from "qs"
5
6
  import {memo} from "react"
@@ -24,16 +25,49 @@ export default memo(shapeComponent(class ApiMakerBootstrapSortLink extends BaseC
24
25
  setup() {
25
26
  this.queryParams = useQueryParams()
26
27
  this.searchKey = this.p.query.queryArgs.searchKey || "q"
28
+ this.qParams = this.calculateQParams()
29
+ this.attribute = inflection.underscore(this.p.attribute)
30
+ this.calculateIsSortedByAttribute()
27
31
  }
28
32
 
29
- attribute = () => inflection.underscore(this.p.attribute)
33
+ calculateIsSortedByAttribute () {
34
+ const {attribute} = this.tt
35
+ const params = this.tt.qParams
36
+
37
+ if (params.s == attribute) {
38
+ this.isSortedByAttribute = true
39
+ this.sortMode = "asc"
40
+ } else if (params.s == `${attribute} asc`) {
41
+ this.isSortedByAttribute = true
42
+ this.sortMode = "asc"
43
+ } else if (params.s == `${attribute} desc`) {
44
+ this.isSortedByAttribute = true
45
+ this.sortMode = "desc"
46
+ } else {
47
+ this.isSortedByAttribute = false
48
+ this.sortMode = null
49
+ }
50
+ }
30
51
 
31
- href () {
32
- const qParams = this.qParams()
52
+ calculateQParams() {
53
+ const {defaultParams} = this.props
33
54
  const {queryParams, searchKey} = this.tt
55
+
56
+ if (searchKey in queryParams) {
57
+ return JSON.parse(queryParams[searchKey])
58
+ } else if (defaultParams) {
59
+ return {...defaultParams}
60
+ }
61
+
62
+ return {}
63
+ }
64
+
65
+ href () {
66
+ const qParams = this.tt.qParams
67
+ const {attribute, queryParams, searchKey, sortMode} = this.tt
34
68
  const newQueryParams = {...queryParams}
35
69
 
36
- qParams.s = `${this.attribute()} ${this.sortMode()}` // eslint-disable-line id-length
70
+ qParams.s = `${attribute} ${sortMode == "asc" ? "desc" : "asc"}` // eslint-disable-line id-length
37
71
 
38
72
  newQueryParams[searchKey] = JSON.stringify(qParams)
39
73
 
@@ -43,16 +77,8 @@ export default memo(shapeComponent(class ApiMakerBootstrapSortLink extends BaseC
43
77
  return newPath
44
78
  }
45
79
 
46
- isSortedByAttribute () {
47
- const params = this.qParams()
48
-
49
- if (params.s == this.attribute()) return true
50
- if (params.s == `${this.attribute()} asc`) return true
51
-
52
- return false
53
- }
54
-
55
80
  render () {
81
+ const {isSortedByAttribute, sortMode} = this.tt
56
82
  const LinkComponent = this.linkComponent()
57
83
  const {attribute, className, defaultParams, linkComponent, onChanged, query, textProps, title, ...restProps} = this.props
58
84
 
@@ -62,39 +88,27 @@ export default memo(shapeComponent(class ApiMakerBootstrapSortLink extends BaseC
62
88
  attribute,
63
89
  class: className,
64
90
  component: "api-maker--bootstrap--sort-link",
65
- sortMode: this.sortMode()
91
+ sortMode: this.tt.sortMode
66
92
  }}
93
+ style={{display: "flex", flexDirection: "row", alignItems: "center"}}
67
94
  to={this.href()}
68
95
  {...restProps}
69
96
  >
70
97
  <Text {...textProps}>
71
98
  {this.title()}
72
99
  </Text>
100
+ {isSortedByAttribute && sortMode == "asc" &&
101
+ <FontAwesomeIcon name="chevron-down" size={14} style={{marginLeft: 3}} />
102
+ }
103
+ {isSortedByAttribute && sortMode == "desc" &&
104
+ <FontAwesomeIcon name="chevron-up" size={14} style={{marginLeft: 3}} />
105
+ }
73
106
  </LinkComponent>
74
107
  )
75
108
  }
76
109
 
77
110
  linkComponent = () => this.props.linkComponent || Link
78
111
 
79
- qParams() {
80
- const {defaultParams} = this.props
81
- const {queryParams, searchKey} = this.tt
82
-
83
- if (searchKey in queryParams) {
84
- return JSON.parse(queryParams[searchKey])
85
- } else if (defaultParams) {
86
- return {...defaultParams}
87
- }
88
-
89
- return {}
90
- }
91
-
92
- sortMode () {
93
- if (this.isSortedByAttribute()) return "desc"
94
-
95
- return "asc"
96
- }
97
-
98
112
  title () {
99
113
  const {attribute, query} = this.p
100
114
  const {title} = this.props
@@ -1,14 +1,16 @@
1
1
  import BaseComponent from "../../base-component"
2
2
  import {memo} from "react"
3
3
  import {shapeComponent} from "set-state-compare/src/shape-component"
4
+ import useBreakpoint from "../../use-breakpoint"
4
5
  import {View} from "react-native"
5
6
 
6
7
  export default memo(shapeComponent(class SharedTableRow extends BaseComponent {
7
8
  render() {
8
9
  const {style, ...restProps} = this.props
10
+ const {name: breakpoint, smDown} = useBreakpoint()
9
11
  const actualStyle = Object.assign(
10
12
  {
11
- flexDirection: "row"
13
+ flexDirection: breakpoint == "sm" || smDown ? "column" : "row"
12
14
  },
13
15
  style
14
16
  )
@@ -9,6 +9,7 @@ import propTypesExact from "prop-types-exact"
9
9
  import {shapeComponent} from "set-state-compare/src/shape-component"
10
10
  import SortLink from "../bootstrap/sort-link"
11
11
  import Text from "../utils/text"
12
+ import useBreakpoint from "../use-breakpoint"
12
13
  import useEventListener from "../use-event-listener.mjs"
13
14
  import Widths from "./widths"
14
15
 
@@ -23,6 +24,10 @@ export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseC
23
24
  })
24
25
 
25
26
  setup() {
27
+ const {name: breakpoint, mdUp, smDown} = useBreakpoint()
28
+
29
+ this.setInstance({breakpoint, mdUp, smDown})
30
+
26
31
  useEventListener(window, "mousemove", this.tt.onWindowMouseMove)
27
32
  useEventListener(window, "mouseup", this.tt.onWindowMouseUp)
28
33
 
@@ -34,6 +39,7 @@ export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseC
34
39
  }
35
40
 
36
41
  render() {
42
+ const {breakpoint, mdUp, smDown} = this.tt
37
43
  const {column, resizing, table, tableSettingColumn, width} = this.p
38
44
  const {defaultParams} = table.props
39
45
  const {styleForHeader, styleForHeaderText} = table.tt
@@ -43,7 +49,7 @@ export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseC
43
49
  const actualStyle = Object.assign(
44
50
  {
45
51
  cursor: resizing ? "col-resize" : undefined,
46
- width
52
+ width: mdUp ? width : "100%"
47
53
  },
48
54
  style
49
55
  )
@@ -75,19 +81,21 @@ export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseC
75
81
  </Text>
76
82
  }
77
83
  </View>
78
- <Pressable
79
- onMouseDown={Platform.OS == "web" ? this.tt.onResizeMouseDown : undefined}
80
- onPressIn={this.tt.onResizePressIn}
81
- style={{
82
- position: "absolute",
83
- top: 0,
84
- right: 0,
85
- width: 10,
86
- height: "100%",
87
- cursor: "col-resize",
88
- zIndex: 9999
89
- }}
90
- />
84
+ {mdUp &&
85
+ <Pressable
86
+ onMouseDown={Platform.OS == "web" ? this.tt.onResizeMouseDown : undefined}
87
+ onPressIn={this.tt.onResizePressIn}
88
+ style={{
89
+ position: "absolute",
90
+ top: 0,
91
+ right: 0,
92
+ width: 10,
93
+ height: "100%",
94
+ cursor: "col-resize",
95
+ zIndex: 9999
96
+ }}
97
+ />
98
+ }
91
99
  </Header>
92
100
  )
93
101
  }
@@ -9,6 +9,7 @@ import propTypesExact from "prop-types-exact"
9
9
  import {memo} from "react"
10
10
  import {shapeComponent} from "set-state-compare/src/shape-component"
11
11
  import Text from "../utils/text"
12
+ import useBreakpoint from "../use-breakpoint"
12
13
 
13
14
  export default memo(shapeComponent(class ApiMakerTableModelColumn extends BaseComponent {
14
15
  static propTypes = propTypesExact({
@@ -23,11 +24,19 @@ export default memo(shapeComponent(class ApiMakerTableModelColumn extends BaseCo
23
24
  })
24
25
 
25
26
  render() {
27
+ const {mdUp} = useBreakpoint()
26
28
  const {column, columnIndex, even, isSmallScreen, model, table, width} = this.props
27
29
  const columnProps = table.columnProps(column)
28
30
  const {style, ...restColumnProps} = columnProps
29
31
  const actualStyle = Object.assign(
30
- table.styleForColumn({column, columnIndex, even, style: {width}}),
32
+ table.styleForColumn({
33
+ column,
34
+ columnIndex,
35
+ even,
36
+ style: {
37
+ width: mdUp ? width : "100%"
38
+ }
39
+ }),
31
40
  style
32
41
  )
33
42
 
@@ -42,7 +51,7 @@ export default memo(shapeComponent(class ApiMakerTableModelColumn extends BaseCo
42
51
  >
43
52
  {isSmallScreen &&
44
53
  <View dataSet={{class: "table--column-label"}}>
45
- <Text>
54
+ <Text style={{fontWeight: "bold"}}>
46
55
  {table.headerLabelForColumn(column)}
47
56
  </Text>
48
57
  </View>
@@ -99,13 +99,14 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
99
99
 
100
100
  setup() {
101
101
  const {t} = useI18n({namespace: "js.api_maker.table"})
102
- const {name: breakpoint} = useBreakpoint()
102
+ const {name: breakpoint, mdUp} = useBreakpoint()
103
103
  const queryParams = useQueryParams()
104
104
 
105
105
  this.setInstance({
106
106
  breakpoint,
107
107
  filterFormRef: useRef(),
108
108
  isSmallScreen: breakpoint == "xs" || breakpoint == "sm",
109
+ mdUp,
109
110
  t
110
111
  })
111
112
 
@@ -517,7 +518,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
517
518
  const {queryWithoutPagination} = this.tt
518
519
 
519
520
  return (
520
- <Row dataSet={{class: "live-table-header-row"}} style={this.styleForRow()}>
521
+ <Row dataSet={{class: "api-maker/table/header-row"}} style={this.styleForRowHeader()}>
521
522
  {this.p.workplace && this.s.currentWorkplace &&
522
523
  <Header style={this.styleForHeader({style: {width: 41}})}>
523
524
  <WorkerPluginsCheckAllCheckbox
@@ -561,7 +562,8 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
561
562
  )
562
563
  }
563
564
 
564
- styleForColumn({column, columnIndex, even, style, type}) {
565
+ styleForColumn = ({column, columnIndex, even, style, type}) => {
566
+ const {mdUp} = this.tt
565
567
  const defaultStyle = {
566
568
  justifyContent: "center",
567
569
  padding: 8,
@@ -572,7 +574,12 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
572
574
  if (type == "actions") {
573
575
  defaultStyle.flexDirection = "row"
574
576
  defaultStyle.alignItems = "center"
575
- defaultStyle.marginLeft = "auto"
577
+
578
+ if (mdUp) {
579
+ defaultStyle.marginLeft = "auto"
580
+ } else {
581
+ defaultStyle.marginRight = "auto"
582
+ }
576
583
  } else {
577
584
  defaultStyle.borderRight = "1px solid #dbdbdb"
578
585
  }
@@ -621,6 +628,15 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
621
628
  return actualStyle
622
629
  }
623
630
 
631
+ styleForRowHeader() {
632
+ const actualStyle = {
633
+ flex: 1,
634
+ alignItems: "stretch"
635
+ }
636
+
637
+ return actualStyle
638
+ }
639
+
624
640
  tableControls() {
625
641
  const {controls} = this.props
626
642
  const {showSettings} = this.s