-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix: Redirect when server file is renamed (#17663)
* make args protected + type generic * add rename event * get new name and unique from modal * dispatch event when file is renamed * get unique from entity context * poc redirect after rename * move logic to controller * dont render code editor if content is undefined * remove unused styling * set unique after create * use replace state * set additionalOptions for rename action * Update workspace-redirect.controller.ts * add focus to name input * add rename redirect controller * clean up * split render methods * Update script-workspace.context.ts * implement EntityDetailWorkspaceBase for stylesheets * remove unused * don't render code editor if there is no content * add rename redirect controller --------- Co-authored-by: Niels Lyngsø <nsl@umbraco.dk>
- Loading branch information
1 parent
bce58a5
commit c4b0bde
Showing
19 changed files
with
277 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/Umbraco.Web.UI.Client/src/packages/core/server-file-system/rename/event/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './server-file-renamed.entity-event.js'; | ||
export type * from './types.js'; |
18 changes: 18 additions & 0 deletions
18
...ent/src/packages/core/server-file-system/rename/event/server-file-renamed.entity-event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { UmbServerFileRenamedEventArgs } from './types.js'; | ||
import { UmbEntityActionEvent } from '@umbraco-cms/backoffice/entity-action'; | ||
|
||
export class UmbServerFileRenamedEntityEvent extends UmbEntityActionEvent<UmbServerFileRenamedEventArgs> { | ||
static readonly TYPE = 'server-file-renamed'; | ||
|
||
constructor(args: UmbServerFileRenamedEventArgs) { | ||
super(UmbServerFileRenamedEntityEvent.TYPE, args); | ||
} | ||
|
||
getNewUnique(): string { | ||
return this._args.newUnique; | ||
} | ||
|
||
getNewName(): string { | ||
return this._args.newName; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/Umbraco.Web.UI.Client/src/packages/core/server-file-system/rename/event/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type { UmbEntityActionEventArgs } from '@umbraco-cms/backoffice/entity-action'; | ||
|
||
export interface UmbServerFileRenamedEventArgs extends UmbEntityActionEventArgs { | ||
newUnique: string; | ||
newName: string; | ||
} |
2 changes: 2 additions & 0 deletions
2
src/Umbraco.Web.UI.Client/src/packages/core/server-file-system/rename/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export type * from './types.js'; | ||
export * from './rename-server-file.action.js'; | ||
export * from './rename-server-file-repository-base.js'; | ||
export * from './event/index.js'; | ||
export * from './workspace-redirect/index.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...aco.Web.UI.Client/src/packages/core/server-file-system/rename/workspace-redirect/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './workspace-redirect.controller.js'; |
64 changes: 64 additions & 0 deletions
64
...ckages/core/server-file-system/rename/workspace-redirect/workspace-redirect.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { UmbServerFileRenamedEntityEvent } from '../event/index.js'; | ||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; | ||
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api'; | ||
import type { UmbRouterSlotElement } from '@umbraco-cms/backoffice/router'; | ||
import { ensurePathEndsWithSlash, umbUrlPatternToString } from '@umbraco-cms/backoffice/utils'; | ||
import { UMB_ACTION_EVENT_CONTEXT } from '@umbraco-cms/backoffice/action'; | ||
import type { UmbSubmittableWorkspaceContextBase } from '@umbraco-cms/backoffice/workspace'; | ||
|
||
export const UmbServerFileRenameWorkspaceRedirectControllerAlias = Symbol( | ||
'ServerFileRenameWorkspaceRedirectControllerAlias', | ||
); | ||
|
||
export class UmbServerFileRenameWorkspaceRedirectController extends UmbControllerBase { | ||
#actionEventContext?: typeof UMB_ACTION_EVENT_CONTEXT.TYPE; | ||
#workspaceContext: UmbSubmittableWorkspaceContextBase<unknown>; | ||
#router: UmbRouterSlotElement; | ||
|
||
constructor( | ||
host: UmbControllerHost, | ||
workspaceContext: UmbSubmittableWorkspaceContextBase<unknown>, | ||
router: UmbRouterSlotElement, | ||
) { | ||
super(host, UmbServerFileRenameWorkspaceRedirectControllerAlias); | ||
|
||
this.#workspaceContext = workspaceContext; | ||
this.#router = router; | ||
|
||
this.consumeContext(UMB_ACTION_EVENT_CONTEXT, (context) => { | ||
this.#actionEventContext = context; | ||
|
||
if (this.#actionEventContext) { | ||
this.#actionEventContext.removeEventListener(UmbServerFileRenamedEntityEvent.TYPE, this.#onFileRenamed); | ||
this.#actionEventContext.addEventListener(UmbServerFileRenamedEntityEvent.TYPE, this.#onFileRenamed); | ||
} | ||
}); | ||
} | ||
|
||
#onFileRenamed = ((event: UmbServerFileRenamedEntityEvent) => { | ||
if (!this.#router) throw new Error('Router is required for this controller.'); | ||
|
||
// Don't redirect if the event is not for the current entity | ||
const currentUnique = this.#workspaceContext.getUnique(); | ||
const eventUnique = event.getUnique(); | ||
if (currentUnique !== eventUnique) return; | ||
|
||
const newUnique = event.getNewUnique(); | ||
if (!newUnique) throw new Error('New unique is required for this event.'); | ||
|
||
const routerPath = this.#router.absoluteRouterPath; | ||
if (!routerPath) throw new Error('Router path is required for this controller.'); | ||
|
||
const newPath: string = umbUrlPatternToString(ensurePathEndsWithSlash(routerPath) + 'edit/:unique', { | ||
unique: newUnique, | ||
}); | ||
|
||
this.destroy(); | ||
window.history.replaceState(null, '', newPath); | ||
}) as EventListener; | ||
|
||
public override destroy(): void { | ||
super.destroy(); | ||
this.#actionEventContext?.removeEventListener(UmbServerFileRenamedEntityEvent.TYPE, this.#onFileRenamed); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.