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:
@@ -1,29 +1,25 @@
|
||||
export const PluginConfigType = {
|
||||
SELF: 0,
|
||||
APP: 1,
|
||||
URL: 2,
|
||||
export const PluginConfigDataSource = {
|
||||
SELF: 'self',
|
||||
APP: 'app',
|
||||
} as const;
|
||||
export type PluginConfigDataSource = (typeof PluginConfigDataSource)[keyof typeof PluginConfigDataSource];
|
||||
|
||||
export interface PluginConfigSelf {
|
||||
type: typeof PluginConfigType.SELF;
|
||||
template: string;
|
||||
dataSource: typeof PluginConfigDataSource.SELF;
|
||||
fieldCode: string;
|
||||
}
|
||||
export interface PluginConfigApp {
|
||||
type: typeof PluginConfigType.APP;
|
||||
dataSource: typeof PluginConfigDataSource.APP;
|
||||
appId: string;
|
||||
template: string;
|
||||
recordId: string;
|
||||
}
|
||||
export interface PluginConfigUrl {
|
||||
type: typeof PluginConfigType.URL;
|
||||
template: string;
|
||||
fieldCode: string;
|
||||
}
|
||||
|
||||
export type PluginConfig = PluginConfigSelf | PluginConfigApp | PluginConfigUrl;
|
||||
export type PluginConfig = PluginConfigSelf | PluginConfigApp;
|
||||
|
||||
const DEFAULT_CONFIG: PluginConfig = {
|
||||
type: PluginConfigType.SELF,
|
||||
template: '',
|
||||
dataSource: PluginConfigDataSource.SELF,
|
||||
fieldCode: '',
|
||||
} as const;
|
||||
|
||||
export const saveConfig = (config: PluginConfig, callback?: () => void): void => {
|
||||
@@ -31,5 +27,15 @@ export const saveConfig = (config: PluginConfig, callback?: () => void): void =>
|
||||
};
|
||||
|
||||
export const loadConfig = (pluginId: string): PluginConfig => {
|
||||
return { ...DEFAULT_CONFIG, ...(kintone.plugin.app.getConfig(pluginId) as PluginConfig) };
|
||||
const config = kintone.plugin.app.getConfig(pluginId);
|
||||
if (!config || Object.keys(config).length === 0) {
|
||||
// initial state
|
||||
return { ...DEFAULT_CONFIG };
|
||||
}
|
||||
if (config.dataSource != null) {
|
||||
// current version of config format
|
||||
return config as PluginConfig;
|
||||
}
|
||||
// old version of config format
|
||||
return { dataSource: PluginConfigDataSource.SELF, fieldCode: config.template || '' };
|
||||
};
|
||||
|
||||
46
src/common/ui/KintonePluginInputText.tsx
Normal file
46
src/common/ui/KintonePluginInputText.tsx
Normal file
@@ -0,0 +1,46 @@
|
||||
import clsx from 'clsx';
|
||||
// biome-ignore lint/style/useImportType: React is required in scope for the old JSX transform.
|
||||
import React from 'react';
|
||||
|
||||
export type KintonePluginInputTextProps = {
|
||||
id?: string;
|
||||
className?: string;
|
||||
value: string;
|
||||
size?: number;
|
||||
maxLength?: number;
|
||||
disabled?: boolean;
|
||||
required?: boolean;
|
||||
placeholder?: string;
|
||||
onChange: (value: string) => void;
|
||||
};
|
||||
|
||||
const KintonePluginInputText: React.FC<KintonePluginInputTextProps> = (props) => {
|
||||
const { id, className, value, size, maxLength, disabled, required, placeholder, onChange } = props;
|
||||
const handleOnChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {
|
||||
onChange(e.target.value);
|
||||
};
|
||||
return (
|
||||
<div className={clsx('kintoneplugin-input-outer', className)}>
|
||||
<input
|
||||
id={id}
|
||||
className="kintoneplugin-input-text"
|
||||
type="text"
|
||||
value={value}
|
||||
size={size}
|
||||
maxLength={maxLength}
|
||||
disabled={disabled}
|
||||
required={required}
|
||||
placeholder={placeholder}
|
||||
aria-required={required}
|
||||
aria-disabled={disabled}
|
||||
aria-invalid={required && value === ''}
|
||||
autoComplete="off"
|
||||
autoCorrect="off"
|
||||
autoCapitalize="off"
|
||||
spellCheck={false}
|
||||
onChange={handleOnChange}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
export default KintonePluginInputText;
|
||||
Reference in New Issue
Block a user