MCPcopy Create free account
hub / github.com/bytebase/bytebase / getTableTreeOptions

Function getTableTreeOptions

frontend/src/utils/v1/databaseResource.ts:72–117  ·  view source on GitHub ↗
({
  prefix,
  tableList,
  filterValueList,
  includeColumn,
}: {
  prefix: string;
  tableList: TableMetadata[];
  filterValueList?: string[];
  includeColumn: boolean;
})

Source from the content-addressed store, hash-verified

70};
71
72const getTableTreeOptions = ({
73 prefix,
74 tableList,
75 filterValueList,
76 includeColumn,
77}: {
78 prefix: string;
79 tableList: TableMetadata[];
80 filterValueList?: string[];
81 includeColumn: boolean;
82}): DatabaseTreeOption<"tables">[] => {
83 const tableNodes = tableList.map((table): DatabaseTreeOption<"tables"> => {
84 const option: DatabaseTreeOption<"tables"> = {
85 level: "tables",
86 value: `${prefix}/tables/${table.name}`,
87 label: table.name,
88 isLeaf: true,
89 };
90 if (includeColumn) {
91 option.children = table.columns.map(
92 (column): DatabaseTreeOption<"columns"> => ({
93 level: "columns",
94 value: `${option.value}/columns/${column.name}`,
95 label: column.name,
96 isLeaf: true,
97 })
98 );
99 if (filterValueList) {
100 option.children = option.children.filter((node) =>
101 filterValueList.includes(node.value)
102 );
103 }
104 }
105 if (option.children && option.children.length > 0) {
106 option.isLeaf = false;
107 }
108 return option;
109 });
110 return filterValueList
111 ? tableNodes.filter((node) =>
112 filterValueList.some(
113 (value) => value.split("/columns/")[0] === node.value
114 )
115 )
116 : tableNodes;
117};
118
119export const getSchemaOrTableTreeOptions = ({
120 database,

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected