Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function* loadSimpleConfig({ payload: { name } }) {
try {
yield put(resetLoading());
yield put(showLoading());
const config = yield call(api, 'simple_config', { $name: name });
yield put({
type: SIMPLE_CONFIG_LOADED,
payload: {
name,
config,
},
});
} catch (error) {
yield put(setMessage(error.toString()));
} finally {
yield put(hideLoading());
if (yield cancelled()) {
// do a thing
}
function* postSimpleConfig({ payload: { name, config } }) {
try {
yield put(resetLoading());
yield put(showLoading());
const csrfToken = yield api('csrf_token');
// @todo It feels like this should be moved into the api wrapper.
yield api(
'simple_config',
{ $name: name },
{
body: JSON.stringify(config),
headers: {
'content-type': 'application/json',
'X-CSRF-Token': csrfToken,
},
method: 'PATCH',
},
);
function* addContent({ payload: { content } }) {
try {
yield put(resetLoading());
yield put(showLoading());
yield all([
call(api, 'node:add', { parameters: { node: content } }),
put(requestContentTypes()),
]);
// Get the content types from the redux state
const contentTypes = yield select(contentTypesSelector);
// Extract the content type from the content data
const contentType = extractContentType(content);
// Map the content type to the human-readable name
const contentName =
mapContentTypeToName(contentTypes, contentType) || 'unknown';
yield put(push('/admin/content'));
function* loadSchema(action) {
const { entityTypeId, bundle } = action.payload;
try {
yield put(resetLoading());
yield put(showLoading());
const entitySchema = yield call(api, 'schema', {
parameters: { entityTypeId, bundle },
queryString: { _describes: 'api_json', _format: 'schema_json' },
});
yield put({
type: SCHEMA_LOADED,
payload: {
entityTypeId,
bundle,
entitySchema,
},
});
} catch (error) {
function* loadTaxonomyVocabulary(action) {
try {
yield put(resetLoading());
yield put(showLoading());
const { data: taxonomyVocabulary } = yield call(
api,
'taxonomy_vocabulary',
{
...((action.payload.vocabulary && {
queryString: {
filter: {
condition: { path: 'vid', value: action.payload.vocabulary },
},
},
}) ||
{}),
},
);
function* loadTaxonomyTerms(action) {
try {
const {
payload: { vocabulary },
} = action;
yield put(resetLoading());
yield put(showLoading());
const { data: taxonomyTerms } = yield call(api, 'taxonomy_term', {
parameters: { type: vocabulary },
});
const {
taxonomy: { taxonomyVocabulary },
} = yield select();
if (
!(
taxonomyVocabulary.length &&
getTaxonomyVocabularyById(taxonomyVocabulary, vocabulary)
)
) {
yield put({
function* loadSingleContent(action) {
const {
payload: { nid },
} = action;
try {
yield put(resetLoading());
yield put(showLoading());
const {
data: [content],
} = yield call(api, 'content', {
queryString: {
filter: { condition: { path: 'nid', value: nid } },
},
});
yield put({
type: CONTENT_SINGLE_LOADED,
payload: {
content,
},
});
function* deleteContent({ payload: { content } }) {
try {
yield put(resetLoading());
yield put(showLoading());
yield call(api, 'node:delete', { parameters: { node: content } });
} catch (error) {
const errorMessage = yield ApiError.errorToHumanString(error);
yield put(setErrorMessage(errorMessage));
} finally {
yield put(hideLoading());
}
}
function* loadUser(action) {
const {
payload: { uid },
} = action;
try {
yield put(resetLoading());
yield put(showLoading());
const {
data: [user],
} = yield call(api, 'user', {
queryString: {
filter: { condition: { path: 'uid', value: uid } },
},
});
yield put({
type: USER_LOADED,
payload: {
user,
},
});
function* loadSchemaByEntityId(action) {
const { entityTypeId, entityId } = action.payload;
try {
yield put(resetLoading());
yield put(showLoading());
const entitySchema = yield call(api, 'schema_by_id', {
parameters: { entityTypeId, entityId },
});
yield put({
type: SCHEMA_BY_ENTITY_ID_LOADED,
payload: {
entityTypeId,
entityId,
entitySchema,
},
});
} catch (error) {
yield put(setErrorMessage(error.toString()));