Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into feat/navbar
Browse files Browse the repository at this point in the history
  • Loading branch information
jcxldn committed Jun 27, 2023
2 parents 3cad084 + e70f971 commit d5effa0
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
name: Lint

on: push
on:
push:
branches:
- main

jobs:
lint:
name: Lint (Prettier)
name: Prettier (check)
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/lint-write.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Lint

on:
pull_request:

jobs:
prettier:
permissions:
contents: write
name: Prettier (write)
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
# Make sure the actual branch is checked out when running on pull requests
ref: ${{ github.head_ref }}

- name: Prettify code
uses: creyD/prettier_action@v4.3
with:
only_changed: True
commit_message: "(lint): Run prettier against ${{ github.sha }}"
prettier_options: "--write ."
11 changes: 9 additions & 2 deletions src/filters/teamEntryFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ import { FilterChip } from "../types/team/filterChip";
const teamEntryFilter = (
entries: React.JSX.Element[],
searchQuery: string,
filterChip: FilterChip
filterChip: FilterChip,
shouldIncludeTagsInSearch: boolean
) => {
return entries.filter(entry => {
// Cast entry (React.JSX.Element to CreditEntry)
const entryCast = entry as unknown as CreditEntry;

return searchFilter(entryCast, searchQuery) && chipFilter(entryCast, filterChip);
return (
searchFilter(entryCast, searchQuery) &&
// If we are not including tags in the search, return true instead of the chipFilter query
// Since we are using an &&, the return statement will not return true unless both filters return true
// Therefore, returning true for this filter is like it never existed
(shouldIncludeTagsInSearch ? chipFilter(entryCast, filterChip) : true)
);
});
};

Expand Down
38 changes: 35 additions & 3 deletions src/pages/team.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import "bootstrap/dist/css/bootstrap.min.css";
import { CreditEntry } from "../components/team/creditEntry";
import { TeamMemberNode } from "../types/graphql/teamMemberNode";
import {
Checkbox,
Chip,
createTheme,
Divider,
FormControlLabel,
FormGroup,
MenuItem,
SimplePaletteColorOptions,
TextField,
Expand All @@ -34,6 +38,7 @@ interface TeamPageState {
isReady: boolean;
searchQuery: string;
filterChip: FilterChip;
shouldIncludeTagsInSearch: boolean;
}

// Use React.PureComponent for TS types on this.props <https://github.com/gatsbyjs/gatsby/issues/8431#issue-362717669>
Expand All @@ -48,6 +53,7 @@ export default class TeamPage extends React.PureComponent<
isReady: false,
searchQuery: "",
filterChip: [],
shouldIncludeTagsInSearch: true,
};
}

Expand All @@ -61,6 +67,8 @@ export default class TeamPage extends React.PureComponent<
muiTheme: Theme | undefined = undefined;
muiPaletteOptions: ExtendablePalette = {};

shouldIncludeTagsInSearch: boolean;

componentDidMount(): void {
this.setState({ isReady: false });

Expand Down Expand Up @@ -195,6 +203,13 @@ export default class TeamPage extends React.PureComponent<
});
}

handleShouldIncTagsChange(event: React.ChangeEvent<HTMLInputElement>) {
console.log(this.shouldIncludeTagsInSearch);
this.setState({
shouldIncludeTagsInSearch: event.target.checked,
});
}

render(): React.ReactNode {
if (!this.state["isReady"]) {
return <div>Preparing...</div>;
Expand All @@ -218,11 +233,11 @@ export default class TeamPage extends React.PureComponent<
elements={this.state.filterChip.map(entry => {
// Filter chips
return (
<MenuItem>
// onClick is on the MenuItem otherwis it only triggers when the chip itself is clicked.
<MenuItem onClick={(event: any) => this.handleChipClick(event, entry)}>
<Chip
variant={entry.enabled ? "filled" : "outlined"}
deleteIcon={entry.enabled ? <></> : <AddIcon />}
onClick={(event: any) => this.handleChipClick(event, entry)}
label={capitalizeWords(entry.tag.name)}
color={entry.tag.paletteName}
size="small"
Expand All @@ -232,8 +247,25 @@ export default class TeamPage extends React.PureComponent<
);
})}
/>
{/** Should be enclosed in FormGroup but that makes a newline. Shhh! */}
<FormControlLabel
control={
<Checkbox
defaultChecked
onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
this.handleShouldIncTagsChange(event)
}
/>
}
label="Include tags in search?"
/>
</div>
{teamEntryFilter(this.entries, this.state.searchQuery, this.state.filterChip)}
{teamEntryFilter(
this.entries,
this.state.searchQuery,
this.state.filterChip,
this.state.shouldIncludeTagsInSearch
)}
</ThemeProvider>
);
}
Expand Down

0 comments on commit d5effa0

Please sign in to comment.