Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions __test__/entry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ describe("Entry", () => {
expect(testData.entry).toEqual(entry.getData());
});

it("getDraftData", () => {
entry._changedData = { title: "Draft Title", content: "Draft Content" };
expect(entry.getDraftData()).toEqual({
title: "Draft Title",
content: "Draft Content",
});

entry._changedData = {};
expect(entry.getDraftData()).toEqual({});
});

describe("getField", () => {
it("getField undefined", function () {
const uid = "group1.group";
Expand Down Expand Up @@ -133,7 +144,7 @@ describe("Entry", () => {
});
it("should use custom Field instance if internal flag is set", () => {
const fieldInstance: any = jest.fn();
entry = new Entry(testData as any, connection as any, emitter ,{
entry = new Entry(testData as any, connection as any, emitter, {
_internalFlags: {
FieldInstance: fieldInstance,
},
Expand Down Expand Up @@ -182,4 +193,4 @@ describe("Entry", () => {
"Callback must be a function"
);
});
});
});
13 changes: 13 additions & 0 deletions src/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ class Entry {
return this._data;
}

/**
* Gets the draft data of the current entry.
* If no changes are available, returns an empty object.
* @return {Object} Returns the draft entry data (_changedData) if available; otherwise, returns an empty object.
*/
getDraftData() {
if (this._changedData && Object.keys(this._changedData).length > 0) {
return this._changedData;
} else {
return {};
}
}

/**
*
*
Expand Down
Loading