Skip to content

Commit

Permalink
Merge pull request #204 from ably/pass-api-key-to-meganav-directly
Browse files Browse the repository at this point in the history
Pass api key to meganav directly
  • Loading branch information
Dominik authored Aug 5, 2022
2 parents 3b88254 + 756d20e commit ef22008
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
ably-ui (8.0.0)
ably-ui (8.0.0.dev.1715d4e)
view_component (>= 2.33, < 2.50)

GEM
Expand Down
2 changes: 1 addition & 1 deletion lib/ably_ui/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module AblyUi
VERSION = '8.0.0'
VERSION = '8.0.0.dev.1715d4e'
end
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ably/ui",
"version": "8.0.0",
"version": "8.0.0-dev.1715d4e",
"description": "Home of the Ably design system library ([design.ably.com](https://design.ably.com)). It provides a showcase, development/test environment and a publishing pipeline for different distributables.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion preview/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ gem 'view_component', '~> 2.33.0', require: 'view_component/engine'

gem 'responders'

gem 'ably-ui', '8.0.0', require: 'ably_ui'
gem 'ably-ui', '8.0.0.dev.1715d4e', require: 'ably_ui'

# https://stackoverflow.com/questions/71191685/visit-psych-nodes-alias-unknown-alias-default-psychbadalias
gem 'psych', '< 4'
Expand Down
4 changes: 2 additions & 2 deletions preview/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GEM
remote: https://rubygems.org/
specs:
ably-ui (8.0.0)
ably-ui (8.0.0.dev.1715d4e)
view_component (>= 2.33, < 2.50)
actioncable (6.0.5.1)
actionpack (= 6.0.5.1)
Expand Down Expand Up @@ -171,7 +171,7 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
ably-ui (= 8.0.0)
ably-ui (= 8.0.0.dev.1715d4e)
bootsnap (>= 1.4.2)
byebug
dotenv-rails
Expand Down
3 changes: 2 additions & 1 deletion preview/app/controllers/components_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ def meganav_react_props
notice: {
props: notice_props,
config: notice_config
}
},
addSearchApiKey: Rails.application.config.add_search_api_key
}

props[:login_link] = '/custom-login-link' if custom_login_link?
Expand Down
2 changes: 1 addition & 1 deletion preview/app/views/components/meganav_vw.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<script type="text/javascript">
document.addEventListener("DOMContentLoaded", () => {
AblyUi.Core.Meganav();
AblyUi.Core.Meganav({ addSearchApiKey: "<%= Rails.application.config.add_search_api_key %>" });
AblyUi.Core.Notice({
bannerContainer: document.querySelector('[data-id="ui-notice"]'),
cookieId: '1',
Expand Down
2 changes: 1 addition & 1 deletion preview/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<%= csp_meta_tag %>
<%= stylesheet_packs_with_chunks_tag 'application' %>
</head>
<body data-add-search-api-key="<%= Rails.application.config.add_search_api_key %>">
<body>
<%= yield %>
<%= javascript_packs_with_chunks_tag 'application' %>

Expand Down
2 changes: 1 addition & 1 deletion preview/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "preview",
"private": true,
"dependencies": {
"@ably/ui": "8.0.0",
"@ably/ui": "8.0.0-dev.1715d4e",
"@babel/preset-react": "^7.12.5",
"@rails/ujs": "^6.0.0",
"@rails/webpacker": "4.3.0",
Expand Down
8 changes: 4 additions & 4 deletions preview/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# yarn lockfile v1


"@ably/[email protected]":
version "8.0.0"
resolved "https://registry.yarnpkg.com/@ably/ui/-/ui-8.0.0.tgz#2166dda0128a3133e01b9c99f78c6a09f8f22950"
integrity sha512-UpbSF2pCDPPCyIKLTJchAPB4AbArl1qIXnX7eIdFWhBtkpL9t7r30Mc1qDrf83ypdxNBA2F75sWMu6PX058+Rw==
"@ably/[email protected]-dev.1715d4e":
version "8.0.0-dev.1715d4e"
resolved "https://registry.yarnpkg.com/@ably/ui/-/ui-8.0.0-dev.1715d4e.tgz#53100feaed4d0d4aba43b384a3b45412e4ccf932"
integrity sha512-M/n1WvT+0l/487edYSyDtE2wyLBgSyBMO6UbD/ysME0/rQJvK2PbGE+DULH1bwFZT8tyV7iEHb0Lit/c352m4g==
dependencies:
addsearch-js-client "^0.6.7"
array-flat-polyfill "^1.0.1"
Expand Down
6 changes: 4 additions & 2 deletions src/core/Meganav/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ const documentScroll = (themeName) => {
};
};

export default function Meganav({ themeName } = { themeName: null }) {
export default function Meganav(
{ themeName, addSearchApiKey } = { themeName: null }
) {
const controls = MeganavControl();
const panelOpenControls = MobilePanelOpenClick();
const panelCloseControls = MobilePanelCloseClick();
const search = MeganavSearchAutocomplete();
const search = MeganavSearchAutocomplete(addSearchApiKey);
const searchSuggestions = MeganavSearchSuggestions();

const mobileDropdownControl = MeganavControlMobileDropdown({
Expand Down
5 changes: 3 additions & 2 deletions src/core/Meganav/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const panels = {
MeganavContentDevelopers: MeganavContentDevelopers,
};

export default function Meganav({ paths, themeName = "white", notice, loginLink = "/login", urlBase }) {
export default function Meganav({ paths, themeName = "white", notice, loginLink = "/login", urlBase, addSearchApiKey }) {
const [sessionState, setSessionState] = useState(null);

useEffect(() => {
Expand All @@ -74,7 +74,7 @@ export default function Meganav({ paths, themeName = "white", notice, loginLink
}, []);

useEffect(() => {
const teardown = MeganavScripts({ themeName });
const teardown = MeganavScripts({ themeName, addSearchApiKey });
return () => teardown();
}, [sessionState]);

Expand Down Expand Up @@ -119,4 +119,5 @@ Meganav.propTypes = {
}),
loginLink: T.string,
urlBase: T.string,
addSearchApiKey: T.string,
};
4 changes: 2 additions & 2 deletions src/core/MeganavItemsSignedIn/component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@

<li>
<%= render(AblyUi::Core::MeganavSearch.new(url_base: url_base)) %>
<li>
</li>

<% if account? %>
<li class="ml-16">
<li>
<%= link_to "Dashboard", @session_data[:account][:links][:dashboard][:href], class: "ui-btn-secondary p-btn-small" %>
</li>
<% end %>
Expand Down
13 changes: 10 additions & 3 deletions src/core/MeganavSearchAutocomplete/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,16 @@ const init = ({ input, container, listContainer, clear, client }) => {

const renderResults =
(query) =>
(results = { suggestions: [] }) => {
(results = {}) => {
toggleClearBtn(query);

// Prevent invalid access error when key is invalid
if (!Array.isArray(results.suggestions)) {
clearResults();
return;
}

// Prevent key error from invalid key
if (results.suggestions.length === 0) {
clearResults();
return;
Expand Down Expand Up @@ -143,12 +150,12 @@ const init = ({ input, container, listContainer, clear, client }) => {
};
};

export default () => {
const apiKey = document.body.dataset.addSearchApiKey;
export default (apiKey) => {
if (!apiKey) {
console.log(`No AddSearch API key provided, skipping search suggestions.`);
return [];
}

const client = new AddSearchClient(apiKey);

return [
Expand Down

0 comments on commit ef22008

Please sign in to comment.