Refactor GlobalVariablesPage component to include default_fields in rowData
This commit is contained in:
parent
15de984bb6
commit
df6924c73e
3 changed files with 27 additions and 3 deletions
|
|
@ -22,7 +22,7 @@ import useFlowsManagerStore from "./stores/flowsManagerStore";
|
||||||
import { useGlobalVariablesStore } from "./stores/globalVariables";
|
import { useGlobalVariablesStore } from "./stores/globalVariables";
|
||||||
import { useStoreStore } from "./stores/storeStore";
|
import { useStoreStore } from "./stores/storeStore";
|
||||||
import { useTypesStore } from "./stores/typesStore";
|
import { useTypesStore } from "./stores/typesStore";
|
||||||
|
import { getUnavailableFields } from "./utils/utils";
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const removeFromTempNotificationList = useAlertStore(
|
const removeFromTempNotificationList = useAlertStore(
|
||||||
(state) => state.removeFromTempNotificationList
|
(state) => state.removeFromTempNotificationList
|
||||||
|
|
@ -48,6 +48,7 @@ export default function App() {
|
||||||
const setGlobalVariables = useGlobalVariablesStore(
|
const setGlobalVariables = useGlobalVariablesStore(
|
||||||
(state) => state.setGlobalVariables
|
(state) => state.setGlobalVariables
|
||||||
);
|
);
|
||||||
|
const setUnavailableFields = useGlobalVariablesStore((state) => state.setUnavaliableFields);
|
||||||
const checkHasStore = useStoreStore((state) => state.checkHasStore);
|
const checkHasStore = useStoreStore((state) => state.checkHasStore);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const dark = useDarkStore((state) => state.dark);
|
const dark = useDarkStore((state) => state.dark);
|
||||||
|
|
@ -95,6 +96,7 @@ export default function App() {
|
||||||
refreshFlows();
|
refreshFlows();
|
||||||
const res = await getGlobalVariables();
|
const res = await getGlobalVariables();
|
||||||
setGlobalVariables(res);
|
setGlobalVariables(res);
|
||||||
|
setUnavailableFields(getUnavailableFields(res));
|
||||||
checkHasStore();
|
checkHasStore();
|
||||||
fetchApiData();
|
fetchApiData();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,15 @@ export default function AddNewVariableButton({ children }): JSX.Element {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const setErrorData = useAlertStore((state) => state.setErrorData);
|
const setErrorData = useAlertStore((state) => state.setErrorData);
|
||||||
const componentFields = useTypesStore((state) => state.ComponentFields);
|
const componentFields = useTypesStore((state) => state.ComponentFields);
|
||||||
|
const unavaliableFields = useGlobalVariablesStore((state) => state.unavaliableFields);
|
||||||
|
const availableFields = Array.from(componentFields).filter((field) => !unavaliableFields.has(field));
|
||||||
const addGlobalVariable = useGlobalVariablesStore(
|
const addGlobalVariable = useGlobalVariablesStore(
|
||||||
(state) => state.addGlobalVariable
|
(state) => state.addGlobalVariable
|
||||||
);
|
);
|
||||||
|
console.log(componentFields);
|
||||||
|
console.log(unavaliableFields);
|
||||||
|
console.log(availableFields);
|
||||||
|
|
||||||
function handleSaveVariable() {
|
function handleSaveVariable() {
|
||||||
let data: { name: string; value: string; type?: string; default_fields?: string[] } = {
|
let data: { name: string; value: string; type?: string; default_fields?: string[] } = {
|
||||||
name: key,
|
name: key,
|
||||||
|
|
@ -39,6 +45,7 @@ export default function AddNewVariableButton({ children }): JSX.Element {
|
||||||
setKey("");
|
setKey("");
|
||||||
setValue("");
|
setValue("");
|
||||||
setType("");
|
setType("");
|
||||||
|
setFields([]);
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
|
@ -98,8 +105,8 @@ export default function AddNewVariableButton({ children }): JSX.Element {
|
||||||
setSelectedOptions={(value) => setFields(value)}
|
setSelectedOptions={(value) => setFields(value)}
|
||||||
selectedOptions={fields}
|
selectedOptions={fields}
|
||||||
password={false}
|
password={false}
|
||||||
options={Array.from(componentFields)}
|
options={availableFields}
|
||||||
placeholder="Choose a type for the variable..."
|
placeholder="Choose a field for the variable..."
|
||||||
></InputComponent>
|
></InputComponent>
|
||||||
</div>
|
</div>
|
||||||
</BaseModal.Content>
|
</BaseModal.Content>
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,21 @@ export function toTitleCase(
|
||||||
.join(" ");
|
.join(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getUnavailableFields(
|
||||||
|
variables:{[key: string]: { id: string; type: string,default_fields:string[] }}
|
||||||
|
): Set<string> {
|
||||||
|
console.log(variables)
|
||||||
|
const set = new Set<string>();
|
||||||
|
Object.keys(variables).forEach((key) => {
|
||||||
|
if(variables[key].default_fields){
|
||||||
|
variables[key].default_fields.forEach((field) => {
|
||||||
|
set.add(field);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
export const upperCaseWords: string[] = ["llm", "uri"];
|
export const upperCaseWords: string[] = ["llm", "uri"];
|
||||||
export function checkUpperWords(str: string): string {
|
export function checkUpperWords(str: string): string {
|
||||||
const words = str.split(" ").map((word) => {
|
const words = str.split(" ").map((word) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue