Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignored properties still show in api table #1981

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions src/features/parser.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,47 @@
import type AtomAssetsParser from '@/assetParsers/atom';
import type { IApi } from '@/types';
import { lodash } from '@umijs/utils';
import assert from 'assert';
import { ATOMS_META_PATH } from './meta';

type IParsedAtomAssets = Awaited<ReturnType<AtomAssetsParser['parse']>>;

function filterIgnoredProps(
props: IParsedAtomAssets['components'][string]['propsConfig']['properties'],
) {
return lodash.pickBy(props, (prop) => {
let isHidden = false;

if (prop.type === 'array' && 'items' in prop) {
prop.items = filterIgnoredProps({ _: prop.items! })._;
} else if (prop.type === 'object' && 'properties' in prop) {
prop.properties = filterIgnoredProps(prop.properties!);
} else if (prop.oneOf) {
prop.oneOf = prop.oneOf.map((item) => filterIgnoredProps({ _: item })._);
} else if (prop.allOf) {
prop.allOf = prop.allOf.map((item) => filterIgnoredProps({ _: item })._);
} else if ('hidden' in prop) {
isHidden = true;
}

return !isHidden;
});
}

export default (api: IApi) => {
let prevData: Awaited<ReturnType<AtomAssetsParser['parse']>>;
let prevData: IParsedAtomAssets;
const writeAtomsMetaFile = (data: typeof prevData) => {
// filter ignored properties
const components = lodash.mapValues(data.components, (component) => ({
...component,
propsConfig: filterIgnoredProps({ _: component.propsConfig })._,
}));

api.writeTmpFile({
noPluginDir: true,
path: ATOMS_META_PATH,
content: `export const components = ${JSON.stringify(
data.components,
components,
null,
2,
)};`,
Expand Down
Loading