From c56771b7f1620026fb80d1737f8e1a2565b325de Mon Sep 17 00:00:00 2001 From: James Cahill Date: Mon, 26 Jun 2023 18:56:19 +0100 Subject: [PATCH 1/7] Move Chip onClick to MenuItem --- src/pages/team.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/team.tsx b/src/pages/team.tsx index 36de9ddf..d8aac9e9 100644 --- a/src/pages/team.tsx +++ b/src/pages/team.tsx @@ -216,11 +216,11 @@ export default class TeamPage extends React.PureComponent< elements={this.state.filterChip.map(entry => { // Filter chips return ( - + // onClick is on the MenuItem otherwis it only triggers when the chip itself is clicked. + this.handleChipClick(event, entry)}> : } - onClick={(event: any) => this.handleChipClick(event, entry)} label={capitalizeWords(entry.tag.name)} color={entry.tag.paletteName} size="small" From 8361d8ad04cabc84f10bd87c531ba0e6d32eaffe Mon Sep 17 00:00:00 2001 From: James Cahill Date: Mon, 26 Jun 2023 19:36:52 +0100 Subject: [PATCH 2/7] (pages/team): Add checkbox to include tag filter in search --- src/filters/teamEntryFilter.ts | 11 +++++++++-- src/pages/team.tsx | 19 ++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/filters/teamEntryFilter.ts b/src/filters/teamEntryFilter.ts index b86e2371..88919b96 100644 --- a/src/filters/teamEntryFilter.ts +++ b/src/filters/teamEntryFilter.ts @@ -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) + ); }); }; diff --git a/src/pages/team.tsx b/src/pages/team.tsx index d8aac9e9..faea93f4 100644 --- a/src/pages/team.tsx +++ b/src/pages/team.tsx @@ -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, @@ -33,6 +37,7 @@ interface TeamPageState { isReady: boolean; searchQuery: string; filterChip: FilterChip; + shouldIncludeTagsInSearch: boolean; } // Use React.PureComponent for TS types on this.props @@ -47,6 +52,7 @@ export default class TeamPage extends React.PureComponent< isReady: false, searchQuery: "", filterChip: [], + shouldIncludeTagsInSearch: true }; } @@ -60,6 +66,8 @@ export default class TeamPage extends React.PureComponent< muiTheme: Theme | undefined = undefined; muiPaletteOptions: ExtendablePalette = {}; + shouldIncludeTagsInSearch: boolean; + componentDidMount(): void { this.setState({ isReady: false }); @@ -194,6 +202,13 @@ export default class TeamPage extends React.PureComponent< }); } + handleShouldIncTagsChange(event: React.ChangeEvent) { + console.log(this.shouldIncludeTagsInSearch) + this.setState({ + shouldIncludeTagsInSearch: event.target.checked + }) + } + render(): React.ReactNode { if (!this.state["isReady"]) { return
Preparing...
; @@ -230,8 +245,10 @@ export default class TeamPage extends React.PureComponent< ); })} /> + {/** Should be enclosed in FormGroup but that makes a newline. Shhh! */} + ) => this.handleShouldIncTagsChange(event)} />} label="Include tags in search?" /> - {teamEntryFilter(this.entries, this.state.searchQuery, this.state.filterChip)} + {teamEntryFilter(this.entries, this.state.searchQuery, this.state.filterChip, this.state.shouldIncludeTagsInSearch)} ); } From 2dac7d034c64b7b8a1d5f94da2297d2b526d8f02 Mon Sep 17 00:00:00 2001 From: James Cahill Date: Tue, 27 Jun 2023 08:07:24 +0100 Subject: [PATCH 3/7] (ci/github): Update prettier action to lint and commit --- .github/workflows/lint.yml | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c43720c9..4f600cf3 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,20 +1,25 @@ name: Lint -on: push +on: + pull_request: + push: + branches: + - main jobs: - lint: - name: Lint (Prettier) + prettier: + name: Prettier 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: Setup Node.js - uses: actions/setup-node@v3 - - - name: Install dependencies - run: npm ci --no-scripts - - - name: Run prettier - run: npx prettier -c . + - name: Prettify code + uses: creyD/prettier_action@v4.3 + with: + only_changed: True + commit_message: "(lint): Run prettier against ${{ github.sha }}" + prettier_options: "--write ." From 2086ef7f3fa5fede6709f678af387a9ce0d617b0 Mon Sep 17 00:00:00 2001 From: James Cahill Date: Tue, 27 Jun 2023 08:13:40 +0100 Subject: [PATCH 4/7] (ci/github/lint): Grant contents:write permission --- .github/workflows/lint.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 4f600cf3..b28712cd 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -8,6 +8,8 @@ on: jobs: prettier: + permissions: + contents: write name: Prettier runs-on: ubuntu-latest steps: From 053dfbdf34b6e5d8fc0bfe82d3c1f874fc753360 Mon Sep 17 00:00:00 2001 From: James Cahill Date: Tue, 27 Jun 2023 08:16:48 +0100 Subject: [PATCH 5/7] (ci/github/lint/write): Only run on PRs, rename file and job --- .github/workflows/{lint.yml => lint-write.yml} | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) rename .github/workflows/{lint.yml => lint-write.yml} (91%) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint-write.yml similarity index 91% rename from .github/workflows/lint.yml rename to .github/workflows/lint-write.yml index b28712cd..acd7edee 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint-write.yml @@ -2,15 +2,12 @@ name: Lint on: pull_request: - push: - branches: - - main jobs: prettier: permissions: contents: write - name: Prettier + name: Prettier (write) runs-on: ubuntu-latest steps: - name: Checkout repository From d4961c08229086a44cfebec11c3f0dc51919265d Mon Sep 17 00:00:00 2001 From: James Cahill Date: Tue, 27 Jun 2023 08:17:36 +0100 Subject: [PATCH 6/7] (ci/github/lint/check): Re-add check job on main branch only --- .github/workflows/lint-check.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/lint-check.yml diff --git a/.github/workflows/lint-check.yml b/.github/workflows/lint-check.yml new file mode 100644 index 00000000..04ff118b --- /dev/null +++ b/.github/workflows/lint-check.yml @@ -0,0 +1,23 @@ +name: Lint + +on: + push: + branches: + - main + +jobs: + lint: + name: Prettier (check) + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v3 + + - name: Install dependencies + run: npm ci --no-scripts + + - name: Run prettier + run: npx prettier -c . From e70f971fab99d5ceebe72eaa8418c648e5bd4e84 Mon Sep 17 00:00:00 2001 From: James Cahill Date: Tue, 27 Jun 2023 08:17:51 +0100 Subject: [PATCH 7/7] (lint): Lint team.tsx --- src/pages/team.tsx | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/pages/team.tsx b/src/pages/team.tsx index faea93f4..b7558466 100644 --- a/src/pages/team.tsx +++ b/src/pages/team.tsx @@ -52,7 +52,7 @@ export default class TeamPage extends React.PureComponent< isReady: false, searchQuery: "", filterChip: [], - shouldIncludeTagsInSearch: true + shouldIncludeTagsInSearch: true, }; } @@ -203,10 +203,10 @@ export default class TeamPage extends React.PureComponent< } handleShouldIncTagsChange(event: React.ChangeEvent) { - console.log(this.shouldIncludeTagsInSearch) + console.log(this.shouldIncludeTagsInSearch); this.setState({ - shouldIncludeTagsInSearch: event.target.checked - }) + shouldIncludeTagsInSearch: event.target.checked, + }); } render(): React.ReactNode { @@ -246,9 +246,24 @@ export default class TeamPage extends React.PureComponent< })} /> {/** Should be enclosed in FormGroup but that makes a newline. Shhh! */} - ) => this.handleShouldIncTagsChange(event)} />} label="Include tags in search?" /> + ) => + this.handleShouldIncTagsChange(event) + } + /> + } + label="Include tags in search?" + /> - {teamEntryFilter(this.entries, this.state.searchQuery, this.state.filterChip, this.state.shouldIncludeTagsInSearch)} + {teamEntryFilter( + this.entries, + this.state.searchQuery, + this.state.filterChip, + this.state.shouldIncludeTagsInSearch + )} ); }