Skip to content

Commit

Permalink
ui: add bluesky and mastodon
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrc committed Dec 3, 2024
1 parent 46c5c6b commit 9371dbd
Show file tree
Hide file tree
Showing 69 changed files with 511 additions and 198 deletions.
14 changes: 14 additions & 0 deletions backend/inspirehep/submissions/marshmallow/author.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class Author(Schema):
status = fields.Raw()
arxiv_categories = fields.Raw()
websites = fields.Raw()
bluesky = fields.Raw()
mastodon = fields.Raw()
twitter = fields.Raw()
blog = fields.Raw()
linkedin = fields.Raw()
Expand Down Expand Up @@ -63,6 +65,12 @@ def before_dump(self, data):
),
"emails": get_value(data, "email_addresses", default=missing),
"status": get_value(data, "status", default=missing),
"bluesky": self.get_first_or_missing(
get_values_for_schema(data.get("ids", []), "BLUESKY")
),
"mastodon": self.get_first_or_missing(
get_values_for_schema(data.get("ids", []), "MASTODON")
),
"twitter": self.get_first_or_missing(
get_values_for_schema(data.get("ids", []), "TWITTER")
),
Expand Down Expand Up @@ -160,6 +168,12 @@ def build_author(self, data):
status = data.get("status")
author.set_status(status)

bluesky = data.get("bluesky")
author.add_bluesky(bluesky)

mastodon = data.get("mastodon")
author.add_mastodon(mastodon)

twitter = data.get("twitter")
author.add_twitter(twitter)

Expand Down
94 changes: 68 additions & 26 deletions backend/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Flask = ">=1.0.2"
msgpack = "==0.6.2"

python = ">=3.11,<3.12"
inspire-schemas = "^61.5.32"
inspire-schemas = "^61.6.1"
inspire-utils = "^3.0.61"
inspire-service-orcid = {git = "https://github.com/inspirehep/inspire-service-orcid.git", rev = "1a0e762e58bc9cac65f7665b9831993c017fd8bb"}
inspire-json-merger = "^11.0.37"
Expand Down
52 changes: 52 additions & 0 deletions backend/tests/unit/submissions/test_authors.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,58 @@ def test_load_author_linkedin():
assert result == expected


def test_dump_author_bluesky():
data = {
**DEFAULT_DATA_TO_DUMP,
"ids": [{"value": "username.bsky.social", "schema": "BLUESKY"}],
}

record = faker.record("aut", data=data)

result = Author().dump(record).data
expected = {**DEFAULT_DATA_DUMP, "bluesky": "username.bsky.social"}

assert result == expected


def test_load_author_bluesky():
data = {**DEFAULT_DATA_TO_DUMP, "bluesky": "username.bsky.social"}

result = Author().load(data).data
expected = {
**DEFAULT_DATA_LOAD,
"ids": [{"schema": "BLUESKY", "value": "username.bsky.social"}],
}

assert result == expected


def test_dump_author_mastodon():
data = {
**DEFAULT_DATA_TO_DUMP,
"ids": [{"value": "username@host", "schema": "MASTODON"}],
}

record = faker.record("aut", data=data)

result = Author().dump(record).data
expected = {**DEFAULT_DATA_DUMP, "mastodon": "username@host"}

assert result == expected


def test_load_author_mastodon():
data = {**DEFAULT_DATA_TO_DUMP, "mastodon": "username@host"}

result = Author().load(data).data
expected = {
**DEFAULT_DATA_LOAD,
"ids": [{"schema": "MASTODON", "value": "username@host"}],
}

assert result == expected


def test_dump_author_twitter():
data = {
**DEFAULT_DATA_TO_DUMP,
Expand Down
2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"lint": "./node_modules/eslint/bin/eslint.js ./src --ext \"**/*.{js,jsx,ts,tsx}\" --config .eslintrc"
},
"dependencies": {
"@ant-design/icons": "^4.0.0",
"@ant-design/icons": "^5.5.1",
"@babel/runtime": "7.0.0-beta.55",
"@craco/craco": "6.4.3",
"@sentry/browser": "^5.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ exports[`AssignDrawer renders assign authors search 1`] = `
<Button
data-test-id="assign-button"
disabled={true}
icon={<ForwardRef(SelectOutlined) />}
icon={<SelectOutlined />}
onClick={[Function]}
type="primary"
>
Expand Down
29 changes: 29 additions & 0 deletions ui/src/authors/components/AuthorBlueskyAction.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import { Tooltip } from 'antd';

import Icon from '@ant-design/icons';
import UserAction from '../../common/components/UserAction';
import LinkWithTargetBlank from '../../common/components/LinkWithTargetBlank';
import EventTracker from '../../common/components/EventTracker';
import { ReactComponent as blueskyLogo } from '../../common/assets/bluesky.svg';

const AuthorBlueskyAction = ({ bluesky }: { bluesky: string }) => {
const href = `//bsky.app/profile/${bluesky}`;
return (
<UserAction>
<EventTracker
eventCategory="Author detail"
eventAction="Link"
eventId="Bluesky"
>
<LinkWithTargetBlank href={href}>
<Tooltip title="Bluesky">
<Icon component={blueskyLogo} style={{ color: 'rgb(95,95,95)' }} />
</Tooltip>
</LinkWithTargetBlank>
</EventTracker>
</UserAction>
);
};

export default AuthorBlueskyAction;
30 changes: 30 additions & 0 deletions ui/src/authors/components/AuthorMastodonAction.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';
import { Tooltip } from 'antd';

import Icon from '@ant-design/icons';
import UserAction from '../../common/components/UserAction';
import LinkWithTargetBlank from '../../common/components/LinkWithTargetBlank';
import EventTracker from '../../common/components/EventTracker';
import { ReactComponent as mastodonLogo } from '../../common/assets/mastodon.svg';

const AuthorMastodonAction = ({ mastodon }: { mastodon: string }) => {
const [user, host] = mastodon ? mastodon.split('@') : [];
const href = `//${host}/@${user}`;
return (
<UserAction>
<EventTracker
eventCategory="Author detail"
eventAction="Link"
eventId="Mastodon"
>
<LinkWithTargetBlank href={href}>
<Tooltip title="Mastodon">
<Icon component={mastodonLogo} />
</Tooltip>
</LinkWithTargetBlank>
</EventTracker>
</UserAction>
);
};

export default AuthorMastodonAction;
Loading

0 comments on commit 9371dbd

Please sign in to comment.