Skip to content

Commit 0de3505

Browse files
AlchezRohan Bansal
andauthored
[project] add strict null checks to improve logic (#234)
Co-authored-by: Rohan Bansal <[email protected]>
1 parent f3bd786 commit 0de3505

29 files changed

+585
-510
lines changed

aform/src/directives/mask.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ function getMask(binding: DirectiveBinding<string>) {
4343
if (maskFn) {
4444
// TODO: (state) replace with state management;
4545
// pass the entire form/table data to the function
46-
const locale = binding.instance['locale']
46+
const locale = binding.instance?.['locale']
4747
mask = maskFn(locale)
4848
}
4949
} else {
5050
// TODO: (state) handle using state management
51-
const schema = binding.instance['schema'] as FormSchema
51+
const schema = binding.instance?.['schema'] as FormSchema
5252
const fieldType: string | undefined = schema?.fieldtype?.toLowerCase()
5353
if (fieldType && NAMED_MASKS[fieldType]) {
5454
mask = NAMED_MASKS[fieldType]
@@ -127,7 +127,7 @@ export function useStringMask(el: HTMLInputElement, binding: DirectiveBinding<st
127127
// most likely fixed with state management;
128128
// a better way could be to emit back to instance;
129129

130-
if (binding.instance['maskFilled']) {
130+
if (binding.instance?.['maskFilled']) {
131131
binding.instance['maskFilled'] = !replacement.includes(maskToken)
132132
}
133133

aform/tests/datepicker.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@ describe('datepicker component', () => {
4848

4949
const $prevMonthBtn = wrapper.find('#previous-month-btn')
5050
await $prevMonthBtn.trigger('click')
51-
expect(wrapper.vm.currentMonth).toBe(new Date().getMonth() - 1)
51+
52+
const currentMonth = new Date().getMonth()
53+
if (currentMonth === 0) {
54+
expect(wrapper.vm.currentMonth).toBe(11)
55+
} else {
56+
expect(wrapper.vm.currentMonth).toBe(currentMonth - 1)
57+
}
5258
})
5359

5460
it('select previous year', async () => {

atable/src/components/ACell.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ const showModal = () => {
9090
state.modal.visible = true
9191
state.modal.colIndex = colIndex
9292
state.modal.rowIndex = rowIndex
93-
state.modal.parent = cellRef.value
94-
state.modal.top = cellRef.value.offsetTop + cellRef.value.offsetHeight
95-
state.modal.left = cellRef.value.offsetLeft
93+
state.modal.parent = cellRef.value!
94+
state.modal.top = cellRef.value!.offsetTop + cellRef.value!.offsetHeight
95+
state.modal.left = cellRef.value!.offsetLeft
9696
state.modal.width = width.value
9797
state.modal.height = height.value
9898
@@ -146,7 +146,7 @@ if (addNavigation) {
146146
147147
const onFocus = () => {
148148
if (cellRef.value) {
149-
currentData.value = cellRef.value.textContent
149+
currentData.value = cellRef.value.textContent!
150150
}
151151
}
152152
@@ -156,14 +156,14 @@ const updateCellData = (payload: Event) => {
156156
return
157157
}
158158
159-
emit('cellInput', colIndex, rowIndex, target.textContent, currentData.value)
160-
currentData.value = target.textContent
159+
emit('cellInput', colIndex, rowIndex, target.textContent!, currentData.value)
160+
currentData.value = target.textContent!
161161
162162
// only apply changes if the cell value has changed after being mounted
163163
if (column.format) {
164164
cellModified.value = target.textContent !== store.getFormattedValue(colIndex, rowIndex, originalData)
165165
// TODO: need to setup reverse format function?
166-
store.setCellText(colIndex, rowIndex, target.textContent)
166+
store.setCellText(colIndex, rowIndex, target.textContent!)
167167
} else {
168168
cellModified.value = target.textContent !== originalData
169169
store.setCellData(colIndex, rowIndex, target.textContent)

atable/src/components/ARow.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
<script setup lang="ts">
2828
import { type KeypressHandlers, useKeyboardNav, defaultKeypressHandlers } from '@stonecrop/utilities'
29-
import { useTemplateRef } from 'vue'
29+
import { computed, useTemplateRef } from 'vue'
3030
3131
import { createTableStore } from '../stores/table'
3232
@@ -43,8 +43,9 @@ const {
4343
}>()
4444
4545
const rowRef = useTemplateRef<HTMLTableRowElement>('rowEl')
46-
const isRowVisible = store.isRowVisible(rowIndex)
47-
const rowExpandSymbol = store.getRowExpandSymbol(rowIndex)
46+
47+
const isRowVisible = computed(() => store.isRowVisible(rowIndex))
48+
const rowExpandSymbol = computed(() => store.getRowExpandSymbol(rowIndex))
4849
4950
if (addNavigation) {
5051
let handlers = defaultKeypressHandlers

atable/src/stores/table.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const createTableStore = (initData: {
5656
defaultDisplay[rowIndex] = {
5757
childrenOpen: false,
5858
expanded: false,
59-
indent: row.indent || null,
59+
indent: row.indent || 0,
6060
isParent: parents.has(rowIndex),
6161
isRoot: row.parent === null || row.parent === undefined,
6262
rowModified: false,
@@ -85,7 +85,9 @@ export const createTableStore = (initData: {
8585
return `${indent}ch`
8686
})
8787

88-
const zeroColumn = computed(() => ['list', 'tree', 'list-expansion'].includes(config.value.view))
88+
const zeroColumn = computed(() =>
89+
config.value.view ? ['list', 'tree', 'list-expansion'].includes(config.value.view) : false
90+
)
8991

9092
// actions
9193
const getCellData = <T = any>(colIndex: number, rowIndex: number): T => table.value[`${colIndex}:${rowIndex}`]
@@ -113,7 +115,7 @@ export const createTableStore = (initData: {
113115
const getHeaderCellStyle = (column: TableColumn): CSSProperties => ({
114116
minWidth: column.width || '40ch',
115117
textAlign: column.align || 'center',
116-
width: config.value.fullWidth ? 'auto' : null,
118+
width: config.value.fullWidth ? 'auto' : undefined,
117119
})
118120

119121
const isRowVisible = (rowIndex: number) => {

beam/src/composables/mqtt.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { IMqttStream } from '../types'
99
* @returns MQTT stream messages
1010
* @beta
1111
*/
12-
export const useMqttStream = (options?: IMqttStream) => {
13-
const client = ref<MqttClient>(null)
12+
export const useMqttStream = (options: IMqttStream) => {
13+
const client = ref<MqttClient>()
1414
const messages = ref<Record<string, string[]>>({})
1515

1616
onMounted(() => {
@@ -38,7 +38,7 @@ export const useMqttStream = (options?: IMqttStream) => {
3838
})
3939

4040
onUnmounted(() => {
41-
client.value.end()
41+
client.value?.end()
4242
})
4343

4444
return { messages }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@stonecrop/aform",
5+
"comment": "add strict null checks to improve logic",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@stonecrop/aform"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@stonecrop/atable",
5+
"comment": "add strict null checks to improve logic",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@stonecrop/atable"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@stonecrop/beam",
5+
"comment": "add strict null checks to improve logic",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@stonecrop/beam"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@stonecrop/desktop",
5+
"comment": "add strict null checks to improve logic",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@stonecrop/desktop"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@stonecrop/stonecrop",
5+
"comment": "add strict null checks to improve logic",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@stonecrop/stonecrop"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@stonecrop/utilities",
5+
"comment": "add strict null checks to improve logic",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@stonecrop/utilities"
10+
}

common/config/rush/pnpm-lock.yaml

Lines changed: 6 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)