fix: edit user password optional

main
jialin 2 years ago
parent b8b0d39635
commit b48be3b883

@ -7,12 +7,18 @@ import Styles from './index.less';
const DeleteModal = forwardRef((props, ref) => {
const intl = useIntl();
const [visible, setVisible] = useState(false);
const [config, setConfig] = useState<ModalFuncProps & { content: string }>(
{}
);
const [config, setConfig] = useState<
ModalFuncProps & { content: string; selection?: boolean; name?: string }
>({});
useImperativeHandle(ref, () => ({
show: (data: ModalFuncProps & { content: string }) => {
show: (
data: ModalFuncProps & {
content: string;
selection?: boolean;
name?: string;
}
) => {
setConfig(data);
setVisible(true);
},
@ -68,8 +74,15 @@ const DeleteModal = forwardRef((props, ref) => {
<div className={Styles['content']}>
{config.content &&
intl.formatMessage(
{ id: 'common.delete.confirm' },
{ type: intl.formatMessage({ id: config.content }) }
{
id: config.selection
? 'common.delete.confirm'
: 'common.delete.single.confirm'
},
{
type: intl.formatMessage({ id: config.content }),
name: config.name
}
)}
</div>
</Modal>

@ -18,6 +18,14 @@ export function useUpdateChunkedList(options: {
computedID?: (d: object) => string;
}) {
const cacheDataListRef = useRef<any[]>(options.dataList || []);
const timerRef = useRef<any>(null);
const debounceUpdateChunckedList = () => {
clearTimeout(timerRef.current);
timerRef.current = setTimeout(() => {
options.setDataList?.([...cacheDataListRef.current]);
}, 100);
};
const updateChunkedList = (
data: ChunkedCollection,
dataList?: { id: string | number }[]
@ -25,7 +33,7 @@ export function useUpdateChunkedList(options: {
console.log('updateChunkedList=====', {
ids: data?.ids,
type: data?.type,
collection: data?.collection,
collection: data?.collection.length,
dataList: _.map(dataList, (o: any) => o.id)
});
let collections = data?.collection || [];
@ -57,7 +65,7 @@ export function useUpdateChunkedList(options: {
console.log('create=========', updateIndex, collections);
});
cacheDataListRef.current = [...newDataList, ...cacheDataListRef.current];
options.setDataList?.([...cacheDataListRef.current]);
// options.setDataList?.([...cacheDataListRef.current]);
}
// DELETE
if (data?.type === WatchEventType.DELETE) {
@ -69,7 +77,8 @@ export function useUpdateChunkedList(options: {
);
// console.log('updateChunkedList=====delete', updatedList);
// return updatedList;
options.setDataList?.([...cacheDataListRef.current]);
// options.setDataList?.([...cacheDataListRef.current]);
}
// UPDATE
if (data?.type === WatchEventType.UPDATE) {
@ -88,8 +97,10 @@ export function useUpdateChunkedList(options: {
}
});
console.log('updateChunkedList=====update', cacheDataListRef.current);
options.setDataList?.([...cacheDataListRef.current]);
// options.setDataList?.([...cacheDataListRef.current]);
}
debounceUpdateChunckedList();
if (options?.callback) {
options?.callback(cacheDataListRef.current);
}

@ -183,6 +183,7 @@ export default {
'common.settings.language': 'Language',
'common.delete.confirm':
'Are you sure you want to delete the selected {type}?',
'common.delete.single.confirm': 'Are you sure you want to delete {name}?',
'common.filter.name': 'Filter by name',
'common.form.password': 'Password',
'common.form.username': 'Username',

@ -175,7 +175,8 @@ export default {
'common.table.user': '用户',
'common.settings.instructions': '操作指引',
'common.settings.language': '语言',
'common.delete.confirm': '删除选中的{type}吗?',
'common.delete.confirm': '删除选中的{type},确定吗?',
'common.delete.single.confirm': '删除 {name},确定吗?',
'common.filter.name': '名称查询',
'common.form.password': '密码',
'common.form.username': '用户名',

@ -28,6 +28,6 @@ export default {
'playground.params.stop.tips':
'停止序列是一个预定义或用户指定的文本字符串,当这些序列出现时,它会提示 AI 停止生成后续的 token。',
'playground.viewcode.tips':
'{here} 查看 API 密钥。您应该使用环境变量或密管理工具将您的密钥暴露给您的应用程序。',
'{here} 查看 API 密钥。您应该使用环境变量或管理工具将您的密钥暴露给您的应用程序。',
'playground.viewcode.here': '这里'
};

@ -25,7 +25,7 @@ const APIKeys: React.FC = () => {
});
const intl = useIntl();
const modalRef = useRef<any>(null);
const [dataSource, setDataSource] = useState([]);
const [dataSource, setDataSource] = useState<ListItem[]>([]);
const [total, setTotal] = useState(0);
const [openAddModal, setOpenAddModal] = useState(false);
const [loading, setLoading] = useState(false);
@ -100,6 +100,7 @@ const APIKeys: React.FC = () => {
const handleDelete = (row: ListItem) => {
modalRef.current.show({
content: 'apikeys.table.apikeys',
name: row.name,
async onOk() {
console.log('OK');
await deleteApisKey(row.id);
@ -111,6 +112,7 @@ const APIKeys: React.FC = () => {
const handleDeleteBatch = () => {
modalRef.current.show({
content: 'apikeys.table.apikeys',
selection: true,
async onOk() {
await handleBatchRequest(rowSelection.selectedRowKeys, deleteApisKey);
rowSelection.clearSelections();

@ -149,6 +149,7 @@ const Models: React.FC<ModelsProps> = ({
const handleDelete = async (row: any) => {
modalRef.current.show({
content: 'models.table.models',
name: row.name,
async onOk() {
await deleteModel(row.id);
updateExpandedRowKeys([row.id]);
@ -158,6 +159,7 @@ const Models: React.FC<ModelsProps> = ({
const handleDeleteBatch = () => {
modalRef.current.show({
content: 'models.table.models',
selection: true,
async onOk() {
await handleBatchRequest(rowSelection.selectedRowKeys, deleteModel);
rowSelection.clearSelections();
@ -181,6 +183,7 @@ const Models: React.FC<ModelsProps> = ({
const handleDeleteInstace = (row: any, list: ModelInstanceListItem[]) => {
modalRef.current.show({
content: 'models.instances',
name: row.name,
async onOk() {
await deleteModelInstance(row.id);
if (list.length === 1) {

@ -74,7 +74,7 @@ const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
const systemList = systemMessage
? [{ role: 'system', content: systemMessage }]
: [];
const code = `const OpenAI = require("openai");\n\nconst openai = new OpenAI({\n "apiKey": "YOUR_GPUSTACK_API_KEY",\n "baseURL": "${BaseURL}"\n});\n\n\nasync function main(){\nconst params = ${JSON.stringify(
const code = `const OpenAI = require("openai");\n\nconst openai = new OpenAI({\n "apiKey": "YOUR_GPUSTACK_API_KEY",\n "baseURL": "${BaseURL}"\n});\n\n\nasync function main(){\n const params = ${JSON.stringify(
{
...parameters,
messages: [
@ -85,8 +85,8 @@ const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
]
},
null,
2
)};\nconst chatCompletion = await openai.chat.completions.create(params);\n console.log(chatCompletion.choices[0]);\n}\nmain();`;
4
)};\nconst chatCompletion = await openai.chat.completions.create(params);\n console.log(chatCompletion.choices[0].message.content);\n}\nmain();`;
setCodeValue(code);
} else if (lang === 'python') {
const formattedParams = _.keys(parameters).reduce(
@ -137,6 +137,9 @@ const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
minimap: {
enabled: false
},
hover: {
enabled: false
},
readOnly: true,
formatOnType: true,
formatOnPaste: true,

@ -54,13 +54,6 @@ const Resources: React.FC = () => {
setLoading(false);
}
};
const handleShowSizeChange = (current: number, size: number) => {
setQueryParams({
...queryParams,
page: current,
perPage: size || 10
});
};
const handlePageChange = (page: number, perPage: number | undefined) => {
console.log(page, perPage);
@ -104,6 +97,7 @@ const Resources: React.FC = () => {
const handleDelete = (row: ListItem) => {
modalRef.current.show({
content: 'worker',
name: row.name,
async onOk() {
console.log('OK');
await deleteWorker(row.id);
@ -115,6 +109,7 @@ const Resources: React.FC = () => {
const handleDeleteBatch = () => {
modalRef.current.show({
content: 'wokers',
selection: true,
async onOk() {
await handleBatchRequest(rowSelection.selectedRowKeys, deleteWorker);
rowSelection.clearSelections();

@ -116,7 +116,7 @@ const AddModal: React.FC<AddModalProps> = ({
name="password"
rules={[
{
required: true,
required: action === PageAction.CREATE,
pattern: PasswordReg,
message: intl.formatMessage({ id: 'users.form.rule.password' })
}
@ -124,7 +124,7 @@ const AddModal: React.FC<AddModalProps> = ({
>
<SealInput.Password
label={intl.formatMessage({ id: 'common.form.password' })}
required
required={action === PageAction.CREATE}
></SealInput.Password>
</Form.Item>
</Form>

@ -144,6 +144,7 @@ const Users: React.FC = () => {
const handleDelete = (row: ListItem) => {
modalRef.current.show({
content: 'users.table.user',
name: row.name,
async onOk() {
console.log('OK');
await deleteUser(row.id);
@ -155,6 +156,7 @@ const Users: React.FC = () => {
const handleDeleteBatch = () => {
modalRef.current.show({
content: 'users.table.user',
selection: true,
async onOk() {
await handleBatchRequest(rowSelection.selectedRowKeys, deleteUser);
rowSelection.clearSelections();

Loading…
Cancel
Save