Skip to content

Commit

Permalink
feat(hub-common): add location props (#1684)
Browse files Browse the repository at this point in the history
Co-authored-by: juliannemarik <[email protected]>
  • Loading branch information
juliannaeapicella and juliannemarik authored Oct 17, 2024
1 parent 62fb8ce commit 5b5e27c
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 3 deletions.
10 changes: 10 additions & 0 deletions packages/common/src/core/schemas/shared/subschemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ export const ENTITY_FEATURED_CONTENT_SCHEMA = {
export const ENTITY_LOCATION_SCHEMA = {
type: "object",
default: { type: "none" },
properties: {
type: {
type: "string",
enum: ["none", "org", "custom"],
default: "none",
},
name: {
type: "string",
},
},
};

/**
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/core/types/IHubLocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface IHubLocation {
orgSpatialReference?: ISpatialReference;
graphic?: any;
geoJson?: any;
name?: string;
}

/**
Expand Down
13 changes: 12 additions & 1 deletion packages/common/src/events/_internal/EventSchemaEdit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
ENTITY_CATEGORIES_SCHEMA,
ENTITY_LOCATION_SCHEMA,
ENTITY_NAME_SCHEMA,
ENTITY_SUMMARY_SCHEMA,
ENTITY_TAGS_SCHEMA,
Expand Down Expand Up @@ -67,7 +68,17 @@ export const buildSchema = (): IConfigurationSchema => {
default: HubEventCapacityType.Unlimited,
},
location: {
type: "object",
...ENTITY_LOCATION_SCHEMA,
allOf: [
{
if: {
properties: { type: { enum: ["custom", "org"] } },
},
then: {
required: ["name"],
},
},
],
},
onlineUrl: {
type: "string",
Expand Down
8 changes: 8 additions & 0 deletions packages/common/src/events/_internal/EventUiSchemaEdit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ export const buildUiSchema = async (
context.portal.name,
context.hubRequestOptions
),
locationNameRequired: true,
messages: [
{
type: "ERROR",
keyword: "if",
hidden: true,
},
],
},
},
{
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/events/_internal/PropertyMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export class EventPropertyMapper extends PropertyMapper<
spatialReference: clonedEntity.location.spatialReference,
extent: clonedEntity.location.extent,
geometries: clonedEntity.location.geometries,
placeName: clonedEntity.location.name,
} as IEventLocation)
: null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export function getLocationFromEvent(event: Partial<IEvent>): IHubLocation {
spatialReference: event.location.spatialReference,
extent: event.location.extent,
geometries: event.location.geometries,
name: event.location.placeName,
}
: { type: "none" };
}
14 changes: 12 additions & 2 deletions packages/common/test/events/_internal/EventSchemaEdit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { buildSchema } from "../../../src/events/_internal/EventSchemaEdit";
import { IConfigurationSchema } from "../../../src/core/schemas/types";
import {
ENTITY_CATEGORIES_SCHEMA,
ENTITY_FEATURED_CONTENT_SCHEMA,
ENTITY_LOCATION_SCHEMA,
ENTITY_NAME_SCHEMA,
ENTITY_SUMMARY_SCHEMA,
ENTITY_TAGS_SCHEMA,
Expand Down Expand Up @@ -80,7 +80,17 @@ describe("EventSchemaEdit", () => {
default: HubEventCapacityType.Unlimited,
},
location: {
type: "object",
...ENTITY_LOCATION_SCHEMA,
allOf: [
{
if: {
properties: { type: { enum: ["custom", "org"] } },
},
then: {
required: ["name"],
},
},
],
},
onlineUrl: {
type: "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,14 @@ describe("EventUiSchemaEdit", () => {
control: "hub-field-input-location-picker",
extent: [],
options: [],
locationNameRequired: true,
messages: [
{
type: "ERROR",
keyword: "if",
hidden: true,
},
],
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ describe("getLocationFromEvent", () => {
spatialReference: Object({ wkid: 4326 }),
},
],
name: null,
} as unknown as IHubLocation);
});
it('should return a location object of type "custom" with a point', () => {
Expand Down Expand Up @@ -132,6 +133,7 @@ describe("getLocationFromEvent", () => {
spatialReference: Object({ wkid: 4326 }),
},
],
name: null,
} as unknown as IHubLocation);
});
it('should return a location object of type "custom" with a polyline', () => {
Expand Down Expand Up @@ -203,6 +205,7 @@ describe("getLocationFromEvent", () => {
spatialReference: { wkid: 4326 },
},
],
name: null,
} as unknown as IHubLocation);
});
it('should return a location object of type "custom" with a polygon', () => {
Expand Down Expand Up @@ -270,6 +273,7 @@ describe("getLocationFromEvent", () => {
spatialReference: { wkid: 4326 },
},
],
name: null,
} as unknown as IHubLocation);
});
it('should return a location object of type "custom" with a extent', () => {
Expand Down Expand Up @@ -329,6 +333,7 @@ describe("getLocationFromEvent", () => {
spatialReference: { wkid: 4326 },
},
],
name: null,
} as unknown as IHubLocation);
});
});
4 changes: 4 additions & 0 deletions packages/common/test/events/edit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ describe("HubEvents edit module", () => {
spatialReference: {},
extent: [[]],
geometries: [],
name: "",
},
referencedContentIds: ["8nd"],
referencedContentIdsByType: [
Expand Down Expand Up @@ -252,6 +253,7 @@ describe("HubEvents edit module", () => {
spatialReference: {},
extent: [[]],
geometries: [],
placeName: "",
},
},
...context.hubRequestOptions,
Expand Down Expand Up @@ -299,6 +301,7 @@ describe("HubEvents edit module", () => {
spatialReference: {},
extent: [[]],
geometries: [],
name: "",
},
referencedContentIds: ["8nd"],
referencedContentIdsByType: [
Expand Down Expand Up @@ -364,6 +367,7 @@ describe("HubEvents edit module", () => {
spatialReference: {},
extent: [[]],
geometries: [],
placeName: "",
},
},
...context.hubRequestOptions,
Expand Down

0 comments on commit 5b5e27c

Please sign in to comment.