Skip to content

Commit 130acf9

Browse files
committed
fix: changed typescript types to correctly handle null/undefined
1 parent d567152 commit 130acf9

35 files changed

+574
-438
lines changed

CHANGELOG.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4-
## [0.3.2] - 2021-03-18
4+
## [0.3.3] - 2022-04-29
5+
### Fixed
6+
- fix: changed typescript types to correctly handle null/undefined.
7+
8+
## [0.3.2] - 2022-03-18
59
### Fixed
610
- fix(Modal): disabled implicit attr inheritance in modals.
711
- fix(ListView): do not assume a specific typescript type for pf-list-view rows.
812

9-
## [0.3.1] - 2021-02-08
13+
## [0.3.1] - 2022-02-08
1014
### Fixed
1115
- fix(Layout): never pass undefined|null to emitted event update:collapsed.
1216
- fix(OUIA): reverted ouia component names to use V-PF3/ prefix.
1317

14-
## [0.3.0] - 2021-02-03
18+
## [0.3.0] - 2022-02-03
1519
### Added
1620
- refactor: converted the whole codebase to typescript.
1721
- feat(typescript): exported type definitions for all components.
@@ -407,7 +411,8 @@ disabled, as per PatternFly design guidelines.
407411
- `pf-toolbar` component
408412
- `pf-utilization-bar-chart` component
409413

410-
[Unreleased]: https://github.com/mtorromeo/vue-patternfly/compare/v0.3.2...HEAD
414+
[Unreleased]: https://github.com/mtorromeo/vue-patternfly/compare/v0.3.3...HEAD
415+
[0.3.3]: https://github.com/mtorromeo/vue-patternfly/compare/v0.3.2...v0.3.3
411416
[0.3.2]: https://github.com/mtorromeo/vue-patternfly/compare/v0.3.1...v0.3.2
412417
[0.3.1]: https://github.com/mtorromeo/vue-patternfly/compare/v0.3.0...v0.3.1
413418
[0.3.0]: https://github.com/mtorromeo/vue-patternfly/compare/v0.2.11...v0.3.0

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-patternfly",
3-
"version": "0.3.2",
3+
"version": "0.3.3",
44
"description": "PatternFly 3 components for Vue 3",
55
"main": "dist/vue-patternfly.umd.js",
66
"module": "dist/vue-patternfly.es.js",

src/components/Card.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div v-bind="ouiaProps" class="card-pf" :class="{'card-pf-accented': accented}">
33
<div v-if="showHeader" :class="{'card-pf-heading': showTitlesSeparator, 'card-pf-heading-no-bottom': !showTitlesSeparator}">
44
<slot name="header">
5-
<pf-dropdown v-if="showFilterInHeader" class="card-pf-time-frame-filter" :text="currentFilter.label" menu-right>
5+
<pf-dropdown v-if="showFilterInHeader" class="card-pf-time-frame-filter" :text="currentFilter?.label" menu-right>
66
<li
77
v-for="(item, i) in filter.filters"
88
:key="i"
@@ -26,7 +26,7 @@
2626
</div>
2727

2828
<div v-if="showFooter || showFilterInFooter" class="card-pf-footer">
29-
<pf-dropdown v-if="showFilterInFooter" class="card-pf-time-frame-filter" :text="currentFilter.label" menu-right>
29+
<pf-dropdown v-if="showFilterInFooter" class="card-pf-time-frame-filter" :text="currentFilter?.label" menu-right>
3030
<li
3131
v-for="(item, i) in filter.filters"
3232
:key="i"

src/components/ColumnPicker.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export default defineComponent({
7474
7575
methods: {
7676
columnValue(column: Column, i: string | number | typeof Symbol.iterator | typeof Symbol.unscopables) {
77-
let value = typeof i === 'string' ? i : column;
77+
let value: Column | undefined = typeof i === 'string' ? i : column;
7878
if (typeof value === 'object') {
7979
value = typeof value.name === 'undefined' ? value.label : value.name;
8080
}
@@ -90,7 +90,7 @@ export default defineComponent({
9090
const iter = Array.isArray(this.columns) ? this.columns.entries() : Object.entries(this.columns);
9191
for (const [i, column] of iter) {
9292
const value = this.columnValue(column, i);
93-
if (this.iValue.indexOf(value) >= 0) {
93+
if (value && this.iValue.includes(value)) {
9494
sortedValue.push(value);
9595
}
9696
}

src/components/Combobox.vue

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<input v-if="name" type="hidden" :name="name" :value="modelValue" :disabled="effectiveDisabled" :required="required">
1212
<div class="input-group">
1313
<label v-if="withCheckbox" class="input-group-addon">
14-
<input v-model="checked" type="checkbox" :name="typeof withCheckbox === 'string' ? withCheckbox : null" value="1">
14+
<input v-model="checked" type="checkbox" :name="typeof withCheckbox === 'string' ? withCheckbox : undefined" value="1">
1515
</label>
1616

1717
<input
@@ -51,7 +51,7 @@
5151
</li>
5252
</ul>
5353

54-
<slot name="dropdownTrigger" :disabled="effectiveDisabled" :clickHandler="dropdownClick">
54+
<slot name="dropdownTrigger" :disabled="effectiveDisabled" :click-handler="dropdownClick">
5555
<a href="javascript:void(0)" role="button" class="input-group-addon dropdown-toggle" :class="{disabled: effectiveDisabled}" data-dropdown="dropdown" :disabled="effectiveDisabled" @click.prevent="dropdownClick">
5656
<span class="caret" />
5757
<pf-icon name="glyphicon-remove" />
@@ -82,7 +82,7 @@ export default defineComponent({
8282
default: null,
8383
},
8484
modelValue: {
85-
type: [String, Number],
85+
type: [String, Number] as PropType<string | number |null>,
8686
default: null,
8787
},
8888
placeholder: {
@@ -108,11 +108,11 @@ export default defineComponent({
108108
default: 'id',
109109
},
110110
match: {
111-
type: Function,
111+
type: Function as PropType<(o: NormalizedOption, q: string) => boolean>,
112112
default: (o: NormalizedOption, q: string) => o.label.toString().toLowerCase().includes(q.toLowerCase()),
113113
},
114114
highlight: {
115-
type: Function,
115+
type: Function as PropType<(o: NormalizedOption, q: string) => string>,
116116
default: (o: NormalizedOption, q: string) => o.label.replace(new RegExp(q.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'), 'ig'), '<strong>$&</strong>'),
117117
},
118118
withCheckbox: {
@@ -123,8 +123,8 @@ export default defineComponent({
123123
},
124124
125125
emits: {
126-
update: (value: string | number) => value !== undefined,
127-
'update:modelValue': (value: string | number) => value !== undefined,
126+
update: (value: string | number | null) => value !== undefined,
127+
'update:modelValue': (value: string | number | null) => value !== undefined,
128128
},
129129
130130
setup(props) {
@@ -133,10 +133,10 @@ export default defineComponent({
133133
134134
data(this: void) {
135135
return {
136-
blurTimeout: null as ReturnType<typeof setTimeout> | null,
136+
blurTimeout: undefined as ReturnType<typeof setTimeout> | undefined,
137137
showOptions: false,
138-
filter: null as string,
139-
active: null as string | number,
138+
filter: null as string | null,
139+
active: null as string | number | null,
140140
hasError: false,
141141
checked: false,
142142
};
@@ -148,7 +148,7 @@ export default defineComponent({
148148
},
149149
150150
label() {
151-
if (!this.hasValue || typeof this.optionsMap[this.modelValue] === 'undefined') {
151+
if (this.modelValue === null || typeof this.optionsMap[this.modelValue] === 'undefined') {
152152
return '';
153153
}
154154
return this.optionsMap[this.modelValue].label;
@@ -173,15 +173,17 @@ export default defineComponent({
173173
if (this.filter === null) {
174174
return [];
175175
}
176-
return Object.values(this.optionsMap).reduce((options, o) => {
176+
177+
const options = [];
178+
for (const o of Object.values(this.optionsMap)) {
177179
if (this.match(o, this.filter)) {
178180
options.push({
179181
...o,
180182
highlighted: this.highlight(o, this.filter),
181183
});
182184
}
183-
return options;
184-
}, []);
185+
}
186+
return options;
185187
},
186188
187189
text: {
@@ -198,7 +200,7 @@ export default defineComponent({
198200
},
199201
200202
effectiveDisabled() {
201-
return this.disabled || (this.withCheckbox && !this.checked);
203+
return this.disabled || Boolean(this.withCheckbox && !this.checked);
202204
},
203205
},
204206
@@ -220,7 +222,7 @@ export default defineComponent({
220222
},
221223
222224
methods: {
223-
setValue(value: string | number) {
225+
setValue(value: string | number | null) {
224226
this.showOptions = false;
225227
this.filter = null;
226228
if (value !== this.modelValue) {

src/components/DrawerGroup.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export default defineComponent({
5454
5555
setup(props) {
5656
return {
57-
activeGroup: inject<Component>('activeGroup', null),
57+
activeGroup: inject<Component | null>('activeGroup', null),
5858
...useOUIAProps(props),
5959
};
6060
},

src/components/DrawerNotification.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
class="pull-right"
3131
:variant="buttonVariant"
3232
:title="action.title"
33-
@click="triggered(action)"
33+
@click="action && triggered(action)"
3434
>
3535
{{ action.name }}
3636
</pf-button>
@@ -85,7 +85,7 @@ export default defineComponent({
8585
setup(props) {
8686
return {
8787
drawerExpanded: inject('drawerExpanded', false),
88-
drawerDropdowns: inject<HTMLElement>('drawerDropdowns', null),
88+
drawerDropdowns: inject<HTMLElement | undefined>('drawerDropdowns', undefined),
8989
...useOUIAProps(props),
9090
};
9191
},

src/components/Dropdown.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,25 +172,25 @@ export default defineComponent({
172172
},
173173
174174
setDropdownPosition() {
175-
if (!(this.$refs.dropdown instanceof HTMLElement) || !(this.$refs.trigger instanceof Element) || !this.appendTo) {
175+
if (!(this.$refs.dropdown instanceof HTMLElement) || !(this.$refs.trigger instanceof Element) || !this.appendTo?.offsetParent) {
176176
return;
177177
}
178178
179179
const rP = this.appendTo.offsetParent.getBoundingClientRect();
180180
const rT = this.$refs.trigger.getBoundingClientRect();
181-
let rD: DOMRect;
181+
let rD: DOMRect | undefined;
182182
if (this.menuRight || this.dropup) {
183183
rD = this.$refs.dropdown.getBoundingClientRect();
184184
}
185185
186186
let top = rT.top - rP.top;
187187
let left = rT.left - rP.left;
188188
189-
if (this.menuRight) {
189+
if (rD && this.menuRight) {
190190
left -= rD.width - rT.width;
191191
}
192192
193-
if (this.dropup) {
193+
if (rD && this.dropup) {
194194
top -= rD.height;
195195
} else {
196196
top += rT.height;

src/components/FilterFields.vue

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<template>
22
<div v-bind="ouiaProps" class="input-group">
3-
<pf-dropdown v-if="showDropdown" :text="current.label" class="input-group-btn">
3+
<pf-dropdown v-if="showDropdown" :text="current?.label" class="input-group-btn">
44
<li v-for="(item, i) in normFields" :key="item.name">
55
<a class="filter-field" role="menuitem" tabindex="-1" @click="selected = i">
66
{{ item.label }}
77
</a>
88
</li>
99
</pf-dropdown>
10-
<pf-select v-if="isSelect" close-on-select class="filter-select" :placeholder="current.placeholder">
10+
<pf-select v-if="current?.values" close-on-select class="filter-select" :placeholder="current.placeholder">
1111
<pf-option v-for="(item, i) in current.values" :key="i" :checked-value="item" @update:model-value="set($event as string)">
1212
{{ item }}
1313
</pf-option>
@@ -18,7 +18,7 @@
1818
class="form-control"
1919
type="text"
2020
:value="value"
21-
:placeholder="showDropdown || current.placeholder ? current.placeholder : current.label"
21+
:placeholder="showDropdown || current?.placeholder ? current?.placeholder : current?.label"
2222
@keyup.enter.stop="set"
2323
>
2424
</div>
@@ -79,7 +79,7 @@ export default defineComponent({
7979
},
8080
8181
computed: {
82-
current(): FilterField {
82+
current(): FilterField | null {
8383
let selected = this.selected;
8484
if (!this.normFields[selected]) {
8585
if (!this.normFields.length) {
@@ -90,10 +90,6 @@ export default defineComponent({
9090
return this.normFields[selected];
9191
},
9292
93-
isSelect() {
94-
return typeof this.current.values !== 'undefined';
95-
},
96-
9793
showDropdown() {
9894
return Object.keys(this.normFields).length > 1;
9995
},
@@ -120,16 +116,16 @@ export default defineComponent({
120116
121117
methods: {
122118
normalizeField(fieldDefinition: FilterFieldDefinition, name?: string): FilterField {
123-
const field: FilterField = {
124-
name: typeof fieldDefinition === 'object' ? fieldDefinition.name : '',
125-
label: typeof fieldDefinition === 'object' ? fieldDefinition.label : fieldDefinition,
119+
const field: Partial<FilterField> = {
120+
name: typeof fieldDefinition === 'object' ? fieldDefinition?.name : '',
121+
label: typeof fieldDefinition === 'object' ? fieldDefinition?.label : fieldDefinition,
126122
placeholder: typeof fieldDefinition === 'object' ? fieldDefinition.placeholder : undefined,
127123
};
128124
field.name = name || field.name || field.label || '';
129125
if (!field.label) {
130-
field.label = name;
126+
field.label = field.name;
131127
}
132-
return field;
128+
return field as FilterField;
133129
},
134130
135131
set(value: KeyboardEvent | string) {

src/components/FilterResults.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
<li v-for="(filter, i) in filters" :key="i">
1111
<span class="active-filter label label-info">
1212
{{ filter.label }}: {{ filter.value }}
13-
<a><pf-icon name="pficon-close" @click="toolbar().clearFilter(i)" /></a>
13+
<a><pf-icon name="pficon-close" @click="toolbar()?.clearFilter(i)" /></a>
1414
</span>
1515
</li>
1616
</ul>
17-
<p><a v-if="filters.length > 0" class="clear-filters" @click="toolbar().clearAllFilters()">Clear All Filters</a></p>
17+
<p><a v-if="filters.length > 0" class="clear-filters" @click="toolbar()?.clearAllFilters()">Clear All Filters</a></p>
1818
</div>
1919
</div>
2020
</div>

0 commit comments

Comments
 (0)