Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[project] add strict null checks to improve logic #234

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions aform/src/directives/mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ function getMask(binding: DirectiveBinding<string>) {
if (maskFn) {
// TODO: (state) replace with state management;
// pass the entire form/table data to the function
const locale = binding.instance['locale']
const locale = binding.instance?.['locale']
mask = maskFn(locale)
}
} else {
// TODO: (state) handle using state management
const schema = binding.instance['schema'] as FormSchema
const schema = binding.instance?.['schema'] as FormSchema
const fieldType: string | undefined = schema?.fieldtype?.toLowerCase()
if (fieldType && NAMED_MASKS[fieldType]) {
mask = NAMED_MASKS[fieldType]
Expand Down Expand Up @@ -127,7 +127,7 @@ export function useStringMask(el: HTMLInputElement, binding: DirectiveBinding<st
// most likely fixed with state management;
// a better way could be to emit back to instance;

if (binding.instance['maskFilled']) {
if (binding.instance?.['maskFilled']) {
binding.instance['maskFilled'] = !replacement.includes(maskToken)
}

Expand Down
8 changes: 7 additions & 1 deletion aform/tests/datepicker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ describe('datepicker component', () => {

const $prevMonthBtn = wrapper.find('#previous-month-btn')
await $prevMonthBtn.trigger('click')
expect(wrapper.vm.currentMonth).toBe(new Date().getMonth() - 1)

const currentMonth = new Date().getMonth()
if (currentMonth === 0) {
expect(wrapper.vm.currentMonth).toBe(11)
} else {
expect(wrapper.vm.currentMonth).toBe(currentMonth - 1)
}
})

it('select previous year', async () => {
Expand Down
14 changes: 7 additions & 7 deletions atable/src/components/ACell.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ const showModal = () => {
state.modal.visible = true
state.modal.colIndex = colIndex
state.modal.rowIndex = rowIndex
state.modal.parent = cellRef.value
state.modal.top = cellRef.value.offsetTop + cellRef.value.offsetHeight
state.modal.left = cellRef.value.offsetLeft
state.modal.parent = cellRef.value!
state.modal.top = cellRef.value!.offsetTop + cellRef.value!.offsetHeight
state.modal.left = cellRef.value!.offsetLeft
state.modal.width = width.value
state.modal.height = height.value

Expand Down Expand Up @@ -146,7 +146,7 @@ if (addNavigation) {

const onFocus = () => {
if (cellRef.value) {
currentData.value = cellRef.value.textContent
currentData.value = cellRef.value.textContent!
}
}

Expand All @@ -156,14 +156,14 @@ const updateCellData = (payload: Event) => {
return
}

emit('cellInput', colIndex, rowIndex, target.textContent, currentData.value)
currentData.value = target.textContent
emit('cellInput', colIndex, rowIndex, target.textContent!, currentData.value)
currentData.value = target.textContent!

// only apply changes if the cell value has changed after being mounted
if (column.format) {
cellModified.value = target.textContent !== store.getFormattedValue(colIndex, rowIndex, originalData)
// TODO: need to setup reverse format function?
store.setCellText(colIndex, rowIndex, target.textContent)
store.setCellText(colIndex, rowIndex, target.textContent!)
} else {
cellModified.value = target.textContent !== originalData
store.setCellData(colIndex, rowIndex, target.textContent)
Expand Down
7 changes: 4 additions & 3 deletions atable/src/components/ARow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<script setup lang="ts">
import { type KeypressHandlers, useKeyboardNav, defaultKeypressHandlers } from '@stonecrop/utilities'
import { useTemplateRef } from 'vue'
import { computed, useTemplateRef } from 'vue'

import { createTableStore } from '../stores/table'

Expand All @@ -43,8 +43,9 @@ const {
}>()

const rowRef = useTemplateRef<HTMLTableRowElement>('rowEl')
const isRowVisible = store.isRowVisible(rowIndex)
const rowExpandSymbol = store.getRowExpandSymbol(rowIndex)

const isRowVisible = computed(() => store.isRowVisible(rowIndex))
const rowExpandSymbol = computed(() => store.getRowExpandSymbol(rowIndex))

if (addNavigation) {
let handlers = defaultKeypressHandlers
Expand Down
8 changes: 5 additions & 3 deletions atable/src/stores/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const createTableStore = (initData: {
defaultDisplay[rowIndex] = {
childrenOpen: false,
expanded: false,
indent: row.indent || null,
indent: row.indent || 0,
isParent: parents.has(rowIndex),
isRoot: row.parent === null || row.parent === undefined,
rowModified: false,
Expand Down Expand Up @@ -85,7 +85,9 @@ export const createTableStore = (initData: {
return `${indent}ch`
})

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

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

const isRowVisible = (rowIndex: number) => {
Expand Down
6 changes: 3 additions & 3 deletions beam/src/composables/mqtt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { IMqttStream } from '../types'
* @returns MQTT stream messages
* @beta
*/
export const useMqttStream = (options?: IMqttStream) => {
const client = ref<MqttClient>(null)
export const useMqttStream = (options: IMqttStream) => {
const client = ref<MqttClient>()
const messages = ref<Record<string, string[]>>({})

onMounted(() => {
Expand Down Expand Up @@ -38,7 +38,7 @@ export const useMqttStream = (options?: IMqttStream) => {
})

onUnmounted(() => {
client.value.end()
client.value?.end()
})

return { messages }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@stonecrop/aform",
"comment": "add strict null checks to improve logic",
"type": "patch"
}
],
"packageName": "@stonecrop/aform"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@stonecrop/atable",
"comment": "add strict null checks to improve logic",
"type": "patch"
}
],
"packageName": "@stonecrop/atable"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@stonecrop/beam",
"comment": "add strict null checks to improve logic",
"type": "patch"
}
],
"packageName": "@stonecrop/beam"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@stonecrop/desktop",
"comment": "add strict null checks to improve logic",
"type": "patch"
}
],
"packageName": "@stonecrop/desktop"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@stonecrop/stonecrop",
"comment": "add strict null checks to improve logic",
"type": "patch"
}
],
"packageName": "@stonecrop/stonecrop"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@stonecrop/utilities",
"comment": "add strict null checks to improve logic",
"type": "patch"
}
],
"packageName": "@stonecrop/utilities"
}
15 changes: 6 additions & 9 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading