Compute correct root path for Solo users (#10993)

- Change paths for cloud assets for users on Solo plan to be `enso://User/<username>/<path>` instead of the legacy `enso://<username>/<path>`

# Important Notes
None

(cherry picked from commit c87053d600)
This commit is contained in:
somebody1234 2024-09-06 23:58:12 +10:00 committed by James Dunkerley
parent a20decb00f
commit 5f12bd52cb
8 changed files with 37 additions and 22 deletions

View File

@ -543,7 +543,7 @@ function LocalBackendPathSynchronizer() {
const localBackend = useLocalBackend()
if (localBackend) {
if (localRootDirectory != null) {
localBackend.rootPath = Path(localRootDirectory)
localBackend.setRootPath(Path(localRootDirectory))
} else {
localBackend.resetRootPath()
}

View File

@ -533,7 +533,7 @@ export default function AssetsTable(props: AssetsTableProps) {
const isLoading = directories.rootDirectory.isLoading
const assetTree = React.useMemo(() => {
const rootPath = 'rootPath' in category ? category.rootPath : backend.rootPath
const rootPath = 'rootPath' in category ? category.rootPath : backend.rootPath(user)
// If the root directory is not loaded, then we cannot render the tree.
// Return null, and wait for the root directory to load.
@ -634,13 +634,14 @@ export default function AssetsTable(props: AssetsTableProps) {
rootId,
)
}, [
directories,
category,
backend,
user,
rootDirectoryContent,
rootDirectory,
rootParentDirectoryId,
backend.rootPath,
rootDirectoryId,
category,
directories.directories,
])
const filter = React.useMemo(() => {

View File

@ -211,7 +211,7 @@ function CategorySwitcherItem(props: InternalCategorySwitcherItemProps) {
case 'local-directory': {
if (category.type === 'local' || category.type === 'local-directory') {
const parentDirectory =
category.type === 'local' ? localBackend?.rootPath : category.rootPath
category.type === 'local' ? localBackend?.rootPath() : category.rootPath
invariant(parentDirectory != null, 'The Local backend is missing a root directory.')
const newParentId = newDirectoryId(parentDirectory)
dispatchAssetEvent({

View File

@ -69,7 +69,7 @@ export default function Settings() {
const updateLocalRootPath = useEventCallback((value: string) => {
setLocalRootDirectory(value)
if (localBackend) {
localBackend.rootPath = projectManager.Path(value)
localBackend.setRootPath(projectManager.Path(value))
}
})
const resetLocalRootPath = useEventCallback(() => {

View File

@ -238,7 +238,7 @@ export const SETTINGS_TAB_DATA: Readonly<Record<SettingsTabType, SettingsTabData
{
type: SettingsEntryType.input,
nameId: 'localRootPathSettingsInput',
getValue: (context) => context.localBackend?.rootPath ?? '',
getValue: (context) => context.localBackend?.rootPath() ?? '',
setValue: async (context, value) => {
context.updateLocalRootPath(value)
await Promise.resolve()

View File

@ -104,12 +104,12 @@ export default class LocalBackend extends Backend {
}
/** Get the root directory of this Backend. */
get rootPath() {
override rootPath() {
return this.projectManager.rootDirectory
}
/** Set the root directory of this Backend. */
set rootPath(value) {
setRootPath(value: projectManager.Path) {
this.projectManager.rootDirectory = value
}
@ -125,7 +125,7 @@ export default class LocalBackend extends Backend {
/** Return the ID of the root directory. */
override rootDirectoryId(
_user: backend.User | null,
_user: backend.User,
_organization: backend.OrganizationInfo | null,
rootDirectory: backend.Path | null | undefined,
): backend.DirectoryId {

View File

@ -127,7 +127,6 @@ interface RemoteBackendPostOptions {
/** Class for sending requests to the Cloud backend API endpoints. */
export default class RemoteBackend extends Backend {
readonly type = backend.BackendType.remote
readonly rootPath = 'enso://'
private defaultVersions: Partial<Record<backend.VersionType, DefaultVersionInfo>> = {}
private user: object.Mutable<backend.User> | null = null
@ -174,16 +173,31 @@ export default class RemoteBackend extends Backend {
}
}
/** Return the ID of the root directory. */
override rootDirectoryId(
user: backend.User | null,
organization: backend.OrganizationInfo | null,
): backend.DirectoryId | null {
switch (user?.plan ?? null) {
case null:
/** The path to the root directory of this {@link Backend}. */
override rootPath(user: backend.User) {
switch (user.plan) {
case undefined:
case backend.Plan.free:
case backend.Plan.solo: {
return user?.rootDirectoryId ?? null
return `enso://Users/${user.name}`
}
case backend.Plan.team:
case backend.Plan.enterprise: {
return 'enso://'
}
}
}
/** Return the ID of the root directory. */
override rootDirectoryId(
user: backend.User,
organization: backend.OrganizationInfo | null,
): backend.DirectoryId | null {
switch (user.plan) {
case undefined:
case backend.Plan.free:
case backend.Plan.solo: {
return user.rootDirectoryId
}
case backend.Plan.team:
case backend.Plan.enterprise: {

View File

@ -1311,10 +1311,10 @@ export default abstract class Backend {
abstract readonly type: BackendType
/** The path to the root directory of this {@link Backend}. */
abstract readonly rootPath: string
abstract rootPath(user: User): string
/** Return the ID of the root directory, if known. */
abstract rootDirectoryId(
user: User | null,
user: User,
organization: OrganizationInfo | null,
localRootDirectory: Path | null | undefined,
): DirectoryId | null