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

Sub-PR: expression fields fix playground root #1098

Merged

Conversation

Skaiir
Copy link
Contributor

@Skaiir Skaiir commented Mar 18, 2024

Sub-pr of #1074

@Skaiir Skaiir requested a review from vsgoulart March 18, 2024 04:53
@bpmn-io-tasks bpmn-io-tasks bot added the needs review Review pending label Mar 18, 2024
@bpmn-io-tasks bpmn-io-tasks bot added in progress Currently worked on and removed needs review Review pending labels Mar 18, 2024
@Skaiir Skaiir changed the title Sub-PR: hidden fields fix playground root Sub-PR: expression fields fix playground root Mar 18, 2024
Copy link
Contributor

@douglasbouttell-camunda douglasbouttell-camunda left a comment

Choose a reason for hiding this comment

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

Nothing major. Happy to discuss if any of them are useful.

Comment on lines +202 to +222
if (!apiLinkTarget) {
return;
}

apiLinkTarget.api = {
attachDataContainer: (node) => inputDataRef.current.attachTo(node),
attachResultContainer: (node) => outputDataRef.current.attachTo(node),
attachFormContainer: (node) => formViewerRef.current.attachTo(node),
attachEditorContainer: (node) => formEditorRef.current.attachTo(node),
attachPaletteContainer: (node) => formEditorRef.current.get('palette').attachTo(node),
attachPropertiesPanelContainer: (node) => formEditorRef.current.get('propertiesPanel').attachTo(node),
get: (name, strict) => formEditorRef.current.get(name, strict),
getDataEditor: () => inputDataRef.current,
getEditor: () => formEditorRef.current,
getForm: () => formViewerRef.current,
getResultView: () => outputDataRef.current,
getSchema: () => formEditorRef.current.getSchema(),
saveSchema: () => formEditorRef.current.saveSchema(),
setSchema: setSchema,
setData: setData
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this better than the callback function? If you use the callback pattern then it means that PlaygroundRoot doesn't need to have any knowledge of how the API object works.

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 guess it's mostly a preference thing. I just found the callback harder to read personally.

In any case, this class isn't exported at the moment so it's mostly just an implementation detail.


}, [ apiLinkTarget ]);

// separate effect for state to avoid re-creating the api object every time
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this a problem?

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 mostly did this because the state changes constantly, while the rest of the API really only gets set up once ideally.

}

apiLinkTarget.api.getState = () => ({ schema, data });
apiLinkTarget.api.load = load;
Copy link
Contributor

Choose a reason for hiding this comment

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

So we have two ways to load data: through the initial props and this api method.

Copy link
Contributor Author

@Skaiir Skaiir Mar 19, 2024

Choose a reason for hiding this comment

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

Yes exactly. I agree this isn't great and not react-like, but I didn't want to make any changes to any of the logic. Initializing with props feels quite hacky.

Comment on lines 180 to +186
useEffect(() => {
dataEditorRef.current.setValue(toString(initialData));
}, [ initialData ]);
if (!config.initialSchema) {
return;
}

load(config.initialSchema, config.initialData || {});
}, [ config.initialSchema, config.initialData, load ]);
Copy link
Contributor

Choose a reason for hiding this comment

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

I would have these be the default values of the useState calls.

const [ schema, setSchema ] = useState(config.initialSchema);
const [ data, setData ] = useState(config.initialData || {});

useEffect(() => {
  if (!schema) { 
    return; 
  }    
  formEditorRef.current.importSchema(schema, data);
  inputDataRef.current.setValue(toString(data));
  if (inputDataContainerRef.current) {
    const variables = getSchemaVariables(schema);
    inputDataRef.current.setVariables(variables);
  }
}, [ data, schema, getSchemaVariables ]);

This means you can git rid of the effect on 188-190, 192-197 and all load does it set the states.

@Skaiir Skaiir merged commit ae6d1d5 into 1073-hidden-fields-schema Mar 20, 2024
15 of 16 checks passed
@Skaiir Skaiir deleted the 1037-hidden-fields-fix-playground-root branch March 20, 2024 09:42
@bpmn-io-tasks bpmn-io-tasks bot removed the in progress Currently worked on label Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants