Changes default representation of facets and defaultFacet in the emptyDraft Def.
Overwrites facets and defaultFacet (instead of merge) if they are set within the usecase itself
@@ -13,21 +13,43 @@ import Immutable from "immutable";
const emptyDraftImm = Immutable.fromJS({
content: {
- facets: [
- { "@id": "#chatFacet", "@type": "won:ChatFacet" },
- { "@id": "#holdableFacet", "@type": "won:HoldableFacet" },
- ],
- defaultFacet: { "@id": "#chatFacet", "@type": "won:ChatFacet" },
+ facets: {
+ "#chatFacet": "won:ChatFacet",
+ "#holdableFacet": "won:HoldableFacet",
+ },
+ defaultFacet: { "#chatFacet": "won:ChatFacet" },
},
seeks: {},
matchingContext: undefined,
});
+/**
+ * This is used so we can inject preset values for certain UseCases, be aware that it does not merge the content completely.
+ *
+ * Facets and defaultFacet will be overwritten if set in the useCase itself FIXME: Figure out a better way to handle or communicate
+ * this
+ * @param contentToMerge
+ * @returns {any|*}
+ */
export function mergeInEmptyDraft(contentToMerge) {
if (!contentToMerge) return emptyDraftImm.toJS();
const contentToMergeImm = Immutable.fromJS(contentToMerge);
+ const mergeFacets = contentToMergeImm.getIn(["content", "facets"]);
+ const mergeDefaultFacet = contentToMergeImm.getIn([
+ "content",
+ "defaultFacet",
+ ]);
+
+ let mergedDraftImm = emptyDraftImm;
+
+ if (mergeFacets && mergeFacets.size > 0) {
+ mergedDraftImm = mergedDraftImm.removeIn(["content", "facets"]);
+ }
+ if (mergeDefaultFacet && mergeDefaultFacet.size > 0) {
+ mergedDraftImm = mergedDraftImm.removeIn(["content", "defaultFacet"]);
+ }
- const mergedDraftImm = emptyDraftImm.mergeDeep(contentToMergeImm);
+ mergedDraftImm = mergedDraftImm.mergeDeep(contentToMergeImm);
return mergedDraftImm.toJS();
}
