Skip to content

Commit f2a6feb

Browse files
committed
feat(function): Improved error handling for markdown plugins for items that have no metadata
ref: #40 #42 nofusscomputing/centurion_erp#466
1 parent 1078779 commit f2a6feb

File tree

2 files changed

+82
-60
lines changed

2 files changed

+82
-60
lines changed

src/functions/markdown_plugins/ModelLink.js

+38-28
Original file line numberDiff line numberDiff line change
@@ -48,51 +48,61 @@ function model_link (state) {
4848
state.pos = start
4949
state.posMax = end
5050

51-
if( state.env.models[item_link.groups.model_type][item_link.groups.model_id] ?? null ) {
5251

53-
const span_o = state.push('span_open', 'span', 1)
54-
span_o.attrPush(['class', 'text-inline'])
52+
if(
53+
(! state.env.models ?? null)
54+
|| (! state.env.models[item_link.groups?.model_type] ?? null)
55+
|| (! state.env.models[item_link.groups.model_type][item_link.groups.model_id] ?? null)
56+
) {
5557

56-
const anchor_o = state.push('a_open', 'a', 1)
57-
anchor_o.attrPush(['href', state.env.models[item_link.groups.model_type][item_link.groups.model_id].url])
58+
const failed_token = state.push('text', '', 0)
59+
failed_token.content = item_link.groups.markdown
5860

61+
continue
5962

60-
const icon_o = state.push('icon_open', 'span', 1)
61-
icon_o.attrPush([
62-
'class', 'badge-icon'
63-
])
63+
}
6464

65-
const icon_t = state.push('html_inline', '', 0)
65+
const span_o = state.push('span_open', 'span', 1)
66+
span_o.attrPush(['class', 'text-inline'])
6667

67-
icon_t.content = renderToStaticMarkup(
68-
<IconLoader
69-
name={String( item_link.groups.model_type ).toLowerCase().replace('kb', 'information')}
70-
fill="#777"
71-
/>
72-
)
68+
const anchor_o = state.push('a_open', 'a', 1)
69+
anchor_o.attrPush(['href', state.env.models[item_link.groups.model_type][item_link.groups.model_id].url])
7370

74-
const icon_c = state.push('icon_close', 'span', -1)
7571

72+
const icon_o = state.push('icon_open', 'span', 1)
73+
icon_o.attrPush([
74+
'class', 'badge-icon'
75+
])
7676

77-
const anchor_t = state.push('text', '', 0)
78-
anchor_t.content = ' ' + state.env.models[item_link.groups.model_type][item_link.groups.model_id].title
77+
const icon_t = state.push('html_inline', '', 0)
7978

79+
icon_t.content = renderToStaticMarkup(
80+
<IconLoader
81+
name={String( item_link.groups.model_type ).toLowerCase().replace('kb', 'information')}
82+
fill="#777"
83+
/>
84+
)
8085

81-
const item_o = state.push('item_open', 'span', 1)
82-
item_o.attrPush(["class", "sub-script metadata"])
86+
const icon_c = state.push('icon_close', 'span', -1)
8387

84-
const item_t = state.push('text', '', 0)
85-
item_t.content = ', ' + String( item_link.groups.model_type ) + ' '
8688

87-
const item_c = state.push('item_close', 'span', -1)
89+
const anchor_t = state.push('text', '', 0)
90+
anchor_t.content = ' ' + state.env.models[item_link.groups.model_type][item_link.groups.model_id].title
8891

8992

90-
const anchor_c = state.push('a_close', 'a', -1)
93+
const item_o = state.push('item_open', 'span', 1)
94+
item_o.attrPush(["class", "sub-script metadata"])
9195

92-
93-
const span_c = state.push('span_close', 'span', -1)
96+
const item_t = state.push('text', '', 0)
97+
item_t.content = ', ' + String( item_link.groups.model_type ) + ' '
9498

95-
}
99+
const item_c = state.push('item_close', 'span', -1)
100+
101+
102+
const anchor_c = state.push('a_close', 'a', -1)
103+
104+
105+
const span_c = state.push('span_close', 'span', -1)
96106

97107
}
98108

src/functions/markdown_plugins/TicketLink.js

+44-32
Original file line numberDiff line numberDiff line change
@@ -51,59 +51,71 @@ function ticket_link (state, silent) {
5151
state.pos = start
5252
state.posMax = end
5353

54-
if( state.env.tickets[item_link.groups.model_id] ?? null ) {
5554

56-
const span_o = state.push('span_open', 'span', 1)
57-
span_o.attrPush(['class', 'text-inline'])
55+
if(
56+
(! state.env.tickets ?? null)
57+
|| (! state.env.tickets[item_link.groups?.model_type] ?? null)
58+
|| (! state.env.tickets[item_link.groups.model_type][item_link.groups.model_id] ?? null)
59+
) {
5860

59-
const anchor_o = state.push('a_open', 'a', 1)
60-
anchor_o.attrPush(['href', state.env.tickets[item_link.groups.model_id].url])
61+
const failed_token = state.push('text', '', 0)
62+
failed_token.content = item_link.groups.markdown
6163

64+
continue
6265

63-
const icon_o = state.push('icon_open', 'span', 1)
64-
icon_o.attrPush([
65-
'class', 'badge-icon ticket-status-icon ticket-status-icon-' + String(state.env.tickets[item_link.groups.model_id].status).toLowerCase().replace(' ', '_').replace('(', '').replace(')', '')
66-
])
66+
}
6767

68-
const icon_t = state.push('html_inline', '', 0)
6968

70-
icon_t.content = renderToStaticMarkup(
71-
<IconLoader
72-
name={'ticket_status_new'}
73-
/>
74-
)
69+
const span_o = state.push('span_open', 'span', 1)
70+
span_o.attrPush(['class', 'text-inline'])
7571

76-
const icon_c = state.push('icon_close', 'span', -1)
72+
const anchor_o = state.push('a_open', 'a', 1)
73+
anchor_o.attrPush(['href', state.env.tickets[item_link.groups.model_id].url])
7774

7875

79-
const ref_o = state.push('ref_open', 'span', 1)
80-
ref_o.attrPush(["class", "sub-script metadata"])
76+
const icon_o = state.push('icon_open', 'span', 1)
77+
icon_o.attrPush([
78+
'class', 'badge-icon ticket-status-icon ticket-status-icon-' + String(state.env.tickets[item_link.groups.model_id].status).toLowerCase().replace(' ', '_').replace('(', '').replace(')', '')
79+
])
8180

82-
const ref_t = state.push('text', '', 0)
83-
ref_t.content = ' #' + String( item_link.groups.model_id ) + ' '
81+
const icon_t = state.push('html_inline', '', 0)
8482

85-
const ref_c = state.push('ref_close', 'span', -1)
83+
icon_t.content = renderToStaticMarkup(
84+
<IconLoader
85+
name={'ticket_status_new'}
86+
/>
87+
)
8688

89+
const icon_c = state.push('icon_close', 'span', -1)
8790

88-
const anchor_t = state.push('text', '', 0)
89-
anchor_t.content = state.env.tickets[item_link.groups.model_id].title
9091

92+
const ref_o = state.push('ref_open', 'span', 1)
93+
ref_o.attrPush(["class", "sub-script metadata"])
9194

92-
const item_o = state.push('item_open', 'span', 1)
93-
item_o.attrPush(["class", "sub-script metadata"])
95+
const ref_t = state.push('text', '', 0)
96+
ref_t.content = ' #' + String( item_link.groups.model_id ) + ' '
9497

95-
const item_t = state.push('text', '', 0)
96-
item_t.content = ', ' + String( state.env.tickets[item_link.groups.model_id].ticket_type ) + ' '
98+
const ref_c = state.push('ref_close', 'span', -1)
9799

98-
const item_c = state.push('item_close', 'span', -1)
99100

101+
const anchor_t = state.push('text', '', 0)
102+
anchor_t.content = state.env.tickets[item_link.groups.model_id].title
100103

101-
const anchor_c = state.push('a_close', 'a', -1)
102104

103-
104-
const span_c = state.push('span_close', 'span', -1)
105+
const item_o = state.push('item_open', 'span', 1)
106+
item_o.attrPush(["class", "sub-script metadata"])
107+
108+
const item_t = state.push('text', '', 0)
109+
item_t.content = ', ' + String( state.env.tickets[item_link.groups.model_id].ticket_type ) + ' '
110+
111+
const item_c = state.push('item_close', 'span', -1)
112+
113+
114+
const anchor_c = state.push('a_close', 'a', -1)
115+
116+
117+
const span_c = state.push('span_close', 'span', -1)
105118

106-
}
107119

108120
}
109121

0 commit comments

Comments
 (0)