Skip to content

Commit

Permalink
Merge pull request #860 from Esri/f/4533-get-types-from-family
Browse files Browse the repository at this point in the history
feat(hub-common): introduces a getFamilyTypes function
  • Loading branch information
drspacemanphd authored Aug 15, 2022
2 parents ae5d24a + 02d7cc7 commit fcc1d04
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 10 deletions.
14 changes: 14 additions & 0 deletions packages/common/src/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,20 @@ export const getCollection = (type?: string) => {
});
};

/**
* The converse of getCollection, returns associated types of provided collection
* @param collection The Hub collection
* @returns An array of types or undefined if collection is not found
* @private
*/
export const getCollectionTypes = (collection?: string) => {
if (!collection) {
return;
}
const lowerCaseCollection = collection.toLocaleLowerCase();
return collections[lowerCaseCollection];
};

// TODO: remove this when we remove the deprecated categories
// and then move the above arrays and getCollection() logic to get-family
export const collections: { [key: string]: string[] } = {
Expand Down
55 changes: 54 additions & 1 deletion packages/common/src/content/get-family.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HubFamily } from "../types";
import { getCollection } from "../collections";
import { getCollection, getCollectionTypes } from "../collections";

// private helper functions
function collectionToFamily(collection: string): string {
Expand Down Expand Up @@ -45,3 +45,56 @@ export function getFamily(type: string) {
}
return family as HubFamily;
}

/**
* return the types associated with a provided Hub Family
* Overrides are provided to match getFamily implementation
* @param type item type
* @returns Hub family
*/
export function getFamilyTypes(family: HubFamily): string[] {
let types;
// override default behavior for the rows that are highlighted in yellow here:
// https://esriis.sharepoint.com/:x:/r/sites/ArcGISHub/_layouts/15/Doc.aspx?sourcedoc=%7BADA1C9DC-4F6C-4DE4-92C6-693EF9571CFA%7D&file=Hub%20Routes.xlsx&nav=MTBfe0VENEREQzI4LUZFMDctNEI0Ri04NjcyLThCQUE2MTA0MEZGRn1fezIwMTIwMEJFLTA4MEQtNEExRC05QzA4LTE5MTAzOUQwMEE1RH0&action=default&mobileredirect=true&cid=df1c874b-c367-4cea-bc13-7bebfad3f2ac
switch (family.toLowerCase()) {
case "content":
types = getCollectionTypes("other");
types = types.concat([
"CAD Drawing",
"Feature Collection Template",
"Report Template",
]);
break;
case "template":
types = getCollectionTypes("solution");
break;
case "dataset":
types = getCollectionTypes(family.toLowerCase()).filter(
(type) =>
type !== "Feature Collection Template" &&
type !== "Feature Service" &&
type !== "Raster Layer" &&
type !== "Microsoft Excel"
);
types = types.concat("Image Service");
break;
case "map":
types = getCollectionTypes(family.toLowerCase()).filter(
(type) => type !== "Image Service"
);
types = types.concat(["Feature Service", "Raster Layer"]);
break;
case "document":
types = getCollectionTypes(family.toLowerCase()).filter(
(type) => type !== "CAD Drawing" && type !== "Report Template"
);
types = types.concat("Microsoft Excel");
break;
case "project":
types = ["Hub Project"];
break;
default:
types = getCollectionTypes(family.toLowerCase());
}
return types;
}
37 changes: 28 additions & 9 deletions packages/common/test/collections.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
import { getCollection } from "../src/collections";
import { getCollection, getCollectionTypes } from "../src/collections";

describe("getCollection", () => {
it("can abort", () => {
expect(getCollection()).toBe(undefined);
});
describe("collections", () => {
describe("getCollections", () => {
it("can abort", () => {
expect(getCollection()).toBe(undefined);
});

it("can retrieve a single category", () => {
expect(getCollection("Feature Layer")).toBe("dataset");
});

it("can retrieve a single category", () => {
expect(getCollection("Feature Layer")).toBe("dataset");
it("can retrieve a single category (from cache)", () => {
expect(getCollection("Feature Layer")).toBe("dataset");
});
});

it("can retrieve a single category (from cache)", () => {
expect(getCollection("Feature Layer")).toBe("dataset");
describe("getTypesFromCollection", () => {
it("can abort", () => {
expect(getCollectionTypes()).toBe(undefined);
});

it("can retrieve types from a collection", () => {
expect(getCollectionTypes("feedback")).toEqual([
"Form",
"Quick Capture Project",
]);
});

it("returns undefined with unknown collection", () => {
expect(getCollectionTypes("dummy")).toBe(undefined);
});
});
});
68 changes: 68 additions & 0 deletions packages/common/test/content/get-family.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { getFamilyTypes } from "../../src";

describe("getFamily", () => {
describe("getFamilyTypes", () => {
it("can get 'content' types", () => {
const types = getFamilyTypes("content");
expect(Array.isArray(types)).toBeTruthy();
expect(types.length > 0).toBeTruthy();
expect(types.includes("CAD Drawing")).toBeTruthy();
expect(types.includes("Feature Collection Template")).toBeTruthy();
expect(types.includes("Report Template")).toBeTruthy();
});

it("can get 'template' types", () => {
const types = getFamilyTypes("template");
expect(Array.isArray(types)).toBeTruthy();
expect(types.length).toBe(1);
expect(types.includes("Solution")).toBeTruthy();
});

it("can get 'dataset' types", () => {
const types = getFamilyTypes("dataset");
expect(Array.isArray(types)).toBeTruthy();
expect(types.length > 0).toBeTruthy();
expect(types.includes("Image Service")).toBeTruthy();
expect(types.includes("Feature Collection Template")).toBeFalsy();
expect(types.includes("Feature Service")).toBeFalsy();
expect(types.includes("Raster Layer")).toBeFalsy();
expect(types.includes("Microsoft Excel")).toBeFalsy();
});

it("can get 'map' types", () => {
const types = getFamilyTypes("map");
expect(Array.isArray(types)).toBeTruthy();
expect(types.length > 0).toBeTruthy();
expect(types.includes("Image Service")).toBeFalsy();
expect(types.includes("Feature Service")).toBeTruthy();
expect(types.includes("Raster Layer")).toBeTruthy();
});

it("can get 'document' types", () => {
const types = getFamilyTypes("document");
expect(Array.isArray(types)).toBeTruthy();
expect(types.length > 0).toBeTruthy();
expect(types.includes("CAD Drawing")).toBeFalsy();
expect(types.includes("Report Template")).toBeFalsy();
expect(types.includes("Microsoft Excel")).toBeTruthy();
});

it("can get 'project' types", () => {
const types = getFamilyTypes("project");
expect(Array.isArray(types)).toBeTruthy();
expect(types.length).toBe(1);
expect(types.includes("Hub Project")).toBeTruthy();
});

it("can get types any other valid family", () => {
const types = getFamilyTypes("site");
expect(Array.isArray(types)).toBeTruthy();
expect(types.length > 0).toBeTruthy();
});

it("can returns undefined for an invalid family", () => {
const types = getFamilyTypes("dummy" as any);
expect(types).toBeUndefined();
});
});
});

0 comments on commit fcc1d04

Please sign in to comment.