-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ComponentList component, ensure correct status behavior
- Loading branch information
1 parent
77782e9
commit 288d05e
Showing
6 changed files
with
178 additions
and
150 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,134 @@ | ||
import * as React from 'react' | ||
import { Action } from 'redux' | ||
import classNames from 'classnames' | ||
import { DatasetStatus, ComponentType } from '../models/store' | ||
|
||
interface FileRowProps { | ||
name: string | ||
displayName: string | ||
filename?: string | ||
selected?: boolean | ||
status?: string | ||
selectionType?: ComponentType | ||
disabled?: boolean | ||
onClick?: (type: ComponentType, activeTab: string) => Action | ||
} | ||
|
||
export const FileRow: React.FunctionComponent<FileRowProps> = (props) => { | ||
let statusColor | ||
switch (props.status) { | ||
case 'modified': | ||
statusColor = '#cab081' | ||
break | ||
case 'add': | ||
statusColor = '#83d683' | ||
break | ||
case 'removed': | ||
statusColor = '#e04f4f' | ||
break | ||
default: | ||
statusColor = 'transparent' | ||
} | ||
|
||
return ( | ||
<div | ||
className={classNames('sidebar-list-item', 'sidebar-list-item-text', { | ||
'selected': props.selected, | ||
'disabled': props.disabled | ||
})} | ||
onClick={() => { | ||
if (props.onClick && props.selectionType && props.name) { | ||
props.onClick(props.selectionType, props.name) | ||
} | ||
}} | ||
> | ||
<div className='text-column'> | ||
<div className='text'>{props.displayName}</div> | ||
<div className='subtext'>{props.filename}</div> | ||
</div> | ||
<div className='status-column'> | ||
<span className='dot' style={{ backgroundColor: statusColor }}></span> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
FileRow.displayName = 'FileRow' | ||
|
||
interface ComponentListProps { | ||
status: DatasetStatus | ||
selectedComponent: string | ||
onComponentClick: (type: ComponentType, activeTab: string) => Action | ||
selectionType: ComponentType | ||
isLinked?: boolean | ||
} | ||
|
||
const components = [ | ||
{ | ||
name: 'meta', | ||
displayName: 'Meta' | ||
}, | ||
{ | ||
name: 'body', | ||
displayName: 'Body' | ||
}, | ||
{ | ||
name: 'schema', | ||
displayName: 'Schema' | ||
} | ||
] | ||
|
||
const ComponentList: React.FunctionComponent<ComponentListProps> = (props: ComponentListProps) => { | ||
const { | ||
status, | ||
selectedComponent, | ||
onComponentClick, | ||
selectionType, | ||
isLinked | ||
} = props | ||
|
||
return ( | ||
<div> | ||
<div className='sidebar-list-item sidebar-list-item-text sidebar-list-header'> | ||
Dataset Components | ||
</div> | ||
{ | ||
components.map(({ name, displayName }) => { | ||
if (status[name]) { | ||
const { filepath, status: fileStatus } = status[name] | ||
let filename | ||
if (filepath === 'repo') { | ||
filename = '' | ||
} else { | ||
filename = filepath.substring((filepath.lastIndexOf('/') + 1)) | ||
} | ||
|
||
return ( | ||
<FileRow | ||
key={name} | ||
displayName={displayName} | ||
name={name} | ||
filename={isLinked ? filename : ''} | ||
status={fileStatus} | ||
selected={selectedComponent === name} | ||
selectionType={selectionType} | ||
onClick={onComponentClick} | ||
/> | ||
) | ||
} else { | ||
return ( | ||
<FileRow | ||
key={name} | ||
displayName={displayName} | ||
name={displayName} | ||
disabled={true} | ||
/> | ||
) | ||
} | ||
}) | ||
} | ||
</div> | ||
) | ||
} | ||
|
||
export default ComponentList |
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.