Skip to content

Commit

Permalink
fixup! fix: git services page
Browse files Browse the repository at this point in the history
  • Loading branch information
akurinnoy committed Nov 25, 2024
1 parent 7df2eb5 commit f6c7a6d
Showing 1 changed file with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export type Props = {

type State = {
selectedItems: IGitOauth[];
sortedGitOauth: IGitOauth[];
};

export class GitServicesList extends React.PureComponent<Props, State> {
Expand All @@ -58,9 +59,20 @@ export class GitServicesList extends React.PureComponent<Props, State> {

this.state = {
selectedItems: [],
sortedGitOauth: this.sortServices(props.gitOauth),
};
}

/**
* Sort by display name
*/
private sortServices(gitOauth: IGitOauth[]): IGitOauth[] {
const services = cloneDeep(gitOauth);
return services.sort((serviceA, serviceB) => {
return GIT_OAUTH_PROVIDERS[serviceA.name].localeCompare(GIT_OAUTH_PROVIDERS[serviceB.name]);
});
}

private buildHeadRow(): React.ReactElement {
return (
<Tr>
Expand All @@ -74,19 +86,19 @@ export class GitServicesList extends React.PureComponent<Props, State> {
}

private handleSelectItem(isSelected: boolean, rowIndex: number): void {
const { gitOauth } = this.props;
const { sortedGitOauth } = this.state;

/* c8 ignore start */
if (rowIndex === -1) {
// Select all (header row checked)
const selectedItems = isSelected && gitOauth.length > 0 ? gitOauth : [];
const selectedItems = isSelected && sortedGitOauth.length > 0 ? sortedGitOauth : [];
this.setState({ selectedItems });
return;
}
/* c8 ignore stop */

// Select single row
const selectedItem = gitOauth[rowIndex];
const selectedItem = sortedGitOauth[rowIndex];
this.setState((prevState: State) => {
return {
selectedItems: isSelected
Expand All @@ -104,18 +116,9 @@ export class GitServicesList extends React.PureComponent<Props, State> {
}

private buildBody(): React.ReactNode[] {
const gitOauth = cloneDeep(this.props.gitOauth);
const { sortedGitOauth } = this.state;

return (
gitOauth
// sort by display name
.sort((serviceA, serviceB) => {
return GIT_OAUTH_PROVIDERS[serviceA.name].localeCompare(
GIT_OAUTH_PROVIDERS[serviceB.name],
);
})
.map((service, rowIndex) => this.buildBodyRow(service, rowIndex))
);
return sortedGitOauth.map((service, rowIndex) => this.buildBodyRow(service, rowIndex));
}

private buildBodyRow(service: IGitOauth, rowIndex: number) {
Expand Down

0 comments on commit f6c7a6d

Please sign in to comment.