Skip to content

Commit a1d8517

Browse files
committed
Remove overzealous use of EMPTY_ARRAY
1 parent 25ce57d commit a1d8517

20 files changed

+49
-70
lines changed

app/gui/src/dashboard/components/JSONSchemaInput.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { useText } from '#/providers/TextProvider'
1111
import { constantValueOfSchema, getSchemaName, lookupDef } from '#/utilities/jsonSchema'
1212
import { asObject, singletonObjectOrNull } from '#/utilities/object'
1313
import { twMerge } from '#/utilities/tailwindMerge'
14-
import { EMPTY_ARRAY } from 'enso-common/src/utilities/data/array'
1514
import { twJoin } from 'tailwind-merge'
1615

1716
// =======================
@@ -50,7 +49,7 @@ export default function JSONSchemaInput(props: JSONSchemaInputProps) {
5049
schema.type === 'string' &&
5150
'format' in schema &&
5251
schema.format === 'enso-secret'
53-
const { data: secrets } = useBackendQuery(remoteBackend, 'listSecrets', EMPTY_ARRAY, {
52+
const { data: secrets } = useBackendQuery(remoteBackend, 'listSecrets', [], {
5453
enabled: isSecret,
5554
})
5655
const autocompleteItems = isSecret ? secrets?.map((secret) => secret.path) ?? null : null

app/gui/src/dashboard/components/dashboard/ProjectIcon.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import * as tailwindMerge from '#/utilities/tailwindMerge'
2222
import { useMemo } from 'react'
2323

2424
import { useEventCallback } from '#/hooks/eventCallbackHooks'
25-
import { EMPTY_ARRAY } from 'enso-common/src/utilities/data/array'
2625

2726
// =================
2827
// === Constants ===
@@ -108,7 +107,7 @@ export default function ProjectIcon(props: ProjectIconProps) {
108107
const isOtherUserUsingProject =
109108
isCloud && itemProjectState.openedBy != null && itemProjectState.openedBy !== user.email
110109

111-
const { data: users } = useBackendQuery(backend, 'listUsers', EMPTY_ARRAY, {
110+
const { data: users } = useBackendQuery(backend, 'listUsers', [], {
112111
enabled: isOtherUserUsingProject,
113112
})
114113

app/gui/src/dashboard/components/dashboard/column/LabelsColumn.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default function LabelsColumn(props: column.AssetColumnProps) {
3535
const { user } = authProvider.useFullUserSession()
3636
const { setModal, unsetModal } = modalProvider.useSetModal()
3737
const { getText } = textProvider.useText()
38-
const { data: labels } = backendHooks.useBackendQuery(backend, 'listTags', EMPTY_ARRAY)
38+
const { data: labels } = backendHooks.useBackendQuery(backend, 'listTags', [])
3939
const driveStore = useDriveStore()
4040
const showDraggedLabelsFallback = useStore(
4141
driveStore,

app/gui/src/dashboard/hooks/backendHooks.tsx

+12-13
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ import { download } from '#/utilities/download'
5858
import { getMessageOrToString } from '#/utilities/error'
5959
import { tryCreateOwnerPermission } from '#/utilities/permissions'
6060
import { usePreventNavigation } from '#/utilities/preventNavigation'
61-
import { EMPTY_ARRAY } from 'enso-common/src/utilities/data/array'
6261
import { toRfc3339 } from 'enso-common/src/utilities/data/dateTime'
6362

6463
// The number of bytes in 1 megabyte.
@@ -298,8 +297,8 @@ export interface UserGroupInfoWithUsers extends UserGroupInfo {
298297
export function useListUserGroupsWithUsers(
299298
backend: Backend,
300299
): readonly UserGroupInfoWithUsers[] | null {
301-
const listUserGroupsQuery = useBackendQuery(backend, 'listUserGroups', EMPTY_ARRAY)
302-
const listUsersQuery = useBackendQuery(backend, 'listUsers', EMPTY_ARRAY)
300+
const listUserGroupsQuery = useBackendQuery(backend, 'listUserGroups', [])
301+
const listUsersQuery = useBackendQuery(backend, 'listUsers', [])
303302
if (listUserGroupsQuery.data == null || listUsersQuery.data == null) {
304303
return null
305304
} else {
@@ -554,8 +553,8 @@ export function useNewFolder(backend: Backend, category: Category) {
554553
const setNewestFolderId = useSetNewestFolderId()
555554
const setSelectedAssets = useSetSelectedAssets()
556555
const { user } = useFullUserSession()
557-
const { data: users } = useBackendQuery(backend, 'listUsers', EMPTY_ARRAY)
558-
const { data: userGroups } = useBackendQuery(backend, 'listUserGroups', EMPTY_ARRAY)
556+
const { data: users } = useBackendQuery(backend, 'listUsers', [])
557+
const { data: userGroups } = useBackendQuery(backend, 'listUserGroups', [])
559558
const createDirectoryMutation = useMutation(backendMutationOptions(backend, 'createDirectory'))
560559

561560
return useEventCallback(async (parentId: DirectoryId, parentPath: string | null | undefined) => {
@@ -598,8 +597,8 @@ export function useNewProject(backend: Backend, category: Category) {
598597
const toggleDirectoryExpansion = useToggleDirectoryExpansion()
599598

600599
const { user } = useFullUserSession()
601-
const { data: users } = useBackendQuery(backend, 'listUsers', EMPTY_ARRAY)
602-
const { data: userGroups } = useBackendQuery(backend, 'listUserGroups', EMPTY_ARRAY)
600+
const { data: users } = useBackendQuery(backend, 'listUsers', [])
601+
const { data: userGroups } = useBackendQuery(backend, 'listUserGroups', [])
603602
const createProjectMutation = useMutation(backendMutationOptions(backend, 'createProject'))
604603

605604
return useEventCallback(
@@ -677,8 +676,8 @@ export function useNewProject(backend: Backend, category: Category) {
677676
export function useNewSecret(backend: Backend, category: Category) {
678677
const toggleDirectoryExpansion = useToggleDirectoryExpansion()
679678
const { user } = useFullUserSession()
680-
const { data: users } = useBackendQuery(backend, 'listUsers', EMPTY_ARRAY)
681-
const { data: userGroups } = useBackendQuery(backend, 'listUserGroups', EMPTY_ARRAY)
679+
const { data: users } = useBackendQuery(backend, 'listUsers', [])
680+
const { data: userGroups } = useBackendQuery(backend, 'listUserGroups', [])
682681
const createSecretMutation = useMutation(backendMutationOptions(backend, 'createSecret'))
683682

684683
return useEventCallback(
@@ -716,8 +715,8 @@ export function useNewSecret(backend: Backend, category: Category) {
716715
export function useNewDatalink(backend: Backend, category: Category) {
717716
const toggleDirectoryExpansion = useToggleDirectoryExpansion()
718717
const { user } = useFullUserSession()
719-
const { data: users } = useBackendQuery(backend, 'listUsers', EMPTY_ARRAY)
720-
const { data: userGroups } = useBackendQuery(backend, 'listUserGroups', EMPTY_ARRAY)
718+
const { data: users } = useBackendQuery(backend, 'listUsers', [])
719+
const { data: userGroups } = useBackendQuery(backend, 'listUserGroups', [])
721720
const createDatalinkMutation = useMutation(backendMutationOptions(backend, 'createDatalink'))
722721

723722
return useEventCallback(
@@ -759,8 +758,8 @@ export function useUploadFiles(backend: Backend, category: Category) {
759758
const toggleDirectoryExpansion = useToggleDirectoryExpansion()
760759
const { setModal } = useSetModal()
761760
const { user } = useFullUserSession()
762-
const { data: users } = useBackendQuery(backend, 'listUsers', EMPTY_ARRAY)
763-
const { data: userGroups } = useBackendQuery(backend, 'listUserGroups', EMPTY_ARRAY)
761+
const { data: users } = useBackendQuery(backend, 'listUsers', [])
762+
const { data: userGroups } = useBackendQuery(backend, 'listUserGroups', [])
764763
const uploadFileMutation = useUploadFileWithToastMutation(backend)
765764
const setSelectedAssets = useSetSelectedAssets()
766765

app/gui/src/dashboard/layouts/AssetProperties.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import { mapNonNullish } from '#/utilities/nullable'
3636
import * as permissions from '#/utilities/permissions'
3737
import { tv } from '#/utilities/tailwindVariants'
3838
import { useMutation } from '@tanstack/react-query'
39-
import { EMPTY_ARRAY } from 'enso-common/src/utilities/data/array'
4039
import { useStore } from '../utilities/zustand'
4140

4241
const ASSET_PROPERTIES_VARIANTS = tv({
@@ -161,7 +160,7 @@ function AssetPropertiesInternal(props: AssetPropertiesInternalProps) {
161160
close: closeSpotlight,
162161
})
163162

164-
const labels = useBackendQuery(backend, 'listTags', EMPTY_ARRAY).data ?? EMPTY_ARRAY
163+
const labels = useBackendQuery(backend, 'listTags', []).data ?? []
165164
const self = permissions.tryFindSelfPermission(user, item.permissions)
166165
const ownsThisAsset = self?.permission === permissions.PermissionAction.own
167166
const canEditThisAsset =

app/gui/src/dashboard/layouts/AssetSearchBar.tsx

+3-8
Original file line numberDiff line numberDiff line change
@@ -625,9 +625,7 @@ const SuggestionRenderer = React.memo(function SuggestionRenderer(props: Suggest
625625
)
626626
})
627627

628-
/**
629-
* Props for a {@link Labels}.
630-
*/
628+
/** Props for a {@link Labels}. */
631629
interface LabelsProps {
632630
readonly isCloud: boolean
633631
readonly query: AssetQuery
@@ -637,14 +635,11 @@ interface LabelsProps {
637635
readonly baseQuery: React.MutableRefObject<AssetQuery>
638636
}
639637

640-
/**
641-
* Renders labels.
642-
*/
638+
/** Renders labels. */
643639
const Labels = React.memo(function Labels(props: LabelsProps) {
644640
const { isCloud, query, setQuery, backend, querySource, baseQuery } = props
645641

646-
const labels =
647-
backendHooks.useBackendQuery(backend, 'listTags', array.EMPTY_ARRAY).data ?? array.EMPTY_ARRAY
642+
const labels = backendHooks.useBackendQuery(backend, 'listTags', []).data ?? []
648643

649644
const labelOnPress = useEventCallback(
650645
(event: aria.PressEvent | React.MouseEvent<HTMLButtonElement>, label?: BackendLabel) => {

app/gui/src/dashboard/layouts/AssetsTable.tsx

+6-7
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ import { withPresence } from '#/utilities/set'
145145
import type { SortInfo } from '#/utilities/sorting'
146146
import { twJoin, twMerge } from '#/utilities/tailwindMerge'
147147
import Visibility from '#/utilities/Visibility'
148-
import { EMPTY_ARRAY } from 'enso-common/src/utilities/data/array'
149148
import invariant from 'tiny-invariant'
150149
import { useStore } from '../utilities/zustand'
151150

@@ -319,7 +318,7 @@ function AssetsTable(props: AssetsTableProps) {
319318
const queryClient = useQueryClient()
320319
const { user } = useFullUserSession()
321320
const backend = useBackend(category)
322-
const { data: labels } = useBackendQuery(backend, 'listTags', EMPTY_ARRAY)
321+
const { data: labels } = useBackendQuery(backend, 'listTags', [])
323322
const { setModal, unsetModal } = useSetModal()
324323
const { localStorage } = useLocalStorage()
325324
const { getText } = useText()
@@ -921,7 +920,7 @@ function AssetsTable(props: AssetsTableProps) {
921920
break
922921
}
923922
case 'Escape': {
924-
setSelectedAssets(EMPTY_ARRAY)
923+
setSelectedAssets([])
925924
setMostRecentlySelectedIndex(null)
926925
selectionStartIndexRef.current = null
927926
break
@@ -977,7 +976,7 @@ function AssetsTable(props: AssetsTableProps) {
977976
} else {
978977
// The arrow key will escape this container. In that case, do not stop propagation
979978
// and let `navigator2D` navigate to a different container.
980-
setSelectedAssets(EMPTY_ARRAY)
979+
setSelectedAssets([])
981980
selectionStartIndexRef.current = null
982981
}
983982
break
@@ -1013,7 +1012,7 @@ function AssetsTable(props: AssetsTableProps) {
10131012
type: 'move',
10141013
data: { backendType: backend.type, category, ids: selectedKeys },
10151014
})
1016-
setSelectedAssets(EMPTY_ARRAY)
1015+
setSelectedAssets([])
10171016
})
10181017

10191018
const doPaste = useEventCallback((newParentKey: DirectoryId, newParentId: DirectoryId) => {
@@ -1599,7 +1598,7 @@ function AssetsTable(props: AssetsTableProps) {
15991598
handleFileDrop(event)
16001599
}}
16011600
onClick={() => {
1602-
setSelectedAssets(EMPTY_ARRAY)
1601+
setSelectedAssets([])
16031602
}}
16041603
>
16051604
<FileTrigger
@@ -1795,7 +1794,7 @@ export function AssetsTableAssetsUnselector(props: AssetsTableAssetsUnselectorPr
17951794
const { pressProps } = usePress({
17961795
isDisabled: !hasSelectedKeys,
17971796
onPress: () => {
1798-
setSelectedAssets(EMPTY_ARRAY)
1797+
setSelectedAssets([])
17991798
},
18001799
})
18011800

app/gui/src/dashboard/layouts/AssetsTableContextMenu.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import { useText } from '#/providers/TextProvider'
3131
import type * as assetTreeNode from '#/utilities/AssetTreeNode'
3232
import * as permissions from '#/utilities/permissions'
3333
import { useMutation } from '@tanstack/react-query'
34-
import { EMPTY_ARRAY } from 'enso-common/src/utilities/data/array'
3534

3635
// =================
3736
// === Constants ===
@@ -101,7 +100,7 @@ export default function AssetsTableContextMenu(props: AssetsTableContextMenuProp
101100
const selectedKeys = selectedAssets.map((asset) => asset.id)
102101
const deleteAll = () => {
103102
unsetModal()
104-
setSelectedAssets(EMPTY_ARRAY)
103+
setSelectedAssets([])
105104

106105
deleteAssetsMutation.mutate([selectedKeys, false])
107106
}
@@ -180,7 +179,7 @@ export default function AssetsTableContextMenu(props: AssetsTableContextMenuProp
180179
: getText('deleteSelectedAssetsForeverActionText', selectedAssets.length)
181180
}
182181
doDelete={() => {
183-
setSelectedAssets(EMPTY_ARRAY)
182+
setSelectedAssets([])
184183
deleteAssetsMutation.mutate([
185184
selectedAssets.map((otherAsset) => otherAsset.id),
186185
true,

app/gui/src/dashboard/layouts/Drive/Categories/Category.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
type UserGroupInfo,
2424
} from '#/services/Backend'
2525
import { newDirectoryId } from '#/services/LocalBackend'
26-
import { EMPTY_ARRAY } from 'enso-common/src/utilities/data/array'
2726

2827
const PATH_SCHEMA = z.string().refine((s): s is Path => true)
2928
const DIRECTORY_ID_SCHEMA = z.string().refine((s): s is DirectoryId => true)
@@ -227,11 +226,7 @@ export function useTransferBetweenCategories(currentCategory: Category) {
227226
const localBackend = useLocalBackend()
228227
const backend = useBackend(currentCategory)
229228
const { user } = useFullUserSession()
230-
const { data: organization = null } = useBackendQuery(
231-
remoteBackend,
232-
'getOrganization',
233-
EMPTY_ARRAY,
234-
)
229+
const { data: organization = null } = useBackendQuery(remoteBackend, 'getOrganization', [])
235230
const deleteAssetsMutation = useMutation(deleteAssetsMutationOptions(backend))
236231
const moveAssetsMutation = useMutation(moveAssetsMutationOptions(backend))
237232

app/gui/src/dashboard/layouts/Labels.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default function Labels(props: LabelsProps) {
3939
const driveStore = useDriveStore()
4040
const nodeMapRef = useNodeMap()
4141
const setLabelsDragPayload = useSetLabelsDragPayload()
42-
const labels = useBackendQuery(backend, 'listTags', array.EMPTY_ARRAY).data ?? array.EMPTY_ARRAY
42+
const labels = useBackendQuery(backend, 'listTags', []).data ?? []
4343
const deleteTagMutation = useMutation(backendMutationOptions(backend, 'deleteTag'))
4444

4545
return (

app/gui/src/dashboard/layouts/Settings/ActivityLogSettingsSection.tsx

+6-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { EVENT_TYPES, EventType, type Event } from '#/services/Backend'
2020
import { formatDateTime } from '#/utilities/dateTime'
2121
import { nextSortDirection, SortDirection, type SortInfo } from '#/utilities/sorting'
2222
import { twMerge } from '#/utilities/tailwindMerge'
23-
import { EMPTY_ARRAY } from 'enso-common/src/utilities/data/array'
2423

2524
// =================
2625
// === Constants ===
@@ -74,14 +73,14 @@ export interface ActivityLogSettingsSectionProps {
7473
export default function ActivityLogSettingsSection(props: ActivityLogSettingsSectionProps) {
7574
const { backend } = props
7675
const { getText } = useText()
77-
const [types, setTypes] = React.useState<readonly EventType[]>(EMPTY_ARRAY)
78-
const [typeIndices, setTypeIndices] = React.useState<readonly number[]>(EMPTY_ARRAY)
79-
const [emails, setEmails] = React.useState<readonly string[]>(EMPTY_ARRAY)
80-
const [emailIndices, setEmailIndices] = React.useState<readonly number[]>(EMPTY_ARRAY)
76+
const [types, setTypes] = React.useState<readonly EventType[]>([])
77+
const [typeIndices, setTypeIndices] = React.useState<readonly number[]>([])
78+
const [emails, setEmails] = React.useState<readonly string[]>([])
79+
const [emailIndices, setEmailIndices] = React.useState<readonly number[]>([])
8180
const [sortInfo, setSortInfo] = React.useState<SortInfo<ActivityLogSortableColumn> | null>(null)
82-
const { data: users } = useBackendQuery(backend, 'listUsers', EMPTY_ARRAY)
81+
const { data: users } = useBackendQuery(backend, 'listUsers', [])
8382
const allEmails = React.useMemo(() => (users ?? []).map((user) => user.email), [users])
84-
const logsQuery = useBackendQuery(backend, 'getLogEvents', EMPTY_ARRAY)
83+
const logsQuery = useBackendQuery(backend, 'getLogEvents', [])
8584
const logs = logsQuery.data
8685

8786
const form = Form.useForm({ schema: createActivityLogSchema() })

app/gui/src/dashboard/layouts/Settings/MembersTable.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { useText } from '#/providers/TextProvider'
1919
import type Backend from '#/services/Backend'
2020
import { UserId, type User } from '#/services/Backend'
2121
import { twMerge } from '#/utilities/tailwindMerge'
22-
import { EMPTY_ARRAY } from 'enso-common/src/utilities/data/array'
2322
import UserRow from './UserRow'
2423

2524
/** Props for a {@link MembersTable}. */
@@ -37,13 +36,13 @@ export default function MembersTable(props: MembersTableProps) {
3736
const { user } = useFullUserSession()
3837
const { getText } = useText()
3938
const toastAndLog = useToastAndLog()
40-
const [selectedKeys, setSelectedKeys] = useState<Selection>(() => new Set())
39+
const [selectedKeys, setSelectedKeys] = useState<Selection>(new Set())
4140
const rootRef = useRef<HTMLTableElement>(null)
4241
const scrollContainerRef = useRef<HTMLDivElement>(null)
4342
const bodyRef = useRef<HTMLTableSectionElement>(null)
4443
const userWithPlaceholder = useMemo(() => ({ isPlaceholder: false, ...user }), [user])
4544

46-
const { data: allUsers } = useBackendQuery(backend, 'listUsers', EMPTY_ARRAY)
45+
const { data: allUsers } = useBackendQuery(backend, 'listUsers', [])
4746

4847
const users = useMemo(
4948
() => allUsers ?? (populateWithSelf ? [userWithPlaceholder] : null),

app/gui/src/dashboard/layouts/Settings/OrganizationProfilePictureInput.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import FocusRing from '#/components/styled/FocusRing'
1212

1313
import { Form, HiddenFile } from '#/components/AriaComponents'
1414
import type Backend from '#/services/Backend'
15-
import { EMPTY_ARRAY } from 'enso-common/src/utilities/data/array'
1615

1716
// =======================================
1817
// === OrganizationProfilePictureInput ===
@@ -29,7 +28,7 @@ export default function OrganizationProfilePictureInput(
2928
) {
3029
const { backend } = props
3130
const { getText } = textProvider.useText()
32-
const { data: organization } = useBackendQuery(backend, 'getOrganization', EMPTY_ARRAY)
31+
const { data: organization } = useBackendQuery(backend, 'getOrganization', [])
3332

3433
const uploadOrganizationPicture = useMutation(
3534
backendMutationOptions(backend, 'uploadOrganizationPicture'),

app/gui/src/dashboard/layouts/Settings/ProfilePictureInput.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import FocusRing from '#/components/styled/FocusRing'
1212

1313
import { Form, HiddenFile } from '#/components/AriaComponents'
1414
import type Backend from '#/services/Backend'
15-
import { EMPTY_ARRAY } from 'enso-common/src/utilities/data/array'
1615

1716
// ===========================
1817
// === ProfilePictureInput ===
@@ -26,7 +25,7 @@ export interface ProfilePictureInputProps {
2625
/** The input for viewing and changing the user's profile picture. */
2726
export default function ProfilePictureInput(props: ProfilePictureInputProps) {
2827
const { backend } = props
29-
const { data: user } = useBackendQuery(backend, 'usersMe', EMPTY_ARRAY)
28+
const { data: user } = useBackendQuery(backend, 'usersMe', [])
3029
const { getText } = textProvider.useText()
3130

3231
const uploadUserPicture = useMutation(backendMutationOptions(backend, 'uploadUserPicture'))

app/gui/src/dashboard/layouts/Settings/UserGroupsSettingsSection.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import {
2828
type UserGroupInfo,
2929
} from '#/services/Backend'
3030
import { twMerge } from '#/utilities/tailwindMerge'
31-
import { EMPTY_ARRAY } from 'enso-common/src/utilities/data/array'
3231
import UserGroupRow from './UserGroupRow'
3332
import UserGroupUserRow from './UserGroupUserRow'
3433

@@ -48,7 +47,7 @@ export default function UserGroupsSettingsSection(props: UserGroupsSettingsSecti
4847
const { getText } = useText()
4948
const { user } = useFullUserSession()
5049
const toastAndLog = useToastAndLog()
51-
const { data: users } = useBackendQuery(backend, 'listUsers', EMPTY_ARRAY)
50+
const { data: users } = useBackendQuery(backend, 'listUsers', [])
5251
const userGroups = useListUserGroupsWithUsers(backend)
5352
const rootRef = useRef<HTMLDivElement>(null)
5453
const bodyRef = useRef<HTMLTableSectionElement>(null)

0 commit comments

Comments
 (0)