I’m trying to create a list of available filters. ...
# gooddata-platform
c
I’m trying to create a list of available filters. Is there an easy way to get the Ldm through the SDK? I can find so little documentation about Ldm.
j
Hi Chris! Thanks for reaching out 🙂
By SDK I assume you mean the GoodData.UI JavaScript/React SDK? right?
If you'd like to "export the Ldm" (export the metadata objects like metrics, attributes, insights, …) into a JSON file, you can use the catalog export tool. It comes bundled with create-gooddata-react-app, so if you used that to start your GD.UI project, it should be ready. Look into package.json for
refresh-md
command (used to be
refresh-ldm
in earlier versions).
If you'd like to list some metadata objects directly in your source code using JavaScript, our SDK has methods you can use. Unfortunately, at this point the methods are only documented in the code – we're working on exporting all the docs into a nice HTML and expose it as part of our official documentation – but for now you can take a look at the source code and let your IDE intellisense help you.
c
Thank you!
I’m looking at this tool and noticed that we will be generating a static file. So the undocumented part would that make it dynamic?
j
Yes, the tool gives you a static file.
If you want something more dynamic directly in your source code, you can try something like this:
Copy code
import bearFactory, { ContextDeferredAuthProvider }from "@gooddata/sdk-backend-bear";
// import tigerFactory, { ContextDeferredAuthProvider } from "@gooddata/sdk-backend-tiger";

const backend = bearFactory(backendConfig).withAuthentication(new ContextDeferredAuthProvider());

backend.workspace('<workspace-id>').attributes();
backend.workspace('<workspace-id>').attributes().getAttribute(idRef("orderdate.year", "attribute")).then(console.log);
"Returns factory that can be used to query workspace catalog items - attributes, measures, facts and date data sets."
backend.workspace('<workspace-id>').catalog();
c
That looks like exactly what I need!
I’m trying this example from the docs:
Copy code
<AttributeFilter
                    filter={newNegativeAttributeFilter(Ldm.EmployeeName.Default, [])}
                    onApply={this.onApply}
                />
However, whatever attribute I try that I get from the call you just gave me. It doesn’t seem to load, I keep getting “Error loading filter”.
Am I getting the wrong attributes here?
j
The example you are trying is actually using the static exported catalog into JSON file. That
Ldm
variable is exposing the JSON file in your source code.
Do you know the identifier of the attribute you'd like to use?
It seems there's two problems you're trying to solve simultaneously, 1️⃣ dynamically list all the available attributes, and 2️⃣ create a functional AttributeFilter based on a specific attribute.
We should resolve them one by one. Which one would you like to tackle first?
c
I think 2 would be easy once I have 1. So any help with #1 would be amazing
j
Alright, let's tackle #1 first 🙂
Do you know the identifier of the attribute you'd like to use?
Let's try to make it work with a hardcoded identifier first, and then we can try to retrieve it dynamically.
c
I’d prefer to get all that are available. But I have an identifier called
label.accounts.account_name
that I know works
Really appreciate all your help btw
j
And this identifier works with your AttributeFilter component?
You can see list all available attributes also by visiting
https://<<http://your.gooddata.domain.com|your.gooddata.domain.com>>/gdc/md/<workspace-id>/query/attributes
.
c
This identifier works with the filter yes. I just called that URL, and surprisingly the
label.accounts.account_name
is not in there.
And none of the identifiers seem to work
j
Please make sure that you are supplying an attribute label (=displayForm), not the attribute itself.
You are looking for an attribute displayForm identifier, not the attribute identifier.
Screen Shot 2021-07-29 at 14.31.21.png
c
😱 That worked!
🎉 1
j
Yay! 👏
c
Thanks for all your help Jiri
j
Happy to help Chris!