Skip to content

Commit

Permalink
feat: Add sane defaults for segment_operators, integration_data, saml…
Browse files Browse the repository at this point in the history
… flags (#4554)
  • Loading branch information
rolodato authored Aug 30, 2024
1 parent 3b20df1 commit ff5c0ed
Show file tree
Hide file tree
Showing 8 changed files with 343 additions and 24 deletions.
309 changes: 309 additions & 0 deletions frontend/common/stores/default-flags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,309 @@
const defaultFlags = {
integration_data: {
'amplitude': {
'description': 'Sends data on what flags served to each identity.',
'docs': 'https://docs.flagsmith.com/integrations/analytics/amplitude',
'fields': [
{
'hidden': true,
'key': 'api_key',
'label': 'API Key',
},
{
'key': 'base_url',
'label': 'Base URL',
},
],
'image': '/static/images/integrations/amplitude.svg',
'perEnvironment': true,
'tags': ['analytics'],
'title': 'Amplitude',
},
'datadog': {
'description':
'Sends events to Datadog for when flags are created, updated and removed. Logs are tagged with the environment they came from e.g. production.',
'docs': 'https://docs.flagsmith.com/integrations/apm/datadog',
'fields': [
{
'key': 'base_url',
'label': 'Base URL',
},
{
'hidden': true,
'key': 'api_key',
'label': 'API Key',
},
{
'default': true,
'inputType': 'checkbox',
'key': 'use_custom_source',
'label': 'Use Custom Source',
},
],
'image': '/static/images/integrations/datadog.svg',
'perEnvironment': false,
'tags': ['logging'],
'title': 'Datadog',
},
'dynatrace': {
'description':
'Sends events to Dynatrace for when flags are created, updated and removed. Logs are tagged with the environment they came from e.g. production.',
'docs': 'https://docs.flagsmith.com/integrations/apm/dynatrace',
'fields': [
{
'key': 'base_url',
'label': 'Base URL',
},
{
'hidden': true,
'key': 'api_key',
'label': 'API Key',
},
{
'key': 'entity_selector',
'label': 'Entity Selector',
},
],
'image': '/static/images/integrations/dynatrace.svg',
'perEnvironment': true,
'tags': ['logging'],
'title': 'Dynatrace',
},
'grafana': {
'description':
'Receive Flagsmith annotations to your Grafana instance on feature flag and segment changes.',
'docs': 'https://docs.flagsmith.com/integrations/apm/grafana',
'fields': [
{
'default': 'https://grafana.com',
'key': 'base_url',
'label': 'Base URL',
},
{
'hidden': true,
'key': 'api_key',
'label': 'Service account token',
},
],
'image': '/static/images/integrations/grafana.svg',
'perEnvironment': false,
'tags': ['logging'],
'title': 'Grafana',
},

'heap': {
'description': 'Sends data on what flags served to each identity.',
'docs': 'https://docs.flagsmith.com/integrations/analytics/heap',
'fields': [
{
'hidden': true,
'key': 'api_key',
'label': 'API Key',
},
],
'image': '/static/images/integrations/heap.svg',
'perEnvironment': true,
'tags': ['analytics'],
'title': 'Heap Analytics',
},
'jira': {
'description': 'View your Flagsmith Flags inside Jira.',
'docs': 'https://docs.flagsmith.com/integrations/project-management/jira',
'external': true,
'image': 'https://docs.flagsmith.com/img/integrations/jira/jira-logo.svg',
'perEnvironment': false,
'title': 'Jira',
},
'mixpanel': {
'description': 'Sends data on what flags served to each identity.',
'docs': 'https://docs.flagsmith.com/integrations/analytics/mixpanel',
'fields': [
{
'hidden': true,
'key': 'api_key',
'label': 'Project Token',
},
],
'image': '/static/images/integrations/mp.svg',
'perEnvironment': true,
'tags': ['analytics'],
'title': 'Mixpanel',
},
'new-relic': {
'description':
'Sends events to New Relic for when flags are created, updated and removed.',
'docs': 'https://docs.flagsmith.com/integrations/apm/newrelic',
'fields': [
{
'key': 'base_url',
'label': 'New Relic Base URL',
},
{
'hidden': true,
'key': 'api_key',
'label': 'New Relic API Key',
},
{
'key': 'app_id',
'label': 'New Relic Application ID',
},
],
'image': '/static/images/integrations/new_relic.svg',
'perEnvironment': false,
'tags': ['analytics'],
'title': 'New Relic',
},
'rudderstack': {
'description': 'Sends data on what flags served to each identity.',
'docs': 'https://docs.flagsmith.com/integrations/analytics/rudderstack',
'fields': [
{
'key': 'base_url',
'label': 'Rudderstack Data Plane URL',
},
{
'hidden': true,
'key': 'api_key',
'label': 'API Key',
},
],
'image': '/static/images/integrations/rudderstack.svg',
'perEnvironment': true,
'tags': ['analytics'],
'title': 'Rudderstack',
},
'segment': {
'description': 'Sends data on what flags served to each identity.',
'docs': 'https://docs.flagsmith.com/integrations/analytics/segment',
'fields': [
{
'hidden': true,
'key': 'api_key',
'label': 'API Key',
},
],
'image': '/static/images/integrations/segment.svg',
'perEnvironment': true,
'tags': ['analytics'],
'title': 'Segment',
},
'slack': {
'description':
'Sends messages to Slack when flags are created, updated and removed. Logs are tagged with the environment they came from e.g. production.',
'docs': 'https://docs.flagsmith.com/integrations/slack',
'image': '/static/images/integrations/slack.svg',
'isOauth': true,
'perEnvironment': true,
'tags': ['messaging'],
'title': 'Slack',
},
'webhook': {
'description':
'Sends data on what flags served to each identity to a Webhook Endpoint you provide.',
'docs': 'https://docs.flagsmith.com/integrations/webhook',
'fields': [
{
'key': 'url',
'label': 'Your Webhook URL Endpoint',
},
{
'hidden': true,
'key': 'secret',
'label': 'Your Webhook Secret',
},
],
'image': '/static/images/integrations/webhooks.svg',
'perEnvironment': true,
'tags': ['analytics'],
'title': 'Webhook',
},
},
segment_operators: [
{
'label': 'Exactly Matches (=)',
'value': 'EQUAL',
},
{
'label': 'Does not match (!=)',
'value': 'NOT_EQUAL',
},
{
'label': '% Split',
'value': 'PERCENTAGE_SPLIT',
},
{
'label': '>',
'type': 'number',
'value': 'GREATER_THAN',
},
{
'label': '>=',
'type': 'number',
'value': 'GREATER_THAN_INCLUSIVE',
},
{
'label': '<',
'type': 'number',
'value': 'LESS_THAN',
},
{
'label': '<=',
'type': 'number',
'value': 'LESS_THAN_INCLUSIVE',
},
{
'append': ':semver',
'label': 'SemVer >',
'value': 'GREATER_THAN:semver',
},
{
'append': ':semver',
'label': 'SemVer >=',
'value': 'GREATER_THAN_INCLUSIVE:semver',
},
{
'append': ':semver',
'label': 'SemVer <',
'value': 'LESS_THAN:semver',
},
{
'append': ':semver',
'label': 'SemVer <=',
'value': 'LESS_THAN_INCLUSIVE:semver',
},
{
'label': 'Modulo',
'value': 'MODULO',
'valuePlaceholder': 'Divisor|Remainder',
},
{
'label': 'Contains',
'value': 'CONTAINS',
},
{
'label': 'Does not contain',
'value': 'NOT_CONTAINS',
},
{
'label': 'In',
'value': 'IN',
'valuePlaceholder': 'Value1,Value2',
},
{
'label': 'Matches regex',
'value': 'REGEX',
},
{
'hideValue': true,
'label': 'Is set',
'value': 'IS_SET',
},
{
'hideValue': true,
'label': 'Is not set',
'value': 'IS_NOT_SET',
},
],
}

export { defaultFlags }
27 changes: 24 additions & 3 deletions frontend/common/utils/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import ErrorMessage from 'components/ErrorMessage'
import WarningMessage from 'components/WarningMessage'
import Constants from 'common/constants'
import Format from './format'
import { defaultFlags } from 'common/stores/default-flags'

const semver = require('semver')

Expand Down Expand Up @@ -165,6 +166,12 @@ const Utils = Object.assign({}, require('./base/_utils'), {

return conditions.find((v) => v.value === operator)
},
/** Checks whether the specified flag exists, which is different from the flag being enabled or not. This is used to
* only add behaviour to Flagsmith-on-Flagsmith flags that have been explicitly created by customers.
*/
flagsmithFeatureExists(flag: string) {
return Object.prototype.hasOwnProperty.call(flagsmith.getAllFlags(), flag)
},
getApproveChangeRequestPermission() {
return 'APPROVE_CHANGE_REQUEST'
},
Expand Down Expand Up @@ -261,6 +268,14 @@ const Utils = Object.assign({}, require('./base/_utils'), {
}
return 'identities'
},

getIntegrationData() {
return Utils.getFlagsmithJSONValue(
'integration_data',
defaultFlags.integration_data,
)
},

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

Expand Down Expand Up @@ -444,6 +459,14 @@ const Utils = Object.assign({}, require('./base/_utils'), {
}
return Project.api
},

getSegmentOperators() {
return Utils.getFlagsmithJSONValue(
'segment_operators',
defaultFlags.segment_operators,
)
},

getShouldHideIdentityOverridesTab(_project: ProjectType) {
const project = _project || ProjectStore.model
if (!Utils.getIsEdge()) {
Expand Down Expand Up @@ -642,9 +665,7 @@ const Utils = Object.assign({}, require('./base/_utils'), {
return true
}

const operators = Utils.getFlagsmithValue('segment_operators')
? JSON.parse(Utils.getFlagsmithValue('segment_operators'))
: []
const operators = Utils.getSegmentOperators()
const operatorObj = Utils.findOperator(rule.operator, rule.value, operators)

if (operatorObj?.type === 'number') {
Expand Down
4 changes: 1 addition & 3 deletions frontend/web/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,7 @@ const App = class extends Component {
return <div>{this.props.children}</div>
}
const isOrganisationSelect = document.location.pathname === '/organisations'
const integrations = Object.keys(
JSON.parse(Utils.getFlagsmithValue('integration_data') || '{}'),
)
const integrations = Object.keys(Utils.getIntegrationData())
return (
<Provider store={getStore()}>
<AccountProvider
Expand Down
Loading

0 comments on commit ff5c0ed

Please sign in to comment.