@powerhousedao/builder-team-admin 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/document-models/expense-report/module.d.ts +2 -2
- package/dist/document-models/expense-report/module.d.ts.map +1 -1
- package/dist/document-models/expense-report/module.js +4 -2
- package/dist/document-models/service-subscriptions/module.d.ts +2 -2
- package/dist/document-models/service-subscriptions/module.d.ts.map +1 -1
- package/dist/document-models/service-subscriptions/module.js +4 -2
- package/dist/package.json +1 -1
- package/dist/powerhouse.manifest.json +9 -1
- package/package.json +1 -1
- package/dist/document-models/builders/actions.d.ts +0 -14
- package/dist/document-models/builders/actions.d.ts.map +0 -1
- package/dist/document-models/builders/actions.js +0 -4
- package/dist/document-models/builders/gen/actions.d.ts +0 -4
- package/dist/document-models/builders/gen/actions.d.ts.map +0 -1
- package/dist/document-models/builders/gen/actions.js +0 -1
- package/dist/document-models/builders/gen/builders/actions.d.ts +0 -12
- package/dist/document-models/builders/gen/builders/actions.d.ts.map +0 -1
- package/dist/document-models/builders/gen/builders/actions.js +0 -1
- package/dist/document-models/builders/gen/builders/creators.d.ts +0 -5
- package/dist/document-models/builders/gen/builders/creators.d.ts.map +0 -1
- package/dist/document-models/builders/gen/builders/creators.js +0 -4
- package/dist/document-models/builders/gen/builders/error.d.ts +0 -2
- package/dist/document-models/builders/gen/builders/error.d.ts.map +0 -1
- package/dist/document-models/builders/gen/builders/error.js +0 -1
- package/dist/document-models/builders/gen/builders/operations.d.ts +0 -8
- package/dist/document-models/builders/gen/builders/operations.d.ts.map +0 -1
- package/dist/document-models/builders/gen/builders/operations.js +0 -3
- package/dist/document-models/builders/gen/creators.d.ts +0 -3
- package/dist/document-models/builders/gen/creators.d.ts.map +0 -1
- package/dist/document-models/builders/gen/creators.js +0 -2
- package/dist/document-models/builders/gen/document-model.d.ts +0 -3
- package/dist/document-models/builders/gen/document-model.d.ts.map +0 -1
- package/dist/document-models/builders/gen/document-model.js +0 -59
- package/dist/document-models/builders/gen/document-schema.d.ts +0 -142
- package/dist/document-models/builders/gen/document-schema.d.ts.map +0 -1
- package/dist/document-models/builders/gen/document-schema.js +0 -33
- package/dist/document-models/builders/gen/document-type.d.ts +0 -2
- package/dist/document-models/builders/gen/document-type.d.ts.map +0 -1
- package/dist/document-models/builders/gen/document-type.js +0 -1
- package/dist/document-models/builders/gen/index.d.ts +0 -12
- package/dist/document-models/builders/gen/index.d.ts.map +0 -1
- package/dist/document-models/builders/gen/index.js +0 -11
- package/dist/document-models/builders/gen/ph-factories.d.ts +0 -23
- package/dist/document-models/builders/gen/ph-factories.d.ts.map +0 -1
- package/dist/document-models/builders/gen/ph-factories.js +0 -47
- package/dist/document-models/builders/gen/reducer.d.ts +0 -3
- package/dist/document-models/builders/gen/reducer.d.ts.map +0 -1
- package/dist/document-models/builders/gen/reducer.js +0 -21
- package/dist/document-models/builders/gen/schema/index.d.ts +0 -3
- package/dist/document-models/builders/gen/schema/index.d.ts.map +0 -1
- package/dist/document-models/builders/gen/schema/index.js +0 -2
- package/dist/document-models/builders/gen/schema/types.d.ts +0 -146
- package/dist/document-models/builders/gen/schema/types.d.ts.map +0 -1
- package/dist/document-models/builders/gen/schema/types.js +0 -1
- package/dist/document-models/builders/gen/schema/zod.d.ts +0 -13
- package/dist/document-models/builders/gen/schema/zod.d.ts.map +0 -1
- package/dist/document-models/builders/gen/schema/zod.js +0 -21
- package/dist/document-models/builders/gen/types.d.ts +0 -12
- package/dist/document-models/builders/gen/types.d.ts.map +0 -1
- package/dist/document-models/builders/gen/types.js +0 -1
- package/dist/document-models/builders/gen/utils.d.ts +0 -15
- package/dist/document-models/builders/gen/utils.d.ts.map +0 -1
- package/dist/document-models/builders/gen/utils.js +0 -51
- package/dist/document-models/builders/hooks.d.ts +0 -11
- package/dist/document-models/builders/hooks.d.ts.map +0 -1
- package/dist/document-models/builders/hooks.js +0 -26
- package/dist/document-models/builders/index.d.ts +0 -10
- package/dist/document-models/builders/index.d.ts.map +0 -1
- package/dist/document-models/builders/index.js +0 -9
- package/dist/document-models/builders/module.d.ts +0 -5
- package/dist/document-models/builders/module.d.ts.map +0 -1
- package/dist/document-models/builders/module.js +0 -10
- package/dist/document-models/builders/src/index.d.ts +0 -2
- package/dist/document-models/builders/src/index.d.ts.map +0 -1
- package/dist/document-models/builders/src/index.js +0 -1
- package/dist/document-models/builders/src/reducers/builders.d.ts +0 -3
- package/dist/document-models/builders/src/reducers/builders.d.ts.map +0 -1
- package/dist/document-models/builders/src/reducers/builders.js +0 -8
- package/dist/document-models/builders/src/tests/builders.test.d.ts +0 -6
- package/dist/document-models/builders/src/tests/builders.test.d.ts.map +0 -1
- package/dist/document-models/builders/src/tests/builders.test.js +0 -29
- package/dist/document-models/builders/src/tests/document-model.test.d.ts +0 -10
- package/dist/document-models/builders/src/tests/document-model.test.d.ts.map +0 -1
- package/dist/document-models/builders/src/tests/document-model.test.js +0 -104
- package/dist/document-models/builders/src/utils.d.ts +0 -2
- package/dist/document-models/builders/src/utils.d.ts.map +0 -1
- package/dist/document-models/builders/src/utils.js +0 -1
- package/dist/document-models/builders/utils.d.ts +0 -14
- package/dist/document-models/builders/utils.d.ts.map +0 -1
- package/dist/document-models/builders/utils.js +0 -7
- package/dist/document-models/expense-report/src/tests/document-model.test.d.ts +0 -10
- package/dist/document-models/expense-report/src/tests/document-model.test.d.ts.map +0 -1
- package/dist/document-models/expense-report/src/tests/document-model.test.js +0 -104
- package/dist/document-models/expense-report/src/tests/wallet.test.d.ts +0 -6
- package/dist/document-models/expense-report/src/tests/wallet.test.d.ts.map +0 -1
- package/dist/document-models/expense-report/src/tests/wallet.test.js +0 -159
- package/dist/editors/builders/editor.d.ts +0 -3
- package/dist/editors/builders/editor.d.ts.map +0 -1
- package/dist/editors/builders/editor.js +0 -204
- package/dist/editors/builders/module.d.ts +0 -4
- package/dist/editors/builders/module.d.ts.map +0 -1
- package/dist/editors/builders/module.js +0 -10
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This is a scaffold file meant for customization:
|
|
3
|
-
* - change it by adding new tests or modifying the existing ones
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* This is a scaffold file meant for customization:
|
|
7
|
-
* - change it by adding new tests or modifying the existing ones
|
|
8
|
-
*/
|
|
9
|
-
import { describe, it, expect } from "vitest";
|
|
10
|
-
import { utils, initialGlobalState, initialLocalState, expenseReportDocumentType, isExpenseReportDocument, assertIsExpenseReportDocument, isExpenseReportState, assertIsExpenseReportState, } from "@powerhousedao/contributor-billing/document-models/expense-report";
|
|
11
|
-
import { ZodError } from "zod";
|
|
12
|
-
describe("ExpenseReport Document Model", () => {
|
|
13
|
-
it("should create a new ExpenseReport document", () => {
|
|
14
|
-
const document = utils.createDocument();
|
|
15
|
-
expect(document).toBeDefined();
|
|
16
|
-
expect(document.header.documentType).toBe(expenseReportDocumentType);
|
|
17
|
-
});
|
|
18
|
-
it("should create a new ExpenseReport document with a valid initial state", () => {
|
|
19
|
-
const document = utils.createDocument();
|
|
20
|
-
expect(document.state.global).toStrictEqual(initialGlobalState);
|
|
21
|
-
expect(document.state.local).toStrictEqual(initialLocalState);
|
|
22
|
-
expect(isExpenseReportDocument(document)).toBe(true);
|
|
23
|
-
expect(isExpenseReportState(document.state)).toBe(true);
|
|
24
|
-
});
|
|
25
|
-
it("should reject a document that is not a ExpenseReport document", () => {
|
|
26
|
-
const wrongDocumentType = utils.createDocument();
|
|
27
|
-
wrongDocumentType.header.documentType = "the-wrong-thing-1234";
|
|
28
|
-
try {
|
|
29
|
-
expect(assertIsExpenseReportDocument(wrongDocumentType)).toThrow();
|
|
30
|
-
expect(isExpenseReportDocument(wrongDocumentType)).toBe(false);
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
expect(error).toBeInstanceOf(ZodError);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
const wrongState = utils.createDocument();
|
|
37
|
-
// @ts-expect-error - we are testing the error case
|
|
38
|
-
wrongState.state.global = {
|
|
39
|
-
...{ notWhat: "you want" },
|
|
40
|
-
};
|
|
41
|
-
try {
|
|
42
|
-
expect(isExpenseReportState(wrongState.state)).toBe(false);
|
|
43
|
-
expect(assertIsExpenseReportState(wrongState.state)).toThrow();
|
|
44
|
-
expect(isExpenseReportDocument(wrongState)).toBe(false);
|
|
45
|
-
expect(assertIsExpenseReportDocument(wrongState)).toThrow();
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
expect(error).toBeInstanceOf(ZodError);
|
|
49
|
-
}
|
|
50
|
-
const wrongInitialState = utils.createDocument();
|
|
51
|
-
// @ts-expect-error - we are testing the error case
|
|
52
|
-
wrongInitialState.initialState.global = {
|
|
53
|
-
...{ notWhat: "you want" },
|
|
54
|
-
};
|
|
55
|
-
try {
|
|
56
|
-
expect(isExpenseReportState(wrongInitialState.state)).toBe(false);
|
|
57
|
-
expect(assertIsExpenseReportState(wrongInitialState.state)).toThrow();
|
|
58
|
-
expect(isExpenseReportDocument(wrongInitialState)).toBe(false);
|
|
59
|
-
expect(assertIsExpenseReportDocument(wrongInitialState)).toThrow();
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
expect(error).toBeInstanceOf(ZodError);
|
|
63
|
-
}
|
|
64
|
-
const missingIdInHeader = utils.createDocument();
|
|
65
|
-
// @ts-expect-error - we are testing the error case
|
|
66
|
-
delete missingIdInHeader.header.id;
|
|
67
|
-
try {
|
|
68
|
-
expect(isExpenseReportDocument(missingIdInHeader)).toBe(false);
|
|
69
|
-
expect(assertIsExpenseReportDocument(missingIdInHeader)).toThrow();
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
expect(error).toBeInstanceOf(ZodError);
|
|
73
|
-
}
|
|
74
|
-
const missingNameInHeader = utils.createDocument();
|
|
75
|
-
// @ts-expect-error - we are testing the error case
|
|
76
|
-
delete missingNameInHeader.header.name;
|
|
77
|
-
try {
|
|
78
|
-
expect(isExpenseReportDocument(missingNameInHeader)).toBe(false);
|
|
79
|
-
expect(assertIsExpenseReportDocument(missingNameInHeader)).toThrow();
|
|
80
|
-
}
|
|
81
|
-
catch (error) {
|
|
82
|
-
expect(error).toBeInstanceOf(ZodError);
|
|
83
|
-
}
|
|
84
|
-
const missingCreatedAtUtcIsoInHeader = utils.createDocument();
|
|
85
|
-
// @ts-expect-error - we are testing the error case
|
|
86
|
-
delete missingCreatedAtUtcIsoInHeader.header.createdAtUtcIso;
|
|
87
|
-
try {
|
|
88
|
-
expect(isExpenseReportDocument(missingCreatedAtUtcIsoInHeader)).toBe(false);
|
|
89
|
-
expect(assertIsExpenseReportDocument(missingCreatedAtUtcIsoInHeader)).toThrow();
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
92
|
-
expect(error).toBeInstanceOf(ZodError);
|
|
93
|
-
}
|
|
94
|
-
const missingLastModifiedAtUtcIsoInHeader = utils.createDocument();
|
|
95
|
-
// @ts-expect-error - we are testing the error case
|
|
96
|
-
delete missingLastModifiedAtUtcIsoInHeader.header.lastModifiedAtUtcIso;
|
|
97
|
-
try {
|
|
98
|
-
expect(isExpenseReportDocument(missingLastModifiedAtUtcIsoInHeader)).toBe(false);
|
|
99
|
-
expect(assertIsExpenseReportDocument(missingLastModifiedAtUtcIsoInHeader)).toThrow();
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
expect(error).toBeInstanceOf(ZodError);
|
|
103
|
-
}
|
|
104
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.test.d.ts","sourceRoot":"","sources":["../../../../../document-models/expense-report/src/tests/wallet.test.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This is a scaffold file meant for customization:
|
|
3
|
-
* - change it by adding new tests or modifying the existing ones
|
|
4
|
-
*/
|
|
5
|
-
import { describe, it, expect } from "vitest";
|
|
6
|
-
import { generateMock } from "@powerhousedao/codegen";
|
|
7
|
-
import { reducer, utils, isExpenseReportDocument, addWallet, AddWalletInputSchema, removeWallet, RemoveWalletInputSchema, addBillingStatement, AddBillingStatementInputSchema, removeBillingStatement, RemoveBillingStatementInputSchema, addLineItem, AddLineItemInputSchema, updateLineItem, UpdateLineItemInputSchema, removeLineItem, RemoveLineItemInputSchema, addLineItemGroup, AddLineItemGroupInputSchema, updateLineItemGroup, UpdateLineItemGroupInputSchema, removeLineItemGroup, RemoveLineItemGroupInputSchema, setGroupTotals, SetGroupTotalsInputSchema, removeGroupTotals, RemoveGroupTotalsInputSchema, setPeriodStart, SetPeriodStartInputSchema, setPeriodEnd, SetPeriodEndInputSchema, updateWallet, UpdateWalletInputSchema, } from "@powerhousedao/contributor-billing/document-models/expense-report";
|
|
8
|
-
describe("Wallet Operations", () => {
|
|
9
|
-
it("should handle addWallet operation", () => {
|
|
10
|
-
const document = utils.createDocument();
|
|
11
|
-
const input = generateMock(AddWalletInputSchema());
|
|
12
|
-
const updatedDocument = reducer(document, addWallet(input));
|
|
13
|
-
expect(isExpenseReportDocument(updatedDocument)).toBe(true);
|
|
14
|
-
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
15
|
-
expect(updatedDocument.operations.global[0].action.type).toBe("ADD_WALLET");
|
|
16
|
-
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
17
|
-
expect(updatedDocument.operations.global[0].index).toEqual(0);
|
|
18
|
-
});
|
|
19
|
-
it("should handle removeWallet operation", () => {
|
|
20
|
-
const document = utils.createDocument();
|
|
21
|
-
const input = generateMock(RemoveWalletInputSchema());
|
|
22
|
-
const updatedDocument = reducer(document, removeWallet(input));
|
|
23
|
-
expect(isExpenseReportDocument(updatedDocument)).toBe(true);
|
|
24
|
-
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
25
|
-
expect(updatedDocument.operations.global[0].action.type).toBe("REMOVE_WALLET");
|
|
26
|
-
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
27
|
-
expect(updatedDocument.operations.global[0].index).toEqual(0);
|
|
28
|
-
});
|
|
29
|
-
it("should handle addBillingStatement operation", () => {
|
|
30
|
-
const document = utils.createDocument();
|
|
31
|
-
const input = generateMock(AddBillingStatementInputSchema());
|
|
32
|
-
const updatedDocument = reducer(document, addBillingStatement(input));
|
|
33
|
-
expect(isExpenseReportDocument(updatedDocument)).toBe(true);
|
|
34
|
-
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
35
|
-
expect(updatedDocument.operations.global[0].action.type).toBe("ADD_BILLING_STATEMENT");
|
|
36
|
-
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
37
|
-
expect(updatedDocument.operations.global[0].index).toEqual(0);
|
|
38
|
-
});
|
|
39
|
-
it("should handle removeBillingStatement operation", () => {
|
|
40
|
-
const document = utils.createDocument();
|
|
41
|
-
const input = generateMock(RemoveBillingStatementInputSchema());
|
|
42
|
-
const updatedDocument = reducer(document, removeBillingStatement(input));
|
|
43
|
-
expect(isExpenseReportDocument(updatedDocument)).toBe(true);
|
|
44
|
-
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
45
|
-
expect(updatedDocument.operations.global[0].action.type).toBe("REMOVE_BILLING_STATEMENT");
|
|
46
|
-
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
47
|
-
expect(updatedDocument.operations.global[0].index).toEqual(0);
|
|
48
|
-
});
|
|
49
|
-
it("should handle addLineItem operation", () => {
|
|
50
|
-
const document = utils.createDocument();
|
|
51
|
-
const input = generateMock(AddLineItemInputSchema());
|
|
52
|
-
const updatedDocument = reducer(document, addLineItem(input));
|
|
53
|
-
expect(isExpenseReportDocument(updatedDocument)).toBe(true);
|
|
54
|
-
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
55
|
-
expect(updatedDocument.operations.global[0].action.type).toBe("ADD_LINE_ITEM");
|
|
56
|
-
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
57
|
-
expect(updatedDocument.operations.global[0].index).toEqual(0);
|
|
58
|
-
});
|
|
59
|
-
it("should handle updateLineItem operation", () => {
|
|
60
|
-
const document = utils.createDocument();
|
|
61
|
-
const input = generateMock(UpdateLineItemInputSchema());
|
|
62
|
-
const updatedDocument = reducer(document, updateLineItem(input));
|
|
63
|
-
expect(isExpenseReportDocument(updatedDocument)).toBe(true);
|
|
64
|
-
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
65
|
-
expect(updatedDocument.operations.global[0].action.type).toBe("UPDATE_LINE_ITEM");
|
|
66
|
-
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
67
|
-
expect(updatedDocument.operations.global[0].index).toEqual(0);
|
|
68
|
-
});
|
|
69
|
-
it("should handle removeLineItem operation", () => {
|
|
70
|
-
const document = utils.createDocument();
|
|
71
|
-
const input = generateMock(RemoveLineItemInputSchema());
|
|
72
|
-
const updatedDocument = reducer(document, removeLineItem(input));
|
|
73
|
-
expect(isExpenseReportDocument(updatedDocument)).toBe(true);
|
|
74
|
-
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
75
|
-
expect(updatedDocument.operations.global[0].action.type).toBe("REMOVE_LINE_ITEM");
|
|
76
|
-
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
77
|
-
expect(updatedDocument.operations.global[0].index).toEqual(0);
|
|
78
|
-
});
|
|
79
|
-
it("should handle addLineItemGroup operation", () => {
|
|
80
|
-
const document = utils.createDocument();
|
|
81
|
-
const input = generateMock(AddLineItemGroupInputSchema());
|
|
82
|
-
const updatedDocument = reducer(document, addLineItemGroup(input));
|
|
83
|
-
expect(isExpenseReportDocument(updatedDocument)).toBe(true);
|
|
84
|
-
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
85
|
-
expect(updatedDocument.operations.global[0].action.type).toBe("ADD_LINE_ITEM_GROUP");
|
|
86
|
-
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
87
|
-
expect(updatedDocument.operations.global[0].index).toEqual(0);
|
|
88
|
-
});
|
|
89
|
-
it("should handle updateLineItemGroup operation", () => {
|
|
90
|
-
const document = utils.createDocument();
|
|
91
|
-
const input = generateMock(UpdateLineItemGroupInputSchema());
|
|
92
|
-
const updatedDocument = reducer(document, updateLineItemGroup(input));
|
|
93
|
-
expect(isExpenseReportDocument(updatedDocument)).toBe(true);
|
|
94
|
-
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
95
|
-
expect(updatedDocument.operations.global[0].action.type).toBe("UPDATE_LINE_ITEM_GROUP");
|
|
96
|
-
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
97
|
-
expect(updatedDocument.operations.global[0].index).toEqual(0);
|
|
98
|
-
});
|
|
99
|
-
it("should handle removeLineItemGroup operation", () => {
|
|
100
|
-
const document = utils.createDocument();
|
|
101
|
-
const input = generateMock(RemoveLineItemGroupInputSchema());
|
|
102
|
-
const updatedDocument = reducer(document, removeLineItemGroup(input));
|
|
103
|
-
expect(isExpenseReportDocument(updatedDocument)).toBe(true);
|
|
104
|
-
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
105
|
-
expect(updatedDocument.operations.global[0].action.type).toBe("REMOVE_LINE_ITEM_GROUP");
|
|
106
|
-
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
107
|
-
expect(updatedDocument.operations.global[0].index).toEqual(0);
|
|
108
|
-
});
|
|
109
|
-
it("should handle setGroupTotals operation", () => {
|
|
110
|
-
const document = utils.createDocument();
|
|
111
|
-
const input = generateMock(SetGroupTotalsInputSchema());
|
|
112
|
-
const updatedDocument = reducer(document, setGroupTotals(input));
|
|
113
|
-
expect(isExpenseReportDocument(updatedDocument)).toBe(true);
|
|
114
|
-
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
115
|
-
expect(updatedDocument.operations.global[0].action.type).toBe("SET_GROUP_TOTALS");
|
|
116
|
-
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
117
|
-
expect(updatedDocument.operations.global[0].index).toEqual(0);
|
|
118
|
-
});
|
|
119
|
-
it("should handle removeGroupTotals operation", () => {
|
|
120
|
-
const document = utils.createDocument();
|
|
121
|
-
const input = generateMock(RemoveGroupTotalsInputSchema());
|
|
122
|
-
const updatedDocument = reducer(document, removeGroupTotals(input));
|
|
123
|
-
expect(isExpenseReportDocument(updatedDocument)).toBe(true);
|
|
124
|
-
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
125
|
-
expect(updatedDocument.operations.global[0].action.type).toBe("REMOVE_GROUP_TOTALS");
|
|
126
|
-
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
127
|
-
expect(updatedDocument.operations.global[0].index).toEqual(0);
|
|
128
|
-
});
|
|
129
|
-
it("should handle setPeriodStart operation", () => {
|
|
130
|
-
const document = utils.createDocument();
|
|
131
|
-
const input = generateMock(SetPeriodStartInputSchema());
|
|
132
|
-
const updatedDocument = reducer(document, setPeriodStart(input));
|
|
133
|
-
expect(isExpenseReportDocument(updatedDocument)).toBe(true);
|
|
134
|
-
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
135
|
-
expect(updatedDocument.operations.global[0].action.type).toBe("SET_PERIOD_START");
|
|
136
|
-
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
137
|
-
expect(updatedDocument.operations.global[0].index).toEqual(0);
|
|
138
|
-
});
|
|
139
|
-
it("should handle setPeriodEnd operation", () => {
|
|
140
|
-
const document = utils.createDocument();
|
|
141
|
-
const input = generateMock(SetPeriodEndInputSchema());
|
|
142
|
-
const updatedDocument = reducer(document, setPeriodEnd(input));
|
|
143
|
-
expect(isExpenseReportDocument(updatedDocument)).toBe(true);
|
|
144
|
-
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
145
|
-
expect(updatedDocument.operations.global[0].action.type).toBe("SET_PERIOD_END");
|
|
146
|
-
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
147
|
-
expect(updatedDocument.operations.global[0].index).toEqual(0);
|
|
148
|
-
});
|
|
149
|
-
it("should handle updateWallet operation", () => {
|
|
150
|
-
const document = utils.createDocument();
|
|
151
|
-
const input = generateMock(UpdateWalletInputSchema());
|
|
152
|
-
const updatedDocument = reducer(document, updateWallet(input));
|
|
153
|
-
expect(isExpenseReportDocument(updatedDocument)).toBe(true);
|
|
154
|
-
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
155
|
-
expect(updatedDocument.operations.global[0].action.type).toBe("UPDATE_WALLET");
|
|
156
|
-
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
157
|
-
expect(updatedDocument.operations.global[0].index).toEqual(0);
|
|
158
|
-
});
|
|
159
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../../../editors/builders/editor.tsx"],"names":[],"mappings":"AA4BA,0CAA0C;AAC1C,MAAM,CAAC,OAAO,UAAU,MAAM,4CAsR7B"}
|
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { DocumentToolbar } from "@powerhousedao/design-system/connect";
|
|
3
|
-
import { useSelectedBuildersDocument } from "../../document-models/builders/hooks.js";
|
|
4
|
-
import { actions as buildersActions } from "../../document-models/builders/actions.js";
|
|
5
|
-
import { setSelectedNode, useParentFolderForSelectedNode, useDocumentsInSelectedDrive, useDrives, useGetDocuments, } from "@powerhousedao/reactor-browser";
|
|
6
|
-
import { useMemo, useCallback } from "react";
|
|
7
|
-
import { ObjectSetTable, PHIDInput, } from "@powerhousedao/document-engineering";
|
|
8
|
-
/** Implement your editor behavior here */
|
|
9
|
-
export default function Editor() {
|
|
10
|
-
const [doc, dispatch] = useSelectedBuildersDocument();
|
|
11
|
-
// Get the parent folder node for the currently selected node
|
|
12
|
-
const parentFolder = useParentFolderForSelectedNode();
|
|
13
|
-
// Set the selected node to the parent folder node (close the editor)
|
|
14
|
-
function handleClose() {
|
|
15
|
-
setSelectedNode(parentFolder?.id);
|
|
16
|
-
}
|
|
17
|
-
const drives = useDrives();
|
|
18
|
-
// Map all builder profile FileNodes from all drives with their driveId
|
|
19
|
-
const builderProfileNodesWithDriveId = useMemo(() => {
|
|
20
|
-
if (!drives)
|
|
21
|
-
return [];
|
|
22
|
-
return drives.flatMap((drive) => {
|
|
23
|
-
const builderProfileNodes = drive.state.global.nodes.filter((node) => node.kind === "file" &&
|
|
24
|
-
"documentType" in node &&
|
|
25
|
-
node.documentType === "powerhouse/builder-profile");
|
|
26
|
-
return builderProfileNodes.map((node) => ({
|
|
27
|
-
node,
|
|
28
|
-
driveId: drive.header.id,
|
|
29
|
-
}));
|
|
30
|
-
});
|
|
31
|
-
}, [drives]);
|
|
32
|
-
// Get all unique builder PHIDs from the nodes
|
|
33
|
-
const builderPhids = useMemo(() => {
|
|
34
|
-
return builderProfileNodesWithDriveId.map(({ node }) => node.id);
|
|
35
|
-
}, [builderProfileNodesWithDriveId]);
|
|
36
|
-
// Fetch all builder profile documents from all drives
|
|
37
|
-
const builderProfileDocuments = useGetDocuments(builderPhids);
|
|
38
|
-
// Create a map of PHID to document for quick lookup
|
|
39
|
-
const builderProfileMap = useMemo(() => {
|
|
40
|
-
if (!builderProfileDocuments)
|
|
41
|
-
return new Map();
|
|
42
|
-
const map = new Map();
|
|
43
|
-
builderProfileDocuments.forEach((doc) => {
|
|
44
|
-
if (doc.header.documentType === "powerhouse/builder-profile") {
|
|
45
|
-
map.set(doc.header.id, doc);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
return map;
|
|
49
|
-
}, [builderProfileDocuments]);
|
|
50
|
-
// Helper function to get builder profile documents from all drives
|
|
51
|
-
const getBuilderProfiles = useCallback(() => {
|
|
52
|
-
return builderProfileNodesWithDriveId.map(({ node }) => {
|
|
53
|
-
const doc = builderProfileMap.get(node.id);
|
|
54
|
-
const name = doc?.state?.global?.name || node.name || node.id;
|
|
55
|
-
return {
|
|
56
|
-
id: node.id,
|
|
57
|
-
label: name,
|
|
58
|
-
value: node.id,
|
|
59
|
-
title: name,
|
|
60
|
-
};
|
|
61
|
-
});
|
|
62
|
-
}, [builderProfileNodesWithDriveId, builderProfileMap]);
|
|
63
|
-
// Helper function to get builder profile data by PHID from all drives
|
|
64
|
-
const getBuilderProfileByPhid = (phid) => {
|
|
65
|
-
const doc = builderProfileMap.get(phid);
|
|
66
|
-
if (!doc)
|
|
67
|
-
return null;
|
|
68
|
-
return {
|
|
69
|
-
name: doc.state.global?.name || doc.header.id,
|
|
70
|
-
slug: doc.state.global?.slug || doc.header.id,
|
|
71
|
-
icon: doc.state.global?.icon || null,
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
const builders = useMemo(() => {
|
|
75
|
-
return doc?.state.global.builders.map((phid) => ({
|
|
76
|
-
phid: phid,
|
|
77
|
-
name: getBuilderProfileByPhid(phid)?.name || "",
|
|
78
|
-
slug: getBuilderProfileByPhid(phid)?.slug || "",
|
|
79
|
-
icon: getBuilderProfileByPhid(phid)?.icon || null,
|
|
80
|
-
}));
|
|
81
|
-
}, [doc, builderProfileMap]);
|
|
82
|
-
const columns = useMemo(() => [
|
|
83
|
-
{
|
|
84
|
-
field: "phid",
|
|
85
|
-
title: "PHID",
|
|
86
|
-
editable: true,
|
|
87
|
-
align: "center",
|
|
88
|
-
width: 200,
|
|
89
|
-
onSave: (newValue, context) => {
|
|
90
|
-
const currentId = context.row.phid || "";
|
|
91
|
-
if (newValue !== currentId && newValue && currentId) {
|
|
92
|
-
// First remove the old agent
|
|
93
|
-
dispatch(buildersActions.removeBuilder({ builderPhid: currentId }));
|
|
94
|
-
// Then add the new agent with the new PHID
|
|
95
|
-
dispatch(buildersActions.addBuilder({
|
|
96
|
-
builderPhid: newValue,
|
|
97
|
-
}));
|
|
98
|
-
return true;
|
|
99
|
-
}
|
|
100
|
-
return false;
|
|
101
|
-
},
|
|
102
|
-
renderCellEditor: (value, onChange, context) => (_jsx(PHIDInput, { value: value || "", onChange: (newValue) => {
|
|
103
|
-
onChange(newValue);
|
|
104
|
-
}, onBlur: (e) => {
|
|
105
|
-
const newValue = e.target.value;
|
|
106
|
-
const currentValue = value || "";
|
|
107
|
-
// If a PHID is entered and it's different from current value
|
|
108
|
-
if (newValue && newValue !== currentValue) {
|
|
109
|
-
const builderProfile = getBuilderProfileByPhid(newValue);
|
|
110
|
-
const existingBuilder = builders?.find((builder) => builder?.phid === newValue);
|
|
111
|
-
if (!existingBuilder) {
|
|
112
|
-
// If we're editing an existing row (has an ID), remove the old one first
|
|
113
|
-
if (context.row.phid && context.row.phid !== newValue) {
|
|
114
|
-
dispatch(buildersActions.removeBuilder({
|
|
115
|
-
builderPhid: context.row.phid,
|
|
116
|
-
}));
|
|
117
|
-
}
|
|
118
|
-
if (builderProfile) {
|
|
119
|
-
// Create new agent with data from builder profile
|
|
120
|
-
dispatch(buildersActions.addBuilder({
|
|
121
|
-
builderPhid: newValue,
|
|
122
|
-
}));
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
// Manual PHID entry - create agent with empty data that user can fill
|
|
126
|
-
dispatch(buildersActions.addBuilder({
|
|
127
|
-
builderPhid: newValue,
|
|
128
|
-
}));
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}, placeholder: "Enter PHID", className: "w-full", variant: "withValueAndTitle", initialOptions: getBuilderProfiles(), fetchOptionsCallback: async (userInput) => {
|
|
133
|
-
const builderProfiles = getBuilderProfiles();
|
|
134
|
-
// Filter profiles based on user input
|
|
135
|
-
if (!userInput.trim()) {
|
|
136
|
-
return builderProfiles;
|
|
137
|
-
}
|
|
138
|
-
const filteredProfiles = builderProfiles.filter((profile) => profile.label
|
|
139
|
-
.toLowerCase()
|
|
140
|
-
.includes(userInput.toLowerCase()) ||
|
|
141
|
-
profile.id.toLowerCase().includes(userInput.toLowerCase()));
|
|
142
|
-
return filteredProfiles;
|
|
143
|
-
} })),
|
|
144
|
-
renderCell: (value) => {
|
|
145
|
-
if (value === "" || !value) {
|
|
146
|
-
return (_jsx("div", { className: "font-light italic text-gray-500 text-center", children: "+ Double-click to add new builder (enter or click outside to save)" }));
|
|
147
|
-
}
|
|
148
|
-
return _jsx("div", { className: "text-center font-mono text-sm", children: value });
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
field: "name",
|
|
153
|
-
title: "Builder Name",
|
|
154
|
-
editable: false,
|
|
155
|
-
align: "center",
|
|
156
|
-
width: 200,
|
|
157
|
-
renderCell: (value) => {
|
|
158
|
-
return _jsx("div", { className: "text-center", children: value });
|
|
159
|
-
},
|
|
160
|
-
},
|
|
161
|
-
{
|
|
162
|
-
field: "slug",
|
|
163
|
-
title: "Builder Slug",
|
|
164
|
-
editable: false,
|
|
165
|
-
align: "center",
|
|
166
|
-
width: 200,
|
|
167
|
-
renderCell: (value) => {
|
|
168
|
-
return _jsx("div", { className: "text-center", children: value });
|
|
169
|
-
},
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
field: "icon",
|
|
173
|
-
title: "Icon",
|
|
174
|
-
editable: false,
|
|
175
|
-
align: "center",
|
|
176
|
-
width: 150,
|
|
177
|
-
renderCell: (value, context) => {
|
|
178
|
-
if (!context.row.icon) {
|
|
179
|
-
return null;
|
|
180
|
-
}
|
|
181
|
-
return (_jsx("div", { className: "text-center", children: _jsx("img", { src: context.row.icon, alt: "Agent icon", className: "w-10 h-10 rounded-sm mx-auto object-cover", onError: (e) => {
|
|
182
|
-
e.currentTarget.style.display = "none";
|
|
183
|
-
e.currentTarget.nextElementSibling?.classList.remove("hidden");
|
|
184
|
-
} }) }));
|
|
185
|
-
},
|
|
186
|
-
},
|
|
187
|
-
], [builders, builderProfileMap, getBuilderProfiles]);
|
|
188
|
-
return (_jsxs("div", { className: "w-full bg-gray-50", children: [_jsx(DocumentToolbar, { document: doc, onClose: handleClose }), _jsxs("div", { className: "p-2 max-w-4xl mx-auto min-h-screen", children: [_jsx("div", { className: "bg-white rounded-lg p-6 mb-6 shadow-sm text-center", children: _jsx("h1", { className: "text-3xl font-bold text-gray-900 mb-2", children: "Builders" }) }), _jsx("div", { className: "mt-4 bg-white", children: _jsx(ObjectSetTable, { columns: columns, data: builders || [], allowRowSelection: true, onDelete: (data) => {
|
|
189
|
-
if (data.length > 0) {
|
|
190
|
-
data.forEach((d) => {
|
|
191
|
-
dispatch(buildersActions.removeBuilder({ builderPhid: d.phid }));
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
}, onAdd: (data) => {
|
|
195
|
-
// Only add if we have a title (name) - PHID will be handled by the PHIDInput onChange
|
|
196
|
-
if (data.title) {
|
|
197
|
-
// Generate a temporary ID if no PHID is provided
|
|
198
|
-
const tempId = data.id || `temp-${Date.now()}`;
|
|
199
|
-
dispatch(buildersActions.addBuilder({
|
|
200
|
-
builderPhid: tempId,
|
|
201
|
-
}));
|
|
202
|
-
}
|
|
203
|
-
} }) })] })] }));
|
|
204
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../editors/builders/module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGnD,6DAA6D;AAC7D,eAAO,MAAM,QAAQ,EAAE,YAOtB,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { lazy } from "react";
|
|
2
|
-
/** Document editor module for the Todo List document type */
|
|
3
|
-
export const Builders = {
|
|
4
|
-
Component: lazy(() => import("./editor.js")),
|
|
5
|
-
documentTypes: ["powerhouse/builders"],
|
|
6
|
-
config: {
|
|
7
|
-
id: "builders-editor",
|
|
8
|
-
name: "builders",
|
|
9
|
-
},
|
|
10
|
-
};
|