|
@@ -52,13 +52,23 @@ export const BuildpackStack: React.FC<{
|
|
|
branch: string;
|
|
branch: string;
|
|
|
hide: boolean;
|
|
hide: boolean;
|
|
|
onChange: (config: BuildConfig) => void;
|
|
onChange: (config: BuildConfig) => void;
|
|
|
-}> = ({ actionConfig, folderPath, branch, hide, onChange }) => {
|
|
|
|
|
|
|
+ currentBuildConfig?: BuildConfig;
|
|
|
|
|
+}> = ({
|
|
|
|
|
+ actionConfig,
|
|
|
|
|
+ folderPath,
|
|
|
|
|
+ branch,
|
|
|
|
|
+ hide,
|
|
|
|
|
+ onChange,
|
|
|
|
|
+ currentBuildConfig,
|
|
|
|
|
+}) => {
|
|
|
const { currentProject } = useContext(Context);
|
|
const { currentProject } = useContext(Context);
|
|
|
|
|
|
|
|
const [builders, setBuilders] = useState<DetectedBuildpack[]>(null);
|
|
const [builders, setBuilders] = useState<DetectedBuildpack[]>(null);
|
|
|
|
|
|
|
|
const [stacks, setStacks] = useState<string[]>(null);
|
|
const [stacks, setStacks] = useState<string[]>(null);
|
|
|
- const [selectedStack, setSelectedStack] = useState<string>(null);
|
|
|
|
|
|
|
+ const [selectedStack, setSelectedStack] = useState<string>(
|
|
|
|
|
+ currentBuildConfig?.builder || null
|
|
|
|
|
+ );
|
|
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
|
|
|
|
|
|
const [selectedBuildpacks, setSelectedBuildpacks] = useState<Buildpack[]>([]);
|
|
const [selectedBuildpacks, setSelectedBuildpacks] = useState<Buildpack[]>([]);
|
|
@@ -66,14 +76,13 @@ export const BuildpackStack: React.FC<{
|
|
|
[]
|
|
[]
|
|
|
);
|
|
);
|
|
|
const renderModalContent = () => {
|
|
const renderModalContent = () => {
|
|
|
|
|
+ console.log(selectedBuildpacks);
|
|
|
return (
|
|
return (
|
|
|
<>
|
|
<>
|
|
|
<Text size={16}>Buildpack Configuration</Text>
|
|
<Text size={16}>Buildpack Configuration</Text>
|
|
|
<Spacer y={1} />
|
|
<Spacer y={1} />
|
|
|
<Scrollable>
|
|
<Scrollable>
|
|
|
- <Text color="helper">
|
|
|
|
|
- Configure your buildpacks here.
|
|
|
|
|
- </Text>
|
|
|
|
|
|
|
+ <Text color="helper">Configure your buildpacks here.</Text>
|
|
|
<Spacer y={1} />
|
|
<Spacer y={1} />
|
|
|
{!!selectedBuildpacks?.length &&
|
|
{!!selectedBuildpacks?.length &&
|
|
|
renderBuildpacksList(selectedBuildpacks, "remove")}
|
|
renderBuildpacksList(selectedBuildpacks, "remove")}
|
|
@@ -92,9 +101,7 @@ export const BuildpackStack: React.FC<{
|
|
|
<AddCustomBuildpackForm onAdd={handleAddCustomBuildpack} />
|
|
<AddCustomBuildpackForm onAdd={handleAddCustomBuildpack} />
|
|
|
</Scrollable>
|
|
</Scrollable>
|
|
|
<Spacer y={1} />
|
|
<Spacer y={1} />
|
|
|
- <Button onClick={() => setIsModalOpen(false)}>
|
|
|
|
|
- Save
|
|
|
|
|
- </Button>
|
|
|
|
|
|
|
+ <Button onClick={() => setIsModalOpen(false)}>Save</Button>
|
|
|
</>
|
|
</>
|
|
|
);
|
|
);
|
|
|
};
|
|
};
|
|
@@ -102,10 +109,10 @@ export const BuildpackStack: React.FC<{
|
|
|
let buildConfig: BuildConfig = {} as BuildConfig;
|
|
let buildConfig: BuildConfig = {} as BuildConfig;
|
|
|
|
|
|
|
|
buildConfig.builder = selectedStack;
|
|
buildConfig.builder = selectedStack;
|
|
|
- console.log(buildConfig);
|
|
|
|
|
buildConfig.buildpacks = selectedBuildpacks?.map((buildpack) => {
|
|
buildConfig.buildpacks = selectedBuildpacks?.map((buildpack) => {
|
|
|
return buildpack.buildpack;
|
|
return buildpack.buildpack;
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
if (typeof onChange === "function") {
|
|
if (typeof onChange === "function") {
|
|
|
onChange(buildConfig);
|
|
onChange(buildConfig);
|
|
|
}
|
|
}
|
|
@@ -155,16 +162,52 @@ export const BuildpackStack: React.FC<{
|
|
|
(builder) => builder.name.toLowerCase() === DEFAULT_BUILDER_NAME
|
|
(builder) => builder.name.toLowerCase() === DEFAULT_BUILDER_NAME
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- const detectedBuildpacks = defaultBuilder.detected;
|
|
|
|
|
- const availableBuildpacks = defaultBuilder.others;
|
|
|
|
|
- const defaultStack = builders
|
|
|
|
|
- .flatMap((builder) => builder.builders)
|
|
|
|
|
- .find((stack) => {
|
|
|
|
|
- return (
|
|
|
|
|
- stack === DEFAULT_HEROKU_STACK || stack === DEFAULT_PAKETO_STACK
|
|
|
|
|
|
|
+ var detectedBuildpacks = defaultBuilder.detected;
|
|
|
|
|
+ var availableBuildpacks = defaultBuilder.others;
|
|
|
|
|
+ var defaultStack = "";
|
|
|
|
|
+ if (currentBuildConfig) {
|
|
|
|
|
+ defaultStack = currentBuildConfig.builder;
|
|
|
|
|
+ for (const buildpackName of currentBuildConfig.buildpacks) {
|
|
|
|
|
+ const matchingBuildpackIndex = availableBuildpacks.findIndex(
|
|
|
|
|
+ (buildpack) => buildpack.buildpack === buildpackName
|
|
|
);
|
|
);
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
|
|
+ if (matchingBuildpackIndex >= 0) {
|
|
|
|
|
+ const matchingBuildpack = availableBuildpacks.splice(
|
|
|
|
|
+ matchingBuildpackIndex,
|
|
|
|
|
+ 1
|
|
|
|
|
+ )[0];
|
|
|
|
|
+ const existingBuildpackIndex = detectedBuildpacks.findIndex(
|
|
|
|
|
+ (buildpack) => buildpack.buildpack === buildpackName
|
|
|
|
|
+ );
|
|
|
|
|
+ if (existingBuildpackIndex < 0) {
|
|
|
|
|
+ detectedBuildpacks.push(matchingBuildpack);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const newBuildpack: Buildpack = {
|
|
|
|
|
+ name: buildpackName,
|
|
|
|
|
+ buildpack: buildpackName,
|
|
|
|
|
+ config: null,
|
|
|
|
|
+ };
|
|
|
|
|
+ const existingBuildpackIndex = detectedBuildpacks.findIndex(
|
|
|
|
|
+ (buildpack) => buildpack.buildpack === buildpackName
|
|
|
|
|
+ );
|
|
|
|
|
+ if (existingBuildpackIndex < 0) {
|
|
|
|
|
+ detectedBuildpacks.push(newBuildpack);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ detectedBuildpacks = defaultBuilder.detected;
|
|
|
|
|
+ availableBuildpacks = defaultBuilder.others;
|
|
|
|
|
+ defaultStack = builders
|
|
|
|
|
+ .flatMap((builder) => builder.builders)
|
|
|
|
|
+ .find((stack) => {
|
|
|
|
|
+ return (
|
|
|
|
|
+ stack === DEFAULT_HEROKU_STACK || stack === DEFAULT_PAKETO_STACK
|
|
|
|
|
+ );
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
setBuilders(builders);
|
|
setBuilders(builders);
|
|
|
setSelectedStack(defaultStack);
|
|
setSelectedStack(defaultStack);
|
|
|
|
|
|
|
@@ -174,6 +217,7 @@ export const BuildpackStack: React.FC<{
|
|
|
setSelectedBuildpacks([]);
|
|
setSelectedBuildpacks([]);
|
|
|
} else {
|
|
} else {
|
|
|
setSelectedBuildpacks(detectedBuildpacks);
|
|
setSelectedBuildpacks(detectedBuildpacks);
|
|
|
|
|
+ console.log(selectedBuildpacks);
|
|
|
}
|
|
}
|
|
|
if (!Array.isArray(availableBuildpacks)) {
|
|
if (!Array.isArray(availableBuildpacks)) {
|
|
|
setAvailableBuildpacks([]);
|
|
setAvailableBuildpacks([]);
|
|
@@ -346,7 +390,9 @@ export const BuildpackStack: React.FC<{
|
|
|
value={selectedStack}
|
|
value={selectedStack}
|
|
|
width="300px"
|
|
width="300px"
|
|
|
options={stackOptions}
|
|
options={stackOptions}
|
|
|
- setValue={(option) => setSelectedStack(option)}
|
|
|
|
|
|
|
+ setValue={(option) => {
|
|
|
|
|
+ setSelectedStack(option);
|
|
|
|
|
+ }}
|
|
|
label="Select your builder and stack"
|
|
label="Select your builder and stack"
|
|
|
/>
|
|
/>
|
|
|
{!!selectedBuildpacks?.length && (
|
|
{!!selectedBuildpacks?.length && (
|
|
@@ -359,14 +405,9 @@ export const BuildpackStack: React.FC<{
|
|
|
<>{renderBuildpacksList(selectedBuildpacks, "remove")}</>
|
|
<>{renderBuildpacksList(selectedBuildpacks, "remove")}</>
|
|
|
)}
|
|
)}
|
|
|
<Spacer y={1} />
|
|
<Spacer y={1} />
|
|
|
- <Button onClick={() => setIsModalOpen(true)}>
|
|
|
|
|
- Add build pack
|
|
|
|
|
- </Button>
|
|
|
|
|
-
|
|
|
|
|
|
|
+ <Button onClick={() => setIsModalOpen(true)}>Add build pack</Button>
|
|
|
{isModalOpen && (
|
|
{isModalOpen && (
|
|
|
- <Modal
|
|
|
|
|
- closeModal={() => setIsModalOpen(false)}
|
|
|
|
|
- >
|
|
|
|
|
|
|
+ <Modal closeModal={() => setIsModalOpen(false)}>
|
|
|
{renderModalContent()}
|
|
{renderModalContent()}
|
|
|
</Modal>
|
|
</Modal>
|
|
|
)}
|
|
)}
|
|
@@ -463,7 +504,7 @@ const StyledCard = styled.div<{ marginBottom?: string }>`
|
|
|
justify-content: space-between;
|
|
justify-content: space-between;
|
|
|
border: 1px solid #494b4f;
|
|
border: 1px solid #494b4f;
|
|
|
background: ${({ theme }) => theme.fg};
|
|
background: ${({ theme }) => theme.fg};
|
|
|
- margin-bottom: ${props => props.marginBottom || "30px"};
|
|
|
|
|
|
|
+ margin-bottom: ${(props) => props.marginBottom || "30px"};
|
|
|
border-radius: 8px;
|
|
border-radius: 8px;
|
|
|
padding: 14px;
|
|
padding: 14px;
|
|
|
overflow: hidden;
|
|
overflow: hidden;
|