-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
187738935 v3 DI caseFormulaSearch (#1372)
* Handle get caseFormulaSearch requests.
- Loading branch information
1 parent
a54699c
commit 6750b30
Showing
8 changed files
with
175 additions
and
10 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
30 changes: 30 additions & 0 deletions
30
v3/src/data-interactive/handlers/case-formula-search-handler.test.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,30 @@ | ||
import { toV2Id } from "../../utilities/codap-utils" | ||
import { DIFullCase } from "../data-interactive-types" | ||
import { diCaseFormulaSearchHandler } from "./case-formula-search-handler" | ||
import { setupTestDataset } from "./handler-test-utils" | ||
|
||
|
||
describe("DataInteractive CaseFormulaSearchHandler", () => { | ||
const handler = diCaseFormulaSearchHandler | ||
|
||
it("get works", () => { | ||
const { dataset: dataContext, c2: collection } = setupTestDataset() | ||
const cases = dataContext.getGroupsForCollection(collection.id).map(c => c.groupedCase) | ||
const caseFormulaSearch = [cases[0], cases[2], cases[3]] | ||
|
||
expect(handler.get?.({ dataContext, collection }).success).toBe(false) | ||
expect(handler.get?.({ dataContext, caseFormulaSearch }).success).toBe(false) | ||
expect(handler.get?.({ collection, caseFormulaSearch }).success).toBe(false) | ||
|
||
const result = handler.get!({ dataContext, collection, caseFormulaSearch }) | ||
expect(result.success).toBe(true) | ||
const values = result.values as DIFullCase[] | ||
caseFormulaSearch.forEach((item, index) => { | ||
expect(values[index].id).toBe(toV2Id(item.__id__)) | ||
const itemIndex = dataContext.getItemIndex(dataContext.caseInfoMap.get(item.__id__)!.childItemIds[0])! | ||
collection.attributes.forEach(attribute => { | ||
expect(attribute && values[index].values?.[attribute.name]).toBe(attribute?.value(itemIndex)) | ||
}) | ||
}) | ||
}) | ||
}) |
18 changes: 16 additions & 2 deletions
18
v3/src/data-interactive/handlers/case-formula-search-handler.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,8 +1,22 @@ | ||
import { registerDIHandler } from "../data-interactive-handler" | ||
import { DIHandler, diNotImplementedYet } from "../data-interactive-types" | ||
import { DIHandler, DIResources } from "../data-interactive-types" | ||
import { getCaseRequestResultValues } from "../data-interactive-type-utils" | ||
import { collectionNotFoundResult, couldNotParseQueryResult, dataContextNotFoundResult } from "./di-results" | ||
|
||
export const diCaseFormulaSearchHandler: DIHandler = { | ||
get: diNotImplementedYet | ||
get(resources: DIResources) { | ||
const { caseFormulaSearch, collection, dataContext, error } = resources | ||
if (!collection) return collectionNotFoundResult | ||
if (!dataContext) return dataContextNotFoundResult | ||
if (error) return { success: false, error } | ||
if (!caseFormulaSearch) return couldNotParseQueryResult | ||
|
||
return { | ||
success: true, | ||
values: caseFormulaSearch?.map(aCase => | ||
getCaseRequestResultValues(aCase, dataContext).case) | ||
} | ||
} | ||
} | ||
|
||
registerDIHandler("caseFormulaSearch", diCaseFormulaSearchHandler) |
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
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