fix(frontend): fix script and flow renaming

This commit is contained in:
Ruben Fiszel
2024-10-29 07:49:05 +01:00
parent 5b7c6d7d62
commit d743e00563
2 changed files with 95 additions and 81 deletions

View File

@@ -119,13 +119,21 @@
if (version === undefined) {
return
}
const flowVersion = await FlowService.getFlowLatestVersion({
workspace: $workspaceStore!,
path: $pathStore
})
onLatest = version === flowVersion?.id
try {
if (initialPath && initialPath != '') {
const flowVersion = await FlowService.getFlowLatestVersion({
workspace: $workspaceStore!,
path: initialPath
})
onLatest = version === flowVersion?.id
} else {
onLatest = true
}
} catch (err) {
console.error('Error comparing versions', err)
onLatest = false
}
}
const dispatch = createEventDispatcher()
@@ -277,9 +285,8 @@
}
async function handleSaveFlow(deploymentMsg?: string) {
await compareVersions();
if (onLatest) {
await compareVersions()
if (onLatest || initialPath == '') {
// Handle directly
await saveFlow(deploymentMsg)
} else {
@@ -294,28 +301,27 @@
open = true
}
}
async function syncWithDeployed(){
const flow = await FlowService.getFlowByPath({
workspace: $workspaceStore!,
path: $pathStore,
withStarredInfo: true
})
deployedValue = {
...flow,
starred: undefined,
id: undefined,
edited_at: undefined,
edited_by: undefined,
workspace_id: undefined,
archived: undefined,
same_worker: undefined,
visible_to_runner_only: undefined,
ws_error_handler_muted: undefined,
}
deployedBy = flow.edited_by
async function syncWithDeployed() {
const flow = await FlowService.getFlowByPath({
workspace: $workspaceStore!,
path: initialPath,
withStarredInfo: true
})
deployedValue = {
...flow,
starred: undefined,
id: undefined,
edited_at: undefined,
edited_by: undefined,
workspace_id: undefined,
archived: undefined,
same_worker: undefined,
visible_to_runner_only: undefined,
ws_error_handler_muted: undefined
}
deployedBy = flow.edited_by
}
async function saveFlow(deploymentMsg?: string): Promise<void> {
loadingSave = true
try {

View File

@@ -18,9 +18,7 @@
encodeState,
formatCron,
orderedJsonStringify,
type Value
} from '$lib/utils'
import Path from './Path.svelte'
import ScriptEditor from './ScriptEditor.svelte'
@@ -92,7 +90,6 @@
let confirmCallback: () => void = () => {} // What happens when user clicks `override` in warning
let open: boolean = false // Is confirmation modal open
let metadataOpen =
!neverShowMeta &&
(showMeta ||
@@ -251,62 +248,74 @@
}
}
async function handleEditScript(stay: boolean, deployMsg?: string): Promise<void>{
// Fetch latest version and fetch entire script after if needed
let actual_parent_hash = (await ScriptService.getScriptLatestVersion({
workspace: $workspaceStore!,
path: script.path,
}))?.script_hash;
async function handleEditScript(stay: boolean, deployMsg?: string): Promise<void> {
// Fetch latest version and fetch entire script after if needed
let actual_parent_hash: string | undefined = undefined
// Usually when we create new script, we put current hash as a parent_hash
// But if we specify parent_hash that is already used, than we get error
// In order to fix it we make sure that client's understanding of parent_hash
// is aligns with understanding of backend.
if (script.parent_hash == actual_parent_hash) {
// Handle directly
await editScript(stay, actual_parent_hash, deployMsg);
} else {
// Fetch entire script, since we need it to show Diff
await syncWithDeployed()
// Handle through confirmation modal
confirmCallback = async () => {
open = false
await editScript(stay, actual_parent_hash, deployMsg);
}
// Open confirmation modal
open = true
try {
if (initialPath && initialPath != '') {
actual_parent_hash = (
await ScriptService.getScriptLatestVersion({
workspace: $workspaceStore!,
path: initialPath
})
)?.script_hash
}
} catch (error) {
//
}
// Usually when we create new script, we put current hash as a parent_hash
// But if we specify parent_hash that is already used, than we get error
// In order to fix it we make sure that client's understanding of parent_hash
// is aligns with understanding of backend.
if (actual_parent_hash == undefined || script.parent_hash == actual_parent_hash) {
// Handle directly
await editScript(stay, script.parent_hash!, deployMsg)
} else {
// Fetch entire script, since we need it to show Diff
await syncWithDeployed()
// Handle through confirmation modal
confirmCallback = async () => {
open = false
await editScript(stay, actual_parent_hash, deployMsg)
}
// Open confirmation modal
open = true
}
}
async function syncWithDeployed(){
const latestScript = await ScriptService.getScriptByPath({
workspace: $workspaceStore!,
path: script.path,
withStarredInfo: true
});
async function syncWithDeployed() {
const latestScript = await ScriptService.getScriptByPath({
workspace: $workspaceStore!,
path: initialPath,
withStarredInfo: true
})
deployedValue = {
...latestScript,
starred: undefined,
workspace_id: undefined,
archived: undefined,
created_at: undefined,
created_by: undefined,
deleted: undefined,
extra_perms: undefined,
is_template: undefined,
lock: undefined,
lock_error_logs: undefined,
parent_hashes: undefined,
};
deployedValue = {
...latestScript,
starred: undefined,
workspace_id: undefined,
archived: undefined,
created_at: undefined,
created_by: undefined,
deleted: undefined,
extra_perms: undefined,
is_template: undefined,
lock: undefined,
lock_error_logs: undefined,
parent_hashes: undefined
}
deployedBy = latestScript.created_by;
deployedBy = latestScript.created_by
}
async function editScript(stay: boolean, parentHash: string, deploymentMsg?: string, ): Promise<void> {
async function editScript(
stay: boolean,
parentHash: string,
deploymentMsg?: string
): Promise<void> {
loadingSave = true
try {
try {
@@ -354,7 +363,6 @@
}
})
console.log('initialPath', initialPath)
const scheduleExists =
initialPath != '' &&
(await ScheduleService.existsSchedule({