diff --git a/static/app/views/settings/project/projectOwnership/addCodeOwnerModal.tsx b/static/app/views/settings/project/projectOwnership/addCodeOwnerModal.tsx index f5aeabc540697b..f46fce5722bfb1 100644 --- a/static/app/views/settings/project/projectOwnership/addCodeOwnerModal.tsx +++ b/static/app/views/settings/project/projectOwnership/addCodeOwnerModal.tsx @@ -42,7 +42,7 @@ type State = { isLoading: boolean; } & DeprecatedAsyncComponent['state']; -class AddCodeOwnerModal extends DeprecatedAsyncComponent { +export default class AddCodeOwnerModal extends DeprecatedAsyncComponent { getDefaultState() { return { ...super.getDefaultState(), @@ -135,83 +135,6 @@ class AddCodeOwnerModal extends DeprecatedAsyncComponent { this.props.closeModal(); } - sourceFile(codeownersFile: CodeownersFile) { - return ( - - - - {codeownersFile.filepath} - - {t('Preview File')} - - - - ); - } - - errorMessage(baseUrl: any) { - const {errorJSON, codeMappingId, codeMappings} = this.state; - const codeMapping = codeMappings.find(mapping => mapping.id === codeMappingId); - const {integrationId, provider} = codeMapping as RepositoryProjectPathConfig; - const errActors = errorJSON?.raw?.[0]!.split('\n').map((el, i) => ( -

{el}

- )); - return ( - - {errActors} - {codeMapping && ( -

- {tct( - 'Configure [userMappingsLink:User Mappings] or [teamMappingsLink:Team Mappings] for any missing associations.', - { - userMappingsLink: ( - - ), - teamMappingsLink: ( - - ), - } - )} -

- )} - {tct( - '[addAndSkip:Add and Skip Missing Associations] will add your codeowner file and skip any rules that having missing associations. You can add associations later for any skipped rules.', - {addAndSkip: Add and Skip Missing Associations} - )} -
- ); - } - - noSourceFile() { - const {codeMappingId, isLoading} = this.state; - if (isLoading) { - return ( - - - - ); - } - if (!codeMappingId) { - return null; - } - return ( - - - {codeMappingId ? ( - - - {t('No codeowner file found.')} - - ) : null} - - - ); - } - renderBody() { const {Header, Body, Footer} = this.props; const {codeownersFile, error, errorJSON, codeMappings, integrations} = this.state; @@ -277,8 +200,22 @@ class AddCodeOwnerModal extends DeprecatedAsyncComponent { /> - {codeownersFile ? this.sourceFile(codeownersFile) : this.noSourceFile()} - {error && errorJSON && this.errorMessage(baseUrl)} + {codeownersFile ? ( + + ) : ( + + )} + {error && errorJSON ? ( + + ) : null} )} @@ -298,7 +235,94 @@ class AddCodeOwnerModal extends DeprecatedAsyncComponent { } } -export default AddCodeOwnerModal; +function SourceFile({codeownersFile}: {codeownersFile: CodeownersFile}) { + return ( + + + + {codeownersFile.filepath} + + {t('Preview File')} + + + + ); +} + +function NoSourceFile({ + codeMappingId, + isLoading, +}: { + codeMappingId: string | null; + isLoading: boolean; +}) { + if (isLoading) { + return ( + + + + ); + } + if (!codeMappingId) { + return null; + } + return ( + + + {codeMappingId ? ( + + + {t('No codeowner file found.')} + + ) : null} + + + ); +} + +function ErrorMessage({ + baseUrl, + codeMappingId, + codeMappings, + errorJSON, +}: { + baseUrl: string; + codeMappingId: string | null; + codeMappings: RepositoryProjectPathConfig[]; + errorJSON: {raw?: string} | null; +}) { + const codeMapping = codeMappings.find(mapping => mapping.id === codeMappingId); + const {integrationId, provider} = codeMapping as RepositoryProjectPathConfig; + const errActors = errorJSON?.raw?.[0]!.split('\n').map((el, i) =>

{el}

); + return ( + + {errActors} + {codeMapping && ( +

+ {tct( + 'Configure [userMappingsLink:User Mappings] or [teamMappingsLink:Team Mappings] for any missing associations.', + { + userMappingsLink: ( + + ), + teamMappingsLink: ( + + ), + } + )} +

+ )} + {tct( + '[addAndSkip:Add and Skip Missing Associations] will add your codeowner file and skip any rules that having missing associations. You can add associations later for any skipped rules.', + {addAndSkip: Add and Skip Missing Associations} + )} +
+ ); +} const StyledSelectField = styled(SelectField)` border-bottom: None;