-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add metadata fields to core entities (FE) (#3212)
Co-authored-by: Matthew Elwell <[email protected]>
- Loading branch information
1 parent
e9246bc
commit c5bd7a2
Showing
35 changed files
with
2,045 additions
and
367 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
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,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. | ||
|
||
 | ||
|
||
### 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. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,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 | ||
*/ |
Oops, something went wrong.