Skip to content

Commit

Permalink
feat(hub-common): add support for discussion settings for entities (#…
Browse files Browse the repository at this point in the history
…1284)

* feat(hub-common): add support for discussion settings for entities

affects: @esri/hub-common, @esri/hub-discussions

ISSUES CLOSED: 7412

* feat(): pr feedback

* feat(): update updateHubEntity to pass hubRequestOptions to updateDiscussion

* feat(): move getDefaultEntitySettings so it can be exported

* feat(): tweak updateDiscussion logic

* feat(): make extending discussion settings to other entities easier

* fix(): rename discussionsSettings to discussionSettings

* fix(): ihubgroup interface extends iwithdiscussions

* fix(hub-common): fixes some tests

affects: @esri/hub-common

ISSUES CLOSED: 7412

* test(): tweak import statements, await removeSetting

* fix(hub-common): add test coverage

affects: @esri/hub-common

ISSUES CLOSED: 7412

---------

Co-authored-by: Randy Weber <rweber@esri.com>
  • Loading branch information
juliannaeapicella and rweber-esri authored Oct 24, 2023
1 parent ce3be36 commit 951c455
Show file tree
Hide file tree
Showing 19 changed files with 425 additions and 59 deletions.
48 changes: 18 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions packages/common/src/core/_internal/getBasePropertyMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,13 @@ export function getBasePropertyMap(): IPropertyMap[] {
entityKey: "boundary",
storeKey: "item.properties.boundary",
});
map.push({
entityKey: "discussionSettings",
storeKey: "entitySettings.settings.discussions",
});
map.push({
entityKey: "entitySettingsId",
storeKey: "entitySettings.id",
});
return map;
}
10 changes: 9 additions & 1 deletion packages/common/src/core/traits/IWithDiscussions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { IDiscussionsSettings } from "../../discussions/api/types";
import { IWithEntitySettings } from "./IWithEntitySettings";

/**
* Discussions-related properties
*/
export interface IWithDiscussions {
export interface IWithDiscussions extends IWithEntitySettings {
/**
* If the item has discussions enabled
*/
isDiscussable?: boolean;

/**
* The entity's discussion settings
*/
discussionSettings?: IDiscussionsSettings;
}
6 changes: 6 additions & 0 deletions packages/common/src/core/traits/IWithEntitySettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Entity settings
*/
export interface IWithEntitySettings {
entitySettingsId?: string;
}
7 changes: 5 additions & 2 deletions packages/common/src/core/types/IHubGroup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IWithPermissions } from "../traits";
import { IWithDiscussions, IWithPermissions } from "../traits";
import { IHubEntityBase } from "./IHubEntityBase";
import {
GroupSortField,
Expand All @@ -12,7 +12,10 @@ import {
* Defines the properties of a Hub Group object
* @internal
*/
export interface IHubGroup extends IHubEntityBase, IWithPermissions {
export interface IHubGroup
extends IHubEntityBase,
IWithPermissions,
IWithDiscussions {
/**
* Access level of the group
* ("private" | "org" | "public")
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/core/updateHubEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const updateHubEntity = async (
case "discussion":
result = await updateDiscussion(
entity as IHubDiscussion,
context.userRequestOptions
context.hubRequestOptions
);
break;
case "content":
Expand Down
11 changes: 7 additions & 4 deletions packages/common/src/discussions/HubDiscussion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ export class HubDiscussion
context: IArcGISContext
): Promise<HubDiscussion> {
try {
const entity = await fetchDiscussion(identifier, context.requestOptions);
const entity = await fetchDiscussion(
identifier,
context.hubRequestOptions
);
// create an instance of HubDiscussion from the entity
return HubDiscussion.fromJson(entity, context);
} catch (ex) {
Expand Down Expand Up @@ -121,14 +124,14 @@ export class HubDiscussion
// update it
this.entity = await updateDiscussion(
this.entity,
this.context.userRequestOptions
this.context.hubRequestOptions
);
} else {
const { createDiscussion } = await import("./edit");
// create it
this.entity = await createDiscussion(
this.entity,
this.context.userRequestOptions
this.context.hubRequestOptions
);
}

Expand All @@ -150,7 +153,7 @@ export class HubDiscussion
const { deleteDiscussion } = await import("./edit");
this.isDestroyed = true;
// Delegate to module fn
await deleteDiscussion(this.entity.id, this.context.userRequestOptions);
await deleteDiscussion(this.entity.id, this.context.hubRequestOptions);
}

/*
Expand Down
5 changes: 4 additions & 1 deletion packages/common/src/discussions/_internal/getPropertyMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export function getPropertyMap(): IPropertyMap[] {
const map = getBasePropertyMap();

// Type specific mappings
map.push({ entityKey: "prompt", storeKey: "data.prompt" });
map.push({
entityKey: "prompt",
storeKey: "data.prompt",
});
map.push({
entityKey: "location",
storeKey: "item.properties.location",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { EntitySettingType, IEntitySetting, IEntitySettings } from "../types";
import { HubEntityType } from "../../../core/types";

const DISCUSSION_SETTINGS: IEntitySettings = {
discussions: {
allowedChannelIds: null,
allowedLocations: null,
},
};

const DEFAULT_ENTITY_SETTINGS_BY_ENTITY_TYPE: Record<
HubEntityType,
{ type: EntitySettingType; settings: IEntitySettings }
> = {
discussion: {
type: EntitySettingType.CONTENT,
settings: { ...DISCUSSION_SETTINGS },
},
site: null,
project: null,
initiative: null,
initiativeTemplate: null,
page: null,
content: null,
org: null,
group: null,
template: null,
};

export function getDefaultEntitySettings(
entityType: HubEntityType
): Partial<IEntitySetting> {
if (!DEFAULT_ENTITY_SETTINGS_BY_ENTITY_TYPE[entityType]) {
throw new Error(`no default entity settings defined for ${entityType}`);
}
return {
type: DEFAULT_ENTITY_SETTINGS_BY_ENTITY_TYPE[entityType].type,
settings: {
...DEFAULT_ENTITY_SETTINGS_BY_ENTITY_TYPE[entityType].settings,
},
};
}
1 change: 1 addition & 0 deletions packages/common/src/discussions/api/settings/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./settings";
export * from "./getDefaultEntitySettings";
10 changes: 5 additions & 5 deletions packages/common/src/discussions/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ export interface IEntitySetting
IWithTimestamps {
id: string;
type: EntitySettingType;
settings: IEntityContentSettings;
settings: IEntitySettings;
}

/**
Expand All @@ -1050,9 +1050,9 @@ export enum EntitySettingType {

/**
* @export
* @interface IEntityContentSettings
* @interface IEntitySettings
*/
export interface IEntityContentSettings {
export interface IEntitySettings {
discussions?: IDiscussionsSettings;
}

Expand Down Expand Up @@ -1081,15 +1081,15 @@ export interface IRemoveSettingResponse {
export interface ICreateSetting {
id: string;
type: EntitySettingType;
settings: IEntityContentSettings;
settings: IEntitySettings;
}

/**
* @export
* @interface IUpdateSetting
*/
export interface IUpdateSetting {
settings: Partial<IEntityContentSettings>;
settings: Partial<IEntitySettings>;
}

/**
Expand Down
Loading

0 comments on commit 951c455

Please sign in to comment.