How to use the @dhis2/d2-ui-core/action/Action.create function in @dhis2/d2-ui-core

To help you get started, we’ve selected a few @dhis2/d2-ui-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dhis2 / d2-ui / packages / translation-dialog / src / translationForm.actions.js View on Github external
return Observable.of(model).flatMap((m) => {
        const modelDefinition = m.modelDefinition;

        if (!modelDefinition && !modelDefinition.name) {
            return Promise.reject(new Error(`Can not find modelDefinition for ${m.id}`));
        }

        return getInstance().then((d2) => {
            const api = d2.Api.getApi();

            return api.get(`${getModelHref(m)}/translations`);
        });
    });
}

export const saveTranslations = Action.create('saveTranslations');

saveTranslations.subscribe(({ data: [model, translations], complete, error }) => {
    const translationHref = `${getModelHref(model)}/translations`;

    getInstance().then((d2) => {
        const api = d2.Api.getApi();

        api
            .update(translationHref, { translations }, { dataType: 'text' })
            .then(() => complete(translations))
            .catch(error);
    });
});