-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Pages datasources #6601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Pages datasources #6601
Conversation
); | ||
|
||
dataListeners.push( | ||
this.createListener(em, 'data:path', ({ path: eventPath }: { path: string }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's use event enums DataSourcesEvents.path
export interface DataCollectionStateMap { | ||
export type RootDataType = Array<ObjectAny> | ObjectAny; | ||
|
||
export type DataCollectionStateMap = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason to change this interface to a type?
|
||
syncComponentsCollectionState() { | ||
super.syncComponentsCollectionState(); | ||
this.components().forEach((cmp) => cmp.syncComponentsCollectionState?.()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like this.components().forEach
is executed twice (super/Component + this one)
super(props, opt); | ||
|
||
const hasDataResolver = this.getDataResolver(); | ||
this.syncComponentsCollectionState(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need to add this inside the condition below?
import EditorModel from '../../editor/model/Editor'; | ||
import { CssRuleJSON } from '../../css_composer/model/CssRule'; | ||
import { ComponentDefinition } from '../../dom_components/model/types'; | ||
import { DataCollectionStateMap } from '../../data_sources/model/data_collection/types'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it unused?
expect(secondChild().get('name')).toBe('user2'); | ||
expect(secondChild().get('custom_property')).toBe('user2'); | ||
expect(secondGrandchild().get('name')).toBe('user2'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you had to make these changes, that means it started to recreate all inner components on data source change
test('sets dataResolver and updates wrapper.page/head collectionsStateMap', () => { | ||
wrapper.setDataResolver(createDataResolver('pagesDataSource.pages.data')); | ||
wrapper.resolverCurrentItem = 0; | ||
const stateMap = wrapper.collectionsStateMap; | ||
|
||
expect(stateMap).toHaveProperty(keyRootData); | ||
expect(wrapper.head.collectionsStateMap).toEqual(stateMap); | ||
expect(wrapper.head.collectionsStateMap).toEqual({ [keyRootData]: firstPageData }); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd avoid "testing" collectionsStateMap, it's more of an implementation detail (eg, if I change its name, I'd not expect to change our tests)
const firstPageData = { id: 'page1', title: 'Title1' }; | ||
const pagesData = [firstPageData, { id: 'page2', title: 'Title2' }, { id: 'page3', title: 'Title3' }]; | ||
const objectData = { | ||
page1: { title: 'page1' }, | ||
page2: { title: 'page2' }, | ||
}; | ||
|
||
beforeEach(() => { | ||
({ em, dsm } = setupTestEditor()); | ||
wrapper = em.getWrapper() as ComponentWrapper; | ||
|
||
pagesDataSource = dsm.add({ | ||
id: 'pagesDataSource', | ||
records: [ | ||
{ id: 'pages', data: pagesData }, | ||
{ | ||
id: 'objectData', | ||
data: objectData, | ||
}, | ||
], | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The data set here is a bit confusing. Can you differentiate it a bit (blogs, products, etc.)?
No description provided.