From 74d9543dfbb9d23b94057202b648f8fc1d450e15 Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Tue, 7 May 2019 19:44:45 +0200 Subject: [PATCH] Fixes. --- .../administration/state/users.state.ts | 4 +- .../app/framework/utils/rxjs-extensions.ts | 16 ++--- src/Squidex/app/shared/state/apps.state.ts | 5 +- src/Squidex/app/shared/state/backups.state.ts | 4 +- src/Squidex/app/shared/state/clients.state.ts | 9 +-- .../app/shared/state/contents.state.ts | 37 +++++----- .../app/shared/state/contributors.state.ts | 3 +- .../app/shared/state/languages.state.ts | 5 +- .../app/shared/state/patterns.state.ts | 7 +- src/Squidex/app/shared/state/roles.state.ts | 5 +- src/Squidex/app/shared/state/rules.state.ts | 5 +- src/Squidex/app/shared/state/schemas.state.ts | 68 ++++++++++--------- 12 files changed, 87 insertions(+), 81 deletions(-) diff --git a/src/Squidex/app/features/administration/state/users.state.ts b/src/Squidex/app/features/administration/state/users.state.ts index c78a7aec7..2fc07e298 100644 --- a/src/Squidex/app/features/administration/state/users.state.ts +++ b/src/Squidex/app/features/administration/state/users.state.ts @@ -139,9 +139,9 @@ export class UsersState extends State { public create(request: CreateUserDto): Observable { return this.usersService.postUser(request).pipe( - tap(payload => { + tap(created => { this.next(s => { - const users = s.users.pushFront(this.createUser(payload)); + const users = s.users.pushFront(this.createUser(created)); const usersPager = s.usersPager.incrementCount(); return { ...s, users, usersPager }; diff --git a/src/Squidex/app/framework/utils/rxjs-extensions.ts b/src/Squidex/app/framework/utils/rxjs-extensions.ts index 8aaa58701..e52173a9d 100644 --- a/src/Squidex/app/framework/utils/rxjs-extensions.ts +++ b/src/Squidex/app/framework/utils/rxjs-extensions.ts @@ -26,9 +26,13 @@ export function mapVersioned(project: (value: T, version: Vers }; } -type Options = { silent?: boolean, project?: ((value: T) => R) }; +type Options = { silent?: boolean }; -export function shareSubscribed(dialogs: DialogService, options?: Options) { +export function shareSubscribed(dialogs: DialogService, options?: Options) { + return shareMapSubscribed(dialogs, x => x, options); +} + +export function shareMapSubscribed(dialogs: DialogService, project: (value: T) => R, options?: Options) { return function mapOperation(source: Observable) { const shared = source.pipe(publishReplay(), refCount()); @@ -42,13 +46,7 @@ export function shareSubscribed(dialogs: DialogService, options?: Opti })) .subscribe(); - if (options && !!options.project) { - const project = options.project; - - return shared.pipe(map(x => project(x))); - } else { - return shared; - } + return shared.pipe(map(x => project(x))); }; } diff --git a/src/Squidex/app/shared/state/apps.state.ts b/src/Squidex/app/shared/state/apps.state.ts index c3bf22d0a..888a8338f 100644 --- a/src/Squidex/app/shared/state/apps.state.ts +++ b/src/Squidex/app/shared/state/apps.state.ts @@ -84,9 +84,10 @@ export class AppsState extends State { public create(request: CreateAppDto, now?: DateTime): Observable { return this.appsService.postApp(request).pipe( - tap(payload => { + map(payload => createApp(request, payload, now)), + tap(created => { this.next(s => { - const apps = s.apps.push(createApp(request, payload, now)).sortByStringAsc(x => x.name); + const apps = s.apps.push(created).sortByStringAsc(x => x.name); return { ...s, apps }; }); diff --git a/src/Squidex/app/shared/state/backups.state.ts b/src/Squidex/app/shared/state/backups.state.ts index 90897dabd..3d0644413 100644 --- a/src/Squidex/app/shared/state/backups.state.ts +++ b/src/Squidex/app/shared/state/backups.state.ts @@ -58,13 +58,13 @@ export class BackupsState extends State { } return this.backupsService.getBackups(this.appName).pipe( - tap(payload => { + tap(items => { if (isReload && !silent) { this.dialogs.notifyInfo('Backups reloaded.'); } this.next(s => { - const backups = ImmutableArray.of(payload); + const backups = ImmutableArray.of(items); return { ...s, backups, isLoaded: true }; }); diff --git a/src/Squidex/app/shared/state/clients.state.ts b/src/Squidex/app/shared/state/clients.state.ts index a9a869c4d..9eeb90603 100644 --- a/src/Squidex/app/shared/state/clients.state.ts +++ b/src/Squidex/app/shared/state/clients.state.ts @@ -15,6 +15,7 @@ import { DialogService, ImmutableArray, mapVersioned, + shareMapSubscribed, shareSubscribed, State, Version @@ -66,12 +67,12 @@ export class ClientsState extends State { } return this.clientsService.getClients(this.appName).pipe( - tap(({ version, payload: newClients }) => { + tap(({ version, payload }) => { if (isReload) { this.dialogs.notifyInfo('Clients reloaded.'); } - const clients = ImmutableArray.of(newClients); + const clients = ImmutableArray.of(payload); this.next(s => { return { ...s, clients, isLoaded: true, version }; @@ -89,7 +90,7 @@ export class ClientsState extends State { return { ...s, clients, version: version }; }); }), - shareSubscribed(this.dialogs, { project: x => x.payload })); + shareMapSubscribed(this.dialogs, x => x.payload)); } public revoke(client: ClientDto): Observable { @@ -114,7 +115,7 @@ export class ClientsState extends State { return { ...s, clients, version }; }); }), - shareSubscribed(this.dialogs, { project: x => x.payload })); + shareMapSubscribed(this.dialogs, x => x.payload)); } private get appName() { diff --git a/src/Squidex/app/shared/state/contents.state.ts b/src/Squidex/app/shared/state/contents.state.ts index 787c27962..ecdf0b8ec 100644 --- a/src/Squidex/app/shared/state/contents.state.ts +++ b/src/Squidex/app/shared/state/contents.state.ts @@ -14,7 +14,6 @@ import { DialogService, ErrorDto, ImmutableArray, - mapVersioned, Pager, shareSubscribed, State, @@ -202,78 +201,78 @@ export abstract class ContentsStateBase extends State { public publishChanges(content: ContentDto, dueTime: string | null, now?: DateTime): Observable { return this.contentsService.changeContentStatus(this.appName, this.schemaName, content.id, 'Publish', dueTime, content.version).pipe( - mapVersioned(({ version }) => { + map(({ version }) => { if (dueTime) { return changeScheduleStatus(content, 'Published', dueTime, this.user, version, now); } else { return confirmChanges(content, this.user, version, now); } }), - tap(({ payload }) => { + tap(updated => { this.dialogs.notifyInfo('Content updated successfully.'); - this.replaceContent(payload); + this.replaceContent(updated); }), shareSubscribed(this.dialogs)); } public changeStatus(content: ContentDto, action: string, status: string, dueTime: string | null, now?: DateTime): Observable { return this.contentsService.changeContentStatus(this.appName, this.schemaName, content.id, action, dueTime, content.version).pipe( - mapVersioned(({ version }) => { + map(({ version }) => { if (dueTime) { return changeScheduleStatus(content, status, dueTime, this.user, version, now); } else { return changeStatus(content, status, this.user, version, now); } }), - tap(({ payload }) => { + tap(updated => { this.dialogs.notifyInfo('Content updated successfully.'); - this.replaceContent(payload); + this.replaceContent(updated); }), shareSubscribed(this.dialogs)); } public update(content: ContentDto, request: any, now?: DateTime): Observable { return this.contentsService.putContent(this.appName, this.schemaName, content.id, request, false, content.version).pipe( - mapVersioned((payload, version) => updateData(content, payload, this.user, version, now)), - tap(({ payload }) => { + map(({ payload, version }) => updateData(content, payload, this.user, version, now)), + tap(updated => { this.dialogs.notifyInfo('Content updated successfully.'); - this.replaceContent(payload, content.version); + this.replaceContent(updated, content.version); }), shareSubscribed(this.dialogs)); } public proposeUpdate(content: ContentDto, request: any, now?: DateTime): Observable { return this.contentsService.putContent(this.appName, this.schemaName, content.id, request, true, content.version).pipe( - mapVersioned((payload, version) => updateDataDraft(content, payload, this.user, version, now)), - tap(({ payload }) => { + map(({ payload, version }) => updateDataDraft(content, payload, this.user, version, now)), + tap(updated => { this.dialogs.notifyInfo('Content updated successfully.'); - this.replaceContent(payload, content.version); + this.replaceContent(updated, content.version); }), shareSubscribed(this.dialogs)); } public discardChanges(content: ContentDto, now?: DateTime): Observable { return this.contentsService.discardChanges(this.appName, this.schemaName, content.id, content.version).pipe( - mapVersioned((_, version) => discardChanges(content, this.user, version, now)), - tap(({ payload }) => { + map(({ version }) => discardChanges(content, this.user, version, now)), + tap(updated => { this.dialogs.notifyInfo('Content updated successfully.'); - this.replaceContent(payload, content.version); + this.replaceContent(updated, content.version); }), shareSubscribed(this.dialogs)); } public patch(content: ContentDto, request: any, now?: DateTime): Observable { return this.contentsService.patchContent(this.appName, this.schemaName, content.id, request, content.version).pipe( - mapVersioned((data, version) => updateData(content, data, this.user, version, now)), - tap(({ payload }) => { + map(({ payload, version }) => updateData(content, payload, this.user, version, now)), + tap(updated => { this.dialogs.notifyInfo('Content updated successfully.'); - this.replaceContent(payload, content.version); + this.replaceContent(updated, content.version); }), shareSubscribed(this.dialogs)); } diff --git a/src/Squidex/app/shared/state/contributors.state.ts b/src/Squidex/app/shared/state/contributors.state.ts index 15de21493..be7a8c83b 100644 --- a/src/Squidex/app/shared/state/contributors.state.ts +++ b/src/Squidex/app/shared/state/contributors.state.ts @@ -13,6 +13,7 @@ import { DialogService, ErrorDto, ImmutableArray, + shareMapSubscribed, shareSubscribed, State, Types, @@ -124,7 +125,7 @@ export class ContributorsState extends State { this.replaceContributors(contributors, version); }), - shareSubscribed(this.dialogs, { project: x => x.payload.isCreated })); + shareMapSubscribed(this.dialogs, x => x.payload.isCreated)); } private updateContributors(id: string, role: string) { diff --git a/src/Squidex/app/shared/state/languages.state.ts b/src/Squidex/app/shared/state/languages.state.ts index 446708c10..a3fe30386 100644 --- a/src/Squidex/app/shared/state/languages.state.ts +++ b/src/Squidex/app/shared/state/languages.state.ts @@ -13,6 +13,7 @@ import { DialogService, ImmutableArray, mapVersioned, + shareMapSubscribed, shareSubscribed, State, Version @@ -121,7 +122,7 @@ export class LanguagesState extends State { this.replaceLanguages(languages, version); }), - shareSubscribed(this.dialogs, { project: x => x.payload })); + shareMapSubscribed(this.dialogs, x => x.payload)); } public remove(language: AppLanguageDto): Observable { @@ -150,7 +151,7 @@ export class LanguagesState extends State { this.replaceLanguages(languages, version); }), - shareSubscribed(this.dialogs)); + shareMapSubscribed(this.dialogs, x => x.payload)); } private replaceLanguages(languages: AppLanguagesList, version: Version, allLanguages?: LanguageList) { diff --git a/src/Squidex/app/shared/state/patterns.state.ts b/src/Squidex/app/shared/state/patterns.state.ts index bf2c0688f..d1c5afbd8 100644 --- a/src/Squidex/app/shared/state/patterns.state.ts +++ b/src/Squidex/app/shared/state/patterns.state.ts @@ -13,6 +13,7 @@ import { DialogService, ImmutableArray, mapVersioned, + shareMapSubscribed, shareSubscribed, State, Version @@ -74,7 +75,7 @@ export class PatternsState extends State { return { ...s, patterns, isLoaded: true, version: version }; }); }), - shareSubscribed(this.dialogs, { project: x => x.payload })); + shareMapSubscribed(this.dialogs, x => x.payload)); } public create(request: EditPatternDto): Observable { @@ -86,7 +87,7 @@ export class PatternsState extends State { return { ...s, patterns, version: version }; }); }), - shareSubscribed(this.dialogs, { project: x => x.payload })); + shareMapSubscribed(this.dialogs, x => x.payload)); } public update(pattern: PatternDto, request: EditPatternDto): Observable { @@ -99,7 +100,7 @@ export class PatternsState extends State { return { ...s, patterns, version: version }; }); }), - shareSubscribed(this.dialogs, { project: x => x.payload })); + shareMapSubscribed(this.dialogs, x => x.payload)); } public delete(pattern: PatternDto): Observable { diff --git a/src/Squidex/app/shared/state/roles.state.ts b/src/Squidex/app/shared/state/roles.state.ts index 4958415a5..d4b924e01 100644 --- a/src/Squidex/app/shared/state/roles.state.ts +++ b/src/Squidex/app/shared/state/roles.state.ts @@ -13,6 +13,7 @@ import { DialogService, ImmutableArray, mapVersioned, + shareMapSubscribed, shareSubscribed, State, Version @@ -87,7 +88,7 @@ export class RolesState extends State { return { ...s, roles, version }; }); }), - shareSubscribed(this.dialogs, { project: x => x.payload })); + shareMapSubscribed(this.dialogs, x => x.payload)); } public delete(role: RoleDto): Observable { @@ -112,7 +113,7 @@ export class RolesState extends State { return { ...s, roles, version }; }); }), - shareSubscribed(this.dialogs, { project: x => x.payload })); + shareMapSubscribed(this.dialogs, x => x.payload)); } private get appName() { diff --git a/src/Squidex/app/shared/state/rules.state.ts b/src/Squidex/app/shared/state/rules.state.ts index d01cb1233..1a0bcac0f 100644 --- a/src/Squidex/app/shared/state/rules.state.ts +++ b/src/Squidex/app/shared/state/rules.state.ts @@ -80,9 +80,10 @@ export class RulesState extends State { public create(request: UpsertRuleDto, now?: DateTime): Observable { return this.rulesService.postRule(this.appName, request).pipe( - tap(response => { + map(payload => createRule(request, payload, this.user, now)), + tap(created => { this.next(s => { - const rules = s.rules.push(createRule(request, response, this.user, now)); + const rules = s.rules.push(created); return { ...s, rules }; }); diff --git a/src/Squidex/app/shared/state/schemas.state.ts b/src/Squidex/app/shared/state/schemas.state.ts index b5285958b..25493e05e 100644 --- a/src/Squidex/app/shared/state/schemas.state.ts +++ b/src/Squidex/app/shared/state/schemas.state.ts @@ -14,6 +14,7 @@ import { DialogService, ImmutableArray, mapVersioned, + shareMapSubscribed, shareSubscribed, State, Types, @@ -139,9 +140,10 @@ export class SchemasState extends State { public create(request: CreateSchemaDto, now?: DateTime): Observable { return this.schemasService.postSchema(this.appName, request).pipe( - tap(response => { + map(payload => createSchema(request, payload, this.user, now)), + tap(created => { this.next(s => { - const schemas = s.schemas.push(createSchema(request, response, this.user, now)).sortByStringAsc(x => x.displayName); + const schemas = s.schemas.push(created).sortByStringAsc(x => x.displayName); return { ...s, schemas }; }); @@ -181,8 +183,8 @@ export class SchemasState extends State { public publish(schema: SchemaDto, now?: DateTime): Observable { return this.schemasService.publishSchema(this.appName, schema.name, schema.version).pipe( map(({ version }) => setPublished(schema, true, this.user, version, now)), - tap(newSchema => { - this.replaceSchema(newSchema); + tap(updated => { + this.replaceSchema(updated); }), shareSubscribed(this.dialogs)); } @@ -190,8 +192,8 @@ export class SchemasState extends State { public unpublish(schema: SchemaDto, now?: DateTime): Observable { return this.schemasService.unpublishSchema(this.appName, schema.name, schema.version).pipe( map(({ version }) => setPublished(schema, false, this.user, version, now)), - tap(newSchema => { - this.replaceSchema(newSchema); + tap(updated => { + this.replaceSchema(updated); }), shareSubscribed(this.dialogs)); } @@ -199,8 +201,8 @@ export class SchemasState extends State { public changeCategory(schema: SchemaDto, name: string, now?: DateTime): Observable { return this.schemasService.putCategory(this.appName, schema.name, { name }, schema.version).pipe( map(({ version }) => changeCategory(schema, name, this.user, version, now)), - tap(newSchema => { - this.replaceSchema(newSchema); + tap(updated => { + this.replaceSchema(updated); }), shareSubscribed(this.dialogs)); } @@ -208,8 +210,8 @@ export class SchemasState extends State { public configurePreviewUrls(schema: SchemaDetailsDto, request: {}, now?: DateTime): Observable { return this.schemasService.putPreviewUrls(this.appName, schema.name, request, schema.version).pipe( map(({ version }) => configurePreviewUrls(schema, request, this.user, version, now)), - tap(newSchema => { - this.replaceSchema(newSchema); + tap(updated => { + this.replaceSchema(updated); }), shareSubscribed(this.dialogs)); } @@ -217,8 +219,8 @@ export class SchemasState extends State { public configureScripts(schema: SchemaDetailsDto, request: {}, now?: DateTime): Observable { return this.schemasService.putScripts(this.appName, schema.name, request, schema.version).pipe( map(({ version }) => configureScripts(schema, request, this.user, version, now)), - tap(newSchema => { - this.replaceSchema(newSchema); + tap(updated => { + this.replaceSchema(updated); }), shareSubscribed(this.dialogs)); } @@ -226,8 +228,8 @@ export class SchemasState extends State { public update(schema: SchemaDetailsDto, request: UpdateSchemaDto, now?: DateTime): Observable { return this.schemasService.putSchema(this.appName, schema.name, request, schema.version).pipe( map(({ version }) => updateProperties(schema, request, this.user, version, now)), - tap(newSchema => { - this.replaceSchema(newSchema); + tap(updated => { + this.replaceSchema(updated); }), shareSubscribed(this.dialogs)); } @@ -235,37 +237,37 @@ export class SchemasState extends State { public addField(schema: SchemaDetailsDto, request: AddFieldDto, parent?: RootFieldDto, now?: DateTime): Observable { return this.schemasService.postField(this.appName, schema.name, request, pid(parent), schema.version).pipe( map(({ version, payload }) => { - let newSchema: SchemaDto; + let updated: SchemaDto; if (Types.is(payload, NestedFieldDto)) { - newSchema = updateField(schema, addNested(parent!, payload), this.user, version, now); + updated = updateField(schema, addNested(parent!, payload), this.user, version, now); } else { - newSchema = addField(schema, payload, this.user, version, now); + updated = addField(schema, payload, this.user, version, now); } - return { newSchema, field: payload }; + return { updated, field: payload }; }), - tap(({ newSchema }) => { - this.replaceSchema(newSchema); + tap(({ updated }) => { + this.replaceSchema(updated); }), - shareSubscribed(this.dialogs, { silent: true, project: x => x.field })); + shareMapSubscribed(this.dialogs, x => x.field, { silent: true })); } public sortFields(schema: SchemaDetailsDto, fields: any[], parent?: RootFieldDto, now?: DateTime): Observable { return this.schemasService.putFieldOrdering(this.appName, schema.name, fields.map(t => t.fieldId), pid(parent), schema.version).pipe( map(({ version }) => { - let newSchema: SchemaDto; + let updated: SchemaDetailsDto; if (!parent) { - newSchema = replaceFields(schema, fields, this.user, version, now); + updated = replaceFields(schema, fields, this.user, version, now); } else { - newSchema = updateField(schema, replaceNested(parent, fields), this.user, version, now); + updated = updateField(schema, replaceNested(parent, fields), this.user, version, now); } - return newSchema; + return updated; }), - tap(newSchema => { - this.replaceSchema(newSchema); + tap(updated => { + this.replaceSchema(updated); }), shareSubscribed(this.dialogs)); } @@ -276,7 +278,7 @@ export class SchemasState extends State { tap(({ version, payload }) => { this.replaceField(schema, payload, version, now); }), - shareSubscribed(this.dialogs, { project: x => x.payload })); + shareMapSubscribed(this.dialogs, x => x.payload)); } public enableField(schema: SchemaDetailsDto, field: T, now?: DateTime): Observable { @@ -285,7 +287,7 @@ export class SchemasState extends State { tap(({ version, payload }) => { this.replaceField(schema, payload, version, now); }), - shareSubscribed(this.dialogs, { project: x => x.payload })); + shareMapSubscribed(this.dialogs, x => x.payload)); } public disableField(schema: SchemaDetailsDto, field: T, now?: DateTime): Observable { @@ -294,7 +296,7 @@ export class SchemasState extends State { tap(({ version, payload }) => { this.replaceField(schema, payload, version, now); }), - shareSubscribed(this.dialogs, { project: x => x.payload })); + shareMapSubscribed(this.dialogs, x => x.payload)); } public showField(schema: SchemaDetailsDto, field: T, now?: DateTime): Observable { @@ -303,7 +305,7 @@ export class SchemasState extends State { tap(({ version, payload }) => { this.replaceField(schema, payload, version, now); }), - shareSubscribed(this.dialogs, { project: x => x.payload })); + shareMapSubscribed(this.dialogs, x => x.payload)); } public hideField(schema: SchemaDetailsDto, field: T, now?: DateTime): Observable { @@ -312,7 +314,7 @@ export class SchemasState extends State { tap(({ version, payload }) => { this.replaceField(schema, payload, version, now); }), - shareSubscribed(this.dialogs, { project: x => x.payload })); + shareMapSubscribed(this.dialogs, x => x.payload)); } public updateField(schema: SchemaDetailsDto, field: T, request: UpdateFieldDto, now?: DateTime): Observable { @@ -321,7 +323,7 @@ export class SchemasState extends State { tap(({ version, payload }) => { this.replaceField(schema, payload, version, now); }), - shareSubscribed(this.dialogs, { project: x => x.payload })); + shareMapSubscribed(this.dialogs, x => x.payload)); } public deleteField(schema: SchemaDetailsDto, field: AnyFieldDto, now?: DateTime): Observable {