Skip to content

Commit

Permalink
chore: simplify useVariables usages
Browse files Browse the repository at this point in the history
Related to #1162
  • Loading branch information
Skaiir committed Sep 2, 2024
1 parent 2ac7c15 commit 3bdb5cb
Show file tree
Hide file tree
Showing 16 changed files with 33 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function PrefixAdorner(props) {

const debounce = useService('debounce');

const variables = useVariables().map((name) => ({ name }));
const variables = useVariables();

return FeelTemplatingEntry({
debounce,
Expand All @@ -72,7 +72,7 @@ function SuffixAdorner(props) {

const debounce = useService('debounce');

const variables = useVariables().map((name) => ({ name }));
const variables = useVariables();

return FeelTemplatingEntry({
debounce,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function AltText(props) {

const debounce = useService('debounce');

const variables = useVariables().map((name) => ({ name }));
const variables = useVariables();

const path = ['alt'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function ColumnsExpression(props) {

const debounce = useService('debounce');

const variables = useVariables().map((name) => ({ name }));
const variables = useVariables();

const getValue = () => {
return get(field, PATH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function Condition(props) {

const debounce = useService('debounce');

const variables = useVariables().map((name) => ({ name }));
const variables = useVariables();

const path = ['conditional', 'hide'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function Description(props) {

const debounce = useService('debounce');

const variables = useVariables().map((name) => ({ name }));
const variables = useVariables();

const path = ['description'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function ExpressionFieldExpression(props) {
const { editField, field, id } = props;

const debounce = useService('debounce');
const variables = useVariables().map((name) => ({ name }));
const variables = useVariables();

const getValue = () => field.expression || '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function Content(props) {

const debounce = useService('debounce');

const variables = useVariables().map((name) => ({ name }));
const variables = useVariables();

const path = ['content'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function Url(props) {

const debounce = useService('debounce');

const variables = useVariables().map((name) => ({ name }));
const variables = useVariables();

const path = ['url'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function Source(props) {

const debounce = useService('debounce');

const variables = useVariables().map((name) => ({ name }));
const variables = useVariables();

const path = ['source'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function Label(props) {

const debounce = useService('debounce');

const variables = useVariables().map((name) => ({ name }));
const variables = useVariables();

const path = ['label'];

Expand Down Expand Up @@ -89,7 +89,7 @@ function DateLabel(props) {

const debounce = useService('debounce');

const variables = useVariables().map((name) => ({ name }));
const variables = useVariables();

const path = DATE_LABEL_PATH;

Expand Down Expand Up @@ -118,7 +118,7 @@ function TimeLabel(props) {

const debounce = useService('debounce');

const variables = useVariables().map((name) => ({ name }));
const variables = useVariables();

const path = TIME_LABEL_PATH;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function OptionsExpression(props) {

const debounce = useService('debounce');

const variables = useVariables().map((name) => ({ name }));
const variables = useVariables();

const path = OPTIONS_SOURCES_PATHS[OPTIONS_SOURCES.EXPRESSION];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function Readonly(props) {

const debounce = useService('debounce');

const variables = useVariables().map((name) => ({ name }));
const variables = useVariables();

const path = ['readonly'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function Source(props) {

const debounce = useService('debounce');

const variables = useVariables().map((name) => ({ name }));
const variables = useVariables();

const path = ['dataSource'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function Text(props) {

const debounce = useService('debounce');

const variables = useVariables().map((name) => ({ name }));
const variables = useVariables();

const path = ['text'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function MinLength(props) {

const debounce = useService('debounce');

const variables = useVariables().map((name) => ({ name }));
const variables = useVariables();

return FeelNumberEntry({
debounce,
Expand All @@ -169,7 +169,7 @@ function MaxLength(props) {

const debounce = useService('debounce');

const variables = useVariables().map((name) => ({ name }));
const variables = useVariables();

return FeelNumberEntry({
debounce,
Expand Down Expand Up @@ -204,7 +204,7 @@ function Min(props) {

const debounce = useService('debounce');

const variables = useVariables().map((name) => ({ name }));
const variables = useVariables();

return FeelNumberEntry({
debounce,
Expand All @@ -224,7 +224,7 @@ function Max(props) {

const debounce = useService('debounce');

const variables = useVariables().map((name) => ({ name }));
const variables = useVariables();

return FeelNumberEntry({
debounce,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import { getSchemaVariables } from '@bpmn-io/form-js-viewer';
import { clone, getSchemaVariables } from '@bpmn-io/form-js-viewer';
import { useService } from './usePropertiesPanelService';
import { useMemo, useState } from 'preact/hooks';

/**
* Retrieve list of variables from the form schema.
* Retrieve list of variables from the form schema in the structure expected by FEEL entries.
*
* @returns { string[] } list of variables used in form schema
* @returns { { name: string; }[] } list of variables used in form schema
*/
export function useVariables() {
const form = useService('formEditor');
const schema = form.getSchema();
const [schema, setSchema] = useState(clone(form.getSchema()));

return getSchemaVariables(schema);
form.on('changed', ({ schema }) => {
if (schema !== undefined) {
setSchema(clone(schema));
}
});

return useMemo(() => getSchemaVariables(schema).map((name) => ({ name, type: 'variable' })), [schema]);
}

0 comments on commit 3bdb5cb

Please sign in to comment.