-
Notifications
You must be signed in to change notification settings - Fork 51
FOUR-26711 Implement the Inspector Extension for Conditional Destination #1944
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
13 commits
Select commit
Hold shift + click to select a range
ea7bbe7
feat: add ConditionalRedirect component
devmiguelangel ee7adc6
feat: enhance styling and structure
devmiguelangel cb46bd0
feat: implement event handlers for saving, duplicating, and removing …
devmiguelangel 0a05585
feat: add external URL input
devmiguelangel 07672ad
feat: add custom dashboard selection
devmiguelangel d998fa7
fix: remove required prop validation for value
devmiguelangel 35001a2
feat: include simplified data for dashboards
devmiguelangel 47619a2
feat: implement debounced save functionality for condition and task d…
devmiguelangel 9529469
fix: remove unused watcher
devmiguelangel 7e695d5
feat: add informational message about rule evaluation order
devmiguelangel 006db36
test: fix Documentation e2e test
devmiguelangel 075fc66
feat: add condition limit and error handling for JSON parsing
devmiguelangel 767c7e1
feat: add data-test attributes for improved testing
devmiguelangel 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
165 changes: 165 additions & 0 deletions
165
src/components/inspectors/ConditionalRedirect/ConditionalRedirect.vue
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,165 @@ | ||
| <template> | ||
| <div> | ||
| <label>{{ $t(label) }}</label> | ||
| <div class="d-flex justify-content-between align-items-center mb-2"> | ||
| <label for="conditionalRedirectEnabled" class="text-muted small"> | ||
| {{ $t("Enable to add rules that route users to different tasks. If none match, the default destination is used.") }} | ||
| </label> | ||
| <b-form-checkbox | ||
| id="conditionalRedirectEnabled" | ||
| v-model="isEnabled" | ||
| name="conditionalRedirectEnabled" | ||
| :aria-checked="isEnabled" | ||
| switch | ||
| data-test="conditional-toggle" | ||
| /> | ||
| </div> | ||
| <div v-if="isEnabled"> | ||
| <button | ||
| type="button" | ||
| class="btn btn-light" | ||
| @click="addCondition" | ||
| :disabled="conditions.length >= MAX_CONDITIONS" | ||
| data-test="conditional-add-button" | ||
| > | ||
| <i class="fas fa-plus-circle" /> | ||
| </button> | ||
|
|
||
| <div | ||
| v-for="condition in conditions" | ||
| :key="condition.id" | ||
| data-test="conditional-box" | ||
| > | ||
| <TaskDestination | ||
| :value="condition" | ||
| :taskDestinationOptions="taskDestinationOptions" | ||
| :conditionId="condition.id" | ||
| @input="onSaveCondition" | ||
| @duplicate="onDuplicateCondition" | ||
| @remove="onRemoveCondition" | ||
| /> | ||
| </div> | ||
|
|
||
| <hr class="my-2"> | ||
|
|
||
| <div class="d-flex justify-content-end"> | ||
| <small class="text-muted text-right"> | ||
| {{ $t('Rules are evaluated top to bottom.') }} | ||
| </small> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script> | ||
| import TaskDestination from './TaskDestination.vue'; | ||
| import { v4 as uuidv4 } from 'uuid'; | ||
|
|
||
| const MAX_CONDITIONS = 10; | ||
|
|
||
| export default { | ||
| components: { | ||
| TaskDestination, | ||
| }, | ||
| props: { | ||
| value: { | ||
| type: String, | ||
| }, | ||
| label: { | ||
| type: String, | ||
| required: true, | ||
| }, | ||
| options: { | ||
| type: Array, | ||
| required: true, | ||
| }, | ||
| }, | ||
| data() { | ||
| return { | ||
| isEnabled: false, | ||
| conditions: [], | ||
| taskDestinationOptions: [], | ||
| MAX_CONDITIONS, | ||
| }; | ||
| }, | ||
| watch: { | ||
| isEnabled: { | ||
| handler() { | ||
| this.updateConditionalRedirect(); | ||
| }, | ||
| }, | ||
| }, | ||
| mounted() { | ||
| this.initTaskDestinationOptions(); | ||
|
|
||
| if (this.value) { | ||
| try { | ||
| const local = JSON.parse(this.value); | ||
|
|
||
| this.isEnabled = local.isEnabled ?? false; | ||
| this.conditions = local.conditions ?? []; | ||
| } catch (error) { | ||
| console.warn(error, 'Error parsing conditional redirect', this.value); | ||
| } | ||
| } | ||
| }, | ||
| methods: { | ||
| initTaskDestinationOptions() { | ||
| this.taskDestinationOptions = this.options.map(({ value, content }) => ({ | ||
| value, | ||
| content: this.$t(content), | ||
| })); | ||
|
|
||
| this.taskDestination = this.taskDestinationOptions?.[0] ?? null; | ||
| }, | ||
| updateConditionalRedirect() { | ||
| const data = JSON.stringify({ | ||
| isEnabled: this.isEnabled, | ||
| conditions: this.conditions, | ||
| }); | ||
|
|
||
| this.$emit('input', data); | ||
| }, | ||
| addCondition() { | ||
| if (this.conditions.length >= MAX_CONDITIONS) { | ||
| return; | ||
| } | ||
|
|
||
| this.conditions.push({ | ||
| id: uuidv4(), | ||
| condition: '', | ||
| taskDestination: null, | ||
| }); | ||
|
|
||
| this.updateConditionalRedirect(); | ||
| }, | ||
| onSaveCondition(value) { | ||
| const index = this.conditions.findIndex((condition) => condition.id === value.conditionId); | ||
|
|
||
| if (index !== -1) { | ||
| this.conditions[index] = { | ||
| ...this.conditions[index], | ||
| ...value.condition, | ||
| }; | ||
| } | ||
|
|
||
| this.updateConditionalRedirect(); | ||
| }, | ||
| onDuplicateCondition(conditionId) { | ||
| const condition = this.conditions.find((condition) => condition.id === conditionId); | ||
|
|
||
| this.conditions.push({ | ||
| ...condition, | ||
| id: uuidv4(), | ||
| }); | ||
|
|
||
| this.updateConditionalRedirect(); | ||
| }, | ||
| onRemoveCondition(conditionId) { | ||
| this.conditions = this.conditions.filter((condition) => condition.id !== conditionId); | ||
|
|
||
| this.updateConditionalRedirect(); | ||
| }, | ||
| }, | ||
| }; | ||
| </script> | ||
Oops, something went wrong.
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.