Skip to content

Commit

Permalink
Merge pull request #230 from ably/pricing-fixes
Browse files Browse the repository at this point in the history
Pricing fixes
  • Loading branch information
Dominik authored Nov 8, 2022
2 parents a4edf7e + 313dbf6 commit 5f8ff62
Show file tree
Hide file tree
Showing 22 changed files with 105 additions and 110 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.7.0.dev.68ea318)
ably-ui (8.7.0.dev.80c4fae)
view_component (>= 2.33, < 2.50)

GEM
Expand Down
4 changes: 2 additions & 2 deletions cypress/integration/core/flash/behaviour.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ describe("Flash", () => {

cy.get(flashesId).within(() => {
cy.get(flashId).filter(":visible").should("have.length", 2);
cy.get(flashId).eq(2).contains("This is an error, very bad");
cy.get(flashId).eq(3).contains("This is an alert");
cy.get(flashId).eq(0).contains("This is an error, very bad");
cy.get(flashId).eq(1).contains("This is an alert");
});
});
});
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.7.0.dev.68ea318'
VERSION = '8.7.0.dev.80c4fae'
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.7.0-dev.68ea318",
"version": "8.7.0-dev.80c4fae",
"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 @@ -37,7 +37,7 @@ gem 'view_component', '~> 2.33.0', require: 'view_component/engine'

gem 'responders'

gem 'ably-ui', '8.7.0.dev.68ea318', require: 'ably_ui'
gem 'ably-ui', '8.7.0.dev.80c4fae', 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.7.0.dev.68ea318)
ably-ui (8.7.0.dev.80c4fae)
view_component (>= 2.33, < 2.50)
actioncable (6.0.5.1)
actionpack (= 6.0.5.1)
Expand Down Expand Up @@ -175,7 +175,7 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
ably-ui (= 8.7.0.dev.68ea318)
ably-ui (= 8.7.0.dev.80c4fae)
bootsnap (>= 1.4.2)
byebug
dotenv-rails
Expand Down
2 changes: 1 addition & 1 deletion preview/app/controllers/components_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def meganav_props
def meganav_react_props
props = {
paths: {
logo: helpers.asset_path('ably_ui/core/images/ably-logo.svg'),
logo: helpers.asset_path('ably_ui/core/images/ably-logo.png'),
icon_sprites: helpers.asset_path('ably_ui/core/sprites.svg'),
ably_stack: helpers.asset_path('ably_ui/core/images/ably-stack.svg'),
aws_logo: helpers.asset_path('ably_ui/core/images/icon-tech-aws.svg')
Expand Down
19 changes: 16 additions & 3 deletions preview/app/views/components/logo_params.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
---
- :name: href
:optional: "Yes"
:default: "/"
:optional: "No"
:type: String
:description: Target URL
- :name: logoUrl
:optional: "No"
:type: String
:description: Link to logo image
- :name: dataId
:optional: "Yes"
:default: ""
:default: '""'
:type: String
:description: Identifier for DOM manipulation
- :name: additionalImgAttrs
:optional: "Yes"
:default: "{}"
:type: Object/Hash
:description: Additional attributes for the image DOM element
- :name: additionalLinkAttrs
:optional: "Yes"
:default: "{}"
:type: Object/Hash
:description: Additional attributes for the link DOM element
2 changes: 1 addition & 1 deletion preview/app/views/components/logo_react.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<%= render(ParameterTableComponent.new(component_parameters, framework)) %>

<%= react_component('logo') %>
<%= react_component('logo', { logo_url: asset_path('ably_ui/core/images/ably-logo.png') }) %>

<% content_for :component do %>
<script type="text/javascript">
Expand Down
2 changes: 1 addition & 1 deletion preview/app/views/components/logo_vw.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<%= render(ParameterTableComponent.new(component_parameters, framework)) %>

<%= render(AblyUi::Core::Logo.new(href: '/')) %>
<%= render(AblyUi::Core::Logo.new(href: '/', logo_url: asset_path('ably_ui/core/images/ably-logo.png'))) %>

<% content_for :component do %>
<script type="text/javascript">
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.7.0-dev.68ea318",
"@ably/ui": "8.7.0-dev.80c4fae",
"@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].68ea318":
version "8.7.0-dev.68ea318"
resolved "https://registry.yarnpkg.com/@ably/ui/-/ui-8.7.0-dev.68ea318.tgz#40cc9f125154946a88c8b0f6904ebf9968f79f89"
integrity sha512-n9ZonFIn0DBNRBDbHlc/JTXcrqSDqocrq+9xT8SQL6vSAxBpkXWgDKg9bTQ8zeV95g3dJltY+7oJOwnQ/CbQ3w==
"@ably/[email protected].80c4fae":
version "8.7.0-dev.80c4fae"
resolved "https://registry.yarnpkg.com/@ably/ui/-/ui-8.7.0-dev.80c4fae.tgz#0ac810518e2761fce5fb3ed27a848f995ab5aa13"
integrity sha512-D7dGGdJqauM3UYzdLhrjpk8c1p4FIKCUfGcIMf9DLbK0sDeAg3KhscWnKC6efkw6TkoowJRbKmGsXDMKcD9Gfg==
dependencies:
addsearch-js-client "^0.7.0"
array-flat-polyfill "^1.0.1"
Expand Down
2 changes: 0 additions & 2 deletions src/core/DropdownMenu/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ const Trigger = ({ children, additionalTriggerCSS = "" }) => {
);
};

<DropdownMenu.Trigger className="list of names">Click me</DropdownMenu.Trigger>;

Trigger.propTypes = {
children: T.node,
additionalTriggerCSS: T.string,
Expand Down
56 changes: 42 additions & 14 deletions src/core/Flash/component.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useEffect, useState, useRef } from "react";
import DOMPurify from "dompurify";
import T from "prop-types";
import { nanoid } from "nanoid/non-secure";

import { getRemoteDataStore } from "../remote-data-store";
import ConnectStateWrapper from "../ConnectStateWrapper/component.jsx";
Expand Down Expand Up @@ -50,30 +51,45 @@ const FLASH_TEXT_COLOR = {
const AUTO_HIDE = ["success", "info", "notice"];
const AUTO_HIDE_TIME = 8000;

const Flash = ({ type, content }) => {
const ref = useRef(null);
const [closed, setClosed] = useState(false);
const [flashHeight, setFlashHeight] = useState(0);
const [triggerEntryAnimation, setTriggerEntryAnimation] = useState(false);
const useAutoHide = (type, closeFlash) => {
const timeoutId = useRef(null);

useEffect(() => setTriggerEntryAnimation(true), []);
useEffect(() => {
if (AUTO_HIDE.includes(type)) {
setTimeout(() => {
// closeFlash is idempotent, we can call it even if the flash has been already closed
timeoutId.current = setTimeout(() => {
closeFlash();
}, AUTO_HIDE_TIME);
}
}, [closed]);

return () => {
if (timeoutId.current) {
clearTimeout(timeoutId.current);
}
};
}, []);
};

const Flash = ({ id, type, content, removeFlash }) => {
const ref = useRef(null);
const [closed, setClosed] = useState(false);
const [flashHeight, setFlashHeight] = useState(0);
const [triggerEntryAnimation, setTriggerEntryAnimation] = useState(false);

const closeFlash = () => {
if (ref.current) {
setFlashHeight(ref.current.getBoundingClientRect().height);
}

setTimeout(() => setClosed(true), 0);
setClosed(true);

setTimeout(() => {
removeFlash(id);
}, 100);
};

useEffect(() => setTriggerEntryAnimation(true), []);
useAutoHide(type, closeFlash);

const animateEntry = triggerEntryAnimation && !closed;

let style;
Expand Down Expand Up @@ -123,13 +139,25 @@ Flash.propTypes = {
};

const Flashes = ({ flashes }) => {
const items = flashes?.items || [];
const [flashesWithIds, setFlashesWithIds] = useState([]);

const removeFlash = (flashId) => setFlashesWithIds((items) => items.filter((item) => item.id !== flashId));

useEffect(() => {
setFlashesWithIds((state) => {
return [...state, ...(flashes?.items || []).map((flash) => ({ ...flash, id: nanoid(), removed: false }))];
});
}, [flashes]);

console.log({ flashesWithIds });

return (
<div className="ui-flash" data-id={FLASH_DATA_ID}>
{items.map((flash) => (
<Flash key={flash.type} {...flash} />
))}
{flashesWithIds
.filter((item) => !item.removed)
.map((flash) => (
<Flash removeFlash={removeFlash} key={flash.id} {...flash} />
))}
</div>
);
};
Expand Down
29 changes: 2 additions & 27 deletions src/core/Logo/component.html.erb
Original file line number Diff line number Diff line change
@@ -1,28 +1,3 @@
<%= link_to logo_href, class: 'h-32' do %>
<%= tag.svg class: ["transition-colors", "text-cool-black"], data: { id: data_id }, width: "108", height: "32", viewBox: "0 0 108 32", xmlns: "http://www.w3.org/2000/svg" do %>
<path
d="M62.922 24.9786V4.08813H66.6933V11.6512C67.9709 10.435 69.6164 9.76044 71.3538 9.76044C75.4318 9.76044 79.0498 12.8674 79.0498 17.5484C79.0498 22.2293 75.4318 25.3465 71.3538 25.3465C69.5244 25.3465 67.7971 24.6209 66.5094 23.3024V24.9786H62.922ZM75.2785 17.5484C75.2785 14.932 73.4183 13.1025 70.9859 13.1025C68.6148 13.1025 66.7853 14.84 66.6933 17.3644V17.5484C66.6933 20.1648 68.5534 21.9942 70.9859 21.9942C73.4183 21.9942 75.2785 20.1648 75.2785 17.5484ZM80.7975 24.9786V4.08813H84.5688V24.9786H80.7975ZM89.8425 30.3954L92.0399 25.1523L86.0712 10.1284H90.1491L93.9511 20.6247L97.8144 10.1284H101.954L93.8591 30.4056H89.8425V30.3954ZM56.9329 10.1284V12.0191C55.6247 10.5883 53.7952 9.77066 51.9147 9.77066C47.8367 9.77066 44.2187 12.8777 44.2187 17.5586C44.2187 22.2497 47.8367 25.3465 51.9147 25.3465C53.8668 25.3465 55.7166 24.4982 57.0555 22.9754V24.9888H60.3465V10.1284H56.9329ZM56.5649 17.5484C56.5649 20.1341 54.7048 21.9942 52.2724 21.9942C49.8399 21.9942 47.9798 20.1341 47.9798 17.5484C47.9798 14.9626 49.8399 13.1025 52.2724 13.1025C54.6435 13.1025 56.473 14.8706 56.5649 17.3644V17.5484Z"
fill="currentColor"
/>
<path d="M19.2858 0L3.14788 29.5369L0 27.3293L14.932 0H19.2858ZM19.5107 0L35.6487 29.5369L38.7965 27.3293L23.8646 0H19.5107Z" fill="url(#<%= gradient_id_0 %>)" />
<path d="M35.4238 29.7107L19.3983 17.16L3.37271 29.7107L6.64323 32L19.3983 22.0147L32.1533 32L35.4238 29.7107Z" fill="url(#<%= gradient_id_1 %>)" />
<defs>
<linearGradient id="<%= gradient_id_0 %>" x1="5.47361" y1="37.4219" x2="32.4603" y2="7.45023" gradientUnits="userSpaceOnUse">
<stop stop-color="#FF5416" />
<stop offset="0.2535" stop-color="#FF5115" />
<stop offset="0.461" stop-color="#FF4712" />
<stop offset="0.6523" stop-color="#FF350E" />
<stop offset="0.8327" stop-color="#FF1E08" />
<stop offset="1" stop-color="#FF0000" />
</linearGradient>
<linearGradient id="<%= gradient_id_1 %>" x1="10.7084" y1="39.3593" x2="26.6583" y2="21.6452" gradientUnits="userSpaceOnUse">
<stop stop-color="#FF5416" />
<stop offset="0.2535" stop-color="#FF5115" />
<stop offset="0.461" stop-color="#FF4712" />
<stop offset="0.6523" stop-color="#FF350E" />
<stop offset="0.8327" stop-color="#FF1E08" />
<stop offset="1" stop-color="#FF0000" />
</linearGradient>
</defs>
<% end %>
<%= link_to logo_href, class: 'block', style: "height: 2.125rem", data: { id: data_id }, **additional_link_attrs do %>
<%= tag.img src: logo_url, width: "108px", alt: "Ably logo", **additional_img_attrs %>
<% end %>
47 changes: 7 additions & 40 deletions src/core/Logo/component.jsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,20 @@
import React, { useMemo } from "react";
import React from "react";
import T from "prop-types";
import { nanoid } from "nanoid/non-secure";

const Logo = ({ dataId, href = "/" }) => {
// This fixes a bug where if the logo is rendered more than once on the page, and one of the instances
// if it is hidden, the other instance will not show the ably shape from the logo.

// This is because the defs in this SVG reference ids that need to be unique ids. The browser discards the "newer"
// linearGradients defined in the other logo, and inherits the `hidden` style from the first.
const gradientIds = useMemo(() => [nanoid(), nanoid()], []);

const Logo = ({ dataId, logoUrl, href = "/", additionalImgAttrs, additionalLinkAttrs }) => {
return (
<a href={href} className="h-32">
<svg data-id={dataId} className="text-cool-black transition-colors" width="108" height="32" viewBox="0 0 108 32" xmlns="http://www.w3.org/2000/svg">
<path
d="M62.922 24.9786V4.08813H66.6933V11.6512C67.9709 10.435 69.6164 9.76044 71.3538 9.76044C75.4318 9.76044 79.0498 12.8674 79.0498 17.5484C79.0498 22.2293 75.4318 25.3465 71.3538 25.3465C69.5244 25.3465 67.7971 24.6209 66.5094 23.3024V24.9786H62.922ZM75.2785 17.5484C75.2785 14.932 73.4183 13.1025 70.9859 13.1025C68.6148 13.1025 66.7853 14.84 66.6933 17.3644V17.5484C66.6933 20.1648 68.5534 21.9942 70.9859 21.9942C73.4183 21.9942 75.2785 20.1648 75.2785 17.5484ZM80.7975 24.9786V4.08813H84.5688V24.9786H80.7975ZM89.8425 30.3954L92.0399 25.1523L86.0712 10.1284H90.1491L93.9511 20.6247L97.8144 10.1284H101.954L93.8591 30.4056H89.8425V30.3954ZM56.9329 10.1284V12.0191C55.6247 10.5883 53.7952 9.77066 51.9147 9.77066C47.8367 9.77066 44.2187 12.8777 44.2187 17.5586C44.2187 22.2497 47.8367 25.3465 51.9147 25.3465C53.8668 25.3465 55.7166 24.4982 57.0555 22.9754V24.9888H60.3465V10.1284H56.9329ZM56.5649 17.5484C56.5649 20.1341 54.7048 21.9942 52.2724 21.9942C49.8399 21.9942 47.9798 20.1341 47.9798 17.5484C47.9798 14.9626 49.8399 13.1025 52.2724 13.1025C54.6435 13.1025 56.473 14.8706 56.5649 17.3644V17.5484Z"
fill="currentColor"
/>
<path
d="M19.2858 0L3.14788 29.5369L0 27.3293L14.932 0H19.2858ZM19.5107 0L35.6487 29.5369L38.7965 27.3293L23.8646 0H19.5107Z"
fill={`url(#${gradientIds[0]})`}
/>
<path d="M35.4238 29.7107L19.3983 17.16L3.37271 29.7107L6.64323 32L19.3983 22.0147L32.1533 32L35.4238 29.7107Z" fill={`url(#${gradientIds[1]})`} />
<defs>
<linearGradient id={gradientIds[0]} x1="5.47361" y1="37.4219" x2="32.4603" y2="7.45023" gradientUnits="userSpaceOnUse">
<stop stopColor="#FF5416" />
<stop offset="0.2535" stopColor="#FF5115" />
<stop offset="0.461" stopColor="#FF4712" />
<stop offset="0.6523" stopColor="#FF350E" />
<stop offset="0.8327" stopColor="#FF1E08" />
<stop offset="1" stopColor="#FF0000" />
</linearGradient>
<linearGradient id={gradientIds[1]} x1="10.7084" y1="39.3593" x2="26.6583" y2="21.6452" gradientUnits="userSpaceOnUse">
<stop stopColor="#FF5416" />
<stop offset="0.2535" stopColor="#FF5115" />
<stop offset="0.461" stopColor="#FF4712" />
<stop offset="0.6523" stopColor="#FF350E" />
<stop offset="0.8327" stopColor="#FF1E08" />
<stop offset="1" stopColor="#FF0000" />
</linearGradient>
</defs>
</svg>
<a href={href} data-id={dataId} className="block" style={{ height: "2.125rem" }} {...additionalLinkAttrs}>
<img src={logoUrl} width="108px" alt="Ably logo" {...additionalImgAttrs} />
</a>
);
};

Logo.propTypes = {
dataId: T.string,
href: T.string,
logoUrl: T.string,
additionalImgAttrs: T.object,
additionalLinkAttrs: T.object,
};

export default React.memo(Logo);
21 changes: 15 additions & 6 deletions src/core/Logo/component.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
require 'securerandom'

module AblyUi
module Core
class Logo < ViewComponent::Base
include AblyUi::Core::MeganavConfig

attr_reader :href, :data_id, :gradient_id_0, :gradient_id_1
attr_reader :href,
:logo_url,
:data_id,
:additional_img_attrs,
:additional_link_attrs

def initialize(data_id: '', href:)
def initialize(
href:,
logo_url:,
data_id: '',
additional_img_attrs: {},
additional_link_attrs: {}
)
@data_id = data_id
@href = href
@gradient_id_0 = "paint_linear_#{SecureRandom.uuid}"
@gradient_id_1 = "paint_linear_#{SecureRandom.uuid}"
@logo_url = logo_url
@additional_img_attrs = additional_img_attrs
@additional_link_attrs = additional_link_attrs
end

def logo_href
Expand Down
2 changes: 1 addition & 1 deletion src/core/Meganav/component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<div class="ui-meganav ui-grid-px">
<div className="mr-24">
<%= render(AblyUi::Core::Logo.new(data_id: "meganav-logo", href: logo_link)) %>
<%= render(AblyUi::Core::Logo.new(data_id: "meganav-logo", href: logo_link, logo_url: ably_logo)) %>
</div>
<%= render(AblyUi::Core::MeganavItemsDesktop.new(theme_name: @theme_name, url_base: url_base)) %>

Expand Down
2 changes: 1 addition & 1 deletion src/core/Meganav/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default function Meganav({ paths, themeName = "white", notice, loginLink
{notice && <Notice {...notice.props} config={notice.config} />}
<div className="ui-meganav ui-grid-px">
<div className="mr-24">
<Logo dataId="meganav-logo" href={urlBase} />
<Logo dataId="meganav-logo" href={urlBase} logoUrl={paths.logo} />
</div>

<MeganavItemsDesktop panels={panels} paths={paths} theme={theme} absUrl={absUrl} />
Expand Down
1 change: 1 addition & 0 deletions src/core/Meganav/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Core
class Meganav < ViewComponent::Base
include MeganavConfig
include Util
include SharedAssets
attr_reader :options, :login_link, :logo_link, :url_base

renders_one :notice, AblyUi::Core::Notice
Expand Down
Loading

0 comments on commit 5f8ff62

Please sign in to comment.