onClick(values)} {...other} />;
}
export function FormRadioGroupItem({ name, text, value }) {
const { setFieldValue, values } = useForm();
return (
setFieldValue(name, value)}
/>
);
}
export function FormReactSelect({ options, name, isMulti = false, Component = Select, ...other }) {
const { setFieldValue, values } = useForm();
const theme = useTheme();
return (
({
...t,
colors: {
...t.colors,
neutral0: theme.input_background,
neutral10: theme.input_background2,
neutral20: theme.input_background3,
neutral30: theme.input_background4,
neutral40: theme.input_font3,
neutral50: theme.input_font3,
neutral60: theme.input_font2,
neutral70: theme.input_font2,
neutral80: theme.input_font2,
neutral90: theme.input_font1,
primary: theme.input_background_blue[5],
primary75: theme.input_background_blue[3],
primary50: theme.input_background_blue[2],
primary25: theme.input_background_blue[0],
danger: theme.input_background_red[5],
dangerLight: theme.input_background_red[1],
},
})}
options={options}
value={
isMulti
? options.filter(x => values[name] && values[name].includes(x.value))
: options.find(x => x.value == values[name])
}
onChange={item => setFieldValue(name, isMulti ? getAsArray(item).map(x => x.value) : item ? item.value : null)}
menuPortalTarget={document.body}
isMulti={isMulti}
closeMenuOnSelect={!isMulti}
{...other}
/>
);
}
export function FormConnectionSelect({ name }) {
const connections = useConnectionList();
const connectionOptions = React.useMemo(
() =>
(connections || []).map(conn => ({
value: conn._id,
label: conn.displayName || conn.server,
})),
[connections]
);
if (connectionOptions.length == 0) return Not available
;
return ;
}
export function FormDatabaseSelect({ conidName, name }) {
const { values } = useForm();
const databases = useDatabaseList({ conid: values[conidName] });
const databaseOptions = React.useMemo(
() =>
(databases || []).map(db => ({
value: db.name,
label: db.name,
})),
[databases]
);
if (databaseOptions.length == 0) return Not available
;
return ;
}
export function FormSchemaSelect({ conidName, databaseName, name }) {
const { values } = useForm();
const dbinfo = useDatabaseInfo({ conid: values[conidName], database: values[databaseName] });
const schemaOptions = React.useMemo(
() =>
((dbinfo && dbinfo.schemas) || []).map(schema => ({
value: schema.schemaName,
label: schema.schemaName,
})),
[dbinfo]
);
if (schemaOptions.length == 0) return Not available
;
return ;
}
export function FormTablesSelect({ conidName, databaseName, schemaName, name }) {
const { values } = useForm();
const dbinfo = useDatabaseInfo({ conid: values[conidName], database: values[databaseName] });
const tablesOptions = React.useMemo(
() =>
[...((dbinfo && dbinfo.tables) || []), ...((dbinfo && dbinfo.views) || [])]
.filter(x => !values[schemaName] || x.schemaName == values[schemaName])
.map(x => ({
value: x.pureName,
label: x.pureName,
})),
[dbinfo, values[schemaName]]
);
if (tablesOptions.length == 0) return Not available
;
return ;
}
export function FormArchiveFilesSelect({ folderName, name }) {
// const { values } = useFormikContext();
const files = useArchiveFiles({ folder: folderName });
const filesOptions = React.useMemo(
() =>
(files || []).map(x => ({
value: x.name,
label: x.name,
})),
[files]
);
if (filesOptions.length == 0) return Not available
;
return ;
}
export function FormArchiveFolderSelect({ name, additionalFolders = [], ...other }) {
const { setFieldValue } = useForm();
const folders = useArchiveFolders();
const folderOptions = React.useMemo(
() => [
...(folders || []).map(folder => ({
value: folder.name,
label: folder.name,
})),
...additionalFolders
.filter(x => !(folders || []).find(y => y.name == x))
.map(folder => ({
value: folder,
label: folder,
})),
],
[folders]
);
const handleCreateOption = folder => {
axios.post('archive/create-folder', { folder });
setFieldValue(name, folder);
};
return (
);
}
export function FormElectronFileSelectorRaw({ name, ...other }) {
const { values, setFieldValue } = useForm();
const handleBrowse = () => {
const electron = getElectron();
if (!electron) return;
const filePaths = electron.remote.dialog.showOpenDialogSync(electron.remote.getCurrentWindow(), {
defaultPath: values[name],
properties: ['showHiddenFiles'],
});
const filePath = filePaths && filePaths[0];
if (filePath) setFieldValue(name, filePath);
};
return (
Browse
);
}
export function FormElectronFileSelector({ label, name, templateProps = undefined, ...other }) {
const FieldTemplate = useFormFieldTemplate();
return (
);
}