Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add metadata fields to core entities (FE) #3212

Merged
merged 136 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 132 commits
Commits
Show all changes
136 commits
Select commit Hold shift + click to select a range
f41c8d5
feat: Add metadata fields to core entities
novakzaballa Oct 13, 2023
e1bc9ec
feat: Add metadata model field
novakzaballa Oct 18, 2023
930c9c8
Add metadata to environments and segments
novakzaballa Oct 19, 2023
625e331
Solve error with metadataselect
novakzaballa Oct 19, 2023
2b0b9d5
Solve content types id
novakzaballa Oct 19, 2023
2293935
wrap the code with the enable_metadata flag
novakzaballa Oct 19, 2023
830a82a
Close MetadataSelect component
novakzaballa Oct 19, 2023
c1a0a7a
Merge branch 'main' into feat/add-metadata-fields-to-core-entities
novakzaballa Oct 20, 2023
95033ed
fix: Conflicts with merge
novakzaballa Oct 20, 2023
1a0c84a
fix: Cannot resolve useMetadata
novakzaballa Oct 20, 2023
db8f13a
fix: Cannot resolve useMetadata
novakzaballa Oct 20, 2023
a9c0490
fix: Rename useMetaData to useMetadata
novakzaballa Oct 20, 2023
2eac883
fix: Solve e2e tests
novakzaballa Oct 20, 2023
dc4d2a2
fix: Solve e2e test
novakzaballa Oct 20, 2023
74db03d
fix: metadata list styles
novakzaballa Oct 23, 2023
9f9b283
Fix behavior when metadata is Created or updated
novakzaballa Oct 24, 2023
5c65852
Update metadata UI
novakzaballa Oct 30, 2023
6f6512e
Update required metadata model fields for segments and flags
novakzaballa Oct 31, 2023
0b6c89b
Add test to metadata for features and segments
novakzaballa Nov 1, 2023
9a25d76
Merge branch 'main' into feat/add-metadata-fields-to-core-entities
novakzaballa Nov 1, 2023
8b08a3e
Update metadata UI required fields
novakzaballa Nov 3, 2023
557f68b
fix: Metadata for features
novakzaballa Nov 15, 2023
cc2bada
fix: Delete moved tests
novakzaballa Nov 15, 2023
c52cb3b
Merge branch 'main' into feat/add-metadata-fields-to-core-entities
novakzaballa Nov 17, 2023
14e0f92
fix responses
novakzaballa Nov 20, 2023
37e79e6
Delete disable, required, and enabled test, add a confirm modal to de…
novakzaballa Nov 20, 2023
5536f45
fix metadata search input
novakzaballa Nov 20, 2023
8a489a2
fix metadata search input
novakzaballa Nov 20, 2023
9ddf027
Update UpdateFeature serialier
novakzaballa Nov 20, 2023
aee6657
fix add metadata in features
novakzaballa Nov 21, 2023
2e19984
Add segment test and update segment serializer
novakzaballa Dec 14, 2023
3057e7c
Change UI in metadata tab
novakzaballa Dec 14, 2023
6f4871a
Merge branch 'main' into feat/add-metadata-fields-to-core-entities
novakzaballa Dec 14, 2023
a12ffa3
reformat files
novakzaballa Dec 14, 2023
429c673
reformat files
novakzaballa Dec 14, 2023
0275c09
Reformat file
novakzaballa Dec 14, 2023
9844cd5
Add description tooltip to metadata
novakzaballa Dec 15, 2023
8763b09
Add metadata docs
novakzaballa Dec 15, 2023
dc60ee4
Add metadata docs
novakzaballa Dec 15, 2023
28a5617
Adjust styles
novakzaballa Dec 19, 2023
0dc05e9
update test to support metadata query
novakzaballa Dec 21, 2023
1ec1125
Merge branch 'main' into feat/add-metadata-fields-to-core-entities
matthewelwell Dec 21, 2023
d06f518
Add logs for debug test on cloud
novakzaballa Dec 21, 2023
6cbd20c
Remove debug logs and update test
novakzaballa Dec 21, 2023
3217c37
adjust metadata styles
novakzaballa Dec 22, 2023
cef4d4e
Merge branch 'main' into feat/add-metadata-fields-to-core-entities
novakzaballa Dec 22, 2023
264bb0d
Add new tests
novakzaballa Jan 9, 2024
df39f39
Use supported content types endpoint
novakzaballa Jan 9, 2024
0643314
Improve code
novakzaballa Jan 9, 2024
8bee370
Rename component and improve supported content types service
novakzaballa Jan 10, 2024
c743a6f
Rename component and improve supported content types service
novakzaballa Jan 10, 2024
b56f8bd
Rename component
novakzaballa Jan 10, 2024
5d0c952
Solve issues with the renamed file
novakzaballa Jan 10, 2024
f0bfc37
Merge branch 'main' into feat/add-metadata-fields-to-core-entities
novakzaballa Jan 12, 2024
f1a4bb0
solve errors
novakzaballa Jan 19, 2024
131e847
Merge branch 'main' into feat/add-metadata-fields-to-core-entities
novakzaballa Jan 19, 2024
0c4d817
Solve tests errors
novakzaballa Jan 23, 2024
3ab272b
Delete unnecessary code
novakzaballa Jan 23, 2024
b342d58
Merge branch 'main' into feat/add-metadata-fields-to-core-entities
novakzaballa Apr 4, 2024
652a9d0
Remove API changes
novakzaballa Apr 4, 2024
67e474f
Fix npm docs error
novakzaballa Apr 4, 2024
e4fec07
Correct types, delete supportedContentTypes Request from store, use RTK
novakzaballa Apr 4, 2024
30af6f6
Delete comment
novakzaballa Apr 4, 2024
3a6864c
Correct segment types
novakzaballa Apr 4, 2024
3341574
Change types in CreateMetadata file
novakzaballa Apr 4, 2024
fba77d8
Merge branch 'main' into feat/add-metadata-fields-to-core-entities
novakzaballa Apr 7, 2024
6282e28
Solve getContentType types
novakzaballa Apr 7, 2024
661ecea
Create MetadataPage component
novakzaballa Apr 7, 2024
2006f79
Refactor feature Metadata select
novakzaballa Apr 7, 2024
dfb7ea4
Change class names
novakzaballa Apr 8, 2024
c7f1f06
Create new metadata components
novakzaballa Apr 8, 2024
98efcd7
New create metadata local logic
novakzaballa Apr 9, 2024
e0036c4
New flow to create MetadataField and MetadataModelField
novakzaballa Apr 9, 2024
85da11c
Update and delete metadata
novakzaballa Apr 10, 2024
f224fdd
Changes variable names
novakzaballa Apr 10, 2024
18b30b5
Change table for a panel search
novakzaballa Apr 10, 2024
77b33ac
Delete unnecesary code from _list.css
novakzaballa Apr 10, 2024
1677ac5
Delete redundant function
novakzaballa Apr 10, 2024
8a87411
Merge branch 'main' into feat/add-metadata-fields-to-core-entities
novakzaballa Apr 10, 2024
b44b863
Fix import error
novakzaballa Apr 10, 2024
7453a51
Add Metadata Docs
novakzaballa Apr 10, 2024
08d9797
change update
novakzaballa Apr 10, 2024
d87dff4
Clean logs
novakzaballa Apr 10, 2024
66ba1d6
Correct merge problem
novakzaballa Apr 10, 2024
a2b2f2f
Move button functionality to save function
novakzaballa Apr 10, 2024
25614d2
Use useMemo instead of useState
novakzaballa Apr 10, 2024
f8f7943
Solve create error
novakzaballa Apr 10, 2024
28872d6
Add content types to metadata table row
novakzaballa Apr 11, 2024
b87c99d
Rename type
novakzaballa Apr 11, 2024
71d5027
Rename type Metadata to MetadataField
novakzaballa Apr 11, 2024
f62bdfc
Create add metadata component
novakzaballa Apr 11, 2024
a2a95e1
Rename Metadata to MetadataField
novakzaballa Apr 11, 2024
2de5489
Improvements in the code
novakzaballa Apr 11, 2024
e985331
Improvement CreateMetadataField
novakzaballa Apr 11, 2024
2be4a6f
Update Documents, update UI in AddMetadataToEntity component
novakzaballa Apr 12, 2024
08318c4
UX/UI
novakzaballa Apr 12, 2024
3c70da6
Change UI metadata
novakzaballa Apr 15, 2024
c0b1f3f
UI/Ux
novakzaballa Apr 16, 2024
9e02761
Add UI changes
novakzaballa Apr 16, 2024
d32bba7
Update Environment metadata
novakzaballa Apr 16, 2024
1c9d52c
Solve error tests
novakzaballa Apr 16, 2024
e3ee0b5
delete duplicate code created by merge error
novakzaballa Apr 16, 2024
3e4392e
Solve error when try create a segment or a feature
novakzaballa Apr 17, 2024
ad2363d
deleted comment
novakzaballa Apr 18, 2024
02af18a
Delete Logs and comments
novakzaballa Apr 18, 2024
3e055c2
Move tooltips positions
novakzaballa Apr 18, 2024
2a70966
Add metadata to environment and segments
novakzaballa Apr 19, 2024
71ea34d
Add validation when the Metadata change
novakzaballa Apr 19, 2024
4be8797
Update types exports
novakzaballa Apr 19, 2024
6535df8
Add validation when save data
novakzaballa Apr 19, 2024
4824e33
Update create feature with metadata
novakzaballa Apr 22, 2024
ea652de
Update segments with metadata correction
novakzaballa Apr 22, 2024
011db90
Update feature-list-store
novakzaballa Apr 22, 2024
6f40645
Correct update environment with metadata
novakzaballa Apr 22, 2024
b395e7e
Delete unnecesary components
novakzaballa Apr 22, 2024
e883981
Merge branch 'main' into feat/add-metadata-fields-to-core-entities
novakzaballa Apr 22, 2024
fc96a29
Solve format issues
novakzaballa Apr 22, 2024
ca4d00d
Clean code
novakzaballa Apr 23, 2024
086cf75
Solve docs format
novakzaballa Apr 23, 2024
0bcd0fe
Update Docs and UI
novakzaballa Apr 23, 2024
2d7c8ca
Solve format issues
novakzaballa Apr 23, 2024
29a11df
Delete logs
novakzaballa Apr 23, 2024
b56b012
Clean code
novakzaballa Apr 23, 2024
ac7cfa8
Add comments in mergeMetadataEntityWithMetadataField function
novakzaballa Apr 23, 2024
f971775
Clean code
novakzaballa Apr 23, 2024
fc965d2
Clean code
novakzaballa Apr 23, 2024
7145d96
Change examples, save onBlur, Change boolean with a switch
novakzaballa Apr 25, 2024
e2d0418
Merge branch 'main' into feat/add-metadata-fields-to-core-entities
novakzaballa Apr 25, 2024
e90d205
Merge branch 'main' into feat/add-metadata-fields-to-core-entities
novakzaballa Apr 30, 2024
8377d38
Merge branch 'main' into feat/add-metadata-fields-to-core-entities
novakzaballa May 13, 2024
b145be7
docs: Move segments metadata docs to segments.md
novakzaballa May 13, 2024
61f2c5f
Solve scss issue
novakzaballa May 13, 2024
6e5f0ed
Merge branch 'main' into feat/add-metadata-fields-to-core-entities
novakzaballa May 15, 2024
e46d285
Solve merge metadata error
novakzaballa May 15, 2024
5501e4b
Merge branch 'main' into feat/add-metadata-fields-to-core-entities
novakzaballa May 15, 2024
17124db
Disable button when feature has metadata required
novakzaballa May 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/docs/basic-features/managing-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,15 @@ other Environments within the Project.
### Multi-Variate Flag Use Cases

The primary use case for using Multi-Variate flags is to drive [A/B tests](/advanced-use/ab-testing.md).

### Use Metadata

When creating or updating a feature, you can add Metadata if you was created Metadata Fields in Project Settings ->
Metadata.

You can add the Metadata in the Feature Setting Tab.

If you have metadata for features, a list of fields that can be filled, saved, and will be stored with the feature's
save flag will be displayed.

![Image](/img/metadata/metadata-feature-1.png)
14 changes: 14 additions & 0 deletions docs/docs/basic-features/segments.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,17 @@ These are the default limits for segments and rules:
- 1000 bytes per segment rule value

See the [documentation on System Limits](system-administration/system-limits.md) for more details.

## Use Metadata

When creating or updating a feature, you can add Metadata if you was created Metadata Fields in Project Settings ->
Metadata.

You can add the Metadata value in the Feature Setting Tab.

When creating or updating a segment, you can add Metadata. You can add the Metadata value in the Settings Setting Tab.

If you have metadata for features, it will create a list of fields that can be filled, saved, and will be stored with
the feature's save flag.

![Image](/img/metadata/metadata-segment-1.png)
10 changes: 10 additions & 0 deletions docs/docs/system-administration/environment-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,13 @@ This will result in identities receiving different variations and being evaluate
split operator) when evaluated against the remote API. Evaluations in local evaluation mode will not be affected.

:::

## Use Metadata

When creating or updating a segment, you can enhance its information by adding previously created and enabled metadata
fields. To create and enable this you can do it in the metadata tab on the project settings page.

If you have metadata for features, it will create a list of fields that can be filled, saved, and will be stored with
the feature's save flag.

![Image](/img/metadata/metadata-environment.png)
42 changes: 42 additions & 0 deletions docs/docs/system-administration/metadata/metadata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: Metadata
sidebar_position: 110
---

Flagsmith allows certain Entities within a Project to have Metadata of different types.

## Core Entities that support Metadata

- **[Features](/basic-features/managing-features#use-metadata)**.
- **[Environment](/system-administration/environment-settings#use-metadata)**.
- **[Segments](/basic-features/segments#use-metadata)**.

## Metadata Fields

To be able to add Metadata to your Entities, you first need to create Metadata fields within Project Settings ->
Metadata.

Here you'll also need to define whether it's optional or required.

- **Optional**: You may or may not add Metadata to your Entities.
- **Required**: You won't be able to update or create an Entity within your Project unless you include this Metadata.

![Image](/img/metadata/metadata-fields.png)

### Types of Metadata Field

Metadata Field supports five primary types of metadata values, each serving distinct purposes:

**String**: A basic data type representing text or alphanumeric characters. Strings are versatile and can describe a
wide range of attributes or characteristics.

**URL**: A type specifically designed to store web addresses or Uniform Resource Locators.

**Integer**: A numeric data type representing whole numbers without decimal points. Integers are useful for quantifiable
properties or attributes.

**Multiline String**: Similar to a standard string but capable of storing multiline text. Multiline strings are
beneficial for longer descriptions or content blocks.

**Boolean**: A data type with only two possible values: true or false. Booleans are ideal for representing binary
attributes or conditions.
kyle-ssg marked this conversation as resolved.
Show resolved Hide resolved
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/static/img/metadata/metadata-feature-1.png
Copy link
Member

@kyle-ssg kyle-ssg Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a save button by each meta is quite clunky can we either

A. Save on blur
B. Save on save settings click

A might make sense, I think in a future PR we can make all settings save without clicking save.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I save on blur.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/static/img/metadata/metadata-fields.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/static/img/metadata/metadata-segment-1.png
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My original comment got swallowed by other commits I think. We should document how meta items are entered

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the docs when the necessary information for creating metadata.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions frontend/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ export default {
'Set different values for your feature based on what segments users are in. Identity overrides will take priority over any segment override.',
TAGS_DESCRIPTION:
'Organise your flags with tags, tagging your features as "<strong>protected</strong>" will prevent them from accidentally being deleted.',
TOOLTIP_METADATA_DESCRIPTION: 'Add metadata in your',
USER_PROPERTY_DESCRIPTION:
'The name of the user trait or custom property belonging to the user, e.g. firstName',
WEBHOOKS_DESCRIPTION:
Expand Down
26 changes: 26 additions & 0 deletions frontend/common/services/useEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ export const environmentService = service
url: `environments/?project=${data.projectId}`,
}),
}),
updateEnvironment: builder.mutation<
Res['environment'],
Req['updateEnvironment']
>({
invalidatesTags: (res) => [
{ id: 'LIST', type: 'Environment' },
{ id: res?.id, type: 'Environment' },
],
query: (query: Req['updateEnvironment']) => ({
body: query.body,
method: 'PUT',
url: `environments/${query.id}/`,
}),
}),
// END OF ENDPOINTS
}),
})
Expand All @@ -47,11 +61,23 @@ export async function getEnvironment(
environmentService.endpoints.getEnvironment.initiate(data, options),
)
}
export async function updateEnvironment(
store: any,
data: Req['updateEnvironment'],
options?: Parameters<
typeof environmentService.endpoints.updateEnvironment.initiate
>[1],
) {
return store.dispatch(
environmentService.endpoints.updateEnvironment.initiate(data, options),
)
}
// END OF FUNCTION_EXPORTS

export const {
useGetEnvironmentQuery,
useGetEnvironmentsQuery,
useUpdateEnvironmentMutation,
// END OF EXPORTS
} = environmentService

Expand Down
137 changes: 137 additions & 0 deletions frontend/common/services/useMetadataField.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import { Res } from 'common/types/responses'
import { Req } from 'common/types/requests'
import { service } from 'common/service'
import Utils from 'common/utils/utils'

export const metadataService = service
.enhanceEndpoints({ addTagTypes: ['Metadata'] })
.injectEndpoints({
endpoints: (builder) => ({
createMetadataField: builder.mutation<
Res['metadataField'],
Req['createMetadataField']
>({
invalidatesTags: [{ id: 'LIST', type: 'Metadata' }],
query: (query: Req['createMetadataField']) => ({
body: query.body,
method: 'POST',
url: `metadata/fields/`,
}),
}),
deleteMetadataField: builder.mutation<
Res['metadataField'],
Req['deleteMetadataField']
>({
invalidatesTags: [{ id: 'LIST', type: 'Metadata' }],
query: (query: Req['deleteMetadataField']) => ({
method: 'DELETE',
url: `metadata/fields/${query.id}/`,
}),
}),
getMetadataField: builder.query<
Res['metadataField'],
Req['getMetadataField']
>({
providesTags: (res) => [{ id: res?.id, type: 'Metadata' }],
query: (query: Req['getMetadataField']) => ({
url: `metadata/fields/${query.organisation_id}/`,
}),
}),
getMetadataFieldList: builder.query<
Res['metadataList'],
Req['getMetadataList']
>({
providesTags: [{ id: 'LIST', type: 'Metadata' }],
query: (query: Req['getMetadataList']) => ({
url: `metadata/fields/?${Utils.toParam(query)}`,
}),
}),
updateMetadataField: builder.mutation<
Res['metadataField'],
Req['updateMetadataField']
>({
invalidatesTags: (res) => [
{ id: 'LIST', type: 'Metadata' },
{ id: res?.id, type: 'Metadata' },
],
query: (query: Req['updateMetadataField']) => ({
body: query.body,
method: 'PUT',
url: `metadata/fields/${query.id}/`,
}),
}),
// END OF ENDPOINTS
}),
})

export async function createMetadataField(
store: any,
data: Req['createMetadataField'],
options?: Parameters<
typeof metadataService.endpoints.createMetadataField.initiate
>[1],
) {
return store.dispatch(
metadataService.endpoints.createMetadataField.initiate(data, options),
)
}
export async function deleteMetadataField(
store: any,
data: Req['deleteMetadataField'],
options?: Parameters<
typeof metadataService.endpoints.deleteMetadataField.initiate
>[1],
) {
return store.dispatch(
metadataService.endpoints.deleteMetadataField.initiate(data, options),
)
}
export async function getMetadata(
store: any,
data: Req['getMetadataField'],
options?: Parameters<
typeof metadataService.endpoints.getMetadataField.initiate
>[1],
) {
return store.dispatch(
metadataService.endpoints.getMetadataField.initiate(data, options),
)
}
export async function getMetadataList(
store: any,
data: Req['getMetadataList'],
options?: Parameters<
typeof metadataService.endpoints.getMetadataFieldList.initiate
>[1],
) {
return store.dispatch(
metadataService.endpoints.getMetadataFieldList.initiate(data, options),
)
}
export async function updateMetadata(
store: any,
data: Req['updateMetadataField'],
options?: Parameters<
typeof metadataService.endpoints.updateMetadataField.initiate
>[1],
) {
return store.dispatch(
metadataService.endpoints.updateMetadataField.initiate(data, options),
)
}
// END OF FUNCTION_EXPORTS

export const {
useCreateMetadataFieldMutation,
useDeleteMetadataFieldMutation,
useGetMetadataFieldListQuery,
useGetMetadataFieldQuery,
useUpdateMetadataFieldMutation,
// END OF EXPORTS
} = metadataService

/* Usage examples:
const { data, isLoading } = useGetMetadataFieldQuery({ id: 2 }, {}) //get hook
const [createMetadataField, { isLoading, data, isSuccess }] = useCreateMetadataFieldMutation() //create hook
metadataService.endpoints.getMetadataField.select({id: 2})(store.getState()) //access data from any function
*/