Skip to content

Commit

Permalink
Merge branch 'master' into snyk-fix-87a3eb74d6e791578105291088fc1ec7
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-bompart committed Oct 28, 2019
2 parents 0cfe903 + de73762 commit 66b8f36
Show file tree
Hide file tree
Showing 7 changed files with 292 additions and 12 deletions.
131 changes: 131 additions & 0 deletions adr/ADR-template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# [Title of the ADR ]

<!-- There are two main reason why an ADR is needed for a feature
If the feature lasts more then one sprint
Or if a non-obvious design choice was chosen during feature development. -->

## Admin

- **Author:** [ Name of the person you developed the feature ]
- **Deciders:** [ Anybody who is reviewing your code and this ADR ]
- **Date:** [ The date of the pull request ]
- **JIRA:** [ The JIRA number associated with feature ]
- **User Story:** [ A link to the JIRA ]

---

## Context and Problem Statement

[ Quick 2-3 sentence background of the User Story. It should describe the context of the changes being made by the feature, and the problem that the feature is solving. ]

---

## Decision Drivers

<!-- Decision drivers are the main design decisions used during the devleopment of a feature -->

### Context

[ Context behind all of the design decisions associated with the feature ]

### Decisions

[ A list of the key decisions which had to made during development ]

1. [ Describe decision 1 ]
1. [ Describe decision 2 ]
1. [ Describe decision 3 ]\
...
N. [ Describe decision N ]

---

## Considered Options

<!-- Give some options regarding the decision drivers mentioned in the previous section -->

**Decision 1** - [ Quick option overview decision 1 from the previous section ]

- [Option 1] - [ Describe option 1 ]
- [Option 2] - [ Describe option 2 ]
- ...
- [Option N] - [ Describe option N ]

**Decision 2** - [ Quick option overview decision 2 from the previous section ]

- [Option 1] - [ Describe option 1 ]
- [Option 2] - [ Describe option 2 ]
- ...
- [Option N] - [ Describe option N ]

**Decision 3** - [ Quick option overview decision 3 from the previous section ]

- [Option 1] - [ Describe option 1 ]
- [Option 2] - [ Describe option 2 ]
- ...
- [Option N] - [ Describe option N ]

...

**Decision N** - [ Quick option overview decision N from the previous section ]

- [Option 1] - [ Describe option 1 ]
- [Option 2] - [ Describe option 2 ]
- ...
- [Option N] - [ Describe option N ]

---

## Decision Outcome

#### Decision 1: [Option X]

[ Give your reasoning behind choosing the option you did from the previous section ]

#### Decision 2: [Option X]

[ Give your reasoning behind choosing the option you did from the previous section ]

#### Decision 3: [Option X]

[ Give your reasoning behind choosing the option you did from the previous section ]

...

#### Decision N: [Option X]

[ Give your reasoning behind choosing the option you did from the previous section ]

---

## Pros & Cons

<!-- List the pros and cons of the options that you chose when developing the feature -->

### Pros

[ List the advantages of developing the feature the way you did ]

### Cons

[ List any cons that come with developing the feature the way that you did ]

---

## Common Pitfalls

[ List any common mistakes that you saw during development of your feature ]

---

## Next Steps & Timeline

[ List any tasks that may follow this one, and the timeline associated with those tasks and the overall feature ]

---

## Related Links

[ List any links related to this feature ie. pull requests, confluence documents, etc.. ]

---
113 changes: 113 additions & 0 deletions adr/components/UserActions/UserActions/ShowViewedByCustomer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# showViewedByCustomer Method (SFINT-2519)

## Admin

- **Author:** Neil Wadden
- **Deciders:** Louis Bompart, Nathan Lafrance-Berger, Andre Theriault, Jeremie Robert
- **Date:** 10/10/2019
- **JIRA:** SFINT-2519
- **User Story:** https://coveord.atlassian.net/browse/SFINT-2519

---

## Context and Problem Statement

<!-- Quick 2-3 sentence background of the User Story -->

The `ViewedByCustomer` component needs to be added on each result template, and therefore could be accidentally missed on one or more, especially if a new template is added at a later time. This would create an inconsistent view of what content the customer has viewed. - From JIRA

---

## Decision Drivers <!-- optional -->

### Context

The main decision drivers were to be able to add the ViewedByCustomer component to each result, without adding it a second time, when the option in the UserActions component is true.

<!-- Number these so that they are easier to reference in the following section -->

### Decisions

1. Need to choose when to edit the results (i.e. need an event)
1. Ensure the `ViewedByCustomer` component is properly added to each result template
1. Ensure that if a template already has the `ViewedByCustomer` component that it won't add a second component
1. There should be an option whether or not to perform that aforementioned actions with the component

---

## Considered Options

<!-- Give some options regarding the decision drivers mentions in the previous section -->

**Decision 1** - What event should be used

- [Option 1] - Leverage the `newResultsDisplayed` event, and loop over every result, performing further action.
- [Option 2] - Leverage the `newResultDisplayed` event, and perform further action.

**Decision 2** - Properly adding the ViewedByDocument Component

- [Option 1] - Add the component using `<div class="CoveoViewedByCustomer">`.
- [Option 2] - Add the component using the `ViewedByCustomer` constructor.

**Decision 3** - Ensure we don't add the template a second time

- [Option 1] - Query the results `HTMLElement` using the `getElementsByClassName` method.
- [Option 2] - Query the results `HTMLElement` using the `querySelectorAll` method.

**Decision 4** - There should be an option whether or not to add the component

- [Option 1] - Have the option be false by default.
- [Option 2] - Have the option be true by default.

---

## Decision Outcome

#### Decision 1: [Option 2]

There are two reason behind this decision selection: First the `newResultsDisplayed` option wasn't passing back the `args.item`, which would have made editing the dom element harder. Second, using the event trigger instead of a for loop made the methods functionality more simple.

#### Decision 2: [Option 2]

The `newResultDisplayed` dom element was firing after the completion of the search-ui, therefore using the `<div>` wasn't possible.

#### Decision 3: [Option 1]

Choosing to use `getElementsByClassName`, in this context I don't think there is a difference between using `querySelectorAll` and `getElementsByClassName`

#### Decision 4: [Option 2]

From what I understand it makes sense for this feature to be true by default, as it's important for their not to be inconsistencies

---

## Pros & Cons

### Pros

- Using the `newResultsDisplayed` method offers an effective way to make dynamic changes to the reuslts, and the functionality of this function could easily be expanded on

### Cons

- Having to call the constructor of `ViewedByCustomer` is a little sketchy. From what I can tell it's not being done anywhere else in the code. It means that a change in the ViewedByCustomer component could negatively affect this method

---

## Gotchas

- The main gotcha for this going forward was that the `newResultsDisplayed` option wasn't passing back the `args.item` with it's event.

---

## Next Steps & Timeline

This was a standalone task and has no additional steps past this.

---

## Related Links

- **search-ui-extensions PR**: https://github.com/coveo/search-ui-extensions/pull/45
- **salesforceIntegrationV2 PR**: https://bitbucket.org/coveord/salesforceintegrationv2/pull-requests/1470/

---
1 change: 1 addition & 0 deletions src/components/UserActions/Strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Translation, Language } from '../../utils/translation';

Translation.register(Language.English, {
UserActions_no_actions: 'No actions available for this user',
UserActions_enable_prompt: 'The User Action feature is not activated for your organization.\nTo activate it, contact Coveo Support.',

QueryList_more: 'Show More',
QueryList_less: 'Show Less',
Expand Down
5 changes: 5 additions & 0 deletions src/components/UserActions/UserActions.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ $search-ui-dropdown-header-color: #1d4f76;
text-align: center;
}

.coveo-enable-prompt {
padding: 1.5em;
text-align: center;
}

.coveo-close {
display: inline-block;
width: 1em;
Expand Down
18 changes: 12 additions & 6 deletions src/components/UserActions/UserActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ export interface IUserActionsOptions {
* Default: `True`
*/
viewedByCustomer: Boolean;

createdBy: string;
}

/**
Expand Down Expand Up @@ -85,8 +83,7 @@ export class UserActions extends Component {
}),
viewedByCustomer: ComponentOptions.buildBooleanOption({
defaultValue: true
}),
createdBy: ComponentOptions.buildStringOption()
})
};

private static readonly USER_ACTION_OPENED = 'coveo-user-actions-opened';
Expand Down Expand Up @@ -146,7 +143,7 @@ export class UserActions extends Component {
(get(this.root, UserProfileModel) as UserProfileModel)
.getActions(this.options.userId)
.then(actions => (actions.length > 0 ? this.render() : this.renderNoActions()))
.catch(() => this.renderNoActions());
.catch(e => (e.statusCode === 404 ? this.renderEnablePrompt() : this.renderNoActions()));

this.bindings.usageAnalytics.logCustomEvent({ name: 'openUserActions', type: 'User Actions' }, {}, this.element);
this.root.classList.add(UserActions.USER_ACTION_OPENED);
Expand Down Expand Up @@ -267,6 +264,15 @@ export class UserActions extends Component {
this.element.appendChild(element);
}

private renderEnablePrompt() {
const element = document.createElement('div');
element.classList.add('coveo-enable-prompt');
element.innerText = l(`${UserActions.ID}_enable_prompt`);

this.element.innerHTML = '';
this.element.appendChild(element);
}

private showViewedByCustomer() {
this.bind.onRootElement(ResultListEvents.newResultDisplayed, (args: IDisplayedNewResultEventArgs) => {
if (Boolean(args.item.getElementsByClassName('CoveoViewedByCustomer').length)) {
Expand All @@ -283,7 +289,7 @@ export class UserActions extends Component {
Coveo.$$(this.root).on('buildingQuery', (e, args) => {
try {
args.queryBuilder.userActions = {
tagViewsOfUser: this.options.createdBy
tagViewsOfUser: this.options.userId
};
} catch (e) {
this.logger.warn("CreatedBy Email wasn't found", e);
Expand Down
5 changes: 4 additions & 1 deletion src/components/ViewedByCustomer/ViewedByCustomer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export interface IViewedByCustomerOptions {
}

/**
* Result component indicating if a search result have been viewed by the targeted user.
* The _ViewedByCustomer_ component allows your agents to see, within the Salesforce Lightning console, every result which the user clicked. It displays an icon and a label on each result, if already viewed by the customer who created the case (see [Coveo Component ViewedByCustomer](https://docs.coveo.com/en/3073/coveoforsalesforce/viewedbycustomercomponent)).
* ```html
* <div class="CoveoViewedByCustomer"></div>
* ```
*/
export class ViewedByCustomer extends Component {
/**
Expand Down
Loading

0 comments on commit 66b8f36

Please sign in to comment.