1
0
Fork 0
mirror of https://gitlab.com/bramw/baserow.git synced 2025-04-18 11:18:40 +00:00

Fix dispatch context name everywhere it's needed

This commit is contained in:
Jérémie Pardou 2023-10-31 16:29:20 +00:00
parent b7340cb947
commit 0ffa48f901
10 changed files with 28 additions and 30 deletions
backend/src/baserow
contrib
builder/data_sources
integrations/local_baserow
core/services
web-frontend/modules

View file

@ -263,7 +263,7 @@ class DataSourceHandler:
Dispatch the service related to the data_sources. Dispatch the service related to the data_sources.
:param data_sources: The data sources to be dispatched. :param data_sources: The data sources to be dispatched.
:param runtime_formula_context: The context used to resolve formulas. :param dispatch_context: The context used for the dispatch.
:return: The result of dispatching the data source mapped by data source ID. :return: The result of dispatching the data source mapped by data source ID.
If an Exception occurred during the dispatch the exception is return as If an Exception occurred during the dispatch the exception is return as
result for this data source. result for this data source.
@ -291,7 +291,7 @@ class DataSourceHandler:
Dispatch the service related to the data_source. Dispatch the service related to the data_source.
:param data_source: The data source to be dispatched. :param data_source: The data source to be dispatched.
:param runtime_formula_context: The context used to resolve formulas. :param dispatch_context: The context used for the dispatch.
:raises DataSourceImproperlyConfigured: If the data source is :raises DataSourceImproperlyConfigured: If the data source is
not properly configured. not properly configured.
:return: The result of dispatching the data source. :return: The result of dispatching the data source.

View file

@ -231,7 +231,7 @@ class DataSourceService:
:param user: The current user. :param user: The current user.
:param data_sources: The data sources to be dispatched. :param data_sources: The data sources to be dispatched.
:param runtime_formula_context: The context used to resolve formulas. :param dispatch_context: The context used for the dispatch.
:return: The result of dispatching the data source mapped by data_source ID. :return: The result of dispatching the data source mapped by data_source ID.
""" """
@ -259,7 +259,7 @@ class DataSourceService:
:param user: The current user. :param user: The current user.
:param page: the page we want to dispatch the data_sources for. :param page: the page we want to dispatch the data_sources for.
:param runtime_formula_context: The context used to resolve formulas. :param dispatch_context: The context used for the dispatch.
:return: The result of dispatching all the data source dispatch mapped by ID. :return: The result of dispatching all the data source dispatch mapped by ID.
""" """
@ -285,7 +285,7 @@ class DataSourceService:
:param user: The current user. :param user: The current user.
:param data_sources: The data source to be dispatched. :param data_sources: The data source to be dispatched.
:param runtime_formula_context: The context used to resolve formulas. :param dispatch_context: The context used for the dispatch.
:return: return the dispatch result. :return: return the dispatch result.
""" """

View file

@ -541,7 +541,7 @@ class LocalBaserowListRowsUserServiceType(
Returns a list of rows from the table stored in the service instance. Returns a list of rows from the table stored in the service instance.
:param service: the local baserow get row service. :param service: the local baserow get row service.
:param runtime_formula_context: the context used for formula resolution. :param dispatch_context: The context used for the dispatch.
:raise ServiceImproperlyConfigured: if the table property is missing. :raise ServiceImproperlyConfigured: if the table property is missing.
:return: The list of rows. :return: The list of rows.
""" """
@ -681,7 +681,7 @@ class LocalBaserowGetRowUserServiceType(
service instance. service instance.
:param service: the local baserow get row service. :param service: the local baserow get row service.
:param runtime_formula_context: the context used for formula resolution. :param dispatch_context: The context used for the dispatch.
:raise ServiceImproperlyConfigured: if the table property is missing or if the :raise ServiceImproperlyConfigured: if the table property is missing or if the
formula can't be resolved. formula can't be resolved.
:raise DoesNotExist: if row id doesn't exist. :raise DoesNotExist: if row id doesn't exist.

View file

@ -203,7 +203,7 @@ class ServiceHandler:
Dispatch the given service. Dispatch the given service.
:param service: The service to be dispatched. :param service: The service to be dispatched.
:param runtime_formula_context: The context used to resolve formulas. :param dispatch_context: The context used for the dispatch.
:return: The result of dispatching the service. :return: The result of dispatching the service.
""" """

View file

@ -3,7 +3,6 @@ from typing import Any, Dict, Optional, Tuple, Type, TypeVar
from django.contrib.auth.models import AbstractUser from django.contrib.auth.models import AbstractUser
from baserow.core.formula.runtime_formula_context import RuntimeFormulaContext
from baserow.core.integrations.handler import IntegrationHandler from baserow.core.integrations.handler import IntegrationHandler
from baserow.core.integrations.models import Integration from baserow.core.integrations.models import Integration
from baserow.core.registry import ( from baserow.core.registry import (
@ -15,6 +14,7 @@ from baserow.core.registry import (
ModelRegistryMixin, ModelRegistryMixin,
Registry, Registry,
) )
from baserow.core.services.dispatch_context import DispatchContext
from .models import Service from .models import Service
from .types import ServiceDictSubClass, ServiceSubClass from .types import ServiceDictSubClass, ServiceSubClass
@ -123,33 +123,31 @@ class ServiceType(
def dispatch_data( def dispatch_data(
self, self,
service: ServiceSubClass, service: ServiceSubClass,
runtime_formula_context: RuntimeFormulaContext, dispatch_context: DispatchContext,
) -> Any: ) -> Any:
""" """
Responsible for executing the service's principle task. Responsible for executing the service's principle task.
:param service: The service instance to dispatch with. :param service: The service instance to dispatch with.
:param runtime_formula_context: The runtime_formula_context instance used to :param dispatch_context: The context used for the dispatch.
resolve formulas (if any).
:return: The service `dispatch_data` result if any. :return: The service `dispatch_data` result if any.
""" """
def dispatch( def dispatch(
self, self,
service: ServiceSubClass, service: ServiceSubClass,
runtime_formula_context: RuntimeFormulaContext, dispatch_context: DispatchContext,
) -> Any: ) -> Any:
""" """
Responsible for calling `dispatch_data` and `dispatch_transform` to execute Responsible for calling `dispatch_data` and `dispatch_transform` to execute
the service's task, and generating the dispatch's response, respectively. the service's task, and generating the dispatch's response, respectively.
:param service: The service instance to dispatch with. :param service: The service instance to dispatch with.
:param runtime_formula_context: The runtime_formula_context instance used to :param dispatch_context: The context used for the dispatch.
resolve formulas (if any).
:return: The service dispatch result if any. :return: The service dispatch result if any.
""" """
data = self.dispatch_data(service, runtime_formula_context) data = self.dispatch_data(service, dispatch_context)
return self.dispatch_transform(data) return self.dispatch_transform(data)
def get_property_for_serialization(self, service: Service, prop_name: str): def get_property_for_serialization(self, service: Service, prop_name: str):

View file

@ -142,7 +142,7 @@ export default {
clearElementContent: 'elementContent/clearElementContent', clearElementContent: 'elementContent/clearElementContent',
}), }),
async fetchContent(range, replace) { async fetchContent(range, replace) {
const dispatchContext = DataProviderType.getAllBackendContext( const dispatchContext = DataProviderType.getAllDispatchContext(
this.$registry.getAll('builderDataProvider'), this.$registry.getAll('builderDataProvider'),
this.applicationContext this.applicationContext
) )

View file

@ -30,7 +30,7 @@ export class DataSourceDataProviderType extends DataProviderType {
'dataSourceContent/fetchPageDataSourceContent', 'dataSourceContent/fetchPageDataSourceContent',
{ {
page: applicationContext.page, page: applicationContext.page,
data: DataProviderType.getAllBackendContext( data: DataProviderType.getAllDispatchContext(
this.app.$registry.getAll('builderDataProvider'), this.app.$registry.getAll('builderDataProvider'),
applicationContext applicationContext
), ),
@ -160,7 +160,7 @@ export class PageParameterDataProviderType extends DataProviderType {
return _.get(content, path.join('.')) return _.get(content, path.join('.'))
} }
getBackendContext(applicationContext) { getDispatchContext(applicationContext) {
return this.getDataContent(applicationContext) return this.getDataContent(applicationContext)
} }
@ -218,7 +218,7 @@ export class CurrentRecordDataProviderType extends DataProviderType {
'dataSource/getPageDataSourceById' 'dataSource/getPageDataSourceById'
](page, element.data_source_id) ](page, element.data_source_id)
const dispatchContext = DataProviderType.getAllBackendContext( const dispatchContext = DataProviderType.getAllDispatchContext(
this.app.$registry.getAll('builderDataProvider'), this.app.$registry.getAll('builderDataProvider'),
{ ...applicationContext, element } { ...applicationContext, element }
) )

View file

@ -94,8 +94,8 @@ export default {
dataSources() { dataSources() {
return this.$store.getters['dataSource/getPageDataSources'](this.page) return this.$store.getters['dataSource/getPageDataSources'](this.page)
}, },
backendContext() { dispatchContext() {
return DataProviderType.getAllBackendContext( return DataProviderType.getAllDispatchContext(
this.$registry.getAll('builderDataProvider'), this.$registry.getAll('builderDataProvider'),
this.applicationContext this.applicationContext
) )
@ -112,12 +112,12 @@ export default {
'dataSourceContent/debouncedFetchPageDataSourceContent', 'dataSourceContent/debouncedFetchPageDataSourceContent',
{ {
page: this.page, page: this.page,
data: this.backendContext, data: this.dispatchContext,
} }
) )
}, },
}, },
backendContext: { dispatchContext: {
deep: true, deep: true,
/** /**
* Update data source content on backend context changes * Update data source content on backend context changes

View file

@ -126,15 +126,15 @@ export default {
mode: this.mode, mode: this.mode,
} }
}, },
backendContext() { dispatchContext() {
return DataProviderType.getAllBackendContext( return DataProviderType.getAllDispatchContext(
this.$registry.getAll('builderDataProvider'), this.$registry.getAll('builderDataProvider'),
this.applicationContext this.applicationContext
) )
}, },
}, },
watch: { watch: {
backendContext: { dispatchContext: {
deep: true, deep: true,
/** /**
* Update data source content on backend context changes * Update data source content on backend context changes

View file

@ -51,12 +51,12 @@ export class DataProviderType extends Registerable {
) )
} }
static getAllBackendContext(dataProviders, applicationContext) { static getAllDispatchContext(dataProviders, applicationContext) {
return Object.fromEntries( return Object.fromEntries(
Object.values(dataProviders).map((dataProvider) => { Object.values(dataProviders).map((dataProvider) => {
return [ return [
dataProvider.type, dataProvider.type,
dataProvider.getBackendContext(applicationContext), dataProvider.getDispatchContext(applicationContext),
] ]
}) })
) )
@ -68,7 +68,7 @@ export class DataProviderType extends Registerable {
* @param {Object} applicationContext the application context. * @param {Object} applicationContext the application context.
* @returns An object if the dataProvider wants to send something to the backend. * @returns An object if the dataProvider wants to send something to the backend.
*/ */
getBackendContext(applicationContext) { getDispatchContext(applicationContext) {
return null return null
} }