Skip to content

Commit

Permalink
Remove overzealous use of EMPTY_ARRAY
Browse files Browse the repository at this point in the history
  • Loading branch information
somebody1234 committed Jan 3, 2025
1 parent 25ce57d commit b0a3b11
Show file tree
Hide file tree
Showing 18 changed files with 45 additions and 60 deletions.
3 changes: 1 addition & 2 deletions app/gui/src/dashboard/components/JSONSchemaInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { useText } from '#/providers/TextProvider'
import { constantValueOfSchema, getSchemaName, lookupDef } from '#/utilities/jsonSchema'
import { asObject, singletonObjectOrNull } from '#/utilities/object'
import { twMerge } from '#/utilities/tailwindMerge'
import { EMPTY_ARRAY } from 'enso-common/src/utilities/data/array'
import { twJoin } from 'tailwind-merge'

// =======================
Expand Down Expand Up @@ -50,7 +49,7 @@ export default function JSONSchemaInput(props: JSONSchemaInputProps) {
schema.type === 'string' &&
'format' in schema &&
schema.format === 'enso-secret'
const { data: secrets } = useBackendQuery(remoteBackend, 'listSecrets', EMPTY_ARRAY, {
const { data: secrets } = useBackendQuery(remoteBackend, 'listSecrets', [], {
enabled: isSecret,
})
const autocompleteItems = isSecret ? secrets?.map((secret) => secret.path) ?? null : null
Expand Down
3 changes: 1 addition & 2 deletions app/gui/src/dashboard/components/dashboard/ProjectIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import * as tailwindMerge from '#/utilities/tailwindMerge'
import { useMemo } from 'react'

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

// =================
// === Constants ===
Expand Down Expand Up @@ -108,7 +107,7 @@ export default function ProjectIcon(props: ProjectIconProps) {
const isOtherUserUsingProject =
isCloud && itemProjectState.openedBy != null && itemProjectState.openedBy !== user.email

const { data: users } = useBackendQuery(backend, 'listUsers', EMPTY_ARRAY, {
const { data: users } = useBackendQuery(backend, 'listUsers', [], {
enabled: isOtherUserUsingProject,
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function LabelsColumn(props: column.AssetColumnProps) {
const { user } = authProvider.useFullUserSession()
const { setModal, unsetModal } = modalProvider.useSetModal()
const { getText } = textProvider.useText()
const { data: labels } = backendHooks.useBackendQuery(backend, 'listTags', EMPTY_ARRAY)
const { data: labels } = backendHooks.useBackendQuery(backend, 'listTags', [])
const driveStore = useDriveStore()
const showDraggedLabelsFallback = useStore(
driveStore,
Expand Down
25 changes: 12 additions & 13 deletions app/gui/src/dashboard/hooks/backendHooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ import { download } from '#/utilities/download'
import { getMessageOrToString } from '#/utilities/error'
import { tryCreateOwnerPermission } from '#/utilities/permissions'
import { usePreventNavigation } from '#/utilities/preventNavigation'
import { EMPTY_ARRAY } from 'enso-common/src/utilities/data/array'
import { toRfc3339 } from 'enso-common/src/utilities/data/dateTime'

// The number of bytes in 1 megabyte.
Expand Down Expand Up @@ -298,8 +297,8 @@ export interface UserGroupInfoWithUsers extends UserGroupInfo {
export function useListUserGroupsWithUsers(
backend: Backend,
): readonly UserGroupInfoWithUsers[] | null {
const listUserGroupsQuery = useBackendQuery(backend, 'listUserGroups', EMPTY_ARRAY)
const listUsersQuery = useBackendQuery(backend, 'listUsers', EMPTY_ARRAY)
const listUserGroupsQuery = useBackendQuery(backend, 'listUserGroups', [])
const listUsersQuery = useBackendQuery(backend, 'listUsers', [])
if (listUserGroupsQuery.data == null || listUsersQuery.data == null) {
return null
} else {
Expand Down Expand Up @@ -554,8 +553,8 @@ export function useNewFolder(backend: Backend, category: Category) {
const setNewestFolderId = useSetNewestFolderId()
const setSelectedAssets = useSetSelectedAssets()
const { user } = useFullUserSession()
const { data: users } = useBackendQuery(backend, 'listUsers', EMPTY_ARRAY)
const { data: userGroups } = useBackendQuery(backend, 'listUserGroups', EMPTY_ARRAY)
const { data: users } = useBackendQuery(backend, 'listUsers', [])
const { data: userGroups } = useBackendQuery(backend, 'listUserGroups', [])
const createDirectoryMutation = useMutation(backendMutationOptions(backend, 'createDirectory'))

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

const { user } = useFullUserSession()
const { data: users } = useBackendQuery(backend, 'listUsers', EMPTY_ARRAY)
const { data: userGroups } = useBackendQuery(backend, 'listUserGroups', EMPTY_ARRAY)
const { data: users } = useBackendQuery(backend, 'listUsers', [])
const { data: userGroups } = useBackendQuery(backend, 'listUserGroups', [])
const createProjectMutation = useMutation(backendMutationOptions(backend, 'createProject'))

return useEventCallback(
Expand Down Expand Up @@ -677,8 +676,8 @@ export function useNewProject(backend: Backend, category: Category) {
export function useNewSecret(backend: Backend, category: Category) {
const toggleDirectoryExpansion = useToggleDirectoryExpansion()
const { user } = useFullUserSession()
const { data: users } = useBackendQuery(backend, 'listUsers', EMPTY_ARRAY)
const { data: userGroups } = useBackendQuery(backend, 'listUserGroups', EMPTY_ARRAY)
const { data: users } = useBackendQuery(backend, 'listUsers', [])
const { data: userGroups } = useBackendQuery(backend, 'listUserGroups', [])
const createSecretMutation = useMutation(backendMutationOptions(backend, 'createSecret'))

return useEventCallback(
Expand Down Expand Up @@ -716,8 +715,8 @@ export function useNewSecret(backend: Backend, category: Category) {
export function useNewDatalink(backend: Backend, category: Category) {
const toggleDirectoryExpansion = useToggleDirectoryExpansion()
const { user } = useFullUserSession()
const { data: users } = useBackendQuery(backend, 'listUsers', EMPTY_ARRAY)
const { data: userGroups } = useBackendQuery(backend, 'listUserGroups', EMPTY_ARRAY)
const { data: users } = useBackendQuery(backend, 'listUsers', [])
const { data: userGroups } = useBackendQuery(backend, 'listUserGroups', [])
const createDatalinkMutation = useMutation(backendMutationOptions(backend, 'createDatalink'))

return useEventCallback(
Expand Down Expand Up @@ -759,8 +758,8 @@ export function useUploadFiles(backend: Backend, category: Category) {
const toggleDirectoryExpansion = useToggleDirectoryExpansion()
const { setModal } = useSetModal()
const { user } = useFullUserSession()
const { data: users } = useBackendQuery(backend, 'listUsers', EMPTY_ARRAY)
const { data: userGroups } = useBackendQuery(backend, 'listUserGroups', EMPTY_ARRAY)
const { data: users } = useBackendQuery(backend, 'listUsers', [])
const { data: userGroups } = useBackendQuery(backend, 'listUserGroups', [])
const uploadFileMutation = useUploadFileWithToastMutation(backend)
const setSelectedAssets = useSetSelectedAssets()

Expand Down
3 changes: 1 addition & 2 deletions app/gui/src/dashboard/layouts/AssetProperties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import { mapNonNullish } from '#/utilities/nullable'
import * as permissions from '#/utilities/permissions'
import { tv } from '#/utilities/tailwindVariants'
import { useMutation } from '@tanstack/react-query'
import { EMPTY_ARRAY } from 'enso-common/src/utilities/data/array'
import { useStore } from '../utilities/zustand'

const ASSET_PROPERTIES_VARIANTS = tv({
Expand Down Expand Up @@ -161,7 +160,7 @@ function AssetPropertiesInternal(props: AssetPropertiesInternalProps) {
close: closeSpotlight,
})

const labels = useBackendQuery(backend, 'listTags', EMPTY_ARRAY).data ?? EMPTY_ARRAY
const labels = useBackendQuery(backend, 'listTags', []).data ?? []
const self = permissions.tryFindSelfPermission(user, item.permissions)
const ownsThisAsset = self?.permission === permissions.PermissionAction.own
const canEditThisAsset =
Expand Down
11 changes: 3 additions & 8 deletions app/gui/src/dashboard/layouts/AssetSearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,7 @@ const SuggestionRenderer = React.memo(function SuggestionRenderer(props: Suggest
)
})

/**
* Props for a {@link Labels}.
*/
/** Props for a {@link Labels}. */
interface LabelsProps {
readonly isCloud: boolean
readonly query: AssetQuery
Expand All @@ -637,14 +635,11 @@ interface LabelsProps {
readonly baseQuery: React.MutableRefObject<AssetQuery>
}

/**
* Renders labels.
*/
/** Renders labels. */
const Labels = React.memo(function Labels(props: LabelsProps) {
const { isCloud, query, setQuery, backend, querySource, baseQuery } = props

const labels =
backendHooks.useBackendQuery(backend, 'listTags', array.EMPTY_ARRAY).data ?? array.EMPTY_ARRAY
const labels = backendHooks.useBackendQuery(backend, 'listTags', []).data ?? []

const labelOnPress = useEventCallback(
(event: aria.PressEvent | React.MouseEvent<HTMLButtonElement>, label?: BackendLabel) => {
Expand Down
13 changes: 6 additions & 7 deletions app/gui/src/dashboard/layouts/AssetsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ import { withPresence } from '#/utilities/set'
import type { SortInfo } from '#/utilities/sorting'
import { twJoin, twMerge } from '#/utilities/tailwindMerge'
import Visibility from '#/utilities/Visibility'
import { EMPTY_ARRAY } from 'enso-common/src/utilities/data/array'
import invariant from 'tiny-invariant'
import { useStore } from '../utilities/zustand'

Expand Down Expand Up @@ -319,7 +318,7 @@ function AssetsTable(props: AssetsTableProps) {
const queryClient = useQueryClient()
const { user } = useFullUserSession()
const backend = useBackend(category)
const { data: labels } = useBackendQuery(backend, 'listTags', EMPTY_ARRAY)
const { data: labels } = useBackendQuery(backend, 'listTags', [])
const { setModal, unsetModal } = useSetModal()
const { localStorage } = useLocalStorage()
const { getText } = useText()
Expand Down Expand Up @@ -921,7 +920,7 @@ function AssetsTable(props: AssetsTableProps) {
break
}
case 'Escape': {
setSelectedAssets(EMPTY_ARRAY)
setSelectedAssets([])
setMostRecentlySelectedIndex(null)
selectionStartIndexRef.current = null
break
Expand Down Expand Up @@ -977,7 +976,7 @@ function AssetsTable(props: AssetsTableProps) {
} else {
// The arrow key will escape this container. In that case, do not stop propagation
// and let `navigator2D` navigate to a different container.
setSelectedAssets(EMPTY_ARRAY)
setSelectedAssets([])
selectionStartIndexRef.current = null
}
break
Expand Down Expand Up @@ -1013,7 +1012,7 @@ function AssetsTable(props: AssetsTableProps) {
type: 'move',
data: { backendType: backend.type, category, ids: selectedKeys },
})
setSelectedAssets(EMPTY_ARRAY)
setSelectedAssets([])
})

const doPaste = useEventCallback((newParentKey: DirectoryId, newParentId: DirectoryId) => {
Expand Down Expand Up @@ -1599,7 +1598,7 @@ function AssetsTable(props: AssetsTableProps) {
handleFileDrop(event)
}}
onClick={() => {
setSelectedAssets(EMPTY_ARRAY)
setSelectedAssets([])
}}
>
<FileTrigger
Expand Down Expand Up @@ -1795,7 +1794,7 @@ export function AssetsTableAssetsUnselector(props: AssetsTableAssetsUnselectorPr
const { pressProps } = usePress({
isDisabled: !hasSelectedKeys,
onPress: () => {
setSelectedAssets(EMPTY_ARRAY)
setSelectedAssets([])
},
})

Expand Down
2 changes: 1 addition & 1 deletion app/gui/src/dashboard/layouts/Labels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function Labels(props: LabelsProps) {
const driveStore = useDriveStore()
const nodeMapRef = useNodeMap()
const setLabelsDragPayload = useSetLabelsDragPayload()
const labels = useBackendQuery(backend, 'listTags', array.EMPTY_ARRAY).data ?? array.EMPTY_ARRAY
const labels = useBackendQuery(backend, 'listTags', []).data ?? []
const deleteTagMutation = useMutation(backendMutationOptions(backend, 'deleteTag'))

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { EVENT_TYPES, EventType, type Event } from '#/services/Backend'
import { formatDateTime } from '#/utilities/dateTime'
import { nextSortDirection, SortDirection, type SortInfo } from '#/utilities/sorting'
import { twMerge } from '#/utilities/tailwindMerge'
import { EMPTY_ARRAY } from 'enso-common/src/utilities/data/array'

// =================
// === Constants ===
Expand Down Expand Up @@ -74,14 +73,14 @@ export interface ActivityLogSettingsSectionProps {
export default function ActivityLogSettingsSection(props: ActivityLogSettingsSectionProps) {
const { backend } = props
const { getText } = useText()
const [types, setTypes] = React.useState<readonly EventType[]>(EMPTY_ARRAY)
const [typeIndices, setTypeIndices] = React.useState<readonly number[]>(EMPTY_ARRAY)
const [emails, setEmails] = React.useState<readonly string[]>(EMPTY_ARRAY)
const [emailIndices, setEmailIndices] = React.useState<readonly number[]>(EMPTY_ARRAY)
const [types, setTypes] = React.useState<readonly EventType[]>([])
const [typeIndices, setTypeIndices] = React.useState<readonly number[]>([])
const [emails, setEmails] = React.useState<readonly string[]>([])
const [emailIndices, setEmailIndices] = React.useState<readonly number[]>([])
const [sortInfo, setSortInfo] = React.useState<SortInfo<ActivityLogSortableColumn> | null>(null)
const { data: users } = useBackendQuery(backend, 'listUsers', EMPTY_ARRAY)
const { data: users } = useBackendQuery(backend, 'listUsers', [])
const allEmails = React.useMemo(() => (users ?? []).map((user) => user.email), [users])
const logsQuery = useBackendQuery(backend, 'getLogEvents', EMPTY_ARRAY)
const logsQuery = useBackendQuery(backend, 'getLogEvents', [])
const logs = logsQuery.data

const form = Form.useForm({ schema: createActivityLogSchema() })
Expand Down
3 changes: 1 addition & 2 deletions app/gui/src/dashboard/layouts/Settings/MembersTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { useText } from '#/providers/TextProvider'
import type Backend from '#/services/Backend'
import { UserId, type User } from '#/services/Backend'
import { twMerge } from '#/utilities/tailwindMerge'
import { EMPTY_ARRAY } from 'enso-common/src/utilities/data/array'
import UserRow from './UserRow'

/** Props for a {@link MembersTable}. */
Expand All @@ -43,7 +42,7 @@ export default function MembersTable(props: MembersTableProps) {
const bodyRef = useRef<HTMLTableSectionElement>(null)
const userWithPlaceholder = useMemo(() => ({ isPlaceholder: false, ...user }), [user])

const { data: allUsers } = useBackendQuery(backend, 'listUsers', EMPTY_ARRAY)
const { data: allUsers } = useBackendQuery(backend, 'listUsers', [])

const users = useMemo(
() => allUsers ?? (populateWithSelf ? [userWithPlaceholder] : null),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import FocusRing from '#/components/styled/FocusRing'

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

// =======================================
// === OrganizationProfilePictureInput ===
Expand All @@ -29,7 +28,7 @@ export default function OrganizationProfilePictureInput(
) {
const { backend } = props
const { getText } = textProvider.useText()
const { data: organization } = useBackendQuery(backend, 'getOrganization', EMPTY_ARRAY)
const { data: organization } = useBackendQuery(backend, 'getOrganization', [])

const uploadOrganizationPicture = useMutation(
backendMutationOptions(backend, 'uploadOrganizationPicture'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import FocusRing from '#/components/styled/FocusRing'

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

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

const uploadUserPicture = useMutation(backendMutationOptions(backend, 'uploadUserPicture'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
type UserGroupInfo,
} from '#/services/Backend'
import { twMerge } from '#/utilities/tailwindMerge'
import { EMPTY_ARRAY } from 'enso-common/src/utilities/data/array'
import UserGroupRow from './UserGroupRow'
import UserGroupUserRow from './UserGroupUserRow'

Expand All @@ -48,7 +47,7 @@ export default function UserGroupsSettingsSection(props: UserGroupsSettingsSecti
const { getText } = useText()
const { user } = useFullUserSession()
const toastAndLog = useToastAndLog()
const { data: users } = useBackendQuery(backend, 'listUsers', EMPTY_ARRAY)
const { data: users } = useBackendQuery(backend, 'listUsers', [])
const userGroups = useListUserGroupsWithUsers(backend)
const rootRef = useRef<HTMLDivElement>(null)
const bodyRef = useRef<HTMLTableSectionElement>(null)
Expand Down
4 changes: 2 additions & 2 deletions app/gui/src/dashboard/layouts/Settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { useLocalStorageState } from '#/providers/LocalStorageProvider'
import { useText } from '#/providers/TextProvider'
import type Backend from '#/services/Backend'
import { Path } from '#/services/ProjectManager'
import { EMPTY_ARRAY, includesPredicate } from '#/utilities/array'
import { includesPredicate } from '#/utilities/array'
import { regexEscape } from '#/utilities/string'
import {
ALL_SETTINGS_TABS,
Expand Down Expand Up @@ -59,7 +59,7 @@ export default function Settings() {
const [query, setQuery] = React.useState('')
const root = useStrictPortalContext()
const [isSidebarPopoverOpen, setIsSidebarPopoverOpen] = React.useState(false)
const { data: organization = null } = useBackendQuery(backend, 'getOrganization', EMPTY_ARRAY)
const { data: organization = null } = useBackendQuery(backend, 'getOrganization', [])
const isQueryBlank = !/\S/.test(query)

const updateUser = useMutation(backendMutationOptions(backend, 'updateUser')).mutateAsync
Expand Down
5 changes: 2 additions & 3 deletions app/gui/src/dashboard/modals/ManageLabelsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { useText } from '#/providers/TextProvider'
import type Backend from '#/services/Backend'
import { findLeastUsedColor, LabelName, type AnyAsset, type LChColor } from '#/services/Backend'
import { regexEscape } from '#/utilities/string'
import { EMPTY_ARRAY } from 'enso-common/src/utilities/data/array'

// =========================
// === ManageLabelsModal ===
Expand All @@ -40,9 +39,9 @@ export default function ManageLabelsModal<Asset extends AnyAsset = AnyAsset>(
const { unsetModal } = useSetModal()
const { getText } = useText()
const toastAndLog = useToastAndLog()
const { data: allLabels } = useBackendQuery(backend, 'listTags', EMPTY_ARRAY)
const { data: allLabels } = useBackendQuery(backend, 'listTags', [])
const [color, setColor] = useState<LChColor | null>(null)
const leastUsedColor = findLeastUsedColor(allLabels ?? EMPTY_ARRAY)
const leastUsedColor = findLeastUsedColor(allLabels ?? [])

const createTagMutation = useMutation(backendMutationOptions(backend, 'createTag'))
const associateTagMutation = useMutation(backendMutationOptions(backend, 'associateTag'))
Expand Down
3 changes: 1 addition & 2 deletions app/gui/src/dashboard/modals/NewLabelModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { useText } from '#/providers/TextProvider'
import type Backend from '#/services/Backend'
import { findLeastUsedColor } from '#/services/Backend'
import { useMutation } from '@tanstack/react-query'
import { EMPTY_ARRAY } from 'enso-common/src/utilities/data/array'

// =====================
// === NewLabelModal ===
Expand All @@ -25,7 +24,7 @@ export interface NewLabelModalProps {
export default function NewLabelModal(props: NewLabelModalProps) {
const { backend } = props
const { getText } = useText()
const labels = useBackendQuery(backend, 'listTags', EMPTY_ARRAY).data ?? EMPTY_ARRAY
const labels = useBackendQuery(backend, 'listTags', []).data ?? []
const labelNames = new Set<string>(labels.map((label) => label.value))
const labelNamesRef = useSyncRef(labelNames)
const leastUsedColor = findLeastUsedColor(labels)
Expand Down
Loading

0 comments on commit b0a3b11

Please sign in to comment.