Unverified Commit b7bb85af authored by zhu-mingye's avatar zhu-mingye Committed by GitHub

[Feature][admin] support suggestion for editor (#2489)

* feature-support-suggestion * Spotless Apply * fix bug && 优化编辑器建议提示代码 * Spotless Apply * FORMAT * modify some code * Spotless Apply * fix code * Spotless Apply * modify some code * Spotless Apply * fix * fix bug * Spotless Apply * fix bug * Spotless Apply * fix bug * fix bug * Spotless Apply --------- Co-authored-by: 's avatarzhu-mingye <zhu-mingye@users.noreply.github.com> Co-authored-by: 's avatarZackYoung <zackyoungh@163.com>
parent f217df23
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.dinky.controller;
import org.dinky.data.dto.SuggestionDTO;
import org.dinky.data.result.Result;
import org.dinky.data.vo.suggestion.SuggestionVO;
import org.dinky.service.SuggestionService;
import java.util.Set;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@Api(tags = "Suggestion Controller")
@RequestMapping("/api/suggestion")
@RequiredArgsConstructor
public class SuggestionController {
private final SuggestionService suggestionService;
@PostMapping("/queryAllSuggestions")
@ApiOperation(value = "QueryAllSuggestions", notes = "queryAllSuggestions")
@ApiImplicitParam(name = "suggestionDTO", value = "suggestionDTO", required = true, dataType = "SuggestionDTO")
public Result<Set<SuggestionVO>> queryAllSuggestions(@RequestBody SuggestionDTO suggestionDTO) {
return Result.succeed(suggestionService.getSuggestions(suggestionDTO.isEnableSchemaSuggestion()));
}
@PostMapping("/queryAllSuggestionsByKeyWord")
@ApiOperation(value = "QueryAllSuggestionsByKeyWord", notes = "queryAllSuggestionsByKeyWord")
@ApiImplicitParam(name = "suggestionDTO", value = "suggestionDTO", required = true, dataType = "SuggestionDTO")
public Result<Set<SuggestionVO>> queryAllSuggestionsByKeyWord(@RequestBody SuggestionDTO suggestionDTO) {
return Result.succeed(suggestionService.getSuggestionsByKeyWord(
suggestionDTO.isEnableSchemaSuggestion(), suggestionDTO.getKeyWord()));
}
@PostMapping("/queryAllSuggestionsBySqlStatement")
@ApiOperation(value = "QueryAllSuggestionsBySqlStatement", notes = "queryAllSuggestionsBySqlStatement")
@ApiImplicitParam(name = "suggestionDTO", value = "suggestionDTO", required = true, dataType = "SuggestionDTO")
public Result<Set<SuggestionVO>> queryAllSuggestionsBySqlStatement(@RequestBody SuggestionDTO suggestionDTO) {
return Result.succeed(suggestionService.getSuggestionsBySqlStatement(
suggestionDTO.isEnableSchemaSuggestion(),
suggestionDTO.getSqlStatement(),
suggestionDTO.getPosition()));
}
}
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.dinky.data.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class SuggestionDTO {
private boolean enableSchemaSuggestion;
private String keyWord;
private String sqlStatement;
private int position;
}
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.dinky.data.vo.suggestion;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class SuggestionLabelVO implements Serializable {
private static final long serialVersionUID = 4631906403475634212L;
// label
private String label;
// value
private String detail;
// description
private String description;
}
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.dinky.data.vo.suggestion;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class SuggestionVO implements Serializable {
private static final long serialVersionUID = 4631906403475634212L;
private Object key;
// label
private SuggestionLabelVO label;
// kind
/**
* 此字段值可选为:
* <p>
* Method = 0, // 方法
* Function = 1, // 函数
* Constructor = 2, // 构造函数
* Field = 3, // 字段
* Variable = 4, // 变量
* Class = 5, // 类
* Struct = 6, // 结构体
* Interface = 7, // 接口
* Module = 8, // 模块
* Property = 9, // 属性
* Event = 10, // 事件
* Operator = 11, // 操作符
* Unit = 12, // 单元
* Value = 13, // 值
* Constant = 14, // 常量
* Enum = 15, // 枚举
* EnumMember = 16, // 枚举成员
* Keyword = 17, // 关键字
* Text = 18, // 文本
* Color = 19, // 颜色
* File = 20, // 文件
* Reference = 21, // 引用
* Customcolor = 22, // 自定义颜色
* Folder = 23, // 文件夹
* TypeParameter = 24, // 类型参数
* User = 25, // 用户
* Issue = 26, // 问题
* Snippet = 27 // 代码片段
*/
private int kind;
// insertText
private String insertText;
// detail
private String detail;
}
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.dinky.service;
import org.dinky.data.vo.suggestion.SuggestionVO;
import java.util.Set;
public interface SuggestionService {
/**
* get suggestions for editor
* @param enableSchemaSuggestion whether enable schema suggestion
* @return suggestions list
*/
Set<SuggestionVO> getSuggestions(boolean enableSchemaSuggestion);
/**
* by keyword get suggestions list
* @param enableSchemaSuggestion whether enable schema suggestion
* @param keyWord keyword
* @return suggestions list
*/
Set<SuggestionVO> getSuggestionsByKeyWord(boolean enableSchemaSuggestion, String keyWord);
/**
* by sql statement get suggestions list
* @param enableSchemaSuggestion whether enable schema suggestion
* @param sqlStatement sql statement
* @return suggestions list
*/
Set<SuggestionVO> getSuggestionsBySqlStatement(boolean enableSchemaSuggestion, String sqlStatement, int position);
}
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.dinky.service.impl;
import org.dinky.data.model.Document;
import org.dinky.data.model.FragmentVariable;
import org.dinky.data.vo.suggestion.SuggestionLabelVO;
import org.dinky.data.vo.suggestion.SuggestionVO;
import org.dinky.service.DocumentService;
import org.dinky.service.FragmentVariableService;
import org.dinky.service.SuggestionService;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@Service
@RequiredArgsConstructor
@Slf4j
public class SuggestionServiceImpl implements SuggestionService {
private final DocumentService documentService;
private final FragmentVariableService fragmentVariableService;
/**
* get suggestions for editor
*
* @param enableSchemaSuggestion whether enable schema suggestion
* @return suggestions list
*/
@Override
public Set<SuggestionVO> getSuggestions(boolean enableSchemaSuggestion) {
Set<SuggestionVO> suggestionVOS = new HashSet<>();
// 1. 构建文档的建议列表
buildDocumentSuggestions(new HashSet<>(documentService.list()), suggestionVOS);
// 2. 全局变量的建议列表
buildGlobalVariableSuggestions(new HashSet<>(fragmentVariableService.listEnabledAll()), suggestionVOS);
// todo: 如果启用了schema,需要构建schema的建议列表
// 3. schema的建议列表
if (enableSchemaSuggestion) {
buildSchemaSuggestions(new HashSet<>(), suggestionVOS);
}
// 4. 自定义关键词提示
buildCustomSuggestions(new HashSet<>(), suggestionVOS);
return suggestionVOS;
}
/**
* build global variable suggestions
*
* @param fragmentVariableList fragment variable list
* @param suggestionVOS suggestion list
*/
private static void buildGlobalVariableSuggestions(
Set<FragmentVariable> fragmentVariableList, Set<SuggestionVO> suggestionVOS) {
fragmentVariableList.stream()
.map(fragmentVariable -> {
SuggestionLabelVO suggestionLabelVO = SuggestionLabelVO.builder()
.label(fragmentVariable.getName())
.detail(fragmentVariable.getNote())
.description(fragmentVariable.getNote())
.build();
return SuggestionVO.builder()
.key(fragmentVariable.getId() + "_fragmentVariable")
.label(suggestionLabelVO)
.kind(4)
.insertText(fragmentVariable.getFragmentValue())
.detail(fragmentVariable.getNote())
.build();
})
.forEach(suggestionVOS::add);
}
/**
* build schema suggestions
*
* @param buildingSchemaList schema list
* @param suggestionVOS suggestion list
*/
private static void buildSchemaSuggestions(Set<Object> buildingSchemaList, Set<SuggestionVO> suggestionVOS) {
// todo: 构建schema的建议列表 , 包含 库名 、表名、字段名、.... , 能做到根据库名点出表名,根据表名点出字段名
}
/**
* build custom suggestions
*
* @param customKeyWordList custom keyword list
* @param suggestionVOS suggestion list
*/
private static void buildCustomSuggestions(Set<Object> customKeyWordList, Set<SuggestionVO> suggestionVOS) {
// todo: 自定义关键词提示,
// 1. 此处自定义是属于 dinky 内部自定义语法关键词提示, 如果有片段, 将片段的建议列表加入到文档中进行提示
// 2. 可以加入 yml 语法的关键词提示 , 因为在集群配置中会有 yml 的配置文件写法 , 获取方式待定
}
/**
* build document suggestions
*
* @param documentList document list
* @param suggestionVOS suggestion list
*/
private static void buildDocumentSuggestions(Set<Document> documentList, Set<SuggestionVO> suggestionVOS) {
documentList.stream()
.map(document -> {
String detail =
document.getCategory() + " ->" + document.getType() + " -> " + document.getSubtype();
SuggestionLabelVO suggestionLabelVO = SuggestionLabelVO.builder()
.label(document.getName())
.detail(detail)
.description(document.getDescription())
.build();
return SuggestionVO.builder()
.key(document.getId() + "_document")
.label(suggestionLabelVO)
.insertText(document.getFillValue())
.kind(4)
.detail(detail)
.build();
})
.forEach(suggestionVOS::add);
}
/**
* by keyword get suggestions list
*
* @param enableSchemaSuggestion whether enable schema suggestion
* @param keyWord keyword
* @return suggestions list
*/
@Override
public Set<SuggestionVO> getSuggestionsByKeyWord(boolean enableSchemaSuggestion, String keyWord) {
return getSuggestions(enableSchemaSuggestion).stream()
.filter(suggestionVO -> suggestionVO.getLabel().getLabel().contains(keyWord))
.collect(Collectors.toSet());
}
/**
* by sql statement get suggestions list
*
* @param enableSchemaSuggestion whether enable schema suggestion
* @param sqlStatement sql statement
* @return suggestions list
*/
@Override
public Set<SuggestionVO> getSuggestionsBySqlStatement(
boolean enableSchemaSuggestion, String sqlStatement, int position) {
// todo: 根据传入的sql,获取建议列表, 需要和flink的sql解析器结合起来
return new HashSet<>();
}
}
...@@ -36,7 +36,7 @@ VALUES ( 2, 1, 'python-udf', 'https://github.com/zackyoungh/dinky-quickstart-pyt ...@@ -36,7 +36,7 @@ VALUES ( 2, 1, 'python-udf', 'https://github.com/zackyoungh/dinky-quickstart-pyt
INSERT INTO `dinky_resources` (`id`, `file_name`, `description`, `user_id`, `type`, `size`, `pid`, `full_name`, INSERT INTO `dinky_resources` (`id`, `file_name`, `description`, `user_id`, `type`, `size`, `pid`, `full_name`,
`is_directory`) `is_directory`)
VALUES (0, 'Root', 'main folder', 1, 0, 0, -1, '/', 1); VALUES (0, 'Root', 'main folder', 1, 0, 0, -1, '', 1);
INSERT INTO `dinky_sys_menu` INSERT INTO `dinky_sys_menu`
......
...@@ -378,9 +378,12 @@ public class UDFUtil { ...@@ -378,9 +378,12 @@ public class UDFUtil {
return getPythonUdfList(SystemConfiguration.getInstances().getPythonHome(), udfFile); return getPythonUdfList(SystemConfiguration.getInstances().getPythonHome(), udfFile);
} }
private static final String PYTHON_FUNC_FILE_MD5 =
MD5.create().digestHex(ResourceUtil.readUtf8Str("getPyFuncList.py"));
public static List<String> getPythonUdfList(String pythonPath, String udfFile) { public static List<String> getPythonUdfList(String pythonPath, String udfFile) {
File checkFile = new File(PathConstant.TMP_PATH, "getPyFuncList.py"); File checkFile = new File(PathConstant.TMP_PATH, "getPyFuncList.py");
if (!checkFile.exists()) { if (!checkFile.exists() || !MD5.create().digestHex(checkFile).equals(PYTHON_FUNC_FILE_MD5)) {
FileUtil.writeUtf8String(ResourceUtil.readUtf8Str("getPyFuncList.py"), checkFile); FileUtil.writeUtf8String(ResourceUtil.readUtf8Str("getPyFuncList.py"), checkFile);
} }
List<String> udfNameList = execPyAndGetUdfNameList(pythonPath, checkFile.getAbsolutePath(), udfFile); List<String> udfNameList = execPyAndGetUdfNameList(pythonPath, checkFile.getAbsolutePath(), udfFile);
......
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
import { Column, ISuggestions, MetaData } from '@/components/CustomEditor/CodeEdit/data'; import { SuggestionInfo } from '@/types/Public/data';
import { Document, GlobalVar } from '@/types/RegCenter/data.d';
import * as monaco from 'monaco-editor'; import * as monaco from 'monaco-editor';
import { editor, languages } from 'monaco-editor';
import keyWordJsonData from './keyword.json'; import keyWordJsonData from './keyword.json';
import ITextModel = editor.ITextModel;
// todo: get sqlMetaData from interface import ProviderResult = languages.ProviderResult;
const buildMetaDataSuggestions = () => { import CompletionList = languages.CompletionList;
let metaDataSuggestions: ISuggestions[] = []; import CompletionItem = languages.CompletionItem;
let metaData: [] = []; // temp // 导入 lodash
metaData.forEach((item: MetaData) => {
metaDataSuggestions.push({
label: item.table,
kind: monaco.languages.CompletionItemKind.Constant,
insertText: item.table,
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
detail: 'FlinkSQL Connector => ' + item.connector
});
item.columns.forEach((column: Column) => {
metaDataSuggestions.push({
label: column.name,
kind: monaco.languages.CompletionItemKind.Field,
insertText: column.name,
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
detail: 'Column => ' + column.type + ' from ' + item.table
});
});
});
return metaDataSuggestions;
};
// todo: get document from interface
const buildFullDocumentSuggestions = () => {
let fullDocumentSuggestions: ISuggestions[] = [];
let fillDocuments: [] = []; // temp
fillDocuments.forEach((item: Document) => {
fullDocumentSuggestions.push({
label: item.name,
kind: monaco.languages.CompletionItemKind.Snippet,
insertText: item.fillValue,
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
detail: item.description
});
});
return fullDocumentSuggestions;
};
/** /**
* get keyWordJson from {@link ./keyword.json} * get keyWordJson from {@link ./keyword.json}
...@@ -72,16 +39,21 @@ const parseKeyWordJson = (type: string) => { ...@@ -72,16 +39,21 @@ const parseKeyWordJson = (type: string) => {
/** /**
* build keyWordJsonSuggestions from {@link ./keyword.json} * build keyWordJsonSuggestions from {@link ./keyword.json}
*/ */
const buildKeyWordJsonSuggestions = () => { export const buildKeyWordJsonSuggestions = (range: monaco.Range) => {
let keyWordJsonSuggestions: ISuggestions[] = [];
// get all keys from keyWordJsonData // get all keys from keyWordJsonData
Object.keys(keyWordJsonData).forEach((key: string) => {
let keyWordJsonSuggestions: CompletionItem[] = [];
Object.keys(keyWordJsonData).map((key: string) => {
// parse data of key // parse data of key
const array = parseKeyWordJson(key); const array = parseKeyWordJson(key);
// build suggestions // build suggestions
array.forEach((item: string) => { return array.forEach((item: string) => {
keyWordJsonSuggestions.push({ keyWordJsonSuggestions.push({
label: item, label: {
label: item,
detail: key + ' ' + item
},
range: range,
kind: monaco.languages.CompletionItemKind.Keyword, kind: monaco.languages.CompletionItemKind.Keyword,
insertText: item, insertText: item,
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet, insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
...@@ -89,34 +61,142 @@ const buildKeyWordJsonSuggestions = () => { ...@@ -89,34 +61,142 @@ const buildKeyWordJsonSuggestions = () => {
}); });
}); });
}); });
return keyWordJsonSuggestions; return keyWordJsonSuggestions;
}; };
// todo: get globalVariable from interface /**
const buildGlobalVariableSuggestions = () => { * Method = 0,
let globalVariableSuggestions: ISuggestions[] = []; * Function = 1,
let globalVariables: [] = []; // temp * Constructor = 2,
globalVariables.forEach((item: GlobalVar) => { * Field = 3,
globalVariableSuggestions.push({ * Variable = 4,
label: item.name, * Class = 5,
kind: monaco.languages.CompletionItemKind.Variable, * Struct = 6,
insertText: item.fragmentValue, * Interface = 7,
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet, * Module = 8,
detail: item.note * Property = 9,
}); * Event = 10,
}); * Operator = 11,
return globalVariableSuggestions; * Unit = 12,
* Value = 13,
* Constant = 14,
* Enum = 15,
* EnumMember = 16,
* Keyword = 17,
* Text = 18,
* Color = 19,
* File = 20,
* Reference = 21,
* Customcolor = 22,
* Folder = 23,
* TypeParameter = 24,
* User = 25,
* Issue = 26,
* Snippet = 27
* @param kind
*/
const mappingKind = (kind: number) => {
switch (kind) {
case 0:
return monaco.languages.CompletionItemKind.Method;
case 1:
return monaco.languages.CompletionItemKind.Function;
case 2:
return monaco.languages.CompletionItemKind.Constructor;
case 3:
return monaco.languages.CompletionItemKind.Field;
case 4:
return monaco.languages.CompletionItemKind.Variable;
case 5:
return monaco.languages.CompletionItemKind.Class;
case 6:
return monaco.languages.CompletionItemKind.Struct;
case 7:
return monaco.languages.CompletionItemKind.Interface;
case 8:
return monaco.languages.CompletionItemKind.Module;
case 9:
return monaco.languages.CompletionItemKind.Property;
case 10:
return monaco.languages.CompletionItemKind.Event;
case 11:
return monaco.languages.CompletionItemKind.Operator;
case 12:
return monaco.languages.CompletionItemKind.Unit;
case 13:
return monaco.languages.CompletionItemKind.Value;
case 14:
return monaco.languages.CompletionItemKind.Constant;
case 15:
return monaco.languages.CompletionItemKind.Enum;
case 16:
return monaco.languages.CompletionItemKind.EnumMember;
case 17:
return monaco.languages.CompletionItemKind.Keyword;
case 18:
return monaco.languages.CompletionItemKind.Text;
case 19:
return monaco.languages.CompletionItemKind.Color;
case 20:
return monaco.languages.CompletionItemKind.File;
case 21:
return monaco.languages.CompletionItemKind.Reference;
case 22:
return monaco.languages.CompletionItemKind.Customcolor;
case 23:
return monaco.languages.CompletionItemKind.Folder;
case 24:
return monaco.languages.CompletionItemKind.TypeParameter;
case 25:
return monaco.languages.CompletionItemKind.User;
case 26:
return monaco.languages.CompletionItemKind.Issue;
case 27:
return monaco.languages.CompletionItemKind.Snippet;
default:
return monaco.languages.CompletionItemKind.Keyword;
}
}; };
/** /**
* build all suggestions * build all suggestions to editor
* @param model ITextModel
* @param position monaco.Position
* @param suggestionsData SuggestionInfo[]
* @returns ProviderResult<CompletionList>
*/ */
export const buildAllSuggestions = () => { export const buildAllSuggestionsToEditor = (
let suggestions: ISuggestions[] = []; model: ITextModel,
suggestions = suggestions position: monaco.Position,
.concat(buildMetaDataSuggestions()) // concat metaDataSuggestions suggestionsData: SuggestionInfo[]
.concat(buildFullDocumentSuggestions()) // concat fullDocumentSuggestions ): ProviderResult<CompletionList> => {
.concat(buildGlobalVariableSuggestions()) // concat globalVariableSuggestions const valueRange = model.getWordUntilPosition(position); //get inout word range
.concat(buildKeyWordJsonSuggestions()); // concat keyWordJsonSuggestions // get range
return suggestions; const range = new monaco.Range(
position.lineNumber,
valueRange.startColumn,
position.lineNumber,
valueRange.endColumn
);
const subgraphOptions: CompletionItem[] = suggestionsData.map((item) => {
return {
key: item.key,
label: {
label: item.label.label,
// detail: item.label?.detail ?? '',
description: item.label?.description ?? ''
},
range: range,
kind: mappingKind(item.kind),
insertText: item.insertText,
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet
// detail: item?.detail,
};
});
//todo: 补充补全建议 关键词建议
return {
suggestions: subgraphOptions
};
}; };
...@@ -18,13 +18,24 @@ ...@@ -18,13 +18,24 @@
*/ */
import * as monaco from 'monaco-editor'; import * as monaco from 'monaco-editor';
import { editor, languages, Position } from 'monaco-editor';
import { buildAllSuggestionsToEditor } from '@/components/CustomEditor/CodeEdit/function';
import EditorFloatBtn from '@/components/CustomEditor/EditorFloatBtn'; import EditorFloatBtn from '@/components/CustomEditor/EditorFloatBtn';
import { StateType } from '@/pages/DataStudio/model';
import { MonacoEditorOptions } from '@/types/Public/data'; import { MonacoEditorOptions } from '@/types/Public/data';
import { convertCodeEditTheme } from '@/utils/function'; import { convertCodeEditTheme } from '@/utils/function';
import { Editor, OnChange } from '@monaco-editor/react'; import { Editor, Monaco, OnChange } from '@monaco-editor/react';
import { editor } from 'monaco-editor'; import { connect } from '@umijs/max';
import { useState } from 'react'; import useMemoCallback from 'rc-menu/es/hooks/useMemoCallback';
import { memo, useCallback, useRef } from 'react';
import ITextModel = editor.ITextModel;
import CompletionItem = languages.CompletionItem;
import CompletionContext = languages.CompletionContext;
let provider = {
dispose: () => {}
};
export type CodeEditFormProps = { export type CodeEditFormProps = {
height?: string; height?: string;
...@@ -38,11 +49,13 @@ export type CodeEditFormProps = { ...@@ -38,11 +49,13 @@ export type CodeEditFormProps = {
theme?: string; theme?: string;
autoWrap?: string; autoWrap?: string;
showFloatButton?: boolean; showFloatButton?: boolean;
editorDidMount?: (editor: editor.IStandaloneCodeEditor, monaco: Monaco) => void;
enableSuggestions?: boolean;
monacoRef?: any;
editorRef?: any;
}; };
const CodeEdit = (props: CodeEditFormProps) => { const CodeEdit = (props: CodeEditFormProps & connect) => {
const [editorRef, setEditorRef] = useState<any>();
/** /**
* 1. height: edit height * 1. height: edit height
* 2. width: edit width * 2. width: edit width
...@@ -67,54 +80,118 @@ const CodeEdit = (props: CodeEditFormProps) => { ...@@ -67,54 +80,118 @@ const CodeEdit = (props: CodeEditFormProps) => {
code, // content code, // content
readOnly = false, // is readOnly readOnly = false, // is readOnly
lineNumbers, // show lineNumbers lineNumbers, // show lineNumbers
theme, // edit theme enableSuggestions = false, // enable suggestions
suggestionsData, // suggestions data
autoWrap = 'on', // auto wrap autoWrap = 'on', // auto wrap
showFloatButton = false showFloatButton = false,
editorDidMount,
editorRef,
monacoRef,
tabs: { activeKey }
} = props; } = props;
const editorInstance = useRef<editor.IStandaloneCodeEditor | any>(editorRef);
const monacoInstance = useRef<Monaco | any>(monacoRef);
const { ScrollType } = editor; const { ScrollType } = editor;
// todo: 已知 bug , 切换 tab 时 , 会造成buildAllSuggestions 的重复调用 , 造成建议项重复 ,但不影响原有数据, 编辑器会将建议项自动缓存,不会进行去重
/**
* build all suggestions
*/
const buildAllSuggestions = (model: ITextModel, position: monaco.Position) => {
return buildAllSuggestionsToEditor(model, position, suggestionsData);
};
const buildAllSuggestionsCallback = useCallback(
async (model: ITextModel, position: monaco.Position) => {
return buildAllSuggestions(model, position);
},
[code, activeKey]
);
// memo
const memoizedBuildAllSuggestionsCallback = useMemoCallback(buildAllSuggestionsCallback);
function reloadCompilation(monacoIns: Monaco) {
provider = monacoIns.languages.registerCompletionItemProvider(language, {
provideCompletionItems: (
model: editor.ITextModel,
position: Position,
context: CompletionContext
) => {
const allSuggestions = memoizedBuildAllSuggestionsCallback(model, position);
context.triggerKind =
monacoIns.languages.CompletionTriggerKind.TriggerForIncompleteCompletions;
return allSuggestions;
},
resolveCompletionItem: (item: CompletionItem) => {
return {
...item,
detail: item.detail ?? `-- ${item.detail}`
};
}
});
}
/** /**
* editorDidMount * editorDidMount
* @param {editor.IStandaloneCodeEditor} editor * @param {editor.IStandaloneCodeEditor} editor
* @param monaco
*/ */
const editorDidMount = (editor: editor.IStandaloneCodeEditor) => { const editorDidMountChange = (editor: editor.IStandaloneCodeEditor, monacoIns: Monaco) => {
setEditorRef(editor); if (editorRef?.current && monacoRef?.current && editorDidMount) {
editorDidMount(editor, monacoIns);
}
editorInstance.current = editor;
monacoInstance.current = monacoIns;
if (enableSuggestions) {
reloadCompilation(monacoIns);
}
// register TypeScript language service
monacoIns.languages.register({
id: language || 'typescript'
});
editor.layout(); editor.layout();
editor.focus(); editor.focus();
}; };
/** /**
* handle scroll to top * handle scroll to top
*/ */
const handleBackTop = () => { const handleBackTop = () => {
editorRef.revealLine(1); editorInstance?.current?.revealLine(1);
}; };
/** /**
* handle scroll to bottom * handle scroll to bottom
*/ */
const handleBackBottom = () => { const handleBackBottom = () => {
editorRef.revealLine(editorRef.getModel().getLineCount()); editorInstance?.current?.revealLine(editorInstance?.current?.getModel()?.getLineCount());
}; };
/** /**
* handle scroll to down * handle scroll to down
*/ */
const handleDownScroll = () => { const handleDownScroll = () => {
editorRef.setScrollPosition({ scrollTop: editorRef.getScrollTop() + 500 }, ScrollType.Smooth); editorInstance?.current?.setScrollPosition(
{ scrollTop: editorInstance?.current?.getScrollTop() + 500 },
ScrollType.Smooth
);
}; };
/** /**
* handle scroll to up * handle scroll to up
*/ */
const handleUpScroll = () => { const handleUpScroll = () => {
editorRef?.setScrollPosition({ scrollTop: editorRef.getScrollTop() - 500 }, ScrollType.Smooth); editorInstance?.current?.setScrollPosition(
{ scrollTop: editorInstance?.current?.getScrollTop() - 500 },
ScrollType.Smooth
);
}; };
// register TypeScript language service // todo: 标记错误信息
monaco.languages.register({
id: language || 'typescript'
});
const restEditBtnProps = { const restEditBtnProps = {
handleBackTop, handleBackTop,
...@@ -123,6 +200,83 @@ const CodeEdit = (props: CodeEditFormProps) => { ...@@ -123,6 +200,83 @@ const CodeEdit = (props: CodeEditFormProps) => {
handleDownScroll handleDownScroll
}; };
const finalEditorOptions = {
...options,
tabCompletion: 'on', // tab 补全
cursorSmoothCaretAnimation: true, // 光标动画
screenReaderAnnounceInlineSuggestion: true, // 屏幕阅读器提示
formatOnPaste: true, // 粘贴时格式化
mouseWheelZoom: true, // 鼠标滚轮缩放
autoClosingBrackets: 'always', // 自动闭合括号
autoClosingOvertype: 'always', // 用于在右引号或括号上键入的选项
autoClosingQuotes: 'always', // 自动闭合引号
showUnused: true, // 显示未使用的代码
unfoldOnClickAfterEndOfLine: true, // 控制在折叠线之后单击空内容是否会展开该线
showFoldingControls: 'always', // 代码折叠控件 'always' | 'mouseover' | 'never'
automaticLayout: true, // 自动布局
readOnly, // 是否只读
wrappingIndent:
language === 'yaml' || language === 'yml' || language === 'json' ? 'indent' : 'none',
inlineSuggest: {
enabled: true,
showToolbar: 'always',
keepOnBlur: false,
allowQuickSuggestions: true,
showOnAllSymbols: true
},
inlineSuggestionVisible: true,
quickSuggestions: true,
guides: {
bracketPairs: true
},
bracketPairColorization: {
enabled: true,
independentColorPoolPerBracketType: true
},
foldingRanges: true,
inlineCompletionsAccessibilityVerbose: true,
suggest: {
shareSuggestSelections: true,
quickSuggestions: true,
showStatusBar: true,
preview: true,
previewMode: 'preview',
showInlineDetails: true,
showMethods: true,
showFunctions: true,
showConstructors: true,
showFields: true,
showEvents: true,
showOperators: true,
showClasses: true,
showModules: true,
showStructs: true,
showInterfaces: true,
showProperties: true,
showUnits: true,
showValues: true,
showConstants: true,
showEnums: true,
showEnumMembers: true,
showKeywords: true,
showWords: true,
showFolders: true,
showReferences: true,
showSnippets: true
},
scrollbar: {
useShadows: false,
vertical: 'visible',
horizontal: 'visible',
verticalScrollbarSize: 8,
horizontalScrollbarSize: 8,
arrowSize: 30
},
wordWrap: autoWrap,
autoDetectHighContrast: true,
lineNumbers
};
return ( return (
<> <>
<div className={'monaco-float'}> <div className={'monaco-float'}>
...@@ -131,15 +285,9 @@ const CodeEdit = (props: CodeEditFormProps) => { ...@@ -131,15 +285,9 @@ const CodeEdit = (props: CodeEditFormProps) => {
height={height} height={height}
value={code} value={code}
language={language} language={language}
options={{ options={finalEditorOptions}
...options,
readOnly,
wordWrap: autoWrap,
autoDetectHighContrast: true,
lineNumbers
}}
className={'editor-develop'} className={'editor-develop'}
onMount={editorDidMount} onMount={editorDidMountChange}
onChange={onChange} onChange={onChange}
theme={convertCodeEditTheme()} theme={convertCodeEditTheme()}
/> />
...@@ -149,4 +297,7 @@ const CodeEdit = (props: CodeEditFormProps) => { ...@@ -149,4 +297,7 @@ const CodeEdit = (props: CodeEditFormProps) => {
); );
}; };
export default CodeEdit; export default connect(({ Studio }: { Studio: StateType }) => ({
suggestionsData: Studio.suggestions,
tabs: Studio.tabs
}))(memo(CodeEdit));
...@@ -19,14 +19,13 @@ ...@@ -19,14 +19,13 @@
import EditorFloatBtn from '@/components/CustomEditor/EditorFloatBtn'; import EditorFloatBtn from '@/components/CustomEditor/EditorFloatBtn';
import { LogLanguage } from '@/components/CustomEditor/languages/javalog'; import { LogLanguage } from '@/components/CustomEditor/languages/javalog';
import useThemeValue from '@/hooks/useThemeValue';
import { Loading } from '@/pages/Other/Loading'; import { Loading } from '@/pages/Other/Loading';
import { MonacoEditorOptions } from '@/types/Public/data'; import { MonacoEditorOptions } from '@/types/Public/data';
import { convertCodeEditTheme } from '@/utils/function'; import { convertCodeEditTheme } from '@/utils/function';
import { Editor, useMonaco } from '@monaco-editor/react'; import { Editor, useMonaco } from '@monaco-editor/react';
import { editor } from 'monaco-editor'; import { editor } from 'monaco-editor';
import { EditorLanguage } from 'monaco-editor/esm/metadata'; import { EditorLanguage } from 'monaco-editor/esm/metadata';
import { CSSProperties, useEffect, useState } from 'react'; import { CSSProperties, useEffect, useRef, useState } from 'react';
import FullscreenBtn from '../FullscreenBtn'; import FullscreenBtn from '../FullscreenBtn';
// loader.config({monaco}); // loader.config({monaco});
...@@ -86,9 +85,8 @@ const CodeShow = (props: CodeShowFormProps) => { ...@@ -86,9 +85,8 @@ const CodeShow = (props: CodeShowFormProps) => {
const [stopping, setStopping] = useState<boolean>(false); const [stopping, setStopping] = useState<boolean>(false);
const [autoRefresh, setAutoRefresh] = useState<boolean>(false); const [autoRefresh, setAutoRefresh] = useState<boolean>(false);
const [fullScreen, setFullScreen] = useState<boolean>(false); const [fullScreen, setFullScreen] = useState<boolean>(false);
const [editorRef, setEditorRef] = useState<any>(); const editorInstance = useRef<editor.IStandaloneCodeEditor | any>();
const [timer, setTimer] = useState<NodeJS.Timer>(); const [timer, setTimer] = useState<NodeJS.Timer>();
const themeValue = useThemeValue();
// 使用编辑器钩子, 拿到编辑器实例 // 使用编辑器钩子, 拿到编辑器实例
const monaco = useMonaco(); const monaco = useMonaco();
...@@ -138,28 +136,34 @@ const CodeShow = (props: CodeShowFormProps) => { ...@@ -138,28 +136,34 @@ const CodeShow = (props: CodeShowFormProps) => {
* handle scroll to top * handle scroll to top
*/ */
const handleBackTop = () => { const handleBackTop = () => {
editorRef.revealLine(1); editorInstance?.current?.revealLine(1);
}; };
/** /**
* handle scroll to bottom * handle scroll to bottom
*/ */
const handleBackBottom = () => { const handleBackBottom = () => {
editorRef.revealLine(editorRef.getModel().getLineCount()); editorInstance?.current?.revealLine(editorInstance?.current?.getModel().getLineCount());
}; };
/** /**
* handle scroll to down * handle scroll to down
*/ */
const handleDownScroll = () => { const handleDownScroll = () => {
editorRef.setScrollPosition({ scrollTop: editorRef.getScrollTop() + 500 }, ScrollType.Smooth); editorInstance?.current?.setScrollPosition(
{ scrollTop: editorInstance?.current?.getScrollTop() + 500 },
ScrollType.Smooth
);
}; };
/** /**
* handle scroll to up * handle scroll to up
*/ */
const handleUpScroll = () => { const handleUpScroll = () => {
editorRef?.setScrollPosition({ scrollTop: editorRef.getScrollTop() - 500 }, ScrollType.Smooth); editorInstance?.current?.setScrollPosition(
{ scrollTop: editorInstance?.current?.getScrollTop() - 500 },
ScrollType.Smooth
);
}; };
/** /**
...@@ -167,7 +171,7 @@ const CodeShow = (props: CodeShowFormProps) => { ...@@ -167,7 +171,7 @@ const CodeShow = (props: CodeShowFormProps) => {
* @param {editor.IStandaloneCodeEditor} editor * @param {editor.IStandaloneCodeEditor} editor
*/ */
const editorDidMount = (editor: editor.IStandaloneCodeEditor) => { const editorDidMount = (editor: editor.IStandaloneCodeEditor) => {
setEditorRef(editor); editorInstance.current = editor;
editor.layout(); editor.layout();
editor.focus(); editor.focus();
if (scrollBeyondLastLine) { if (scrollBeyondLastLine) {
......
...@@ -471,12 +471,12 @@ export const LogSvg = () => { ...@@ -471,12 +471,12 @@ export const LogSvg = () => {
xmlns='http://www.w3.org/2000/svg' xmlns='http://www.w3.org/2000/svg'
> >
<path <path
d='M704 64c35.328 0 64 28.672 64 64v321.7408A288 288 0 0 0 496.5376 896H128c-35.328 0-64-28.672-64-64V128c0-35.328 28.672-64 64-64h576zM480 384h-256a32 32 0 0 0-31.488 26.2656l-0.512 5.7344v32c0 15.7184 11.3152 28.7744 26.2656 31.488l5.7344 0.512h256a32 32 0 0 0 31.488-26.2656L512 448v-32a32 32 0 0 0-26.2656-31.488l-5.7344-0.512z m128-192h-384a32 32 0 0 0-31.488 26.2656l-0.512 5.7344V256c0 15.7184 11.3152 28.7744 26.2656 31.488l5.7344 0.512h384a32 32 0 0 0 31.488-26.2656L640 256v-32a32 32 0 0 0-26.2656-31.488l-5.7344-0.512z' d='M109.7 697c40.2-24.1 115.8-36.2 226.6-36.2 77.9 0 168.5 42.8 335.4 70.6 83.9 14 164.8 14 242.6 0l-22.4 208-782.2 11.4V697z m782.2-104.2c-40.4 0-73.1-32.7-73.1-73.1s32.7-73.1 73.1-73.1 73.1 32.7 73.1 73.1-32.7 73.1-73.1 73.1z'
fill='#007AF5' fill='#66CCFF'
></path> ></path>
<path <path
d='M736 512a224 224 0 1 1 0 448 224 224 0 0 1 0-448z m0 80.0256a32 32 0 0 0-31.488 26.2144l-0.512 5.7856v128l0.512 5.7344a32.0512 32.0512 0 0 0 25.7536 25.7024l5.7344 0.512h128l5.7344-0.512a32.0512 32.0512 0 0 0 25.7536-25.7024l0.512-5.7856-0.512-5.7344a32.0512 32.0512 0 0 0-25.7536-25.7024l-5.7344-0.512H768v-96.0512l-0.512-5.7344a32 32 0 0 0-31.488-26.2144z' d='M71.7 688.9V324.5H64c-15.1 0-27.4-12.3-27.4-27.4 0-15.1 12.3-27.4 27.4-27.4h7.7V139c0-51.5 41.8-93.3 93.3-93.3h672.9c51.5 0 93.3 41.8 93.3 93.3v309.6h-54.9V139c0-21.2-17.2-38.4-38.4-38.4h-673c-21.2 0-38.4 17.2-38.4 38.4v130.7h7.7c15.1 0 27.4 12.3 27.4 27.4 0 15.1-12.3 27.4-27.4 27.4h-7.7v364.3h7.7c15.1 0 27.4 12.3 27.4 27.4 0 15.1-12.3 27.4-27.4 27.4h-7.7V885c0 21.2 17.2 38.4 38.4 38.4h672.9c21.2 0 38.4-17.2 38.4-38.4V558.8h54.9V885c0 51.5-41.8 93.3-93.3 93.3H164.9c-51.5 0-93.3-41.8-93.3-93.3V743.7H64c-15.1 0-27.4-12.3-27.4-27.4 0-15.1 12.3-27.4 27.4-27.4h7.7z m211.7-396.3h384c15.1 0 27.4 12.3 27.4 27.4s-12.3 27.4-27.4 27.4h-384c-15.1 0-27.4-12.3-27.4-27.4s12.3-27.4 27.4-27.4z m0 182.8h384c15.1 0 27.4 12.3 27.4 27.4 0 15.1-12.3 27.4-27.4 27.4h-384c-15.1 0-27.4-12.3-27.4-27.4 0-15.1 12.3-27.4 27.4-27.4zM896 594.3c-50.5 0-91.4-40.9-91.4-91.4s40.9-91.4 91.4-91.4 91.4 40.9 91.4 91.4-40.9 91.4-91.4 91.4z m0-36.6c30.3 0 54.9-24.6 54.9-54.9S926.3 448 896 448s-54.9 24.6-54.9 54.9 24.6 54.8 54.9 54.8z'
fill='#66AFF9' fill='#4E5F80'
></path> ></path>
</svg> </svg>
)} )}
......
...@@ -281,6 +281,7 @@ ol { ...@@ -281,6 +281,7 @@ ol {
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
height: 100%; height: 100%;
box-shadow: 0 0 2px 1px rgba(171, 165, 165, 0.32);
.float-button { .float-button {
position: absolute; position: absolute;
......
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import { import {
createContext, createContext,
Dispatch, Dispatch,
...@@ -19,7 +38,7 @@ export const FullScreenContext = createContext<FullScreenContextProps>( ...@@ -19,7 +38,7 @@ export const FullScreenContext = createContext<FullScreenContextProps>(
{} as FullScreenContextProps {} as FullScreenContextProps
); );
export const FullScreenProvider: FC = memo(({ children }) => { export const FullScreenProvider: FC = memo(({ children }: any) => {
const [fullscreen, setFullscreen] = useState<boolean>(false); const [fullscreen, setFullscreen] = useState<boolean>(false);
const { initialState, setInitialState } = useModel('@@initialState'); const { initialState, setInitialState } = useModel('@@initialState');
......
/* /*
* *
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* *
*/ */
...@@ -41,7 +41,7 @@ type PermissionsFormProps = { ...@@ -41,7 +41,7 @@ type PermissionsFormProps = {
*/ */
const CodeEditProps = { const CodeEditProps = {
height: '25vh', height: '25vh',
lineNumbers: 'off' lineNumbers: 'on'
}; };
const PermissionsForm: React.FC<PermissionsFormProps> = (props) => { const PermissionsForm: React.FC<PermissionsFormProps> = (props) => {
...@@ -99,9 +99,7 @@ const PermissionsForm: React.FC<PermissionsFormProps> = (props) => { ...@@ -99,9 +99,7 @@ const PermissionsForm: React.FC<PermissionsFormProps> = (props) => {
]} ]}
> >
<CodeEdit <CodeEdit
onChange={(value) => { onChange={setExpression}
setExpression(value ?? '');
}}
code={expression} code={expression}
language={'sql'} language={'sql'}
{...CodeEditProps} {...CodeEditProps}
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
* *
*/ */
import CodeEdit from '@/components/CustomEditor/CodeEdit';
import { useEditor } from '@/hooks/useEditor'; import { useEditor } from '@/hooks/useEditor';
import { getCurrentTab } from '@/pages/DataStudio/function'; import { getCurrentTab } from '@/pages/DataStudio/function';
import { TASK_VAR_FILTER } from '@/pages/DataStudio/MiddleContainer/Editor/constants'; import { TASK_VAR_FILTER } from '@/pages/DataStudio/MiddleContainer/Editor/constants';
...@@ -25,18 +26,18 @@ import { ...@@ -25,18 +26,18 @@ import {
DataStudioTabsItemType, DataStudioTabsItemType,
StateType, StateType,
STUDIO_MODEL, STUDIO_MODEL,
STUDIO_MODEL_ASYNC,
TaskDataType TaskDataType
} from '@/pages/DataStudio/model'; } from '@/pages/DataStudio/model';
import { JOB_LIFE_CYCLE } from '@/pages/DevOps/constants'; import { JOB_LIFE_CYCLE } from '@/pages/DevOps/constants';
import { API_CONSTANTS } from '@/services/endpoints'; import { API_CONSTANTS } from '@/services/endpoints';
import { convertCodeEditTheme } from '@/utils/function';
import { l } from '@/utils/intl'; import { l } from '@/utils/intl';
import { connect, useRequest } from '@@/exports'; import { connect, useRequest } from '@@/exports';
import { FullscreenExitOutlined, FullscreenOutlined } from '@ant-design/icons'; import { FullscreenExitOutlined, FullscreenOutlined } from '@ant-design/icons';
import { Editor } from '@monaco-editor/react'; import { Monaco } from '@monaco-editor/react';
import { Button, Spin } from 'antd'; import { Button, Spin } from 'antd';
import { editor, KeyCode, KeyMod } from 'monaco-editor'; import { editor, KeyCode, KeyMod } from 'monaco-editor';
import React, { useState } from 'react'; import React, { useEffect, useRef, useState } from 'react';
import { format } from 'sql-formatter'; import { format } from 'sql-formatter';
export type EditorProps = { export type EditorProps = {
...@@ -52,10 +53,20 @@ const CodeEditor: React.FC<EditorProps & any> = (props) => { ...@@ -52,10 +53,20 @@ const CodeEditor: React.FC<EditorProps & any> = (props) => {
height height
} = props; } = props;
useEffect(() => {
dispatch({
type: STUDIO_MODEL_ASYNC.querySuggestions,
payload: {
enableSchemaSuggestions: false
}
});
}, []);
const [isModalOpen, setIsModalOpen] = useState(false); const [isModalOpen, setIsModalOpen] = useState(false);
const [diff, setDiff] = useState<any>([]); const [diff, setDiff] = useState<any>([]);
const { fullscreen, setFullscreen } = useEditor(); const { fullscreen, setFullscreen } = useEditor();
const [editorIns, setEditorIns] = useState<editor.IStandaloneCodeEditor>(null); const editorInstance = useRef<editor.IStandaloneCodeEditor | any>();
const monacoInstance = useRef<Monaco | any>();
const currentTab = getCurrentTab(panes, activeKey) as DataStudioTabsItemType; const currentTab = getCurrentTab(panes, activeKey) as DataStudioTabsItemType;
const currentData = currentTab.params.taskData; const currentData = currentTab.params.taskData;
...@@ -96,6 +107,40 @@ const CodeEditor: React.FC<EditorProps & any> = (props) => { ...@@ -96,6 +107,40 @@ const CodeEditor: React.FC<EditorProps & any> = (props) => {
setIsModalOpen(false); setIsModalOpen(false);
}; };
const editorDidMount = (editor: editor.IStandaloneCodeEditor, monaco: Monaco) => {
editor.layout();
editor.focus();
monacoInstance.current = monaco;
editorInstance.current = editor;
editor.onDidChangeCursorPosition((e) => {
props.footContainer.codePosition = [e.position.lineNumber, e.position.column];
dispatch({
type: STUDIO_MODEL.saveFooterValue,
payload: { ...props.footContainer }
});
});
editor.addCommand(KeyMod.Alt | KeyCode.Digit3, () => {
editor?.trigger('anyString', 'editor.action.formatDocument', '');
editor.setValue(format(editor.getValue()));
});
};
const handleEditChange = (v: string | undefined) => {
if (!currentData || !currentTab) {
return;
}
if (typeof v === 'string') {
currentData.statement = v;
}
currentTab.isModified = true;
dispatch({
type: STUDIO_MODEL.saveTabs,
payload: { ...props.tabs }
});
};
return ( return (
<Spin spinning={loading} delay={600}> <Spin spinning={loading} delay={600}>
<div style={{ width: '100%', height: fullscreen ? 'calc(100vh - 50px)' : height }}> <div style={{ width: '100%', height: fullscreen ? 'calc(100vh - 50px)' : height }}>
...@@ -105,78 +150,39 @@ const CodeEditor: React.FC<EditorProps & any> = (props) => { ...@@ -105,78 +150,39 @@ const CodeEditor: React.FC<EditorProps & any> = (props) => {
fileName={currentData?.name} fileName={currentData?.name}
onUse={upDateTask} onUse={upDateTask}
/> />
<Editor <CodeEdit
value={currentTab?.params?.taskData?.statement} monacoRef={monacoInstance}
editorRef={editorInstance}
code={currentTab?.params?.taskData?.statement}
language={'sql'} language={'sql'}
editorDidMount={editorDidMount}
onChange={handleEditChange}
enableSuggestions={true}
options={{ options={{
readOnlyMessage: { value: l('pages.datastudio.editor.onlyread') }, readOnlyMessage: { value: l('pages.datastudio.editor.onlyread') },
readOnly: currentData?.step == JOB_LIFE_CYCLE.PUBLISH, readOnly: currentData?.step == JOB_LIFE_CYCLE.PUBLISH,
scrollBeyondLastLine: false, scrollBeyondLastLine: false,
wordWrap: 'on', wordWrap: 'on'
autoDetectHighContrast: true,
scrollbar: {
// Subtle shadows to the left & top. Defaults to true.
useShadows: false,
// Defaults to 'auto'
vertical: 'visible',
// Defaults to 'auto'
horizontal: 'visible',
verticalScrollbarSize: 8,
horizontalScrollbarSize: 8,
arrowSize: 30
},
automaticLayout: true
}} }}
className={'editor-develop'} />
onMount={(editor: editor.IStandaloneCodeEditor) => {
editor.layout();
editor.focus();
editor.onDidChangeCursorPosition((e) => {
props.footContainer.codePosition = [e.position.lineNumber, e.position.column];
dispatch({
type: STUDIO_MODEL.saveFooterValue,
payload: { ...props.footContainer }
});
});
editor.addCommand(KeyMod.Alt | KeyCode.Digit3, () => {
editor?.trigger('anyString', 'editor.action.formatDocument');
editor.setValue(format(editor.getValue()));
});
setEditorIns(editor);
}}
onChange={(v) => {
if (!currentData || !currentTab) {
return;
}
if (typeof v === 'string') {
currentData.statement = v;
}
currentTab.isModified = true;
dispatch({
type: STUDIO_MODEL.saveTabs,
payload: { ...props.tabs }
});
}}
theme={convertCodeEditTheme()}
></Editor>
<div <div
style={{ style={{
position: 'absolute', position: 'absolute',
top: 20, top: 15,
right: '7%' right: '10%',
boxShadow: '0 0 10px #ccc'
}} }}
> >
{fullscreen ? ( {fullscreen ? (
<Button <Button
type='text' type='text'
style={{ style={{
color: '#fff' zIndex: 999
}} }}
title={l('global.fullScreen.exit')}
icon={<FullscreenExitOutlined />} icon={<FullscreenExitOutlined />}
onClick={() => { onClick={() => {
editorIns.layout(); editorInstance?.current?.layout();
setFullscreen(false); setFullscreen(false);
}} }}
/> />
...@@ -184,11 +190,12 @@ const CodeEditor: React.FC<EditorProps & any> = (props) => { ...@@ -184,11 +190,12 @@ const CodeEditor: React.FC<EditorProps & any> = (props) => {
<Button <Button
type='text' type='text'
style={{ style={{
color: '#fff' zIndex: 999
}} }}
title={l('global.fullScreen')}
icon={<FullscreenOutlined />} icon={<FullscreenOutlined />}
onClick={() => { onClick={() => {
editorIns.layout(); editorInstance?.current?.layout();
setFullscreen(true); setFullscreen(true);
}} }}
/> />
......
/* /*
* *
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* *
*/ */
...@@ -27,12 +27,12 @@ export const KEY_BOARD_MIDDLE = [ ...@@ -27,12 +27,12 @@ export const KEY_BOARD_MIDDLE = [
}, },
{ {
key: 'alt2', key: 'alt2',
label: 'Alt + 2', label: 'Alt / Option + 2',
description: l('shortcut.key.check') description: l('shortcut.key.check')
}, },
{ {
key: 'alt3', key: 'alt3',
label: 'Alt + 3', label: 'Alt / Option + 3',
description: l('shortcut.key.beautify') description: l('shortcut.key.beautify')
} }
// { // {
......
/* /*
* *
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* *
*/ */
import { queryDataByParams } from '@/services/BusinessCrud'; import { getDataByParams, queryDataByParams } from '@/services/BusinessCrud';
export function getSessionData() { export function getSessionData() {
return queryDataByParams('api/cluster/listSessionEnable'); return queryDataByParams('api/cluster/listSessionEnable');
...@@ -32,3 +32,7 @@ export function getClusterConfigurationData() { ...@@ -32,3 +32,7 @@ export function getClusterConfigurationData() {
export function getFlinkConfigs() { export function getFlinkConfigs() {
return queryDataByParams('/api/flinkConf/configOptions'); return queryDataByParams('/api/flinkConf/configOptions');
} }
export function querySuggessionData(params: any) {
return getDataByParams('/api/suggestion/queryAllSuggestions', params);
}
...@@ -19,8 +19,12 @@ ...@@ -19,8 +19,12 @@
import { getFooterValue, isDataStudioTabsItemType } from '@/pages/DataStudio/function'; import { getFooterValue, isDataStudioTabsItemType } from '@/pages/DataStudio/function';
import { getTaskData } from '@/pages/DataStudio/LeftContainer/Project/service'; import { getTaskData } from '@/pages/DataStudio/LeftContainer/Project/service';
import { getFlinkConfigs } from '@/pages/DataStudio/RightContainer/JobConfig/service'; import {
getFlinkConfigs,
querySuggessionData
} from '@/pages/DataStudio/RightContainer/JobConfig/service';
import { QueryParams } from '@/pages/RegCenter/DataSource/components/DataSourceDetail/RightTagsRouter/data'; import { QueryParams } from '@/pages/RegCenter/DataSource/components/DataSourceDetail/RightTagsRouter/data';
import { SuggestionInfo } from '@/types/Public/data';
import { Cluster, DataSources } from '@/types/RegCenter/data'; import { Cluster, DataSources } from '@/types/RegCenter/data';
import { l } from '@/utils/intl'; import { l } from '@/utils/intl';
import { createModelTypes } from '@/utils/modelUtils'; import { createModelTypes } from '@/utils/modelUtils';
...@@ -284,6 +288,7 @@ export type StateType = { ...@@ -284,6 +288,7 @@ export type StateType = {
tabs: TabsType; tabs: TabsType;
bottomContainerContent: BottomContainerContent; bottomContainerContent: BottomContainerContent;
footContainer: FooterType; footContainer: FooterType;
suggestions: SuggestionInfo[];
}; };
export type ModelType = { export type ModelType = {
...@@ -292,6 +297,7 @@ export type ModelType = { ...@@ -292,6 +297,7 @@ export type ModelType = {
effects: { effects: {
queryProject: Effect; queryProject: Effect;
queryFlinkConfigOptions: Effect; queryFlinkConfigOptions: Effect;
querySuggestions: Effect;
}; };
reducers: { reducers: {
updateToolContentHeight: Reducer<StateType>; updateToolContentHeight: Reducer<StateType>;
...@@ -324,6 +330,7 @@ export type ModelType = { ...@@ -324,6 +330,7 @@ export type ModelType = {
saveFooterValue: Reducer<StateType>; saveFooterValue: Reducer<StateType>;
updateJobRunningMsg: Reducer<StateType>; updateJobRunningMsg: Reducer<StateType>;
saveFlinkConfigOptions: Reducer<StateType>; saveFlinkConfigOptions: Reducer<StateType>;
updateSuggestions: Reducer<StateType>;
}; };
}; };
...@@ -387,7 +394,8 @@ const Model: ModelType = { ...@@ -387,7 +394,8 @@ const Model: ModelType = {
jobState: '', jobState: '',
runningLog: '' runningLog: ''
} }
} },
suggestions: []
}, },
effects: { effects: {
*queryProject({ payload }, { call, put }) { *queryProject({ payload }, { call, put }) {
...@@ -403,6 +411,13 @@ const Model: ModelType = { ...@@ -403,6 +411,13 @@ const Model: ModelType = {
type: 'saveFlinkConfigOptions', type: 'saveFlinkConfigOptions',
payload: response payload: response
}); });
},
*querySuggestions({ payload }, { call, put }) {
const response: SuggestionInfo[] = yield call(querySuggessionData, payload);
yield put({
type: 'updateSuggestions',
payload: response
});
} }
}, },
reducers: { reducers: {
...@@ -829,6 +844,12 @@ const Model: ModelType = { ...@@ -829,6 +844,12 @@ const Model: ModelType = {
jobRunningMsg: payload jobRunningMsg: payload
} }
}; };
},
updateSuggestions(state, { payload }) {
return {
...state,
suggestions: payload
};
} }
} }
}; };
......
/* /*
* *
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* *
*/ */
......
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
import CodeEdit from '@/components/CustomEditor/CodeEdit'; import CodeEdit from '@/components/CustomEditor/CodeEdit';
...@@ -153,7 +155,7 @@ const DataSourceProForm: React.FC<DataSourceProFormProps> = (props) => { ...@@ -153,7 +155,7 @@ const DataSourceProForm: React.FC<DataSourceProFormProps> = (props) => {
> >
<CodeEdit <CodeEdit
{...CodeEditProps} {...CodeEditProps}
onChange={(value) => flinkConfigChange(value ?? '')} onChange={flinkConfigChange}
code={values.flinkConfig || ''} code={values.flinkConfig || ''}
/> />
</ProForm.Item> </ProForm.Item>
...@@ -165,7 +167,7 @@ const DataSourceProForm: React.FC<DataSourceProFormProps> = (props) => { ...@@ -165,7 +167,7 @@ const DataSourceProForm: React.FC<DataSourceProFormProps> = (props) => {
> >
<CodeEdit <CodeEdit
{...CodeEditProps} {...CodeEditProps}
onChange={(value) => flinkTemplateChange(value ?? '')} onChange={flinkTemplateChange}
code={values.flinkTemplate || ''} code={values.flinkTemplate || ''}
/> />
</ProForm.Item> </ProForm.Item>
......
/* /*
* *
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* *
*/ */
...@@ -133,9 +133,10 @@ const DocumentForm: React.FC<DocumentFormProps> = (props) => { ...@@ -133,9 +133,10 @@ const DocumentForm: React.FC<DocumentFormProps> = (props) => {
rules={[{ required: true, message: l('rc.doc.fillValueHelp') }]} rules={[{ required: true, message: l('rc.doc.fillValueHelp') }]}
> >
<CodeEdit <CodeEdit
onChange={(value) => handleFillValueChange(value ?? '')} onChange={handleFillValueChange}
code={codeFillValue} code={codeFillValue}
language={'sql'} language={'sql'}
enableSuggestions={false}
{...CodeEditProps} {...CodeEditProps}
/> />
</ProFormItem> </ProFormItem>
......
...@@ -186,7 +186,7 @@ export const BuildSteps: React.FC<BuildStepsProps> = (props) => { ...@@ -186,7 +186,7 @@ export const BuildSteps: React.FC<BuildStepsProps> = (props) => {
type={'primary'} type={'primary'}
danger danger
hidden={!onReTry} hidden={!onReTry}
disabled={onReTry && Number(steps[currentStep]?.status) !== 2} disabled={steps[currentStep - 1]?.status !== 'error'}
onClick={() => handleReTry()} onClick={() => handleReTry()}
> >
{l('button.retry')} {l('button.retry')}
...@@ -196,6 +196,7 @@ export const BuildSteps: React.FC<BuildStepsProps> = (props) => { ...@@ -196,6 +196,7 @@ export const BuildSteps: React.FC<BuildStepsProps> = (props) => {
type={'dashed'} type={'dashed'}
hidden={showLog} hidden={showLog}
loading={currentStep !== steps.length && percent !== 99} loading={currentStep !== steps.length && percent !== 99}
disabled={onReTry && steps[currentStep - 1]?.status === 'error'}
onClick={() => onRebuild()} onClick={() => onRebuild()}
> >
{l('button.rebuild')} {l('button.rebuild')}
...@@ -203,6 +204,8 @@ export const BuildSteps: React.FC<BuildStepsProps> = (props) => { ...@@ -203,6 +204,8 @@ export const BuildSteps: React.FC<BuildStepsProps> = (props) => {
<Button <Button
key={'finish'} key={'finish'}
type={showLog ? 'default' : 'primary'} type={showLog ? 'default' : 'primary'}
danger={showLog}
disabled={steps[currentStep - 1]?.status === 'error' && percent !== 99}
loading={currentStep !== steps.length && percent !== 99} loading={currentStep !== steps.length && percent !== 99}
onClick={() => handleCancel()} onClick={() => handleCancel()}
> >
......
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
import FadeIn from '@/components/Animation/FadeIn'; import FadeIn from '@/components/Animation/FadeIn';
...@@ -26,7 +28,6 @@ import { ...@@ -26,7 +28,6 @@ import {
ResourceIcon ResourceIcon
} from '@/components/Icons/CustomIcons'; } from '@/components/Icons/CustomIcons';
import { TagAlignCenter } from '@/components/StyledComponents'; import { TagAlignCenter } from '@/components/StyledComponents';
import { useAccess } from '@/hooks/useAccess';
import { SettingConfigKeyEnum } from '@/pages/SettingCenter/GlobalSetting/SettingOverView/constants'; import { SettingConfigKeyEnum } from '@/pages/SettingCenter/GlobalSetting/SettingOverView/constants';
import { DSConfig } from '@/pages/SettingCenter/GlobalSetting/SettingOverView/DSConfig'; import { DSConfig } from '@/pages/SettingCenter/GlobalSetting/SettingOverView/DSConfig';
import { EnvConfig } from '@/pages/SettingCenter/GlobalSetting/SettingOverView/EnvConfig'; import { EnvConfig } from '@/pages/SettingCenter/GlobalSetting/SettingOverView/EnvConfig';
...@@ -46,8 +47,6 @@ const imgSize = 25; ...@@ -46,8 +47,6 @@ const imgSize = 25;
const SettingOverView = () => { const SettingOverView = () => {
const [activeKey, setActiveKey] = useState(SettingConfigKeyEnum.DINKY); const [activeKey, setActiveKey] = useState(SettingConfigKeyEnum.DINKY);
const [tags, setTags] = useState([]);
const access = useAccess();
const [data, setData] = useState<Settings>({ const [data, setData] = useState<Settings>({
dolphinscheduler: [], dolphinscheduler: [],
...@@ -198,12 +197,20 @@ const SettingOverView = () => { ...@@ -198,12 +197,20 @@ const SettingOverView = () => {
<div style={{ paddingBottom: '20px' }}> <div style={{ paddingBottom: '20px' }}>
<ProCard <ProCard
ghost ghost
bodyStyle={{ height: '80vh' }}
className={'schemaTree'} className={'schemaTree'}
size='small' size='small'
bordered bordered
tabs={{ tabs={{
activeKey: activeKey, activeKey: activeKey,
type: 'card', type: 'card',
cardProps: {
hoverable: true,
bodyStyle: {
height: parent.innerHeight - 155
},
boxShadow: true
},
animated: true, animated: true,
onChange: (key: any) => setActiveKey(key), onChange: (key: any) => setActiveKey(key),
// todo: 目前无法通过这种方式进行权限显示 多 Tag 的方式,待实现 // todo: 目前无法通过这种方式进行权限显示 多 Tag 的方式,待实现
......
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
import CodeShow, { CodeShowFormProps } from '@/components/CustomEditor/CodeShow'; import CodeShow, { CodeShowFormProps } from '@/components/CustomEditor/CodeShow';
...@@ -21,7 +23,7 @@ import { Empty } from 'antd'; ...@@ -21,7 +23,7 @@ import { Empty } from 'antd';
import React from 'react'; import React from 'react';
const CodeEditProps: any = { const CodeEditProps: any = {
height: '82vh', height: '100%',
width: '100%', width: '100%',
lineNumbers: 'on', lineNumbers: 'on',
language: 'java' language: 'java'
......
/* /*
* *
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* *
*/ */
...@@ -42,11 +42,11 @@ export const buildLogInfoTreeData = (data: LogInfo[]): any => ...@@ -42,11 +42,11 @@ export const buildLogInfoTreeData = (data: LogInfo[]): any =>
name: item.name, name: item.name,
parentId: item.parentId, parentId: item.parentId,
label: item.path, label: item.path,
icon: item.leaf && renderIcon(item.name, '.', item.leaf), icon: renderIcon(item.name, '.', item.leaf),
path: item.path, path: item.path,
title: buildTitleLabel(item), title: buildTitleLabel(item),
fullInfo: item, fullInfo: item,
key: item.id, key: item.id ?? item.name,
id: item.id, id: item.id,
children: buildLogInfoTreeData(item.children) children: buildLogInfoTreeData(item.children)
}; };
......
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
import LogsShow from '@/pages/SettingCenter/SystemLogs/TagInfo/LogList/LogsShow'; import LogsShow from '@/pages/SettingCenter/SystemLogs/TagInfo/LogList/LogsShow';
...@@ -62,12 +64,19 @@ const LogList = () => { ...@@ -62,12 +64,19 @@ const LogList = () => {
return ( return (
<> <>
<ProCard ghost bordered> <ProCard bodyStyle={{ height: parent.innerHeight - 160 }} ghost bordered>
<ProCard ghost hoverable bordered colSpan={'18%'} className={'siderTree'}> <ProCard
ghost
bodyStyle={{ height: parent.innerHeight - 160 }}
hoverable
bordered
colSpan={'18%'}
className={'siderTree'}
>
<LogsTree treeData={treeData} onNodeClick={(info: any) => handleNodeClick(info)} /> <LogsTree treeData={treeData} onNodeClick={(info: any) => handleNodeClick(info)} />
</ProCard> </ProCard>
<ProCard.Divider type={'vertical'} /> <ProCard.Divider type={'vertical'} />
<ProCard ghost hoverable bordered> <ProCard ghost bodyStyle={{ height: parent.innerHeight - 175 }} hoverable bordered>
<LogsShow code={log} refreshLogCallback={() => refreshLogByClickNode()} /> <LogsShow code={log} refreshLogCallback={() => refreshLogByClickNode()} />
</ProCard> </ProCard>
</ProCard> </ProCard>
......
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
import { LogSvg } from '@/components/Icons/CodeLanguageIcon'; import { LogSvg } from '@/components/Icons/CodeLanguageIcon';
...@@ -74,6 +76,7 @@ const TagInfo = () => { ...@@ -74,6 +76,7 @@ const TagInfo = () => {
size='small' size='small'
bordered bordered
tabs={{ tabs={{
size: 'small',
activeKey: activeKey, activeKey: activeKey,
type: 'card', type: 'card',
animated: true, animated: true,
......
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
/**
* theme of nav
*/
export const THEME = { export const THEME = {
NAV_THEME: 'navTheme', NAV_THEME: 'navTheme',
dark: 'realDark', dark: 'realDark',
...@@ -54,3 +53,17 @@ export type ExcludeNameAndEnableColumns = { ...@@ -54,3 +53,17 @@ export type ExcludeNameAndEnableColumns = {
createTime: Date; createTime: Date;
updateTime: Date; updateTime: Date;
}; };
export type SuggestionLabel = {
label: string;
detail?: string;
description?: string;
};
export type SuggestionInfo = {
key: string | number;
label: SuggestionLabel;
kind: number;
insertText: string;
detail?: string;
};
This diff is collapsed.
...@@ -2338,7 +2338,7 @@ COMMENT ON COLUMN "public"."dinky_resources"."update_time" IS 'update time'; ...@@ -2338,7 +2338,7 @@ COMMENT ON COLUMN "public"."dinky_resources"."update_time" IS 'update time';
-- ---------------------------- -- ----------------------------
-- Records of dinky_resources -- Records of dinky_resources
-- ---------------------------- -- ----------------------------
INSERT INTO "public"."dinky_resources" VALUES (1, 'Root', 'main folder', 1, 0, 0, -1, '/', 1, '2023-06-28 20:20:13', '2023-06-28 20:20:13'); INSERT INTO "public"."dinky_resources" VALUES (1, 'Root', 'main folder', 1, 0, 0, -1, '', 1, '2023-06-28 20:20:13', '2023-06-28 20:20:13');
-- ---------------------------- -- ----------------------------
-- Indexes structure for table dinky_resources -- Indexes structure for table dinky_resources
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
SET NAMES utf8mb4; SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0; SET FOREIGN_KEY_CHECKS = 0;
begin ;
-- rename table -- rename table
ALTER TABLE dlink_alert_group RENAME dinky_alert_group; ALTER TABLE dlink_alert_group RENAME dinky_alert_group;
ALTER TABLE dlink_alert_history RENAME dinky_alert_history; ALTER TABLE dlink_alert_history RENAME dinky_alert_history;
...@@ -312,4 +313,6 @@ drop table if exists dinky_jar; ...@@ -312,4 +313,6 @@ drop table if exists dinky_jar;
drop table if exists dinky_schema_history; drop table if exists dinky_schema_history;
drop table if exists dinky_upload_file_record; drop table if exists dinky_upload_file_record;
commit ;
SET FOREIGN_KEY_CHECKS = 1; SET FOREIGN_KEY_CHECKS = 1;
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
*/ */
begin ;
delete from `dinky_task_statement` where id in (select id from `dinky_task` where `name` = 'dlink_default_catalog'); delete from `dinky_task_statement` where id in (select id from `dinky_task` where `name` = 'dlink_default_catalog');
delete from `dinky_task` where `name` = 'dlink_default_catalog'; delete from `dinky_task` where `name` = 'dlink_default_catalog';
...@@ -58,7 +59,7 @@ UPDATE `dinky_sys_config` SET `name` = 'flink.settings.useRestAPI' where `name` ...@@ -58,7 +59,7 @@ UPDATE `dinky_sys_config` SET `name` = 'flink.settings.useRestAPI' where `name`
UPDATE `dinky_sys_config` SET `name` = 'flink.settings.sqlSeparator' where `name` = 'sqlSeparator'; UPDATE `dinky_sys_config` SET `name` = 'flink.settings.sqlSeparator' where `name` = 'sqlSeparator';
UPDATE `dinky_sys_config` SET `name` = 'flink.settings.jobIdWait' where `name` = 'jobIdWait'; UPDATE `dinky_sys_config` SET `name` = 'flink.settings.jobIdWait' where `name` = 'jobIdWait';
INSERT INTO `dinky_resources` (`id`, `file_name`, `description`, `user_id`, `type`, `size`, `pid`, `full_name`, `is_directory`) VALUES (0, 'Root', 'main folder', 1, 0, 0, -1, '/Root', 1); INSERT INTO `dinky_resources` (`id`, `file_name`, `description`, `user_id`, `type`, `size`, `pid`, `full_name`, `is_directory`) VALUES (0, 'Root', 'main folder', 1, 0, 0, -1, '', 1);
-- ---------------------------- -- ----------------------------
...@@ -685,4 +686,8 @@ AS SELECT id, name, age FROM source_table WHERE mod(id, 10) = 0;', 'All Versions ...@@ -685,4 +686,8 @@ AS SELECT id, name, age FROM source_table WHERE mod(id, 10) = 0;', 'All Versions
-- 修改 dinky_udf_template 表的 enable 字段 不允许为空 默认为 1 -- 修改 dinky_udf_template 表的 enable 字段 不允许为空 默认为 1
alter table dinky_udf_template modify column `enabled` tinyint(1) not null default 1 comment 'is enable, 0:no 1:yes'; alter table dinky_udf_template modify column `enabled` tinyint(1) not null default 1 comment 'is enable, 0:no 1:yes';
\ No newline at end of file
commit ;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment