Skip to content

Debug - #1

Open
roares wants to merge 10 commits into
oss-know:masterfrom
roares:debug
Open

roares wants to merge 10 commits into
oss-know:masterfrom
roares:debug

Conversation

@roares

@roares roares commented Nov 9, 2022 •

Copy link
Copy Markdown

SUMMARY

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

};

export const TableSelectorMultiple: FunctionComponent<TableSelectorProps> =
export const TableSelectorMultiple: FunctionComponent<TableSelectorProps>=

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此处删掉了空格(应该保留),最好在IDE中配置好prettier,在Save文件时,自动执行prettier进行代码格式化,避免手工维护代码格式

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的,已修改.

];
setTemplatesInfo(templatesInfo);
// 获取templates
// 赋值

@crystaldust crystaldust Nov 9, 2022 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对于语义已经很明显的代码,不必再额外写注释说明(100行)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

删掉了多余的注释.


// 触发template切换事件,然后这里要替换currentTemplate
function changeTemplate(value) {
if (value) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里有一个潜在的陷阱,如果template id从0开始编号, if (0) 会判定为false。
最好和后端接口开发人员限定好,value用字符串类型,并且具备一定的语义,如"COMPANY_CONTRIBUTION_DISTRIBUTION"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里我参数命名错误,value实际上是一个object,
类似 {key: ...,label:...,value: ...}

Comment thread superset-frontend/src/components/TemplateSelector/index.jsx
);
}

function renderParamsInput(templateParams) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的变量命名注意名词的单复数,根据169行,传入的是"某一个模板参数",这里用复数容易引起误解,以为是一个数组类型,用templateParam即可

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的,已修改

schema: activeQueryEditor ? activeQueryEditor.schema : null,
autorun: false,
sql: `${warning}SELECT ...`,
sql: `${warning}SELECT ...。。。。。ss`,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这部分提示信息不是必需的

@@ -0,0 +1,51 @@
/**

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/components目录下新增的几个组件,看上去功能和代码量都不大,可以考虑直接写成components/AddLabel.tsx这样的文件即可。components/COMPONENT_NAME/index.tsx这种结构,一般会用于大型的组件,大型组件中为了完成相关功能,又包含很多小型组件,最终结构大概会变成:

  • components/index.tsx
  • components/sub_component_1.tsx
  • components/sub_component_2.tsx
  • components/utils.ts

因为单个子组件或者工具脚本要单独存放在代码文件中,才会创建component/COMPONENT_NAME/这个目录

@@ -0,0 +1,50 @@
/**

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此外,AddLabel,DeleteLabel的命名非常通用化,字面意思似乎是“添加Label”,“删除Label”,无法直接理解其含义。可以考虑用具体一些的名称,或者能够准确表达组件功能的名称。


const [buttonLoading, setButtonLoading] = useState(false);
const [params, setParams] = useState({});
const [template_id, setTemplateId] = useState('');

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

变量的命名尽量统一,在JavaScript/TypeScript里一般推荐驼峰命名,python和http接口一般用下划线风格


function postTemplateParamsData(payload: object) {
return SupersetClient.post({
url: 'http://192.168.8.60:5000/api/dataset',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一般访问地址不能写死在代码里,通过环境变量、配置文件等方式传入

.catch(e => {
setButtonLoading(false);
console.log('error', e);
// 这里应该改成错误提示信息弹出框

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果是待完成的功能,可以在注释开头增加TODO字样,这样现代IDE会自动分析,可以看到所有代办的任务:

// TODO Do something in the future

</>
);
}
function DatasetNameChange(value: string) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

函数命名风格统一,保持驼峰命名


export const TableSelectorMultiple: FunctionComponent<TableSelectorProps> =
props => <TableSelector tableSelectMode="multiple" {...props} />;
export const TableSelectorMultiple: FunctionComponent<

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这部分代码没有实质变化,原代码的风格是推荐的风格


useEffect(() => {
if (currentTemplate) {
const par = {};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

par命名过于简略,容易产生多种含以上的猜测,用param即可

}

function renderParamsInput(templateParam) {
return templateParam.description.indexOf('json数组') === -1

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个判定条件有点不稳定,需要前后端一起确认一种比较可靠的校验方式

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants