forked from metabase/metabase
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
112 changed files
with
3,230 additions
and
717 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
frontend/src/metabase/admin/settings/components/widgets/PublicLinksListing.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* @flow */ | ||
|
||
import React, { Component, PropTypes } from "react"; | ||
|
||
import Icon from "metabase/components/Icon"; | ||
import Link from "metabase/components/Link"; | ||
import ExternalLink from "metabase/components/ExternalLink"; | ||
import LoadingAndErrorWrapper from "metabase/components/LoadingAndErrorWrapper"; | ||
|
||
import { CardApi, DashboardApi } from "metabase/services"; | ||
import Urls from "metabase/lib/urls"; | ||
|
||
type PublicLink = { | ||
id: string, | ||
name: string, | ||
public_uuid: string | ||
}; | ||
|
||
type Props = { | ||
load: () => Promise<PublicLink[]>, | ||
revoke: (link: PublicLink) => Promise<void>, | ||
getUrl: (link: PublicLink) => string, | ||
getPublicUrl: (link: PublicLink) => string, | ||
}; | ||
|
||
type State = { | ||
list: ?PublicLink[], | ||
error: ?any | ||
}; | ||
|
||
export default class PublicLinksListing extends Component<*, Props, State> { | ||
props: Props; | ||
state: State; | ||
|
||
constructor(props: Props) { | ||
super(props); | ||
this.state = { | ||
list: null, | ||
error: null | ||
}; | ||
} | ||
|
||
componentWillMount() { | ||
this.load(); | ||
} | ||
|
||
async load() { | ||
try { | ||
const list = await this.props.load(); | ||
this.setState({ list }); | ||
} catch (error) { | ||
this.setState({ error }); | ||
} | ||
} | ||
|
||
async revoke(link: PublicLink) { | ||
try { | ||
await this.props.revoke(link); | ||
this.load(); | ||
} catch (error) { | ||
alert(error) | ||
} | ||
} | ||
|
||
render() { | ||
const { getUrl, getPublicUrl } = this.props; | ||
const { list, error } = this.state; | ||
return ( | ||
<LoadingAndErrorWrapper loading={!list} error={error}> | ||
{ () => | ||
<table className="ContentTable"> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
<th>Public Link</th> | ||
<th>Revoke Link</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{ list && list.map(link => | ||
<tr> | ||
<td> | ||
<Link to={getUrl(link)}> | ||
{link.name} | ||
</Link> | ||
</td> | ||
<td> | ||
<ExternalLink href={getPublicUrl(link)}> | ||
{getPublicUrl(link)} | ||
</ExternalLink> | ||
</td> | ||
<td className="flex layout-centered"> | ||
<Icon | ||
name="close" | ||
className="text-grey-2 text-grey-4-hover cursor-pointer" | ||
onClick={() => this.revoke(link)} | ||
/> | ||
</td> | ||
</tr> | ||
) } | ||
</tbody> | ||
</table> | ||
} | ||
</LoadingAndErrorWrapper> | ||
); | ||
} | ||
} | ||
|
||
export const PublicLinksDashboardListing = () => | ||
<PublicLinksListing | ||
load={DashboardApi.listPublic} | ||
revoke={DashboardApi.deletePublicLink} | ||
getUrl={({ id }) => Urls.dashboard(id)} | ||
getPublicUrl={({ public_uuid }) => window.location.origin + Urls.publicDashboard(public_uuid)} | ||
/>; | ||
|
||
export const PublicLinksQuestionListing = () => | ||
<PublicLinksListing | ||
load={CardApi.listPublic} | ||
revoke={CardApi.deletePublicLink} | ||
getUrl={({ id }) => Urls.card(id)} | ||
getPublicUrl={({ public_uuid }) => window.location.origin + Urls.publicCard(public_uuid)} | ||
/>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.