Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 03657d6

Browse files
sarikesunlei
authored andcommitted
fix: query cancel block other query execution and some table issues
(cherry picked from commit 6c6d33a47bbf15e06a3acec09291fede6bcef45e)
1 parent 6915aa3 commit 03657d6

File tree

11 files changed

+53
-26
lines changed

11 files changed

+53
-26
lines changed

client/packages/openblocks-design/src/components/CustomModal.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ const ModalHeaderWrapper = styled.div<{ $draggable?: boolean }>`
3535
cursor: ${(props) => (props.$draggable ? "move" : "auto")};
3636
display: flex;
3737
align-items: center;
38-
line-height: 26px;
39-
padding: 11px 16px;
38+
padding: 16px;
4039
`;
4140

4241
const ModalHeaderTitle = styled.div`

client/packages/openblocks/src/api/queryApi.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ export class QueryApi extends Api {
5050

5151
static queryExecuteCancelTokenSource: Record<string, CancelTokenSource> = {};
5252

53+
static cancelAllQuery() {
54+
Object.values(QueryApi.queryExecuteCancelTokenSource).forEach((s) => {
55+
s.cancel();
56+
});
57+
QueryApi.queryExecuteCancelTokenSource = {};
58+
}
59+
5360
static executeQuery(
5461
request: QueryExecuteRequest,
5562
timeout?: number

client/packages/openblocks/src/comps/comps/layout/mobileTabLayout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ MobileTabLayoutTmp = withViewFn(MobileTabLayoutTmp, (comp) => {
157157
currentTab.children.app.getAppId() &&
158158
currentTab.children.app.getView()) || (
159159
<EmptyContent
160-
text={trans("aggregation.emptyTabTooltip")}
160+
text={readOnly ? "" : trans("aggregation.emptyTabTooltip")}
161161
style={{ height: "100%", backgroundColor: "white" }}
162162
/>
163163
);

client/packages/openblocks/src/comps/comps/tableComp/column/tableColumnListComp.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { ColumnComp, newPrimaryColumn } from "comps/comps/tableComp/column/tableColumnComp";
2-
import { calcColumnWidth, COLUMN_CHILDREN_KEY } from "comps/comps/tableComp/tableUtils";
2+
import {
3+
calcColumnWidth,
4+
COLUMN_CHILDREN_KEY,
5+
supportChildrenTree,
6+
} from "comps/comps/tableComp/tableUtils";
37
import { list } from "comps/generators/list";
48
import { getReduceContext } from "comps/utils/reduceContext";
59
import _ from "lodash";
@@ -123,18 +127,18 @@ export class ColumnListComp extends ColumnListTmpComp {
123127
return;
124128
}
125129
const dataIndex = column.getView().dataIndex;
126-
if (!dataKeys.find((key) => dataIndex === key)) {
130+
if (dataIndex === COLUMN_CHILDREN_KEY || !dataKeys.find((key) => dataIndex === key)) {
127131
// to Delete
128132
actions.push(this.deleteAction(index - deleteCnt));
129133
deleteCnt += 1;
130134
}
131135
});
132136
// The order should be the same as the data
133137
dataKeys.forEach((key) => {
134-
if (
135-
key !== COLUMN_CHILDREN_KEY &&
136-
!columnsView.find((column) => column.getView().dataIndex === key)
137-
) {
138+
if (key === COLUMN_CHILDREN_KEY && supportChildrenTree(data)) {
139+
return;
140+
}
141+
if (!columnsView.find((column) => column.getView().dataIndex === key)) {
138142
// to Add
139143
actions.push(this.pushAction(newPrimaryColumn(key, calcColumnWidth(key, data))));
140144
}

client/packages/openblocks/src/comps/comps/tableComp/tableComp.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
sortData,
1616
transformDispalyData,
1717
tranToTableRecord,
18+
supportChildrenTree,
1819
} from "comps/comps/tableComp/tableUtils";
1920
import { isTriggerAction } from "comps/controls/actionSelector/actionSelectorControl";
2021
import { withPropertyViewFn, withViewFn } from "comps/generators";
@@ -60,6 +61,7 @@ export class TableImplComp extends TableInitComp implements IContainer {
6061
private getSlotContainer() {
6162
return this.children.expansion.children.slot.getSelectedComp().getComp().children.container;
6263
}
64+
6365
findContainer(key: string) {
6466
return this.getSlotContainer().findContainer(key);
6567
}
@@ -291,8 +293,11 @@ export class TableImplComp extends TableInitComp implements IContainer {
291293
const filteredDataNode = withFunction(fromRecord(nodes), (input) => {
292294
const { data, searchValue, filter, showFilter } = input;
293295
const filteredData = filterData(data, searchValue.value, filter, showFilter.value);
296+
const supportChildren = supportChildrenTree(filteredData);
294297
// console.info("filterNode. data: ", data, " filter: ", filter, " filteredData: ", filteredData);
295-
return filteredData.map((row) => tranToTableRecord(row, row[OB_ROW_ORI_INDEX]));
298+
return filteredData.map((row) =>
299+
tranToTableRecord(row, row[OB_ROW_ORI_INDEX], supportChildren)
300+
);
296301
});
297302
return lastValueIfEqual(this, "filteredDataNode", [filteredDataNode, nodes] as const, (a, b) =>
298303
shallowEqual(a[1], b[1])
@@ -390,7 +395,7 @@ function _indexKeyToRecord(data: JSONObject[], key: string) {
390395
let res = undefined;
391396
for (let k of keyPath) {
392397
const index = Number(k);
393-
if (index >= 0 && currentData && index < currentData.length) {
398+
if (index >= 0 && Array.isArray(currentData) && index < currentData.length) {
394399
res = currentData[index];
395400
currentData = res[COLUMN_CHILDREN_KEY] as JSONObject[];
396401
}

client/packages/openblocks/src/comps/comps/tableComp/tableCompView.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
CustomColumnType,
1111
onTableChange,
1212
RecordType,
13+
supportChildrenTree,
1314
} from "comps/comps/tableComp/tableUtils";
1415
import {
1516
defaultTheme,
@@ -137,7 +138,7 @@ const getStyle = (style: TableStyleType) => {
137138
}
138139
139140
// link color
140-
td a {
141+
td :not(li) > a {
141142
color: ${isDark && "#A6FFFF"};
142143
143144
&:hover {
@@ -568,6 +569,7 @@ export function TableCompView(props: {
568569
onEvent={onEvent}
569570
/>
570571
);
572+
const supportChildren = supportChildrenTree(data);
571573

572574
return (
573575
<BackgroundColorContext.Provider value={style.background}>
@@ -576,7 +578,9 @@ export function TableCompView(props: {
576578
<ResizeableTable<RecordType>
577579
expandable={{
578580
...expansion.expandableConfig,
579-
childrenColumnName: COLUMN_CHILDREN_KEY,
581+
childrenColumnName: supportChildren
582+
? COLUMN_CHILDREN_KEY
583+
: "OB_CHILDREN_KEY_PLACEHOLDER",
580584
fixed: "left",
581585
}}
582586
rowColor={compChildren.rowColor.getView() as any}

client/packages/openblocks/src/comps/comps/tableComp/tableUtils.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { EditableIcon } from "openblocks-design";
1616
import { tryToNumber } from "util/convertUtils";
1717
import { JSONObject, JSONValue } from "util/jsonTypes";
1818
import { StatusType } from "./column/columnTypeComps/columnStatusComp";
19-
import { ColumnListComp } from "./column/tableColumnListComp";
19+
import { ColumnListComp, tableDataRowExample } from "./column/tableColumnListComp";
2020

2121
export const COLUMN_CHILDREN_KEY = "children";
2222
export const OB_ROW_ORI_INDEX = "__ob_origin_index";
@@ -113,14 +113,18 @@ export function buildOriginIndex(index: string, childIndex: string) {
113113
return index + "-" + childIndex;
114114
}
115115

116-
export function tranToTableRecord(dataObj: JSONObject, index: string | number): RecordType {
116+
export function tranToTableRecord(
117+
dataObj: JSONObject,
118+
index: string | number,
119+
supportChildren: boolean
120+
): RecordType {
117121
const indexString = index + "";
118-
if (Array.isArray(dataObj[COLUMN_CHILDREN_KEY])) {
122+
if (supportChildren && Array.isArray(dataObj[COLUMN_CHILDREN_KEY])) {
119123
return {
120124
...dataObj,
121125
[OB_ROW_ORI_INDEX]: indexString,
122126
children: dataObj[COLUMN_CHILDREN_KEY].map((child: any, i: number) =>
123-
tranToTableRecord(child, buildOriginIndex(indexString, i + ""))
127+
tranToTableRecord(child, buildOriginIndex(indexString, i + ""), supportChildren)
124128
),
125129
};
126130
}
@@ -135,6 +139,7 @@ export function getOriDisplayData(
135139
pageSize: number,
136140
columns: Array<{ dataIndex: string; render: NodeToValue<ReturnType<Render["node"]>> }>
137141
) {
142+
const supportChildren = supportChildrenTree(data);
138143
return data.map((row, idx) => {
139144
const displayData: JSONObject = {};
140145
columns.forEach((col) => {
@@ -145,7 +150,7 @@ export function getOriDisplayData(
145150
currentIndex: idx % pageSize,
146151
currentOriginalIndex: row[OB_ROW_ORI_INDEX],
147152
}) as any;
148-
if (Array.isArray(row[COLUMN_CHILDREN_KEY])) {
153+
if (supportChildren && Array.isArray(row[COLUMN_CHILDREN_KEY])) {
149154
displayData[COLUMN_CHILDREN_KEY] = getOriDisplayData(
150155
row[COLUMN_CHILDREN_KEY] as Array<RecordType>,
151156
pageSize,
@@ -380,3 +385,8 @@ export function genSelectionParams(
380385
currentOriginalIndex: tryToNumber(currentRow[OB_ROW_ORI_INDEX]),
381386
};
382387
}
388+
389+
export function supportChildrenTree(data: Array<JSONObject>) {
390+
const rowSample = tableDataRowExample(data) as any;
391+
return rowSample && Array.isArray(rowSample[COLUMN_CHILDREN_KEY]);
392+
}

client/packages/openblocks/src/i18n/locales/en.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,9 +1952,9 @@ export const en = {
19521952
app: "App",
19531953
navigation: "Navigation",
19541954
navLayout: "PC Navigation",
1955-
navLayoutDesc: "Provide left side navigation",
1955+
navLayoutDesc: "Left-side menu for easy desktop navigation.",
19561956
mobileTabLayout: "Mobile Navigation",
1957-
mobileTabLayoutDesc: "Provide bottom side navigation",
1957+
mobileTabLayoutDesc: "Bottom navigation bar for smooth mobile browsing.",
19581958
folders: "Folders",
19591959
folder: "Folder",
19601960
rootFolder: "Root",

client/packages/openblocks/src/pages/ApplicationV2/CreateDropdown.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ const LayoutPickWrapper = styled.div`
9393
const LayoutItemWrapper = styled.div`
9494
background: #f9fafb;
9595
cursor: pointer;
96-
width: 160px;
96+
width: 184px;
9797
border: 1px solid #eeeeee;
9898
border-radius: 4px;
9999
display: flex;

client/packages/openblocks/src/pages/ApplicationV2/HomeResCard.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const ExecButton = styled(TacoButton)`
3636
width: 52px;
3737
height: 24px;
3838
padding: 5px 12px;
39-
margin-right: 44px;
39+
margin-right: 24px;
4040
background: #fafbff;
4141
border: 1px solid #c9d1fc;
4242
border-radius: 4px;
@@ -105,6 +105,7 @@ const CardInfo = styled.div`
105105
flex-grow: 1;
106106
cursor: pointer;
107107
overflow: hidden;
108+
padding-right: 12px;
108109
109110
:hover {
110111
.ant-typography {

client/packages/openblocks/src/pages/editor/appEditorInternal.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,7 @@ export function useRootCompInstance(appInfo: AppSummaryInfo, readOnly: boolean,
9292

9393
useUnmount(() => {
9494
comp?.clearPreload();
95-
96-
Object.values(QueryApi.queryExecuteCancelTokenSource).forEach((s) => {
97-
s.cancel();
98-
});
95+
QueryApi.cancelAllQuery();
9996
});
10097

10198
return useMemo(() => {

0 commit comments

Comments
 (0)