-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #178 from devtron-labs/tag-label
App Tag label
- Loading branch information
Showing
13 changed files
with
474 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { PATTERNS } from '../../config'; | ||
import React, { lazy, Suspense, useCallback, useRef, useEffect, useState } from 'react'; | ||
|
||
export function validateTags(tag) { | ||
var re = PATTERNS.APP_LABEL_CHIP; | ||
let regExp = new RegExp(re); | ||
let result = regExp.test(String(tag)); | ||
return result; | ||
} | ||
|
||
export const TAG_VALIDATION_MESSAGE = { | ||
error: 'Please provide tags in key:value format only' | ||
} | ||
|
||
export const createOption = (label: string) => ( | ||
{ | ||
label: label, | ||
value: label, | ||
}); | ||
|
||
export function handleKeyDown(labelTags, setAppTagLabel, event) { | ||
|
||
labelTags.inputTagValue = labelTags.inputTagValue.trim(); | ||
switch (event.key) { | ||
case 'Enter': | ||
case 'Tab': | ||
case ',': | ||
case ' ': // space | ||
if (labelTags.inputTagValue) { | ||
setAppTagLabel() | ||
} | ||
if (event.key !== 'Tab') { | ||
event.preventDefault(); | ||
} | ||
break; | ||
} | ||
} |
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,64 @@ | ||
import React from 'react' | ||
import { ReactComponent as Close } from '../../../assets/icons/ic-close.svg'; | ||
import moment from 'moment' | ||
import { Moment12HourFormat } from '../../../config'; | ||
import { Progressing } from '../../common'; | ||
import TagLabelSelect from './TagLabelSelect'; | ||
import { ReactComponent as Error } from '../../../assets/icons/ic-warning.svg'; | ||
import { validateTags } from '../appLabelCommon' | ||
|
||
export default function AboutAppInfoModal({ onClose, appMetaResult, isLoading, labelTags, handleInputChange, handleTagsChange, handleKeyDown, handleCreatableBlur, handleSubmit, submitting }) { | ||
|
||
const renderAboutModalInfoHeader = () => { | ||
return <div className="modal__header"> | ||
<div className="fs-20 cn-9 fw-6">About</div> | ||
<button className="transparent" onClick={() => onClose(false)}> | ||
<Close className="icon-dim-24 cursor" /> | ||
</button> | ||
</div> | ||
} | ||
|
||
const renderValidationMessaging = () => { | ||
if (labelTags.tagError !== "") { | ||
return <div className="cr-5 fs-11"> | ||
<Error className="form__icon form__icon--error" />{labelTags.tagError} | ||
</div> | ||
} | ||
} | ||
|
||
const renderAboutModalInfo = () => { | ||
return <div> | ||
<div className="pt-12"> | ||
<div className="cn-6 fs-12 mb-2">App name</div> | ||
<div className="cn-9 fs-14 mb-16">{appMetaResult?.appName}</div> | ||
</div> | ||
<div> | ||
<div className="cn-6 fs-12 mb-2">Created on</div> | ||
<div className="cn-9 fs-14 mb-16">{moment(appMetaResult?.createdOn).format(Moment12HourFormat)}</div> | ||
</div> | ||
<div> | ||
<div className="cn-6 fs-12 mb-2">Created by</div> | ||
<div className="cn-9 fs-14 mb-16">{appMetaResult?.createdBy}</div> | ||
</div> | ||
<div> | ||
<div className="cn-6 fs-12 mb-2">Project</div> | ||
<div className="cn-9 fs-14 mb-16">{appMetaResult?.projectName}</div> | ||
</div> | ||
<TagLabelSelect validateTags={validateTags} labelTags={labelTags} onInputChange={handleInputChange} onTagsChange={handleTagsChange} onKeyDown={handleKeyDown} onCreatableBlur={handleCreatableBlur} /> | ||
{renderValidationMessaging()} | ||
<div className='form__buttons mt-40'> | ||
<button className=' cta' type="submit" disabled={submitting} onClick={(e) => { e.preventDefault(); handleSubmit(e) }} tabIndex={5} > | ||
{submitting ? <Progressing /> : ' Save'} | ||
</button> | ||
</div> | ||
</div> | ||
} | ||
|
||
return (<div> | ||
{renderAboutModalInfoHeader()} | ||
{isLoading ? <div className="flex" style={{ minHeight: "400px" }}> | ||
<Progressing pageLoader /> | ||
</div> : renderAboutModalInfo()} | ||
</div> | ||
) | ||
} |
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,63 @@ | ||
import React,{useMemo} from 'react'; | ||
import Creatable from 'react-select/creatable'; | ||
import { ClearIndicator, MultiValueRemove, MultiValueChipContainer } from '../../common'; | ||
|
||
export default function TagLabelSelect({ validateTags, labelTags, onInputChange, onKeyDown, onTagsChange, onCreatableBlur }) { | ||
const creatableOptions = useMemo(() => ([]), []) | ||
const CreatableChipStyle = { | ||
multiValue: (base, state) => { | ||
return ({ | ||
...base, | ||
border: validateTags(state.data.value) ? `1px solid var(--N200)` : `1px solid var(--R500)`, | ||
borderRadius: `4px`, | ||
background: validateTags(state.data.value) ? 'white' : 'var(--R100)', | ||
height: '28px', | ||
margin: '8px 8px 4px 0px', | ||
paddingLeft: '4px', | ||
fontSize: '12px', | ||
}) | ||
}, | ||
control: (base, state) => ({ | ||
...base, | ||
border: state.isFocused ? '1px solid #06c' : '1px solid #d0d4d9', // default border color | ||
boxShadow: 'none', // no box-shadow | ||
minHeight: '72px', | ||
alignItems: "end", | ||
}), | ||
indicatorsContainer: () => ({ | ||
height: '28px' | ||
}) | ||
} | ||
|
||
return ( | ||
<div> | ||
<span className="form__label cn-6"> Tags (only key:value allowed)</span> | ||
<Creatable | ||
className={"create-app_tags"} | ||
options={creatableOptions} | ||
components={{ | ||
DropdownIndicator: () => null, | ||
ClearIndicator, | ||
MultiValueRemove, | ||
MultiValueContainer: ({ ...props }) => <MultiValueChipContainer {...props} validator={validateTags} />, | ||
IndicatorSeparator: () => null, | ||
Menu: () => null, | ||
}} | ||
styles={CreatableChipStyle} | ||
autoFocus | ||
isMulti | ||
isClearable | ||
inputValue={labelTags.inputTagValue} | ||
placeholder="Add a tag..." | ||
isValidNewOption={() => false} | ||
backspaceRemovesValue | ||
value={labelTags.tags} | ||
onBlur={onCreatableBlur} | ||
onInputChange={onInputChange} | ||
onKeyDown={onKeyDown} | ||
onChange={onTagsChange} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
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 |
---|---|---|
@@ -1,3 +1,10 @@ | ||
.tab-list__tab-link.active .tab-list__icon path { | ||
fill: var(--B500); | ||
} | ||
} | ||
|
||
.tab-list__info-icon + .tab-list__info{ | ||
min-width: 400px; | ||
position: absolute; | ||
top: 40px; | ||
margin-left: 140px; | ||
} |
Oops, something went wrong.