Skip to content

Commit 77ba2b7

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 77ba2b7

File tree

2 files changed

+81
-60
lines changed

2 files changed

+81
-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

+43-32
Original file line numberDiff line numberDiff line change
@@ -51,59 +51,70 @@ 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_id] ?? null)
58+
) {
5859

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

63+
continue
6264

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-
])
65+
}
6766

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

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

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

7874

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

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

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

88+
const icon_c = state.push('icon_close', 'span', -1)
8789

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

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

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

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

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

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

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

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

106-
}
107118

108119
}
109120

0 commit comments

Comments
 (0)