-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "Code" badge to code-configured data sources (#264)
* Add "Code" badge to code-configured data sources * Add tooltip
- Loading branch information
1 parent
5e9a8e2
commit 534f12f
Showing
3 changed files
with
87 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { Icon, Tooltip } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { chevronRightSmall } from '@wordpress/icons'; | ||
|
||
import { DataSourceConfig } from '@/data-sources/types'; | ||
import './DataSourceList.scss'; | ||
|
||
interface DataSourceMetaTagsProps { | ||
source: DataSourceConfig; | ||
} | ||
|
||
interface DataSourceMetaTag { | ||
key: string; | ||
primaryValue: string; | ||
secondaryValue?: string; | ||
} | ||
|
||
const DataSourceDescriptor = ( props: DataSourceMetaTagsProps ) => { | ||
let tag: DataSourceMetaTag | undefined; | ||
|
||
switch ( props.source.service ) { | ||
case 'airtable': | ||
tag = { | ||
key: 'base', | ||
primaryValue: props.source.service_config.base?.name, | ||
secondaryValue: props.source.service_config.tables?.[ 0 ]?.name, | ||
}; | ||
break; | ||
case 'shopify': | ||
tag = { key: 'store', primaryValue: props.source.service_config.store_name }; | ||
break; | ||
case 'google-sheets': | ||
tag = { | ||
key: 'spreadsheet', | ||
primaryValue: props.source.service_config.spreadsheet.name ?? 'Google Sheet', | ||
secondaryValue: props.source.service_config.sheets[ 0 ]?.name, | ||
}; | ||
break; | ||
} | ||
|
||
if ( ! tag ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<span key={ tag.key } className="data-source-meta"> | ||
{ tag.primaryValue } | ||
{ tag.secondaryValue && ( | ||
<> | ||
<Icon icon={ chevronRightSmall } style={ { fill: '#949494', verticalAlign: 'middle' } } /> | ||
{ tag.secondaryValue } | ||
</> | ||
) } | ||
</span> | ||
); | ||
}; | ||
|
||
const CodeBadge = () => { | ||
return ( | ||
<Tooltip text={ __( 'This data source is configured in code.', 'remote-data-blocks' ) }> | ||
<span className="data-source-badge">Code</span> | ||
</Tooltip> | ||
); | ||
}; | ||
|
||
const DataSourceMetaTags = ( props: DataSourceMetaTagsProps ) => { | ||
return ( | ||
<> | ||
{ ! props.source.uuid && <CodeBadge /> } | ||
<DataSourceDescriptor source={ props.source } /> | ||
</> | ||
); | ||
}; | ||
|
||
export default DataSourceMetaTags; |