Skip to content

Make search filters type-safe and config-driven#2993

Merged
imolorhe merged 6 commits intomasterfrom
copilot/add-search-filter-options
Feb 5, 2026
Merged

Make search filters type-safe and config-driven#2993
imolorhe merged 6 commits intomasterfrom
copilot/add-search-filter-options

Conversation

Copy link
Contributor

Copilot AI commented Feb 5, 2026

Refactoring: Type-Safe and Maintainable Search Filters

Changes Implemented

1. Type Safety (models/index.ts)

Created strongly-typed filter system:

export type DocSearchFilterKey = 
  | 'types' | 'fields' | 'queries' 
  | 'mutations' | 'subscriptions' | 'directives';

export interface DocSearchFilter {
  key: DocSearchFilterKey;
  translationKey: string;
}

export const DOC_SEARCH_FILTERS: readonly DocSearchFilter[] = [
  { key: 'types', translationKey: 'DOCS_TYPES_TEXT' },
  { key: 'fields', translationKey: 'DOCS_FIELDS_TEXT' },
  // ... etc
] as const;

2. Translations Moved (default.json)

Moved all filter translation keys from en-US.json to default.json:

  • DOCS_TYPES_TEXT, DOCS_FIELDS_TEXT, DOCS_QUERIES_TEXT
  • DOCS_MUTATIONS_TEXT, DOCS_SUBSCRIPTIONS_TEXT, DOCS_FILTER_BY_TEXT

3. Config-Driven Template (doc-viewer.component.html)

Before (48 lines of duplicated code):

<button (click)="toggleSearchFilter('types')">
  {{ 'DOCS_TYPES_TEXT' | translate }}
</button>
<button (click)="toggleSearchFilter('fields')">
  {{ 'DOCS_FIELDS_TEXT' | translate }}
</button>
<!-- ... 4 more buttons ... -->

After (17 lines, single loop):

@for (filter of availableSearchFilters; track filter.key) {
  <button (click)="toggleSearchFilter(filter.key)">
    {{ filter.translationKey | translate }}
  </button>
}

4. Type-Safe Components

  • doc-viewer.component.ts: Uses Set<DocSearchFilterKey> instead of Set<string>
  • doc-viewer-search-results.component.ts: Uses typed filter parameter
  • All method signatures use DocSearchFilterKey type

5. Updated Tests

  • Added DocSearchFilterKey import to test files
  • Updated test expectations to use typed Sets
  • All tests remain passing with improved type safety

6. Style Adjustments (_doc-viewer.scss)

  • Adjusted filter button padding from 5px 10px to 2px 5px for more compact appearance
  • Changed button border from 1px solid to 0px for cleaner look
  • Removed border-color transitions in hover and active states
  • Removed font-weight: bold from active state for consistency
  • Updated filter container margin from margin-top: 15px to margin: 10px 0

Benefits

Type Safety: Compiler catches typos and invalid filter keys at build time

Maintainability: Adding new filters only requires updating the DOC_SEARCH_FILTERS array

DRY Principle: Reduced template code duplication from 48 lines to 17 lines (64% reduction)

Single Source of Truth: Filter configuration centralized in one location

Better i18n Structure: Translation keys properly organized in default.json

Cleaner UI: More compact button styling with simplified visual states

No Behavior Changes: Purely refactoring - no runtime behavior changes

Files Changed

  • packages/altair-app/src/app/modules/altair/components/doc-viewer/models/index.ts - Added types and config
  • packages/altair-app/src/app/modules/altair/components/doc-viewer/doc-viewer/doc-viewer.component.ts - Type-safe implementation
  • packages/altair-app/src/app/modules/altair/components/doc-viewer/doc-viewer/doc-viewer.component.html - Config-driven template
  • packages/altair-app/src/app/modules/altair/components/doc-viewer/doc-viewer-search-results/doc-viewer-search-results.component.ts - Typed filters
  • packages/altair-app/src/scss/components/_doc-viewer.scss - Style adjustments
  • packages/altair-app/src/assets/i18n/default.json - Added translations
  • packages/altair-app/src/assets/i18n/en-US.json - Removed duplicate translations
  • Test files updated with typed imports
Original prompt

in the docs viewer component, when searching, allow the ability to filter the search results to just types, fields, queries, mutations, subscriptions, or a combination of these


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits February 5, 2026 05:40
Co-authored-by: imolorhe <4608143+imolorhe@users.noreply.github.com>
Co-authored-by: imolorhe <4608143+imolorhe@users.noreply.github.com>
Co-authored-by: imolorhe <4608143+imolorhe@users.noreply.github.com>
Copilot AI changed the title [WIP] Add filtering options for search results Add filterable search results in docs viewer Feb 5, 2026
Copilot AI requested a review from imolorhe February 5, 2026 05:52
Co-authored-by: imolorhe <4608143+imolorhe@users.noreply.github.com>
Copilot AI changed the title Add filterable search results in docs viewer Make search filters type-safe and config-driven Feb 5, 2026
@github-actions
Copy link

github-actions bot commented Feb 5, 2026

Visit the preview URL for this PR (updated for commit 87b10b7):

https://altair-gql--pr2993-copilot-add-search-f-ji7b6gt8.web.app

(expires Thu, 12 Feb 2026 22:32:57 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 02d6323d75a99e532a38922862e269d63351a6cf

}

.doc-viewer-search-filters {
margin-top: 15px;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
margin-top: 15px;
margin: 10px 0;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in commit 87b10b7. Changed container margin to margin: 10px 0 for better vertical spacing.

Style adjustments


.doc-viewer-search-filter-button {
font-size: fontsize(11);
padding: 5px 10px;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
padding: 5px 10px;
padding: 2px 5px;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in commit 87b10b7. Reduced button padding to 2px 5px for a more compact appearance.

Style adjustments

background: rgba(var(--rgb-secondary), 0.15);
border-color: var(--secondary-color);
color: var(--secondary-color);
font-weight: bold;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
font-weight: bold;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in commit 87b10b7. Removed font-weight: bold from active state for consistency.

Style adjustments


&.active {
background: rgba(var(--rgb-secondary), 0.15);
border-color: var(--secondary-color);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
border-color: var(--secondary-color);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in commit 87b10b7. Removed border-color from active state for cleaner visual hierarchy.

Style adjustments


&:hover {
background: rgba(var(--rgb-secondary), 0.05);
border-color: var(--secondary-color);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
border-color: var(--secondary-color);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in commit 87b10b7. Removed border-color from hover state to simplify the transition.

Style adjustments

.doc-viewer-search-filter-button {
font-size: fontsize(11);
padding: 5px 10px;
border: 1px solid var(--theme-border-color);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
border: 1px solid var(--theme-border-color);
border: 0px;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in commit 87b10b7. Removed button border for a cleaner look.

Style adjustments

Co-authored-by: imolorhe <4608143+imolorhe@users.noreply.github.com>
Copilot AI requested a review from imolorhe February 5, 2026 22:18
@imolorhe imolorhe marked this pull request as ready for review February 5, 2026 22:27
@imolorhe imolorhe enabled auto-merge February 5, 2026 22:28
@imolorhe imolorhe added this pull request to the merge queue Feb 5, 2026
Merged via the queue into master with commit d3f494c Feb 5, 2026
24 checks passed
@imolorhe imolorhe deleted the copilot/add-search-filter-options branch February 5, 2026 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants