feat: Upgrade plugin version to 2.0.0 and refactor configuration handling
- Updated version numbers in package.json, package-lock.json, and manifest.json to 2.0.0. - Refactored configuration types to use data sources (SELF, APP) instead of type-based configurations. - Enhanced settings UI to allow selection between using the current record or another app's record. - Improved error handling and validation for configuration settings. - Added new input component for better handling of text inputs in settings. - Updated localization files for new settings structure and error messages. - Optimized API calls with memoization for fetching form field properties and checking configurations.
This commit is contained in:
@@ -3,18 +3,17 @@ import i18n from 'i18next';
|
||||
import {
|
||||
type PluginConfig,
|
||||
type PluginConfigApp,
|
||||
PluginConfigDataSource,
|
||||
type PluginConfigSelf,
|
||||
PluginConfigType,
|
||||
type PluginConfigUrl,
|
||||
} from '../common/config';
|
||||
import { DOCX_CONTENT_TYPE } from '../common/constants';
|
||||
|
||||
const checkConfigSelf = (config: PluginConfigSelf, record: kintone.types.SavedFields): string => {
|
||||
const { template } = config;
|
||||
if (template === '') {
|
||||
const { fieldCode } = config;
|
||||
if (fieldCode === '') {
|
||||
throw new Error(i18n.t('errors.template-field-is-required'));
|
||||
}
|
||||
const field = record[template];
|
||||
const field = record[fieldCode];
|
||||
if (!field) {
|
||||
throw new Error(i18n.t('errors.template-field-is-not-available'));
|
||||
}
|
||||
@@ -35,21 +34,21 @@ const checkConfigSelf = (config: PluginConfigSelf, record: kintone.types.SavedFi
|
||||
};
|
||||
|
||||
const checkConfigApp = async (config: PluginConfigApp): Promise<string> => {
|
||||
const { appId, template, recordId } = config;
|
||||
const { appId, fieldCode, recordId } = config;
|
||||
if (appId === '') {
|
||||
throw new Error(i18n.t('errors.app-id-is-required'));
|
||||
}
|
||||
if (recordId === '') {
|
||||
throw new Error(i18n.t('errors.record-id-is-required'));
|
||||
}
|
||||
if (template === '') {
|
||||
if (fieldCode === '') {
|
||||
throw new Error(i18n.t('errors.template-field-is-required'));
|
||||
}
|
||||
const client = new KintoneRestAPIClient();
|
||||
const { record } = await client.record.getRecord({ app: appId, id: recordId }).catch((_error) => {
|
||||
throw new Error(i18n.t('errors.record-is-not-available'));
|
||||
});
|
||||
const field = record[template];
|
||||
const field = record[fieldCode];
|
||||
if (!field) {
|
||||
throw new Error(i18n.t('errors.template-field-is-not-available'));
|
||||
}
|
||||
@@ -69,24 +68,11 @@ const checkConfigApp = async (config: PluginConfigApp): Promise<string> => {
|
||||
return files[0].fileKey;
|
||||
};
|
||||
|
||||
const checkConfigUrl = (config: PluginConfigUrl): string => {
|
||||
const { template } = config;
|
||||
if (template === '') {
|
||||
throw new Error(i18n.t('errors.template-field-is-required'));
|
||||
}
|
||||
if (!template.startsWith('http://') && !template.startsWith('https://')) {
|
||||
throw new Error(i18n.t('errors.template-field-must-be-a-valid-url'));
|
||||
}
|
||||
return template;
|
||||
};
|
||||
|
||||
export const checkConfig = async (config: PluginConfig, record: kintone.types.SavedFields): Promise<string> => {
|
||||
if (config.type === PluginConfigType.SELF) {
|
||||
if (config.dataSource === PluginConfigDataSource.SELF) {
|
||||
return checkConfigSelf(config, record);
|
||||
} else if (config.type === PluginConfigType.APP) {
|
||||
} else if (config.dataSource === PluginConfigDataSource.APP) {
|
||||
return checkConfigApp(config);
|
||||
} else if (config.type === PluginConfigType.URL) {
|
||||
return checkConfigUrl(config);
|
||||
}
|
||||
throw new Error(i18n.t('errors.unexpected-error-occurred'));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user