Skip to content

Commit

Permalink
fix: some overall page types (#44)
Browse files Browse the repository at this point in the history
fix: some overall page types
  • Loading branch information
easy1090 authored Dec 6, 2023
1 parent 96d0d68 commit 8d34bc8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/three-bulldogs-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rsdoctor/components': patch
---

fix(components): some components types.
4 changes: 0 additions & 4 deletions packages/components/src/components/Alert/change.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ export const CodeChangeDrawerContent: React.FC<CodeChangeAlertProps & FixedProps
};

const FixButton = () => {
if (process.env.NODE_ENV !== 'development') {
// TODO implement open codebase mr.
return null;
}
return (
<Popconfirm
title={`Did you confirm to apply the change i the area below ?`}
Expand Down
29 changes: 15 additions & 14 deletions packages/components/src/utils/file.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { get, startsWith } from 'lodash-es';
import { Common } from '@rsdoctor/types';
import { message, UploadFile } from 'antd';
import { FieldDataNode } from 'rc-tree';

export type DataNode = any; // TODO: types
type DataNode = FieldDataNode<{
key: string | number;
title?: React.ReactNode | ((data: DataNode) => React.ReactNode);
}> & { __BASENAME__?: any; __RESOURCEPATH__?: any; children?: DataNode[] };

export const rootDirname = (file: string, sep = '/'): string | null => {
const idx = file?.indexOf(sep);
Expand Down Expand Up @@ -42,7 +46,7 @@ export function flattenDirectory(
n: DataNode,
parent: DataNode,
sep = '/',
inlinedResourcePathKey: string,
inlinedResourcePathKey: keyof DataNode,
dirTitle = (_dir: DataNode, defaultTitle: string): JSX.Element | string => defaultTitle,
) {
if (n.isLeaf) return;
Expand All @@ -55,15 +59,15 @@ export function flattenDirectory(
parent.title = dirTitle(parent, defaultTitle);

n.children &&
n.children.forEach((c: any) => {
n.children.forEach((c) => {
flattenDirectory(c, parent, sep, inlinedResourcePathKey, dirTitle);
});
} else {
// parent has more than 1 child.
n.title = dirTitle(n, n[basenameKey]);

n.children &&
n.children.forEach((c: any) => {
n.children.forEach((c) => {
flattenDirectory(c, n, sep, inlinedResourcePathKey, dirTitle);
});
}
Expand All @@ -79,7 +83,7 @@ export function createFileStructures({
files: string[];
cwd?: string;
sep?: string;
inlinedResourcePathKey?: string;
inlinedResourcePathKey?: keyof DataNode;
dirTitle?(dir: DataNode, defaultTitle: string): JSX.Element | string;
fileTitle?(file: string, basename: string): JSX.Element | string;
}): DataNode[] {
Expand All @@ -93,8 +97,7 @@ export function createFileStructures({

while (dir) {
// find the match directory.
// eslint-disable-next-line no-loop-func
let exist = parent.children!.find((e: { title: string | null; }) => e.title === dir);
let exist = parent.children!.find((e) => e.title === dir) as DataNode;
if (!exist) {
const p = [parent[inlinedResourcePathKey], dir].filter(Boolean).join(sep);
exist = {
Expand All @@ -114,7 +117,7 @@ export function createFileStructures({
}

// uniq
if (parent.children!.some((e: any) => get(e, inlinedResourcePathKey) === file)) return t;
if (parent.children!.some((e) => get(e, inlinedResourcePathKey) === file)) return t;

parent.children!.push({
title() {
Expand All @@ -125,21 +128,19 @@ export function createFileStructures({
isLeaf: true,
[inlinedResourcePathKey]: file,
[basenameKey]: basename,
} as any);
});

return t;
},
{ key: '0', children: [] },
).children!;

res.forEach((e: { children: any[]; }) => {
res.forEach((e) => {
e.children &&
e.children.forEach((item: any) => {
flattenDirectory(item, e, sep, inlinedResourcePathKey, dirTitle);
});
e.children.forEach((item) => flattenDirectory(item, e, sep, inlinedResourcePathKey, dirTitle));
});

return res as DataNode[];
return res;
}

export function beautifyPath(path: string, cwd: string) {
Expand Down
5 changes: 2 additions & 3 deletions packages/components/src/utils/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ const manifestUrlForDev = '/manifest.json';
export function getManifestUrl(): string {
let file: string | void;

if (window[Manifest.DoctorManifestClientConstant.WindowPropertyForManifestUrl as any]) {
if ((window as { [key: string]: any })[Manifest.DoctorManifestClientConstant.WindowPropertyForManifestUrl]) {
// load from window property
// @ts-ignore
file = window[Manifest.DoctorManifestClientConstant.WindowPropertyForManifestUrl]; // TODO: types
file = (window as { [key: string]: any })[Manifest.DoctorManifestClientConstant.WindowPropertyForManifestUrl];
} else {
// load from url query
file = getManifestUrlFromUrlQuery();
Expand Down

0 comments on commit 8d34bc8

Please sign in to comment.