refactor: enhance configuration handling and error checking for template fields in the Word output plugin
This commit is contained in:
@@ -8,11 +8,6 @@ interface Props {
|
||||
|
||||
const ErrorFallback: React.FC<Props> = (props) => {
|
||||
const { error } = props;
|
||||
return (
|
||||
<KintonePluginAlert>
|
||||
<p>Something went wrong:</p>
|
||||
<pre>{error.message}</pre>
|
||||
</KintonePluginAlert>
|
||||
);
|
||||
return <KintonePluginAlert>{error.message}</KintonePluginAlert>;
|
||||
};
|
||||
export default ErrorFallback;
|
||||
|
||||
35
src/common/config.ts
Normal file
35
src/common/config.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
export const PluginConfigType = {
|
||||
SELF: 0,
|
||||
APP: 1,
|
||||
URL: 2,
|
||||
} as const;
|
||||
|
||||
export interface PluginConfigSelf {
|
||||
type: typeof PluginConfigType.SELF;
|
||||
template: string;
|
||||
}
|
||||
export interface PluginConfigApp {
|
||||
type: typeof PluginConfigType.APP;
|
||||
appId: string;
|
||||
template: string;
|
||||
recordId: string;
|
||||
}
|
||||
export interface PluginConfigUrl {
|
||||
type: typeof PluginConfigType.URL;
|
||||
template: string;
|
||||
}
|
||||
|
||||
export type PluginConfig = PluginConfigSelf | PluginConfigApp | PluginConfigUrl;
|
||||
|
||||
const DEFAULT_CONFIG: PluginConfig = {
|
||||
type: PluginConfigType.SELF,
|
||||
template: '',
|
||||
} as const;
|
||||
|
||||
export const saveConfig = (config: PluginConfig, callback?: () => void): void => {
|
||||
kintone.plugin.app.setConfig(config, callback);
|
||||
};
|
||||
|
||||
export const loadConfig = (pluginId: string): PluginConfig => {
|
||||
return { ...DEFAULT_CONFIG, ...(kintone.plugin.app.getConfig(pluginId) as PluginConfig) };
|
||||
};
|
||||
Reference in New Issue
Block a user