From 97cd9bc29f2703c4a35d1c3c39e21a2316cc8def Mon Sep 17 00:00:00 2001 From: Mike Wu Date: Wed, 15 Jan 2025 15:38:26 +0900 Subject: [PATCH 1/4] expand isLockDevice to check more properties --- src/lib/seam/locks/lock-device.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/lib/seam/locks/lock-device.ts b/src/lib/seam/locks/lock-device.ts index 8acab2a90..e7b12198b 100644 --- a/src/lib/seam/locks/lock-device.ts +++ b/src/lib/seam/locks/lock-device.ts @@ -5,5 +5,14 @@ export type LockDevice = Omit & { NonNullable>> } -export const isLockDevice = (device: Device): device is LockDevice => - 'locked' in device.properties +export const isLockDevice = (device: Device): device is LockDevice => { + return ( + 'locked' in device.properties || + 'can_remotely_lock' in device || + 'can_remotely_unlock' in device || + 'can_program_online_access_code' in device || + 'can_program_offline_access_code' in device || + device.properties.online_access_codes_enabled === true || + device.properties.offline_access_codes_enabled === true + ) +} From b281732b77f233f97ca44c1d8d55028ff321ada2 Mon Sep 17 00:00:00 2001 From: Mike Wu Date: Wed, 15 Jan 2025 15:58:53 +0900 Subject: [PATCH 2/4] conditionally render UI based on availability: online, device property, access code type, etc. --- .../AccessCodeDetails/AccessCodeDetails.tsx | 4 +- .../AccessCodeDetails/AccessCodeDevice.tsx | 2 +- .../AccessCodeTable/AccessCodeTable.tsx | 27 +++++++---- .../DeviceDetails/LockDeviceDetails.tsx | 47 +++++++++++-------- src/lib/ui/device/LockStatus.tsx | 4 ++ 5 files changed, 53 insertions(+), 31 deletions(-) diff --git a/src/lib/seam/components/AccessCodeDetails/AccessCodeDetails.tsx b/src/lib/seam/components/AccessCodeDetails/AccessCodeDetails.tsx index e1725bdc2..24e9ffeb1 100644 --- a/src/lib/seam/components/AccessCodeDetails/AccessCodeDetails.tsx +++ b/src/lib/seam/components/AccessCodeDetails/AccessCodeDetails.tsx @@ -217,7 +217,7 @@ export function AccessCodeDetails({ {(!disableEditAccessCode || !disableDeleteAccessCode) && (
- {!disableEditAccessCode && ( + {!disableEditAccessCode && !accessCode.is_offline_access_code && (
- {!disableLockUnlock && ( + {!disableLockUnlock && device.properties.online && ( - )} + {device.properties.locked && device.properties.online && ( +
+
+ {t.lockStatus} + {lockStatus} +
+
+ {!disableLockUnlock && + device.capabilities_supported.includes('lock') && ( + + )} +
- + )} + From 0cf126c760f6f11fa36accda4963da9659641f06 Mon Sep 17 00:00:00 2001 From: Mike Wu Date: Wed, 15 Jan 2025 16:21:54 +0900 Subject: [PATCH 3/4] add test assertion --- .../DeviceTable/DeviceTable.test.tsx | 29 ++++++++++++++++++- test/fixtures/api.ts | 9 +++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/lib/seam/components/DeviceTable/DeviceTable.test.tsx b/src/lib/seam/components/DeviceTable/DeviceTable.test.tsx index 29d8d1444..cc2742acc 100644 --- a/src/lib/seam/components/DeviceTable/DeviceTable.test.tsx +++ b/src/lib/seam/components/DeviceTable/DeviceTable.test.tsx @@ -5,7 +5,34 @@ import { render, screen } from 'fixtures/react.js' import { DeviceTable } from './DeviceTable.js' -test('DeviceTable', async (ctx) => { +test('DeviceTable renders devices', async (ctx) => { render(, ctx) await screen.findByText('Fake August Lock 1') }) + +test('DeviceTable renders generic lock device', async (ctx) => { + const existingDevice = ctx.database.devices[0] + + ctx.database.addDevice({ + device_id: 'august_generic_lock_device', + device_type: 'august_lock', + name: 'Generic August Device', + display_name: 'Generic August Device', + connected_account_id: existingDevice?.connected_account_id, + can_remotely_unlock: false, + can_remotely_lock: false, + can_program_online_access_codes: true, + properties: { + online: false, + manufacturer: 'august', + name: 'Generic August Device', + }, + workspace_id: existingDevice?.workspace_id ?? '', + errors: [], + warnings: [], + custom_metadata: {}, + }) + + render(, ctx) + await screen.findByText('Generic August Device') +}) diff --git a/test/fixtures/api.ts b/test/fixtures/api.ts index 94570fee2..8889c88f0 100644 --- a/test/fixtures/api.ts +++ b/test/fixtures/api.ts @@ -2,12 +2,18 @@ import { createFake as createFakeDevicedb, type Fake as FakeDevicedb, } from '@seamapi/fake-devicedb' -import { createFake, type Fake, type Seed } from '@seamapi/fake-seam-connect' +import { + createFake, + type Database, + type Fake, + type Seed, +} from '@seamapi/fake-seam-connect' import { beforeEach } from 'vitest' export interface ApiTestContext { endpoint: string seed: Seed + database: Database } beforeEach(async (ctx) => { @@ -22,6 +28,7 @@ beforeEach(async (ctx) => { ctx.endpoint = endpoint ctx.seed = seed + ctx.database = fake.database return () => { fake.server?.close() From f672f1ad46c6bc98f5cbb8e995b2f8c9799a3b96 Mon Sep 17 00:00:00 2001 From: Seam Bot Date: Wed, 15 Jan 2025 07:39:30 +0000 Subject: [PATCH 4/4] ci: Format code --- src/lib/seam/components/AccessCodeTable/AccessCodeTable.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/seam/components/AccessCodeTable/AccessCodeTable.tsx b/src/lib/seam/components/AccessCodeTable/AccessCodeTable.tsx index 764529c18..c3286f759 100644 --- a/src/lib/seam/components/AccessCodeTable/AccessCodeTable.tsx +++ b/src/lib/seam/components/AccessCodeTable/AccessCodeTable.tsx @@ -4,6 +4,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react' import { compareByCreatedAtDesc } from 'lib/dates.js' import { AddIcon } from 'lib/icons/Add.js' +import { useDevice } from 'lib/index.js' import { useAccessCodes } from 'lib/seam/access-codes/use-access-codes.js' import { NestedAccessCodeDetails } from 'lib/seam/components/AccessCodeDetails/AccessCodeDetails.js' import { @@ -29,7 +30,6 @@ import { TableTitle } from 'lib/ui/Table/TableTitle.js' import { SearchTextField } from 'lib/ui/TextField/SearchTextField.js' import { Caption } from 'lib/ui/typography/Caption.js' import { useToggle } from 'lib/ui/use-toggle.js' -import { useDevice } from 'lib/index.js' export const NestedAccessCodeTable = withRequiredCommonProps(AccessCodeTable)