|
@@ -13,7 +13,8 @@ import {IconCheckmark, IconNot} from 'app/icons';
|
|
|
import {t, tct} from 'app/locale';
|
|
|
import space from 'app/styles/space';
|
|
|
import {
|
|
|
- CodeOwners,
|
|
|
+ CodeOwner,
|
|
|
+ CodeownersFile,
|
|
|
Integration,
|
|
|
Organization,
|
|
|
Project,
|
|
@@ -30,26 +31,20 @@ type Props = {
|
|
|
project: Project;
|
|
|
codeMappings: RepositoryProjectPathConfig[];
|
|
|
integrations: Integration[];
|
|
|
- onSave: (data: CodeOwners) => void;
|
|
|
+ onSave: (data: CodeOwner) => void;
|
|
|
} & ModalRenderProps;
|
|
|
|
|
|
type State = {
|
|
|
- codeownerFile: CodeOwnerFile | null;
|
|
|
+ codeownersFile: CodeownersFile | null;
|
|
|
codeMappingId: string | null;
|
|
|
isLoading: boolean;
|
|
|
error: boolean;
|
|
|
errorJSON: {raw?: string} | null;
|
|
|
};
|
|
|
|
|
|
-type CodeOwnerFile = {
|
|
|
- raw: string;
|
|
|
- filepath: string;
|
|
|
- html_url: string;
|
|
|
-};
|
|
|
-
|
|
|
class AddCodeOwnerModal extends Component<Props, State> {
|
|
|
state: State = {
|
|
|
- codeownerFile: null,
|
|
|
+ codeownersFile: null,
|
|
|
codeMappingId: null,
|
|
|
isLoading: false,
|
|
|
error: false,
|
|
@@ -60,19 +55,19 @@ class AddCodeOwnerModal extends Component<Props, State> {
|
|
|
const {organization} = this.props;
|
|
|
this.setState({
|
|
|
codeMappingId,
|
|
|
- codeownerFile: null,
|
|
|
+ codeownersFile: null,
|
|
|
error: false,
|
|
|
errorJSON: null,
|
|
|
isLoading: true,
|
|
|
});
|
|
|
try {
|
|
|
- const data: CodeOwnerFile = await this.props.api.requestPromise(
|
|
|
+ const data: CodeownersFile = await this.props.api.requestPromise(
|
|
|
`/organizations/${organization.slug}/code-mappings/${codeMappingId}/codeowners/`,
|
|
|
{
|
|
|
method: 'GET',
|
|
|
}
|
|
|
);
|
|
|
- this.setState({codeownerFile: data, isLoading: false});
|
|
|
+ this.setState({codeownersFile: data, isLoading: false});
|
|
|
} catch (_err) {
|
|
|
this.setState({isLoading: false});
|
|
|
}
|
|
@@ -80,15 +75,15 @@ class AddCodeOwnerModal extends Component<Props, State> {
|
|
|
|
|
|
addFile = async () => {
|
|
|
const {organization, project, codeMappings} = this.props;
|
|
|
- const {codeownerFile, codeMappingId} = this.state;
|
|
|
+ const {codeownersFile, codeMappingId} = this.state;
|
|
|
|
|
|
- if (codeownerFile) {
|
|
|
+ if (codeownersFile) {
|
|
|
const postData: {
|
|
|
codeMappingId: string | null;
|
|
|
raw: string;
|
|
|
} = {
|
|
|
codeMappingId,
|
|
|
- raw: codeownerFile.raw,
|
|
|
+ raw: codeownersFile.raw,
|
|
|
};
|
|
|
|
|
|
try {
|
|
@@ -113,18 +108,18 @@ class AddCodeOwnerModal extends Component<Props, State> {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- handleAddedFile(data: CodeOwners) {
|
|
|
+ handleAddedFile(data: CodeOwner) {
|
|
|
this.props.onSave(data);
|
|
|
this.props.closeModal();
|
|
|
}
|
|
|
|
|
|
- sourceFile(codeownerFile: CodeOwnerFile) {
|
|
|
+ sourceFile(codeownersFile: CodeownersFile) {
|
|
|
return (
|
|
|
<Panel>
|
|
|
<SourceFileBody>
|
|
|
<IconCheckmark size="md" isCircled color="green200" />
|
|
|
- {codeownerFile.filepath}
|
|
|
- <Button size="small" href={codeownerFile.html_url} target="_blank">
|
|
|
+ {codeownersFile.filepath}
|
|
|
+ <Button size="small" href={codeownersFile.html_url} target="_blank">
|
|
|
{t('Preview File')}
|
|
|
</Button>
|
|
|
</SourceFileBody>
|
|
@@ -196,7 +191,7 @@ class AddCodeOwnerModal extends Component<Props, State> {
|
|
|
|
|
|
render() {
|
|
|
const {Header, Body, Footer} = this.props;
|
|
|
- const {codeownerFile, error, errorJSON} = this.state;
|
|
|
+ const {codeownersFile, error, errorJSON} = this.state;
|
|
|
const {codeMappings, integrations, organization} = this.props;
|
|
|
const baseUrl = `/settings/${organization.slug}/integrations`;
|
|
|
|
|
@@ -247,7 +242,7 @@ class AddCodeOwnerModal extends Component<Props, State> {
|
|
|
/>
|
|
|
|
|
|
<FileResult>
|
|
|
- {codeownerFile ? this.sourceFile(codeownerFile) : this.noSourceFile()}
|
|
|
+ {codeownersFile ? this.sourceFile(codeownersFile) : this.noSourceFile()}
|
|
|
{error && errorJSON && this.errorMessage(baseUrl)}
|
|
|
</FileResult>
|
|
|
</Form>
|
|
@@ -255,7 +250,7 @@ class AddCodeOwnerModal extends Component<Props, State> {
|
|
|
</Body>
|
|
|
<Footer>
|
|
|
<Button
|
|
|
- disabled={codeownerFile ? false : true}
|
|
|
+ disabled={codeownersFile ? false : true}
|
|
|
label={t('Add File')}
|
|
|
priority="primary"
|
|
|
onClick={this.addFile}
|