Skip to content

Commit

Permalink
adds new method
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagoapolo committed Jan 16, 2025
1 parent a7f37a8 commit be4e81b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
25 changes: 11 additions & 14 deletions frontend/common/utils/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,16 @@ const Utils = Object.assign({}, require('./base/_utils'), {
getFlagsmithValue(key: string) {
return flagsmith.getValue(key)
},
copyToClipboard: async (value: string, successMessage?: string, errorMessage?: string) => {
try {
await navigator.clipboard.writeText(value)
toast(successMessage ?? 'Copied to clipboard')
} catch (error) {
toast(errorMessage ?? 'Failed to copy to clipboard')
throw error
}
},

getIdentitiesEndpoint(_project: ProjectType) {
const project = _project || ProjectStore.model
if (project && project.use_edge_identities) {
Expand All @@ -285,7 +295,6 @@ const Utils = Object.assign({}, require('./base/_utils'), {
defaultFlags.integration_data,
)
},

getIsEdge() {
const model = ProjectStore.model as null | ProjectType

Expand Down Expand Up @@ -329,14 +338,14 @@ const Utils = Object.assign({}, require('./base/_utils'), {
}
}
},

getOrganisationHomePage(id?: string) {
const orgId = id || AccountStore.getOrganisation()?.id
if (!orgId) {
return `/organisations`
}
return `/organisation/${orgId}/projects`
},

getPlanName: (plan: string) => {
if (plan && plan.includes('free')) {
return planNames.free
Expand All @@ -358,15 +367,6 @@ const Utils = Object.assign({}, require('./base/_utils'), {
}
return planNames.free
},
copyToClipboard: async (value: string, successMessage?: string, errorMessage?: string) => {
try {
await navigator.clipboard.writeText(value)
toast(successMessage ?? 'Copied to clipboard')
} catch (error) {
toast(errorMessage ?? 'Failed to copy to clipboard')
throw error
}
},
getPlanPermission: (plan: string, feature: PaidFeature) => {
const planName = Utils.getPlanName(plan)
if (!plan || planName === planNames.free) {
Expand Down Expand Up @@ -403,7 +403,6 @@ const Utils = Object.assign({}, require('./base/_utils'), {
)
return !!found
},

getProjectColour(index: number) {
return Constants.projectColors[index % (Constants.projectColors.length - 1)]
},
Expand Down Expand Up @@ -624,7 +623,6 @@ const Utils = Object.assign({}, require('./base/_utils'), {
</Tooltip>
)
},

sanitiseDiffString: (value: FlagsmithValue) => {
if (value === undefined || value == null) {
return ''
Expand Down Expand Up @@ -707,7 +705,6 @@ const Utils = Object.assign({}, require('./base/_utils'), {
)
}
},

valueToFeatureState(value: FlagsmithValue, trimSpaces = true) {
const val = Utils.getTypedValue(value, undefined, trimSpaces)

Expand Down
2 changes: 1 addition & 1 deletion frontend/web/components/CompareEnvironments.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class CompareEnvironments extends Component {
</div>
<Button
onClick={() => {
Utils.copyFeatureName(p.projectFlagLeft.name)
Utils.copyToClipboard(p.projectFlagLeft.name)
}}
theme='icon'
className='ms-2 me-2'
Expand Down
2 changes: 1 addition & 1 deletion frontend/web/components/CompareIdentities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ const CompareIdentities: FC<CompareIdentitiesType> = ({
</Tooltip>
</span>
<Button
onClick={() => Utils.copyFeatureName(name)}
onClick={() => Utils.copyToClipboard(name)}
theme='icon'
className='ms-2 me-2'
>
Expand Down
4 changes: 2 additions & 2 deletions frontend/web/components/pages/UserPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ const UserPage: FC<UserPageType> = (props) => {
<span className='standard-case'>{projectFlag.name}</span>
<Button
onClick={() => {
Utils.copyFeatureName(projectFlag.name)
Utils.copyToClipboard(projectFlag.name)
}}
theme='icon'
className='ms-2'
Expand Down Expand Up @@ -701,7 +701,7 @@ const UserPage: FC<UserPageType> = (props) => {
onClick={(e) => {
e?.stopPropagation()
e?.currentTarget?.blur()
Utils.copyFeatureName(
Utils.copyToClipboard(
projectFlag.name,
)
}}
Expand Down

0 comments on commit be4e81b

Please sign in to comment.