-
Notifications
You must be signed in to change notification settings - Fork 0
feat: improve template behavior #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| from dataclasses import dataclass | ||
| from enum import Enum | ||
| from typing import List, Optional | ||
|
|
||
|
|
||
| class FilterType(Enum): | ||
| MULTI_SELECT = "multi_select" | ||
| TOGGLE = "toggle" | ||
|
|
||
|
|
||
| @dataclass | ||
| class FilterOptions: | ||
| name: str | ||
| value: str | ||
|
|
||
|
|
||
| @dataclass | ||
| class Filter: | ||
| name: str | ||
| display_name: str | ||
| type: FilterType | ||
| display_name_plural: Optional[str] = None | ||
| options: Optional[List[FilterOptions]] = None | ||
|
|
||
|
|
||
| LANGUAGES_FILTER = Filter( | ||
| name="languages", | ||
| display_name="Language", | ||
| display_name_plural="Languages", | ||
| type=FilterType.MULTI_SELECT.value, | ||
| options=[ | ||
| FilterOptions(name="Python", value="python"), | ||
| FilterOptions(name="Java", value="java"), | ||
| FilterOptions(name="JavaScript", value="javascript"), | ||
| FilterOptions(name="TypeScript", value="typescript"), | ||
| ], | ||
| ) | ||
|
|
||
| TEMPLATES_FILTER = Filter(name="template", display_name="Templates", type=FilterType.TOGGLE.value) | ||
|
|
||
|
|
||
| SAMPLES_FILTER = Filter(name="sample", display_name="Samples", type=FilterType.TOGGLE.value) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,62 +1,38 @@ | ||
| import logging | ||
| from enum import Enum | ||
| from typing import List, Optional, TypedDict | ||
| from dataclasses import asdict | ||
| from typing import Dict | ||
|
|
||
| from slack_bolt import Ack, Complete, Fail | ||
|
|
||
| from listeners.filters import LANGUAGES_FILTER, SAMPLES_FILTER, TEMPLATES_FILTER | ||
|
|
||
| FILTER_PROCESSING_ERROR_MSG = ( | ||
| "We encountered an issue processing filter results. Please try again or contact the app owner if the problem persists." | ||
| ) | ||
|
|
||
|
|
||
| class FilterType(Enum): | ||
| MULTI_SELECT = "multi_select" | ||
| TOGGLE = "toggle" | ||
|
|
||
|
|
||
| class FilterOptions(TypedDict): | ||
| name: str | ||
| value: str | ||
|
|
||
|
|
||
| class SearchFilter(TypedDict): | ||
| name: str | ||
| display_name: str | ||
| filter_type: FilterType | ||
| options: Optional[List[FilterOptions]] | ||
| def filter_none(items: Dict): | ||
| return {k: v for k, v in items if v is not None} | ||
|
|
||
|
|
||
| def filters_step_callback(ack: Ack, inputs: dict, fail: Fail, complete: Complete, logger: logging.Logger): | ||
| try: | ||
| user_context = inputs.get("user_context", {}) | ||
| logger.debug(f"User {user_context.get('id')} executing filter request") | ||
|
|
||
| filters: List[SearchFilter] = [ | ||
| { | ||
| "name": "languages", | ||
| "display_name": "Languages", | ||
| "type": FilterType.MULTI_SELECT.value, | ||
| "options": [ | ||
| {"name": "Python", "value": "python"}, | ||
| {"name": "Java", "value": "java"}, | ||
| {"name": "JavaScript", "value": "javascript"}, | ||
| {"name": "TypeScript", "value": "typescript"}, | ||
| ], | ||
| }, | ||
| { | ||
| "name": "type", | ||
| "display_name": "Type", | ||
| "type": FilterType.MULTI_SELECT.value, | ||
| "options": [ | ||
| {"name": "Template", "value": "template"}, | ||
| {"name": "Sample", "value": "sample"}, | ||
| ], | ||
| }, | ||
| ] | ||
|
|
||
| complete(outputs={"filters": filters}) | ||
| complete( | ||
| outputs={ | ||
| "filters": [ | ||
| asdict(LANGUAGES_FILTER, dict_factory=filter_none), | ||
| asdict(TEMPLATES_FILTER, dict_factory=filter_none), | ||
| asdict(SAMPLES_FILTER, dict_factory=filter_none), | ||
| ] | ||
| } | ||
| ) | ||
| except Exception as e: | ||
| logger.error(f"Unexpected error occurred while processing filter request: {type(e).__name__} - {str(e)}", exc_info=e) | ||
| logger.error( | ||
| f"Unexpected error occurred while processing filter request: {type(e).__name__} - {str(e)}", | ||
| exc_info=e, | ||
| ) | ||
| fail(error=FILTER_PROCESSING_ERROR_MSG) | ||
| finally: | ||
| ack() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.