Skip to content

Commit

Permalink
fix: remove readonly props from react components (#2946)
Browse files Browse the repository at this point in the history
* fix: remove readonly props from react components

React components were incorrectly exposing readonly properties as setable via Props
This change updates the generation script to correctly handle readonly properties
The generation script now handles empty propTypes and import collections
Empty prop types are not exported
  • Loading branch information
gavinbarron authored Jan 16, 2024
1 parent 11459db commit 267bc19
Show file tree
Hide file tree
Showing 22 changed files with 62 additions and 84 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,4 @@
"responselike": "2.0.0"
},
"packageManager": "yarn@3.6.3"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
/**
* The type of user to search for. Default is any.
*
* @readonly
* @type {UserType}
* @memberof MgtPeoplePicker
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/mgt-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@
"publishConfig": {
"access": "public"
}
}
}
23 changes: 14 additions & 9 deletions packages/mgt-react/scripts/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const generateTags = (tags, fileName) => {
const prop = tag.members[i];
let type = prop.type?.text;

if (type && prop.kind === 'field' && prop.privacy === 'public' && !prop.static) {
if (type && prop.kind === 'field' && prop.privacy === 'public' && !prop.static && !prop.readonly) {
if (prop.name) {
props[prop.name] = type;
}
Expand Down Expand Up @@ -148,8 +148,11 @@ const generateTags = (tags, fileName) => {
}
}
}

output += `\nexport type ${className}Props = {\n${propsType}}\n`;
if (propsType) {
output += `\nexport type ${className}Props = {\n${propsType}}\n`;
} else {
output += `\ntype ${className}Props = Record<string, never>\n`;
}
}

for (const wrapper of wrappers) {
Expand All @@ -160,16 +163,18 @@ const generateTags = (tags, fileName) => {

const componentTypeImports = Array.from(mgtComponentImports).join(',');
const initialLine = componentTypeImports
? `import { ${componentTypeImports} } from '@microsoft/mgt-components/dist/es6/exports';
? `import { ${componentTypeImports} } from '@microsoft/mgt-components';
`
: '';
output = `/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/consistent-type-definitions */
${initialLine}import { ${Array.from(registrationFunctions).join(
','
)} } from '@microsoft/mgt-components/dist/es6/components/components';
import { ${Array.from(mgtElementImports).join(',')} } from '@microsoft/mgt-element';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
${initialLine}import { ${Array.from(registrationFunctions).join(',')} } from '@microsoft/mgt-components';
${
mgtElementImports.size > 0
? `import { ${Array.from(mgtElementImports).join(',')} } from '@microsoft/mgt-element';
`
: ''
}// eslint-disable-next-line @typescript-eslint/no-unused-vars
import * as MicrosoftGraph from '@microsoft/microsoft-graph-types';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import * as MicrosoftGraphBeta from '@microsoft/microsoft-graph-types-beta';
Expand Down
5 changes: 2 additions & 3 deletions packages/mgt-react/src/generated/agenda.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/consistent-type-definitions */
import { registerMgtAgendaComponent } from '@microsoft/mgt-components/dist/es6/components/components';
import { TemplateContext,ComponentMediaQuery,TemplateRenderedData } from '@microsoft/mgt-element';
import { registerMgtAgendaComponent } from '@microsoft/mgt-components';
import { TemplateContext,TemplateRenderedData } from '@microsoft/mgt-element';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import * as MicrosoftGraph from '@microsoft/microsoft-graph-types';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand All @@ -18,7 +18,6 @@ export type AgendaProps = {
groupByDay?: boolean;
preferredTimezone?: string;
templateContext?: TemplateContext;
mediaQuery?: ComponentMediaQuery;
templateRendered?: (e: CustomEvent<TemplateRenderedData>) => void;
}

Expand Down
9 changes: 3 additions & 6 deletions packages/mgt-react/src/generated/file-list.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/consistent-type-definitions */
import { OfficeGraphInsightString,ViewType } from '@microsoft/mgt-components/dist/es6/exports';
import { registerMgtFileListComponent } from '@microsoft/mgt-components/dist/es6/components/components';
import { TemplateContext,ComponentMediaQuery,TemplateRenderedData } from '@microsoft/mgt-element';
import { OfficeGraphInsightString,ViewType } from '@microsoft/mgt-components';
import { registerMgtFileListComponent } from '@microsoft/mgt-components';
import { TemplateContext,TemplateRenderedData } from '@microsoft/mgt-element';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import * as MicrosoftGraph from '@microsoft/microsoft-graph-types';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand All @@ -11,8 +11,6 @@ import {wrapMgt} from '../Mgt';

export type FileListProps = {
fileListQuery?: string;
displayName?: string;
cardTitle?: string;
fileQueries?: string[];
files?: MicrosoftGraph.DriveItem[];
siteId?: string;
Expand All @@ -32,7 +30,6 @@ export type FileListProps = {
maxUploadFile?: number;
excludedFileExtensions?: string[];
templateContext?: TemplateContext;
mediaQuery?: ComponentMediaQuery;
itemClick?: (e: CustomEvent<MicrosoftGraph.DriveItem>) => void;
templateRendered?: (e: CustomEvent<TemplateRenderedData>) => void;
}
Expand Down
7 changes: 3 additions & 4 deletions packages/mgt-react/src/generated/file.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/consistent-type-definitions */
import { OfficeGraphInsightString,ViewType } from '@microsoft/mgt-components/dist/es6/exports';
import { registerMgtFileComponent } from '@microsoft/mgt-components/dist/es6/components/components';
import { TemplateContext,ComponentMediaQuery,TemplateRenderedData } from '@microsoft/mgt-element';
import { OfficeGraphInsightString,ViewType } from '@microsoft/mgt-components';
import { registerMgtFileComponent } from '@microsoft/mgt-components';
import { TemplateContext,TemplateRenderedData } from '@microsoft/mgt-element';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import * as MicrosoftGraph from '@microsoft/microsoft-graph-types';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand All @@ -28,7 +28,6 @@ export type FileProps = {
line3Property?: string;
view?: ViewType;
templateContext?: TemplateContext;
mediaQuery?: ComponentMediaQuery;
templateRendered?: (e: CustomEvent<TemplateRenderedData>) => void;
}

Expand Down
7 changes: 3 additions & 4 deletions packages/mgt-react/src/generated/get.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/consistent-type-definitions */
import { ResponseType,DataChangedDetail } from '@microsoft/mgt-components/dist/es6/exports';
import { registerMgtGetComponent } from '@microsoft/mgt-components/dist/es6/components/components';
import { TemplateContext,ComponentMediaQuery,TemplateRenderedData } from '@microsoft/mgt-element';
import { ResponseType,DataChangedDetail } from '@microsoft/mgt-components';
import { registerMgtGetComponent } from '@microsoft/mgt-components';
import { TemplateContext,TemplateRenderedData } from '@microsoft/mgt-element';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import * as MicrosoftGraph from '@microsoft/microsoft-graph-types';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand All @@ -20,7 +20,6 @@ export type GetProps = {
cacheInvalidationPeriod?: number;
response?: any;
templateContext?: TemplateContext;
mediaQuery?: ComponentMediaQuery;
dataChange?: (e: CustomEvent<DataChangedDetail>) => void;
templateRendered?: (e: CustomEvent<TemplateRenderedData>) => void;
}
Expand Down
7 changes: 3 additions & 4 deletions packages/mgt-react/src/generated/login.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/consistent-type-definitions */
import { IDynamicPerson,LoginViewType } from '@microsoft/mgt-components/dist/es6/exports';
import { registerMgtLoginComponent } from '@microsoft/mgt-components/dist/es6/components/components';
import { TemplateContext,ComponentMediaQuery,TemplateRenderedData } from '@microsoft/mgt-element';
import { IDynamicPerson,LoginViewType } from '@microsoft/mgt-components';
import { registerMgtLoginComponent } from '@microsoft/mgt-components';
import { TemplateContext,TemplateRenderedData } from '@microsoft/mgt-element';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import * as MicrosoftGraph from '@microsoft/microsoft-graph-types';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand All @@ -14,7 +14,6 @@ export type LoginProps = {
showPresence?: boolean;
loginView?: LoginViewType;
templateContext?: TemplateContext;
mediaQuery?: ComponentMediaQuery;
loginInitiated?: (e: CustomEvent<undefined>) => void;
loginCompleted?: (e: CustomEvent<undefined>) => void;
loginFailed?: (e: CustomEvent<undefined>) => void;
Expand Down
7 changes: 3 additions & 4 deletions packages/mgt-react/src/generated/people-picker.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/consistent-type-definitions */
import { PersonType,GroupType,UserType,IDynamicPerson } from '@microsoft/mgt-components/dist/es6/exports';
import { registerMgtPeoplePickerComponent } from '@microsoft/mgt-components/dist/es6/components/components';
import { TemplateContext,ComponentMediaQuery,TemplateRenderedData } from '@microsoft/mgt-element';
import { PersonType,GroupType,UserType,IDynamicPerson } from '@microsoft/mgt-components';
import { registerMgtPeoplePickerComponent } from '@microsoft/mgt-components';
import { TemplateContext,TemplateRenderedData } from '@microsoft/mgt-element';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import * as MicrosoftGraph from '@microsoft/microsoft-graph-types';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down Expand Up @@ -33,7 +33,6 @@ export type PeoplePickerProps = {
groupFilters?: string;
ariaLabel?: string;
templateContext?: TemplateContext;
mediaQuery?: ComponentMediaQuery;
selectionChanged?: (e: CustomEvent<IDynamicPerson[]>) => void;
templateRendered?: (e: CustomEvent<TemplateRenderedData>) => void;
}
Expand Down
7 changes: 3 additions & 4 deletions packages/mgt-react/src/generated/people.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/consistent-type-definitions */
import { IDynamicPerson,PersonCardInteraction } from '@microsoft/mgt-components/dist/es6/exports';
import { registerMgtPeopleComponent } from '@microsoft/mgt-components/dist/es6/components/components';
import { TemplateContext,ComponentMediaQuery,TemplateRenderedData } from '@microsoft/mgt-element';
import { IDynamicPerson,PersonCardInteraction } from '@microsoft/mgt-components';
import { registerMgtPeopleComponent } from '@microsoft/mgt-components';
import { TemplateContext,TemplateRenderedData } from '@microsoft/mgt-element';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import * as MicrosoftGraph from '@microsoft/microsoft-graph-types';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand All @@ -22,7 +22,6 @@ export type PeopleProps = {
scopes?: string[];
fallbackDetails?: IDynamicPerson[];
templateContext?: TemplateContext;
mediaQuery?: ComponentMediaQuery;
templateRendered?: (e: CustomEvent<TemplateRenderedData>) => void;
}

Expand Down
7 changes: 3 additions & 4 deletions packages/mgt-react/src/generated/person-card.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/consistent-type-definitions */
import { IDynamicPerson } from '@microsoft/mgt-components/dist/es6/exports';
import { registerMgtPersonCardComponent } from '@microsoft/mgt-components/dist/es6/components/components';
import { TemplateContext,ComponentMediaQuery,TemplateRenderedData } from '@microsoft/mgt-element';
import { IDynamicPerson } from '@microsoft/mgt-components';
import { registerMgtPersonCardComponent } from '@microsoft/mgt-components';
import { TemplateContext,TemplateRenderedData } from '@microsoft/mgt-element';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import * as MicrosoftGraph from '@microsoft/microsoft-graph-types';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand All @@ -21,7 +21,6 @@ export type PersonCardProps = {
showPresence?: boolean;
personPresence?: MicrosoftGraph.Presence;
templateContext?: TemplateContext;
mediaQuery?: ComponentMediaQuery;
expanded?: (e: CustomEvent<null>) => void;
templateRendered?: (e: CustomEvent<TemplateRenderedData>) => void;
}
Expand Down
7 changes: 3 additions & 4 deletions packages/mgt-react/src/generated/person.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/consistent-type-definitions */
import { IDynamicPerson,AvatarSize,PersonCardInteraction,ViewType,PersonViewType } from '@microsoft/mgt-components/dist/es6/exports';
import { registerMgtPersonComponent } from '@microsoft/mgt-components/dist/es6/components/components';
import { TemplateContext,ComponentMediaQuery,TemplateRenderedData } from '@microsoft/mgt-element';
import { IDynamicPerson,AvatarSize,PersonCardInteraction,ViewType,PersonViewType } from '@microsoft/mgt-components';
import { registerMgtPersonComponent } from '@microsoft/mgt-components';
import { TemplateContext,TemplateRenderedData } from '@microsoft/mgt-element';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import * as MicrosoftGraph from '@microsoft/microsoft-graph-types';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down Expand Up @@ -30,7 +30,6 @@ export type PersonProps = {
line4Property?: string;
view?: ViewType | PersonViewType;
templateContext?: TemplateContext;
mediaQuery?: ComponentMediaQuery;
line1clicked?: (e: CustomEvent<IDynamicPerson>) => void;
line2clicked?: (e: CustomEvent<IDynamicPerson>) => void;
line3clicked?: (e: CustomEvent<IDynamicPerson>) => void;
Expand Down
5 changes: 2 additions & 3 deletions packages/mgt-react/src/generated/picker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/consistent-type-definitions */
import { registerMgtPickerComponent } from '@microsoft/mgt-components/dist/es6/components/components';
import { TemplateContext,ComponentMediaQuery,TemplateRenderedData } from '@microsoft/mgt-element';
import { registerMgtPickerComponent } from '@microsoft/mgt-components';
import { TemplateContext,TemplateRenderedData } from '@microsoft/mgt-element';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import * as MicrosoftGraph from '@microsoft/microsoft-graph-types';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand All @@ -20,7 +20,6 @@ export type PickerProps = {
cacheInvalidationPeriod?: number;
selectedValue?: string;
templateContext?: TemplateContext;
mediaQuery?: ComponentMediaQuery;
selectionChanged?: (e: CustomEvent<any>) => void;
templateRendered?: (e: CustomEvent<TemplateRenderedData>) => void;
}
Expand Down
7 changes: 3 additions & 4 deletions packages/mgt-react/src/generated/planner.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/consistent-type-definitions */
import { TaskFilter,ITask } from '@microsoft/mgt-components/dist/es6/exports';
import { registerMgtPlannerComponent } from '@microsoft/mgt-components/dist/es6/components/components';
import { TemplateContext,ComponentMediaQuery,TemplateRenderedData } from '@microsoft/mgt-element';
import { TaskFilter,ITask } from '@microsoft/mgt-components';
import { registerMgtPlannerComponent } from '@microsoft/mgt-components';
import { TemplateContext,TemplateRenderedData } from '@microsoft/mgt-element';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import * as MicrosoftGraph from '@microsoft/microsoft-graph-types';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand All @@ -21,7 +21,6 @@ export type PlannerProps = {
groupId?: string;
taskFilter?: TaskFilter;
templateContext?: TemplateContext;
mediaQuery?: ComponentMediaQuery;
taskAdded?: (e: CustomEvent<ITask>) => void;
taskChanged?: (e: CustomEvent<ITask>) => void;
taskClick?: (e: CustomEvent<ITask>) => void;
Expand Down
4 changes: 1 addition & 3 deletions packages/mgt-react/src/generated/search-box.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/consistent-type-definitions */
import { registerMgtSearchBoxComponent } from '@microsoft/mgt-components/dist/es6/components/components';
import { ComponentMediaQuery } from '@microsoft/mgt-element';
import { registerMgtSearchBoxComponent } from '@microsoft/mgt-components';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import * as MicrosoftGraph from '@microsoft/microsoft-graph-types';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand All @@ -12,7 +11,6 @@ export type SearchBoxProps = {
placeholder?: string;
searchTerm?: string;
debounceDelay?: number;
mediaQuery?: ComponentMediaQuery;
searchTermChanged?: (e: CustomEvent<string>) => void;
}

Expand Down
8 changes: 3 additions & 5 deletions packages/mgt-react/src/generated/search-results.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/consistent-type-definitions */
import { DataChangedDetail } from '@microsoft/mgt-components/dist/es6/exports';
import { registerMgtSearchResultsComponent } from '@microsoft/mgt-components/dist/es6/components/components';
import { TemplateContext,ComponentMediaQuery,TemplateRenderedData } from '@microsoft/mgt-element';
import { DataChangedDetail } from '@microsoft/mgt-components';
import { registerMgtSearchResultsComponent } from '@microsoft/mgt-components';
import { TemplateContext,TemplateRenderedData } from '@microsoft/mgt-element';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import * as MicrosoftGraph from '@microsoft/microsoft-graph-types';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand All @@ -16,7 +16,6 @@ export type SearchResultsProps = {
scopes?: string[];
contentSources?: string[];
version?: string;
from?: number;
size?: number;
pagingMax?: number;
fetchThumbnail?: boolean;
Expand All @@ -26,7 +25,6 @@ export type SearchResultsProps = {
cacheInvalidationPeriod?: number;
currentPage?: number;
templateContext?: TemplateContext;
mediaQuery?: ComponentMediaQuery;
dataChange?: (e: CustomEvent<DataChangedDetail>) => void;
templateRendered?: (e: CustomEvent<TemplateRenderedData>) => void;
}
Expand Down
7 changes: 2 additions & 5 deletions packages/mgt-react/src/generated/spinner.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/consistent-type-definitions */
import { registerMgtSpinnerComponent } from '@microsoft/mgt-components/dist/es6/components/components';
import { ComponentMediaQuery } from '@microsoft/mgt-element';
import { registerMgtSpinnerComponent } from '@microsoft/mgt-components';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import * as MicrosoftGraph from '@microsoft/microsoft-graph-types';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import * as MicrosoftGraphBeta from '@microsoft/microsoft-graph-types-beta';
import {wrapMgt} from '../Mgt';

export type SpinnerProps = {
mediaQuery?: ComponentMediaQuery;
}
type SpinnerProps = Record<string, never>

export const Spinner = wrapMgt<SpinnerProps>('spinner', registerMgtSpinnerComponent);

5 changes: 2 additions & 3 deletions packages/mgt-react/src/generated/taxonomy-picker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/consistent-type-definitions */
import { registerMgtTaxonomyPickerComponent } from '@microsoft/mgt-components/dist/es6/components/components';
import { TemplateContext,ComponentMediaQuery,TemplateRenderedData } from '@microsoft/mgt-element';
import { registerMgtTaxonomyPickerComponent } from '@microsoft/mgt-components';
import { TemplateContext,TemplateRenderedData } from '@microsoft/mgt-element';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import * as MicrosoftGraph from '@microsoft/microsoft-graph-types';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand All @@ -22,7 +22,6 @@ export type TaxonomyPickerProps = {
cacheEnabled?: boolean;
cacheInvalidationPeriod?: number;
templateContext?: TemplateContext;
mediaQuery?: ComponentMediaQuery;
selectionChanged?: (e: CustomEvent<MicrosoftGraph.TermStore.Term>) => void;
templateRendered?: (e: CustomEvent<TemplateRenderedData>) => void;
}
Expand Down
Loading

0 comments on commit 267bc19

Please sign in to comment.