mirror of
https://github.com/flarum/core.git
synced 2025-08-07 08:56:38 +02:00
feat: use common component for ip address display (#4042)
This commit is contained in:
@@ -91,6 +91,7 @@ import AlertManagerState from './states/AlertManagerState';
|
|||||||
import ModalManagerState from './states/ModalManagerState';
|
import ModalManagerState from './states/ModalManagerState';
|
||||||
import PageState from './states/PageState';
|
import PageState from './states/PageState';
|
||||||
import LabelValue from './components/LabelValue';
|
import LabelValue from './components/LabelValue';
|
||||||
|
import IPAddress from './components/IPAddress';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
extenders,
|
extenders,
|
||||||
@@ -169,6 +170,7 @@ export default {
|
|||||||
'components/Tooltip': Tooltip,
|
'components/Tooltip': Tooltip,
|
||||||
'components/EditUserModal': EditUserModal,
|
'components/EditUserModal': EditUserModal,
|
||||||
'components/LabelValue': LabelValue,
|
'components/LabelValue': LabelValue,
|
||||||
|
'components/IPAddress': IPAddress,
|
||||||
Model: Model,
|
Model: Model,
|
||||||
Application: Application,
|
Application: Application,
|
||||||
'helpers/fullTime': fullTime,
|
'helpers/fullTime': fullTime,
|
||||||
|
38
framework/core/js/src/common/components/IPAddress.tsx
Normal file
38
framework/core/js/src/common/components/IPAddress.tsx
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import Component, { ComponentAttrs } from '../Component';
|
||||||
|
import type Mithril from 'mithril';
|
||||||
|
import ItemList from '../utils/ItemList';
|
||||||
|
|
||||||
|
export interface IIPAddressAttrs extends ComponentAttrs {
|
||||||
|
ip: string | undefined | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A component to wrap an IP address for display.
|
||||||
|
* Designed to be customizable for different use cases.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* <IPAddress ip="127.0.0.1" />
|
||||||
|
* @example
|
||||||
|
* <IPAddress ip={post.data.attributes.ipAddress} />
|
||||||
|
*/
|
||||||
|
export default class IPAddress<CustomAttrs extends IIPAddressAttrs = IIPAddressAttrs> extends Component<CustomAttrs> {
|
||||||
|
ip!: string;
|
||||||
|
|
||||||
|
oninit(vnode: Mithril.Vnode<CustomAttrs, this>) {
|
||||||
|
super.oninit(vnode);
|
||||||
|
|
||||||
|
this.ip = this.attrs.ip || '';
|
||||||
|
}
|
||||||
|
|
||||||
|
view() {
|
||||||
|
return <span className="IPAddress">{this.viewItems().toArray()}</span>;
|
||||||
|
}
|
||||||
|
|
||||||
|
viewItems(): ItemList<Mithril.Children> {
|
||||||
|
const items = new ItemList<Mithril.Children>();
|
||||||
|
|
||||||
|
items.add('ip', <span>{this.ip}</span>, 100);
|
||||||
|
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
}
|
@@ -11,6 +11,7 @@ import Tooltip from '../../common/components/Tooltip';
|
|||||||
import type Mithril from 'mithril';
|
import type Mithril from 'mithril';
|
||||||
import type AccessToken from '../../common/models/AccessToken';
|
import type AccessToken from '../../common/models/AccessToken';
|
||||||
import { NestedStringArray } from '@askvortsov/rich-icu-message-formatter';
|
import { NestedStringArray } from '@askvortsov/rich-icu-message-formatter';
|
||||||
|
import IPAddress from '../../common/components/IPAddress';
|
||||||
|
|
||||||
export interface IAccessTokensListAttrs extends ComponentAttrs {
|
export interface IAccessTokensListAttrs extends ComponentAttrs {
|
||||||
tokens: AccessToken[];
|
tokens: AccessToken[];
|
||||||
@@ -100,7 +101,12 @@ export default class AccessTokensList<CustomAttrs extends IAccessTokensListAttrs
|
|||||||
token.lastActivityAt() ? (
|
token.lastActivityAt() ? (
|
||||||
<>
|
<>
|
||||||
{humanTime(token.lastActivityAt())}
|
{humanTime(token.lastActivityAt())}
|
||||||
{token.lastIpAddress() && ` — ${token.lastIpAddress()}`}
|
{token.lastIpAddress() && (
|
||||||
|
<span>
|
||||||
|
{' '}
|
||||||
|
— <IPAddress ip={token.lastIpAddress()} />
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
{this.attrs.type === 'developer_token' && token.device() && (
|
{this.attrs.type === 'developer_token' && token.device() && (
|
||||||
<>
|
<>
|
||||||
{' '}
|
{' '}
|
||||||
|
@@ -3,6 +3,7 @@ import Component from '../../common/Component';
|
|||||||
import humanTime from '../../common/helpers/humanTime';
|
import humanTime from '../../common/helpers/humanTime';
|
||||||
import fullTime from '../../common/helpers/fullTime';
|
import fullTime from '../../common/helpers/fullTime';
|
||||||
import ItemList from '../../common/utils/ItemList';
|
import ItemList from '../../common/utils/ItemList';
|
||||||
|
import IPAddress from '../../common/components/IPAddress';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `PostMeta` component displays the time of a post, and when clicked, shows
|
* The `PostMeta` component displays the time of a post, and when clicked, shows
|
||||||
@@ -78,7 +79,13 @@ export default class PostMeta extends Component {
|
|||||||
|
|
||||||
items.add('post-time', <span className="PostMeta-time">{fullTime(time)}</span>, 90);
|
items.add('post-time', <span className="PostMeta-time">{fullTime(time)}</span>, 90);
|
||||||
|
|
||||||
items.add('post-ip', <span className="PostMeta-ip">{post.data.attributes.ipAddress}</span>, 80);
|
items.add(
|
||||||
|
'post-ip',
|
||||||
|
<span className="PostMeta-ip">
|
||||||
|
<IPAddress ip={post.data.attributes.ipAddress} />
|
||||||
|
</span>,
|
||||||
|
80
|
||||||
|
);
|
||||||
|
|
||||||
items.add(
|
items.add(
|
||||||
'permalink',
|
'permalink',
|
||||||
|
Reference in New Issue
Block a user