remove kintone-pretty-fields library dependency.
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import React from 'react';
|
||||
|
||||
import { KintoneRestAPIClient } from '@kintone/rest-api-client';
|
||||
import { kintonePrettyFields } from 'kintone-pretty-fields';
|
||||
import { Properties as KintoneFormFieldProperties } from '@kintone/rest-api-client/lib/src/client/types';
|
||||
import moize from 'moize';
|
||||
import invariant from 'tiny-invariant';
|
||||
import { PLUGIN_ID } from '../common/global';
|
||||
@ -16,28 +16,30 @@ import KintonePluginTitle from '../common/ui/KintonePluginTitle';
|
||||
|
||||
import styles from './Settings.module.css';
|
||||
|
||||
const cachedFields = moize.promise(async (appId: number) => {
|
||||
const cachedFormFieldsProperties = moize.promise(async (appId: number): Promise<KintoneFormFieldProperties> => {
|
||||
const client = new KintoneRestAPIClient();
|
||||
const fields = await kintonePrettyFields.getFields({ client, app: appId, lang: 'en', preview: false });
|
||||
return fields;
|
||||
const { properties } = await client.app.getFormFields({ app: appId, lang: 'en', preview: false });
|
||||
return properties;
|
||||
});
|
||||
|
||||
const Settings: React.FC = () => {
|
||||
const config = kintone.plugin.app.getConfig(PLUGIN_ID);
|
||||
const appId = kintone.app.getId();
|
||||
invariant(appId, 'The app ID is not available. Please ensure you are on a Kintone app page.');
|
||||
const { fields } = React.use(cachedFields(appId));
|
||||
const fileFields = fields.filter(kintonePrettyFields.isFile);
|
||||
const properties = React.use(cachedFormFieldsProperties(appId));
|
||||
const fileFields = Object.values(properties).filter((property) => property.type === 'FILE');
|
||||
const options: KintonePluginSelectOptionData[] = [
|
||||
{ key: '-', value: '', label: 'Select a File field', disabled: true }, // Default option
|
||||
...fileFields.map((field) => ({
|
||||
key: field.code,
|
||||
value: field.code,
|
||||
label: field.label,
|
||||
...fileFields.map((property) => ({
|
||||
key: property.code,
|
||||
value: property.code,
|
||||
label: property.label,
|
||||
})),
|
||||
];
|
||||
|
||||
const [template, setTemplate] = React.useState<string>(config.template ?? '');
|
||||
const [template, setTemplate] = React.useState<string>(
|
||||
() => options.find((option) => option.value === (config.template ?? ''))?.value ?? '',
|
||||
);
|
||||
|
||||
const handleOnSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
|
Reference in New Issue
Block a user