Skip to content
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

Implements the configuration #10

Merged
merged 51 commits into from Apr 19, 2022
Merged

Implements the configuration #10

merged 51 commits into from Apr 19, 2022

Conversation

Gerben-T
Copy link
Collaborator

also added the use of `ApiGenericError` for errors when the API didn't provide one
also handle/show errors in chat
also remove axe-core (doesn't work and keeps throwing errors)
also; moved/renamed context.js => Scripts/Context.js
also; add a Logger for logging stuff with log levels
…e same

when overriding interfaceTexts using `window.parleySettings.runOptions.interfaceTexts` and switching language, we don't want your custom overrides to get replaced by the InterfaceText.{language} defaults
Also; fixed issue where proxy would keep triggering `setState()` after being unmounted
Also; added eslint plugin to remove unused imports
…well

Also; added plugin to disallow `.only` tests
Also; renamed v1 props to v2 in InterfaceTexts
Also; moved some functions around
Also; added jsdocs
Also; fixed issue where errorNotfication render gave an error that it didn't exist
…AfterBusinessHours) settings

Also; made them hide the Launcher if we are outside working hours and hideChatxxx is true
Also; Copied the script from v1 that checks if we are inside/outside working hours
@Gerben-T Gerben-T self-assigned this Jul 22, 2021
@Gerben-T Gerben-T marked this pull request as ready for review July 22, 2021 18:52
@Gerben-T
Copy link
Collaborator Author

@daanleenders ik denk eerlijk gezegt dat het beter is om van die hele Proxy af te stappen
ten eerste; het is voor niemand duidelijk/logisch dat als je iets aanpast in window.parleySettings dat ie dan meteen een actie gaat uitvoeren (misschien alleen voor ui teksten)
ten tweede; het maakt errors echt super lelijk, bv
image
1e error is de normale en 2e wordt nog extra gegooid
ten derde; er komt echt een shitload aan complexiteit bij in de UI en om eerlijk te zijn vind ik dat echt niet kunnen. De UI moet gwn simpel blijven.

Dus mijn voorstel is een functie die je zelf moet aanroepen als je een change wilt doen.

window.parleySettings.country = "en";
window.applyParleySettings();

of

window.applyParleySettings({
  country: "en"
})

Dit zal dan niet backwards compatible zijn met v1 die een (halve) proxy heeft

@Gerben-T Gerben-T mentioned this pull request Jul 23, 2021
3 tasks
@daanleenders
Copy link
Member

Vergeet de merge conflicts niet 😉

We don't need to throw an Error here with a stack trace because the API made the error so there is no stack trace that points to the API..
I can't test line 92 on workingHours.js because it checks the current date and to change that i need to change the system time..
Couldn't use `parcel serve` for this because the index.html page contained multiple assets
… feature/config

� Conflicts:
�	.postcssrc.json
�	index.html
�	index.js
�	package-lock.json
�	package.json
�	src/Api/Api.js
�	src/UI/App.jsx
�	src/UI/index.jsx
cypress/integration/working-hours_spec.js Outdated Show resolved Hide resolved
],
])).to.be.equal(false);
});
it("should return true while inside office hours", () => {
Copy link
Member

Choose a reason for hiding this comment

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

Ik begrijp niet hoe je ervoor zorgt dat je tijdens de test altijd in date 2 zit. Date 1 zou outside office hours zijn, en alleen day 2 erin. Ik begrijp alleen niet hoe je ervoor zorgt dat je tijdens de test niet als day 1 wordt gezien, maar altijd als day2.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if(currentDate.getTime() > endDate.getTime() && currentDate.getDate() === endDate.getDate()) { // Return true if current time is between start and end
isOnline = !isOpen;
continue; // If there is another timestamp after this one, we give it the possibility to set us back to `online`
} else if(currentDate.getTime() >= startDate.getTime() && currentDate.getTime() <= endDate.getTime()) { // Return false if current time is after end, BUT only when current day is the same day as end

Deze check zorgt daarvoor

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

// If there is another timestamp after this one, we give it the possibility to set us back to online

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Zodat je meerdere timestamps op 1 dag kan instellen

Copy link
Member

Choose a reason for hiding this comment

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

O ja, het is niet verschillende dagen. Maar verschillende momenten op 1 dag.

Also ignore gitlink
@daanleenders daanleenders merged commit ee3c6bc into master Apr 19, 2022
@daanleenders daanleenders deleted the feature/config branch April 19, 2022 12:29
daanleenders added a commit that referenced this pull request Apr 26, 2022
* Add support for strict CSP's (#8)

* Initial commit

* Initial commit

* Use babel-eslint parser to support arrow functions (and other)

* Use babel-eslint parser to support arrow functions (part 2)

* Intitial commit for components

* Add Api abstraction layer

This abstraction layer is the base layer which contains all the Api calls done with fetch().

* Add step comments to EventLog.jsx

* Add some comments to api scripts

* We dont have a release branch anymore (due to creating a new repo)

* Fix ESLint issues, especially no-invalid-this

no-invalid-this had to be replaced by @babel/no-invalid-this, otherwise it would show false positives in arrow functions

* Removed console logs and fixed `curly` rule to be used always

* Innitial commit for:
Announcement
Image.jsx
ImageViewer.jsx
ReplyActions.jsx

Removed
MarkdownText.jsx

Changed:
Arrow functions and removed binds
Disabled Image.jsx (not required in first version)

* Add build targets to package.json

* Remove babel presets that are handled automatically in Parcel beta 3

https://v2.parceljs.org/blog/beta3/

Had to install a plugin for eslint otherwise it showed errors because it is missing je react-preset

* Working on build targets

* Added .postcssrc for more control over CSS transformations

* Update readme with info about building

* Add CSP

* Pulled from /components

* Pulled from /build

* Create index.html with CSP

* Forgot to load the css stylesheet

* Add Cypress and Polling and first basic test

* Add unit tests for polling mechanism

* Implement PollingService in ApiEventTarget

And demo this in the example application

* Implement Polling Service in UI (because we don't use the logic in ApiEventTarget anymore)

* Add polling test for restartPolling()

* Fix regex

* Remove duplicated files

* Remove duplicated files

* Only stop(& restart) the polling interval when we go on to the next interval

If we keep the current interval there is no need to stop and restart..

* Reset variables when calling restartPolling()

* Remove unneeded dependency with account/deviceIdentification

* Rename stuff & fix issue with `currentIntervalAmount` being greater than the max

Also fixed last test for polling; it didn't stop after `resolve()` so it needed a `return`

* Remove config const for polling tests and let each test define their own

also lowered the intervals for the first test

* Use timeouts in Polling

* Rename message send event to "sent" (past tense)

* Rename interfaceTexts.js to tempConfig.js, becuase we will be storing config values aswell

Also disabled quickreplies

* Start polling when device is subscribed and reset polling when message is sent

Also added; Message sending on submit, Device registration when chat opens, Stop polling on unmount

* Disable input field while sending message to parley

* Remove comments about implementing stuff later

We have tickets and that should be enough

* Use ow package to validate params

* Rename var to timeout

* Remove commented console logs

* Wait for getMessages before continuing the next interval

* Forgot a variable

* Test polling reaction to api events

* Show messages in conversation

* Restart polling when there is focus on the input field

Also open the chat when there is a new message

* Fixed issue in code that finds a new message id

* Let Conversation.jsx restart polling when it mounts

This way you should always see your new messages when the conversation window opens

* Scroll down when there is a new message

* Suppress eslint error

When i remove this variable the IDEA complains about the override not being the same as the original..

* Only render Agent's name once if there are more agent messages

* Refocus input field after sending a message

* Updating axe-core

Was hoping this would fix it..

* Remove auto start of polling in constructor

Also clear event listeners on stopPolling()
And fixed tests

* Restart polling when page/window receives visibility/focus

* Fix scroll to bottom when new messages come in

Had to compare last id's instead of array lengths because the API gives out max 50 messages..

* Fix typo in test

* Merge

* Only load code-coverage code when in development mode

* (re)create index CSP file

* Turn default imports (css) into namespace imports

https://v2.parceljs.org/languages/postcss/#css-modules-tree-shaking

* Fix issue where CSS was not correctly build in index_CSP.html

* Dont check unused vars in args because they can conflict with phpstorm's "signature mismatch" inspection

* No need for a variable here

* Remove unused npmrc

* Use Parcel nightly for css scope hoisting fix

fix: parcel-bundler/parcel#6489
Also used parcel's babel presets as defined here: https://v2.parceljs.org/languages/babel/#extending-the-default-babel-config

* Remove idea gitignore (we have our own one)

* Revert change to parley-web-library.iml

* Remove pageVisibilityApi.js, we dont need it anymore

* Make sure fontawesome css is bundled in our css

so that we don't need to include it separately in the index.html

* Remove axe-core and fix csp

* Dont need postcss (installed automatically by Parcel)

* Fix building css finally

Co-authored-by: Gydo Titulaer <gydo.titulaer@tracebuzz.com>
Co-authored-by: Daan Leenders <daan@tracebuzz.com>

* Save device registration in storage (#9)

* Save device registration in local storage and check it upon `subscribeDevice()`

* Add ability to load settings from window.parleySettings (for now)

* Add start wrapper function for loading the chat in the advanced demo page (for now)

* Add css to index.html

* Use namespace imports for styles

* Use parcel's own babel presets

* Use css scoped names

* Fix issue with Parcel

* Add js for demo page (taken from v1 so not optimized, might also be temporary)

* Only load code coverage on development builds

* Compare localStorage device information with new one when calling subscribeDevice

when they both match, it means we don't have any new data for the api
so calling it would be a waste of resources.

* Add authorization and language options to demo

# Conflicts:
#	index.js
#	parleycdn-demo/index.html

* Add authorization and language options to demo

* Compare authorization before registering device

* Make storage prefix customizable

Somehow is also missed some npm packages so i needed to install those

* Add storage prefix from settings

* Update index.html

Co-authored-by: Daan Leenders <daanleenders@gmail.com>

Co-authored-by: Daan Leenders <daanleenders@gmail.com>

* Implements the configuration (#10)

* Fix problem where error notification returned a object and not just text

also added the use of `ApiGenericError` for errors when the API didn't provide one

* Add context providers

also handle/show errors in chat
also remove axe-core (doesn't work and keeps throwing errors)

* Add tests for ui errors

* Working changing language

* No need for contextType

* Create test for testing parley settings reactivity

* Make window.parleySettings reactive using Proxies

also; moved/renamed context.js => Scripts/Context.js
also; add a Logger for logging stuff with log levels

* When language changes, make sure the interfaceTexts overrides stay the same

when overriding interfaceTexts using `window.parleySettings.runOptions.interfaceTexts` and switching language, we don't want your custom overrides to get replaced by the InterfaceText.{language} defaults

* Create new Api instance (and device) when switching roomNumber

* Re-register device when authHeader changes

* Re-register device when userAdditionalInformation changes

* When infoText setting changes, the UI needs to change as well

Also; fixed issue where proxy would keep triggering `setState()` after being unmounted
Also; added eslint plugin to remove unused imports

* When placeholderMessenger setting changes, the UI needs to change as well

Also; added plugin to disallow `.only` tests

* Add some comments

* Change how Proxy works to make it more robust and easier to understand

Also; renamed v1 props to v2 in InterfaceTexts
Also; moved some functions around
Also; added jsdocs
Also; fixed issue where errorNotfication render gave an error that it didn't exist

* Add workingHours (weekdays) and hideChatOutsideWorkingHours (hideChatAfterBusinessHours) settings

Also; made them hide the Launcher if we are outside working hours and hideChatxxx is true
Also; Copied the script from v1 that checks if we are inside/outside working hours

* Add mobile recognition

* Add device version to state

* Move country to runOptions layer

* Authorization can't be empty when calling subscribeDevice()

* Fix issue where device version is empty if it didn't have pre-release tags

* Add hide button for error messages

* Default value for error message colors

* Load all interface texts default on construct

* Remove todo comments

* Set stylelint config path to auto-detect

somehow Phpstorm was messing up the path (probably because of a new update..)

* Remove unused css

* Rename referer to referrer if we are talking about anything other than the HTTP header / Api payload

* Remove unused var and remove optional params

* Make sure code coverage and index.html are CSP compliant

* Not sure why Phpstorm deleted this but i don't think it is important

* Data can be null if no messages are found, so it's better if we check if data is set

* Remove eslint rule `prefer-promise-reject-errors`

We don't need to throw an Error here with a stack trace because the API made the error so there is no stack trace that points to the API..

* Return `null` when get messages api call throws an error

* fix typo

* Remove event listener on unmount

* Make the api generic error configurable in the UI

* Make unit tests for working hours script

* Add code coverage for unit test

* Add missing tests so we reach ~99% code coverage

I can't test line 92 on workingHours.js because it checks the current date and to change that i need to change the system time..

* Install light-server to serve code coverage page with live reload

Couldn't use `parcel serve` for this because the index.html page contained multiple assets

* Use array destructuring for readability

* Use `toLocaleString()` so we don't need an extra array

* Make sure office hours are 24/7 otherwise tests will fail

* Add an extra test which tests the `false` part of the `format [day, start, end, false]` office hours format

* Add storagePrefix to state

* Use `componentDidUpdate()` instead of `shouldComponentUpdate()` because it is a better place for these checks

* Ignore stuff we don't need in the repo

* Forgot to change copied test

Also ignore gitlink

* Don't allow falsy values in the `state.messages`, it should always be an array

* Fix some bad merges

* Add functionality that clears your local messages if you don't have access (anymore) to the API

Co-authored-by: Gydo Titulaer <gydo.titulaer@tracebuzz.com>
Co-authored-by: Daan Leenders <daan@tracebuzz.com>
Co-authored-by: Daan Leenders <daanleenders@gmail.com>
daanleenders added a commit that referenced this pull request Jun 30, 2022
* Add support for strict CSP's (#8)

* Initial commit

* Initial commit

* Use babel-eslint parser to support arrow functions (and other)

* Use babel-eslint parser to support arrow functions (part 2)

* Intitial commit for components

* Add Api abstraction layer

This abstraction layer is the base layer which contains all the Api calls done with fetch().

* Add step comments to EventLog.jsx

* Add some comments to api scripts

* We dont have a release branch anymore (due to creating a new repo)

* Fix ESLint issues, especially no-invalid-this

no-invalid-this had to be replaced by @babel/no-invalid-this, otherwise it would show false positives in arrow functions

* Removed console logs and fixed `curly` rule to be used always

* Innitial commit for:
Announcement
Image.jsx
ImageViewer.jsx
ReplyActions.jsx

Removed
MarkdownText.jsx

Changed:
Arrow functions and removed binds
Disabled Image.jsx (not required in first version)

* Add build targets to package.json

* Remove babel presets that are handled automatically in Parcel beta 3

https://v2.parceljs.org/blog/beta3/

Had to install a plugin for eslint otherwise it showed errors because it is missing je react-preset

* Working on build targets

* Added .postcssrc for more control over CSS transformations

* Update readme with info about building

* Add CSP

* Pulled from /components

* Pulled from /build

* Create index.html with CSP

* Forgot to load the css stylesheet

* Add Cypress and Polling and first basic test

* Add unit tests for polling mechanism

* Implement PollingService in ApiEventTarget

And demo this in the example application

* Implement Polling Service in UI (because we don't use the logic in ApiEventTarget anymore)

* Add polling test for restartPolling()

* Fix regex

* Remove duplicated files

* Remove duplicated files

* Only stop(& restart) the polling interval when we go on to the next interval

If we keep the current interval there is no need to stop and restart..

* Reset variables when calling restartPolling()

* Remove unneeded dependency with account/deviceIdentification

* Rename stuff & fix issue with `currentIntervalAmount` being greater than the max

Also fixed last test for polling; it didn't stop after `resolve()` so it needed a `return`

* Remove config const for polling tests and let each test define their own

also lowered the intervals for the first test

* Use timeouts in Polling

* Rename message send event to "sent" (past tense)

* Rename interfaceTexts.js to tempConfig.js, becuase we will be storing config values aswell

Also disabled quickreplies

* Start polling when device is subscribed and reset polling when message is sent

Also added; Message sending on submit, Device registration when chat opens, Stop polling on unmount

* Disable input field while sending message to parley

* Remove comments about implementing stuff later

We have tickets and that should be enough

* Use ow package to validate params

* Rename var to timeout

* Remove commented console logs

* Wait for getMessages before continuing the next interval

* Forgot a variable

* Test polling reaction to api events

* Show messages in conversation

* Restart polling when there is focus on the input field

Also open the chat when there is a new message

* Fixed issue in code that finds a new message id

* Let Conversation.jsx restart polling when it mounts

This way you should always see your new messages when the conversation window opens

* Scroll down when there is a new message

* Suppress eslint error

When i remove this variable the IDEA complains about the override not being the same as the original..

* Only render Agent's name once if there are more agent messages

* Refocus input field after sending a message

* Updating axe-core

Was hoping this would fix it..

* Remove auto start of polling in constructor

Also clear event listeners on stopPolling()
And fixed tests

* Restart polling when page/window receives visibility/focus

* Fix scroll to bottom when new messages come in

Had to compare last id's instead of array lengths because the API gives out max 50 messages..

* Fix typo in test

* Merge

* Only load code-coverage code when in development mode

* (re)create index CSP file

* Turn default imports (css) into namespace imports

https://v2.parceljs.org/languages/postcss/#css-modules-tree-shaking

* Fix issue where CSS was not correctly build in index_CSP.html

* Dont check unused vars in args because they can conflict with phpstorm's "signature mismatch" inspection

* No need for a variable here

* Remove unused npmrc

* Use Parcel nightly for css scope hoisting fix

fix: parcel-bundler/parcel#6489
Also used parcel's babel presets as defined here: https://v2.parceljs.org/languages/babel/#extending-the-default-babel-config

* Remove idea gitignore (we have our own one)

* Revert change to parley-web-library.iml

* Remove pageVisibilityApi.js, we dont need it anymore

* Make sure fontawesome css is bundled in our css

so that we don't need to include it separately in the index.html

* Remove axe-core and fix csp

* Dont need postcss (installed automatically by Parcel)

* Fix building css finally

Co-authored-by: Gydo Titulaer <gydo.titulaer@tracebuzz.com>
Co-authored-by: Daan Leenders <daan@tracebuzz.com>

* Save device registration in storage (#9)

* Save device registration in local storage and check it upon `subscribeDevice()`

* Add ability to load settings from window.parleySettings (for now)

* Add start wrapper function for loading the chat in the advanced demo page (for now)

* Add css to index.html

* Use namespace imports for styles

* Use parcel's own babel presets

* Use css scoped names

* Fix issue with Parcel

* Add js for demo page (taken from v1 so not optimized, might also be temporary)

* Only load code coverage on development builds

* Compare localStorage device information with new one when calling subscribeDevice

when they both match, it means we don't have any new data for the api
so calling it would be a waste of resources.

* Add authorization and language options to demo

# Conflicts:
#	index.js
#	parleycdn-demo/index.html

* Add authorization and language options to demo

* Compare authorization before registering device

* Make storage prefix customizable

Somehow is also missed some npm packages so i needed to install those

* Add storage prefix from settings

* Update index.html

Co-authored-by: Daan Leenders <daanleenders@gmail.com>

Co-authored-by: Daan Leenders <daanleenders@gmail.com>

* Implements the configuration (#10)

* Fix problem where error notification returned a object and not just text

also added the use of `ApiGenericError` for errors when the API didn't provide one

* Add context providers

also handle/show errors in chat
also remove axe-core (doesn't work and keeps throwing errors)

* Add tests for ui errors

* Working changing language

* No need for contextType

* Create test for testing parley settings reactivity

* Make window.parleySettings reactive using Proxies

also; moved/renamed context.js => Scripts/Context.js
also; add a Logger for logging stuff with log levels

* When language changes, make sure the interfaceTexts overrides stay the same

when overriding interfaceTexts using `window.parleySettings.runOptions.interfaceTexts` and switching language, we don't want your custom overrides to get replaced by the InterfaceText.{language} defaults

* Create new Api instance (and device) when switching roomNumber

* Re-register device when authHeader changes

* Re-register device when userAdditionalInformation changes

* When infoText setting changes, the UI needs to change as well

Also; fixed issue where proxy would keep triggering `setState()` after being unmounted
Also; added eslint plugin to remove unused imports

* When placeholderMessenger setting changes, the UI needs to change as well

Also; added plugin to disallow `.only` tests

* Add some comments

* Change how Proxy works to make it more robust and easier to understand

Also; renamed v1 props to v2 in InterfaceTexts
Also; moved some functions around
Also; added jsdocs
Also; fixed issue where errorNotfication render gave an error that it didn't exist

* Add workingHours (weekdays) and hideChatOutsideWorkingHours (hideChatAfterBusinessHours) settings

Also; made them hide the Launcher if we are outside working hours and hideChatxxx is true
Also; Copied the script from v1 that checks if we are inside/outside working hours

* Add mobile recognition

* Add device version to state

* Move country to runOptions layer

* Authorization can't be empty when calling subscribeDevice()

* Fix issue where device version is empty if it didn't have pre-release tags

* Add hide button for error messages

* Default value for error message colors

* Load all interface texts default on construct

* Remove todo comments

* Set stylelint config path to auto-detect

somehow Phpstorm was messing up the path (probably because of a new update..)

* Remove unused css

* Rename referer to referrer if we are talking about anything other than the HTTP header / Api payload

* Remove unused var and remove optional params

* Make sure code coverage and index.html are CSP compliant

* Not sure why Phpstorm deleted this but i don't think it is important

* Data can be null if no messages are found, so it's better if we check if data is set

* Remove eslint rule `prefer-promise-reject-errors`

We don't need to throw an Error here with a stack trace because the API made the error so there is no stack trace that points to the API..

* Return `null` when get messages api call throws an error

* fix typo

* Remove event listener on unmount

* Make the api generic error configurable in the UI

* Make unit tests for working hours script

* Add code coverage for unit test

* Add missing tests so we reach ~99% code coverage

I can't test line 92 on workingHours.js because it checks the current date and to change that i need to change the system time..

* Install light-server to serve code coverage page with live reload

Couldn't use `parcel serve` for this because the index.html page contained multiple assets

* Use array destructuring for readability

* Use `toLocaleString()` so we don't need an extra array

* Make sure office hours are 24/7 otherwise tests will fail

* Add an extra test which tests the `false` part of the `format [day, start, end, false]` office hours format

* Add storagePrefix to state

* Use `componentDidUpdate()` instead of `shouldComponentUpdate()` because it is a better place for these checks

* Ignore stuff we don't need in the repo

* Forgot to change copied test

Also ignore gitlink

* Merge changes in Release/2.0.0 alpha.1 & Release/2.0.0 alpha.2 (#13)

* fix Styling Issue after call Triodos (#12)

* Remove global CSS selectors (#14)

* Workaround for issue when testing window.location.href

* Add library version to parley settings

* Dont use double quotes in test names

* Create new Api instance (and device) when switching roomNumber

* Create new Api and Polling service when device identification changes

* Fix issue where we wouldn't create a new device when account identification changes

* Added a demo page for parleycdn

* Added - Font color,family,size and weight to text area's so they can be modified

* Add aria label for text input

Also; renamed variables for aria labels to start with "ariaLabel"

* Rename public functions

* Fix some issues from the previous merge

* Fix test that was broken after merge

Welcome message showed up immediately, but this shouldn't happen as per https://github.com/parley-messaging/web-library-v1/issues/223

* Fix another test that failed

I think this one was never fixed and was introduced by 3542aa0
before, we never shown the ApiGenericError (i think) and now we do.
The new error message is a bit more user-friendly (clients don't know what an API is).

* Not sure why this was deleted

* Remove unused setting

* Remove escaped characters

I think these are problematic for the build pipeline

Co-authored-by: Gydo Titulaer <gydo.titulaer@tracebuzz.com>
Co-authored-by: Daan Leenders <daan@tracebuzz.com>
Co-authored-by: Daan Leenders <daanleenders@gmail.com>
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.

None yet

2 participants