-
Notifications
You must be signed in to change notification settings - Fork 117
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
Refactor common code to use full paths #4393
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
import { getRouteFromName } from "@rilldata/web-common/features/entity-management/entity-mappers"; | ||
import { | ||
ResourceKind, | ||
useResource, | ||
} from "@rilldata/web-common/features/entity-management/resource-selectors"; | ||
import { EntityType } from "@rilldata/web-common/features/entity-management/types"; | ||
import { useMainEntityFiles } from "../entity-management/file-selectors"; | ||
|
||
export function useChartFileNames(instanceId: string) { | ||
return useMainEntityFiles(instanceId, "charts"); | ||
} | ||
|
||
export function useChartRoutes(instanceId: string) { | ||
return useMainEntityFiles(instanceId, "charts", (name) => | ||
getRouteFromName(name, EntityType.Chart), | ||
); | ||
} | ||
|
||
export const useChart = (instanceId: string, chartName: string) => { | ||
return useResource(instanceId, chartName, ResourceKind.Chart); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
import { getRouteFromName } from "@rilldata/web-common/features/entity-management/entity-mappers"; | ||
import { EntityType } from "@rilldata/web-common/features/entity-management/types"; | ||
import { useMainEntityFiles } from "../entity-management/file-selectors"; | ||
|
||
export function useCustomDashboardFileNames(instanceId: string) { | ||
return useMainEntityFiles(instanceId, "custom-dashboards"); | ||
} | ||
|
||
export function useCustomDashboardRoutes(instanceId: string) { | ||
return useMainEntityFiles(instanceId, "custom-dashboards", (name) => | ||
getRouteFromName(name, EntityType.Dashboard), | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,11 @@ | |
import * as yup from "yup"; | ||
import { runtime } from "../../runtime-client/runtime-store"; | ||
import { renameFileArtifact } from "./actions"; | ||
import { getLabel, getRouteFromName } from "./entity-mappers"; | ||
import { | ||
getFileAPIPathFromNameAndType, | ||
getLabel, | ||
getRouteFromName, | ||
} from "./entity-mappers"; | ||
import { | ||
INVALID_NAME_MESSAGE, | ||
VALID_NAME_PATTERN, | ||
|
@@ -50,8 +54,8 @@ | |
try { | ||
await renameFileArtifact( | ||
runtimeInstanceId, | ||
currentAssetName, | ||
values.newName, | ||
getFileAPIPathFromNameAndType(currentAssetName, entityType), | ||
getFileAPIPathFromNameAndType(values.newName, entityType), | ||
Comment on lines
+57
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When we migrate, the modal should take a |
||
entityType, | ||
); | ||
goto(getRouteFromName(values.newName, entityType), { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,31 @@ | ||
import { goto } from "$app/navigation"; | ||
import { notifications } from "@rilldata/web-common/components/notifications"; | ||
import { extractFileName } from "@rilldata/web-common/features/sources/extract-file-name"; | ||
import { appScreen } from "@rilldata/web-common/layout/app-store"; | ||
import { | ||
runtimeServiceDeleteFile, | ||
runtimeServiceRenameFile, | ||
} from "@rilldata/web-common/runtime-client"; | ||
import { httpRequestQueue } from "@rilldata/web-common/runtime-client/http-client"; | ||
import { get } from "svelte/store"; | ||
import { | ||
getFileAPIPathFromNameAndType, | ||
getLabel, | ||
getRouteFromName, | ||
removeLeadingSlash, | ||
} from "./entity-mappers"; | ||
import { getLabel, removeLeadingSlash } from "./entity-mappers"; | ||
import { getNextEntityName } from "./name-utils"; | ||
import type { EntityType } from "./types"; | ||
|
||
export async function renameFileArtifact( | ||
instanceId: string, | ||
fromName: string, | ||
toName: string, | ||
fromPath: string, | ||
toPath: string, | ||
type: EntityType, | ||
) { | ||
await runtimeServiceRenameFile(instanceId, { | ||
fromPath: getFileAPIPathFromNameAndType(fromName, type), | ||
toPath: getFileAPIPathFromNameAndType(toName, type), | ||
fromPath, | ||
toPath, | ||
}); | ||
|
||
const fromName = extractFileName(fromPath); | ||
const toName = extractFileName(toPath); | ||
|
||
httpRequestQueue.removeByName(fromName); | ||
notifications.send({ | ||
message: `Renamed ${getLabel(type)} ${fromName} to ${toName}`, | ||
|
@@ -35,24 +34,22 @@ export async function renameFileArtifact( | |
|
||
export async function deleteFileArtifact( | ||
instanceId: string, | ||
name: string, | ||
filePath: string, | ||
type: EntityType, | ||
names: Array<string>, | ||
allPaths: Array<string>, | ||
showNotification = true, | ||
) { | ||
const path = getFileAPIPathFromNameAndType(name, type); | ||
const name = extractFileName(filePath); | ||
try { | ||
await runtimeServiceDeleteFile(instanceId, removeLeadingSlash(path)); | ||
await runtimeServiceDeleteFile(instanceId, removeLeadingSlash(filePath)); | ||
|
||
httpRequestQueue.removeByName(name); | ||
if (showNotification) { | ||
notifications.send({ message: `Deleted ${getLabel(type)} ${name}` }); | ||
} | ||
|
||
if (get(appScreen)?.name === name) { | ||
const route = getRouteFromName(getNextEntityName(names, name), type); | ||
|
||
await goto(route); | ||
await goto(getNextEntityName(allPaths, name)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When we migrate, navigation to the "next entity name" will be confusing in cases where users do not have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm true. I thought we could navigate to the next file in the folder. But i havent seen any editor do that. |
||
} | ||
} catch (err) { | ||
console.error(err); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import { createRuntimeServiceListFiles } from "@rilldata/web-common/runtime-clie | |
export function useMainEntityFiles( | ||
instanceId: string, | ||
prefix: "sources" | "models" | "dashboards" | "charts" | "custom-dashboards", | ||
transform = (name: string) => name, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than this transform parameter, can we instead just edit the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but it is still used in a lot of places without the fill path. Lets do that refactor once we get to different entities. |
||
) { | ||
let extension: string; | ||
switch (prefix) { | ||
|
@@ -40,7 +41,9 @@ export function useMainEntityFiles( | |
}) | ||
.map((filePath) => { | ||
// Remove the directory and extension from the filePath to get the file name | ||
return filePath.replace(`/${prefix}/`, "").replace(extension, ""); | ||
return transform( | ||
filePath.replace(`/${prefix}/`, "").replace(extension, ""), | ||
); | ||
}) | ||
// Sort the file names alphabetically in a case-insensitive manner | ||
.sort((fileNameA, fileNameB) => | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than
chartName
, this should now bechartPath
. Then we can use the path directly in thedeleteFileArtifact
function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. This PR makes an effort to not touch the components to update such params.