Skip to content

Commit

Permalink
fix(model generation): schema names and count
Browse files Browse the repository at this point in the history
  • Loading branch information
Libertonius authored Jan 27, 2025
1 parent b5d7457 commit d66b948
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 40 deletions.
3 changes: 2 additions & 1 deletion public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@
"row_limit": "Row Limit",
"versions": "Versions",
"version": "Version",
"default": "default",
"default": "Default",
"no_schema": "No schema",
"find": "Find",
"edit_teams": "Edit teams",
"roles_and_access": "Roles and access",
Expand Down
3 changes: 2 additions & 1 deletion public/locales/ru/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@
"row_limit": "Лимит строк",
"versions": "Версии",
"version": "Версия",
"default": "по умолчанию",
"default": "По умолчанию",
"no_schema": "Без схемы",
"find": "Найти",
"edit_teams": "Редактировать команды",
"roles_and_access": "Роли и доступ",
Expand Down
1 change: 1 addition & 0 deletions public/locales/zh/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"versions": "版本",
"version": "版本",
"default": "默认",
"no_schema": "无模式",
"find": "查找",
"edit_teams": "编辑命令",
"roles_and_access": "角色与访问",
Expand Down
2 changes: 1 addition & 1 deletion src/components/BranchSelection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const BranchSelection: React.FC<BranchSelectionProps> = ({
label: b.name,
title:
b.status === Branch_Statuses_Enum.Active
? `${b.name}-${t("common:words.default")}`
? `${b.name}-${t("common:words.default").toLowerCase()}`
: b.name,
status: b.status,
}))}
Expand Down
19 changes: 13 additions & 6 deletions src/components/DataModelGeneration/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,18 @@ const DataModelGeneration: FC<DataModelGenerationProps> = ({
const [searchValue, setSearchValue] = useState<string>("");

const getCount = (val: DynamicForm, key: string) => {
if (val[key]) {
return Object.keys(val[key]).filter((k) => val?.[key]?.[k] === true)
.length;
} else {
return 0;
const keys = key.split(".");
let current = val;

for (const k of keys) {
if (current[k]) {
current = current[k];
} else {
return 0;
}
}

return Object.keys(current).filter((k) => current[k] === true).length;
};

const onFormSubmit = (data: DynamicForm, type: string) => {
Expand Down Expand Up @@ -132,7 +138,8 @@ const DataModelGeneration: FC<DataModelGenerationProps> = ({
className={styles.collapse}
header={
<span className={styles.collapseHeader}>
{s} {count > 0 && <span>({count})</span>}
{s === "no_schema" ? t("common:words.no_schema") : s}
{count > 0 && <span>({count})</span>}
</span>
}
key={s}
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useOnboarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import type {
} from "@/types/dataSource";
import useCheckResponse from "@/hooks/useCheckResponse";
import { getSourceAndBranch } from "@/pages/Explore";
import flattenTables from "@/utils/helpers/flattenTables";
import getTables from "@/utils/helpers/getTables";

interface Props {
editId?: string;
Expand Down Expand Up @@ -101,7 +101,7 @@ export default ({ editId }: Props) => {
const onDataModelGenerationSubmit = async (data: DynamicForm) => {
let tables = { ...data } as any;
delete tables.type;
tables = flattenTables(tables);
tables = getTables(tables);

if (dataSourceSetup && !branchId) {
message.error(`${t("no_branch")} ${dataSourceSetup.name}`);
Expand Down
12 changes: 0 additions & 12 deletions src/utils/helpers/flattenTables.ts

This file was deleted.

36 changes: 19 additions & 17 deletions src/utils/helpers/getTables.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
export default function getTables(obj: object, prefix: string = "") {
return Object.entries(obj).reduce((acc: { name: string }[], [key, value]) => {
let result = acc;
const newPath = prefix ? `${prefix}.${key}` : key;
return Object.entries(obj).reduce(
(acc: { schema: string; name: string }[], [key, value]) => {
let result = acc;
const newPath = prefix ? `${prefix}.${key}` : key;

if (value === true) {
const lastSlashIndex = newPath.lastIndexOf(".");
const formattedPath = `${newPath.slice(
0,
lastSlashIndex
)}.${newPath.slice(lastSlashIndex + 1)}`;
result.push({ name: formattedPath });
}
if (value === true) {
const lastDotIndex = newPath.lastIndexOf(".");
const schema =
lastDotIndex !== -1 ? newPath.slice(0, lastDotIndex) : "";
const name = newPath.slice(lastDotIndex + 1);
result.push({ schema, name });
}

if (typeof value === "object") {
const childResults = getTables(value, newPath);
result = acc.concat(childResults);
}
if (typeof value === "object" && value !== null) {
const childResults = getTables(value, newPath);
result = acc.concat(childResults);
}

return result;
}, []);
return result;
},
[]
);
}

0 comments on commit d66b948

Please sign in to comment.